-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
30 lines (27 loc) · 858 Bytes
/
app.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
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse,Body,Media,Message
from utils import fetch_reply
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, World!"
@app.route("/sms", methods=['POST'])
def sms_reply():
"""Respond to incoming calls with a simple text message."""
# Fetch the message
print(request.form)
msg = request.form.get('Body')
sender = request.form.get('From')
# Create reply
resp = MessagingResponse()
reply = fetch_reply(msg,sender)
if isinstance(reply, str):
resp.message(reply)
elif isinstance(reply, tuple):
resp.message(reply[0]).media(reply[1])
else:
for msg in list(map(lambda x:Message(x),reply)):
resp.append(msg)
return str(resp)
if __name__ == "__main__":
app.run(debug=True)