-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (44 loc) · 1.23 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
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from flask import Flask
from flask import request
from help import help_action
from welcome import welcome_action
from schedule import schedule_action
from sponsors import sponsors_action
from tracks import tracks_action
# Flask app should start in global layout
app = Flask(__name__)
log = app.logger
actions = {
'help': help_action,
'welcome': welcome_action,
'schedule': schedule_action,
'sponsors': sponsors_action,
'tracks': tracks_action
}
@app.route('/status', methods=['GET'])
def status():
return 'OK'
@app.route('/static_reply', methods=['POST'])
def static_reply():
global actions
req = request.get_json(silent=True, force=True)
print(req)
try:
action = req['queryResult']['action']
except AttributeError:
return 'json error'
if action in actions:
functor = actions[action]
if functor.__doc__:
print(functor.__doc__.split('\n')[0])
response = functor(req)
else:
log.error('action unable')
return response
if __name__ == '__main__':
port = int(os.getenv('PORT', 50000))
print("App running in port %d" % port)
app.run(debug=True, port=port, host='127.0.0.1')