-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
36 lines (26 loc) · 1.01 KB
/
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
31
32
33
34
35
36
from flask import Flask, request
import os, sys, json
from pprint import pprint
from main import controller
app = Flask(__name__)
@app.route('/', methods=['GET'])
def welcome():
data = request.args.to_dict()
if request.args.get('last clicked button name') == 'Get Started' and request.args.get('last user freeform input') == '':
message = '/start'
else:
message = request.args.get('last user freeform input')
user_id = request.args.get('messenger user id')
first_name = request.args.get('first name')
last_name = request.args.get('last name')
name = first_name+' '+last_name if first_name != last_name else last_name
log(data)
return send_message(user_id, message, name)
def send_message(user_id, message, name):
return json.dumps({"messages": [{"text": controller(message, user_id, name)}]})
def log(data):
pprint(data)
sys.stdout.flush()
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(debug=True, host='0.0.0.0', port=port)