-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (50 loc) · 1.79 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python3
"""
@author Isaac Keeher
This program is an sms forwarder meant to recieve a
text message and forward it on to multiple numbers
It should also reply when texted for event details
"""
from flask import Flask, Response, request
from twilio import twiml
from dotenv import load_dotenv
import os
load_dotenv()
EVENT_LOCATION = os.environ.get('EVENT_LOCATION')
GEO_LOCATION = os.environ.get('GEO_LOCATION')
EVENT_TIME = os.environ.get('EVENT_TIME')
app = Flask(__name__)
@app.route("/")
def hello():
return Response("App is running!"), 200
@app.route("/getLocation", methods=["POST"])
def inbound_sms():
"""This function returns the location of the rave when somebody sends a message
"""
response = twiml.Response()
# we get the SMS message from the request. we can also get
# "To" and the "From" phone number as well
inbound_message = request.form.get("Body")
# we can now use the incoming message text
# TODO: maybe use a regex here to search for "location" or "where"?
if inbound_message == "YES":
response.message(
f"Hey tripper! The party location is \
{EVENT_LOCATION} - {GEO_LOCATION} - starting at {EVENT_TIME}"
)
else:
response.message(
"Do you want to know where the party is? If so, reply 'YES'"
)
# we return back the mimetype because Twilio needs an XML response
return Response(str(response), mimetype="application/xml"), 200
@app.route("/forwardMsg", methods=["POST"])
def recieve_sms():
"""This function is to forward messages to existing users
"""
# response = twiml.Response()
inbound_message = request.form.get("Body")
print(inbound_message)
# TODO: add some database connecting code
if __name__ == "__main__":
app.run(debug=True)