-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.py
40 lines (32 loc) · 997 Bytes
/
receiver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, request
from store import Store
from dispatcher import Dispatcher
import requests
import json
app = Flask(__name__)
def msg_process(msg, tstamp):
js = json.loads(msg)
storeData = Store()
storeData.storeRequest(js['originationNumber'], js['messageBody'])
print("Passed to store")
d = Dispatcher(js['originationNumber'], js['messageBody'])
print("Dispatcher Generated")
@app.route('/', methods = ['GET', 'POST', 'PUT'])
def sns():
try:
js = json.loads(request.data)
hdr = request.headers.get('X-Amz-Sns-Message-Type')
# subscribe to the SNS topic
if hdr == 'SubscriptionConfirmation' and 'SubscribeURL' in js:
r = requests.get(js['SubscribeURL'])
if hdr == 'Notification':
msg_process(js['Message'], js['Timestamp'])
except:
pass
return 'OK\n'
if __name__ == '__main__':
app.run(
host = "0.0.0.0",
port = 8000,
debug = True
)