-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
56 lines (47 loc) · 1.74 KB
/
application.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
from flask import Flask, jsonify, render_template, redirect, request
import json
import twilio.twiml
from utils import connect_db
from validate_email import validate_email
from whitenoise import WhiteNoise
application = Flask(__name__) #establishing flask app
static = WhiteNoise(application, root='./static/')
def verify(email):
is_valid = validate_email(email, verify = True)
return is_valid
@application.route('/')
def index():
return render_template('index.html')
@application.route("/received/", methods=['GET', 'POST'])
def receive_message():
sender = request.values.get('From',None)
db = connect_db('MONGOHQ_URL', 'MONGO_DATABASE_NAME')
user = db.users.find_one({"number":sender})
message = request.values.get('Body',None)
resp = twilio.twiml.Response()
if user != None:
try:
email = user['email']
except KeyError:
is_valid = verify(message)
if is_valid or is_valid == None:
db.users.update_one({
'_id': user['_id']
},{
'$set': {
'email': message
}
}, upsert=False)
resp.message("Thank you! You've been added to the waitlist. As soon as we can work through our current orders, we'll be in touch!")
else:
resp.message("Please send us a valid email address!")
else:
resp.message("You are currently on the waitlist. We will contact you shortly!")
else:
"""Respond to incoming calls with a simple text message."""
resp.message("Welcome to Green Street! To get started, please send us your email address. We will only use it to send you order confirmations, receipts, and updates.")
db.users.insert({"number":sender})
return str(resp)
if __name__ == "__main__":
application.debug = True
application.run()