Spaces:
Sleeping
Sleeping
alanchen1115
commited on
Update main.py
Browse files
main.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from fastapi.middleware.cors import CORSMiddleware
|
2 |
-
from fastapi import FastAPI, Request, Header, HTTPException, status
|
3 |
|
4 |
import json
|
5 |
import os
|
@@ -33,14 +33,18 @@ def root():
|
|
33 |
return {"title": "Echo Bot"}
|
34 |
|
35 |
@app.post("/webhook")
|
36 |
-
async def webhook(
|
37 |
-
|
|
|
|
|
|
|
38 |
body = await request.body()
|
39 |
try:
|
40 |
-
|
|
|
|
|
41 |
except InvalidSignatureError:
|
42 |
-
raise HTTPException(status_code=400, detail="
|
43 |
-
|
44 |
return "ok"
|
45 |
|
46 |
@line_handler.add(MessageEvent, message=TextMessage)
|
|
|
1 |
from fastapi.middleware.cors import CORSMiddleware
|
2 |
+
from fastapi import FastAPI, Request, Header, BackgroundTasks, HTTPException, status
|
3 |
|
4 |
import json
|
5 |
import os
|
|
|
33 |
return {"title": "Echo Bot"}
|
34 |
|
35 |
@app.post("/webhook")
|
36 |
+
async def webhook(
|
37 |
+
request: Request,
|
38 |
+
background_tasks: BackgroundTasks,
|
39 |
+
x_line_signature=Header(None),
|
40 |
+
):
|
41 |
body = await request.body()
|
42 |
try:
|
43 |
+
background_tasks.add_task(
|
44 |
+
line_handler.handle, body.decode("utf-8"), x_line_signature
|
45 |
+
)
|
46 |
except InvalidSignatureError:
|
47 |
+
raise HTTPException(status_code=400, detail="Invalid signature")
|
|
|
48 |
return "ok"
|
49 |
|
50 |
@line_handler.add(MessageEvent, message=TextMessage)
|