-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (33 loc) · 980 Bytes
/
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
from KinshipBot import KinshipBot
from flask import Flask, request, abort
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import (
MessageEvent, TextMessage,
)
app = Flask(__name__)
kinshipBot = KinshipBot()
lineBot = LineBotApi(kinshipBot.Config['LINE_ACCESS_TOKEN'])
handler = WebhookHandler(kinshipBot.Config['LINE_SECRET_TOKEN'])
kinshipBot.setLineBot(lineBot)
@app.route("/health", methods=['GET'])
def health():
return "OK"
@app.route("/callback", methods=['POST'])
def callback():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
try:
handler.handle(body, signature)
except InvalidSignatureError:
abort(400)
return 'OK'
@handler.add(MessageEvent, message=TextMessage)
def message_text(event):
kinshipBot.handleMessage(event, event.message.text)
if __name__ == "__main__":
app.run()