-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-line.py
More file actions
50 lines (38 loc) · 1.3 KB
/
start-line.py
File metadata and controls
50 lines (38 loc) · 1.3 KB
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
from flask import Flask, request, abort
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import (
MessageEvent, TextMessage, TextSendMessage,
)
from UtteranceGenerator import DialogSystem
app = Flask(__name__)
line_bot_api = LineBotApi('Il5ntJJbGapc2265f9neBuJBQ9xyV/08zLfnwicaWsO80JyIOPFy8topmAtZOsggneggfMgPkZmQEvdbd1o5Qc2fYPMEnQEH7rsJButuhDQQtDO336AIon4dcFe2QfUgXNGteVZdgGGPAjFuD4+trwdB04t89/1O/w1cDnyilFU=')
handler = WebhookHandler('f5a89be9136ceacd3bfaf63709a8df4b')
@app.route("/callback", methods=['POST'])
def callback():
# get X-Line-Signature header value
signature = request.headers['X-Line-Signature']
# get request body as text
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)
# handle webhook body
try:
handler.handle(body, signature)
except InvalidSignatureError:
abort(400)
return 'OK'
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
event.message.text
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=dia.main(event.message.text)))
if __name__ == "__main__":
dia = DialogSystem()
dia.preprocessor.GTPP[0] = ["NEWGAME!",None]
dia.url = None
app.run()