-
Notifications
You must be signed in to change notification settings - Fork 3
/
flask_handler.py
40 lines (29 loc) · 1020 Bytes
/
flask_handler.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
"""Handler For Flask App"""
from flask import Flask, request, abort
from flask.logging import create_logger
from cryptography.exceptions import InvalidSignature
from LineHandler import handler, os
APP = Flask(__name__)
LOG = create_logger(APP)
@APP.route('/')
def hello_world():
"""Hello world function"""
return 'Hello World! Testing deployer(again)'
@APP.route('/callback', methods=['POST'])
def callback():
"""Callback Function"""
# get X-Line-Signature header value
signature = request.headers['X-Line-Signature']
# get request body as text
body = request.get_data(as_text=True)
LOG.debug("Request Body:" + body)
# handle webhook body
try:
handler.handle(body, signature)
except InvalidSignature:
print("Invalid signature. Please check your channel access token and/or channel secret.")
abort(400)
return 'OK'
if __name__ == '__main__':
PORT = int(os.environ.get('PORT', 5000))
APP.run(host='0.0.0.0', port=PORT, debug=True)