Spaces:
Sleeping
Sleeping
alanchen1115
commited on
Commit
•
4a7f8d2
1
Parent(s):
04161a8
Update main.py
Browse files
main.py
CHANGED
@@ -18,23 +18,34 @@ def root():
|
|
18 |
@app.post("/callback")
|
19 |
async def callback(
|
20 |
request: Request,
|
21 |
-
background_tasks: BackgroundTasks,
|
22 |
-
x_line_signature=Header(None),
|
23 |
):
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
try:
|
27 |
-
|
28 |
-
handler.handle, body.decode("utf-8"), x_line_signature
|
29 |
-
)
|
30 |
except InvalidSignatureError:
|
31 |
-
|
32 |
-
|
33 |
-
return "ok"
|
34 |
|
35 |
-
@
|
36 |
def handle_message(event):
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
38 |
return
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
@app.post("/callback")
|
19 |
async def callback(
|
20 |
request: Request,
|
|
|
|
|
21 |
):
|
22 |
+
# get X-Line-Signature header value
|
23 |
+
signature = request.headers['X-Line-Signature']
|
24 |
+
# get request body as text
|
25 |
+
body = request.get_data(as_text=True)
|
26 |
+
app.logger.info("Request body: " + body)
|
27 |
+
# handle webhook body
|
28 |
try:
|
29 |
+
line_handler.handle(body, signature)
|
|
|
|
|
30 |
except InvalidSignatureError:
|
31 |
+
abort(400)
|
32 |
+
return 'OK'
|
|
|
33 |
|
34 |
+
@line_handler.add(MessageEvent, message=TextMessage)
|
35 |
def handle_message(event):
|
36 |
+
global working_status
|
37 |
+
if event.message.text == "再見":
|
38 |
+
working_status = True
|
39 |
+
line_bot_api.reply_message(
|
40 |
+
event.reply_token,
|
41 |
+
TextSendMessage(text="Bye!"))
|
42 |
return
|
43 |
+
|
44 |
+
if working_status:
|
45 |
+
|
46 |
+
out = event.message.text
|
47 |
+
if not out:
|
48 |
+
out = "不懂您的意思!"
|
49 |
+
line_bot_api.reply_message(
|
50 |
+
event.reply_token,
|
51 |
+
TextSendMessage(text=out))
|