Spaces:
Sleeping
Sleeping
alanchen1115
commited on
Commit
•
0385c62
1
Parent(s):
3bf6983
Update main.py
Browse files
main.py
CHANGED
@@ -26,20 +26,22 @@ app.add_middleware(
|
|
26 |
line_bot_api = LineBotApi(os.environ["line_bot_api"])
|
27 |
line_handler = WebhookHandler(os.environ["line_handler"])
|
28 |
|
29 |
-
working_status =
|
30 |
|
31 |
@app.get("/")
|
32 |
def root():
|
33 |
return {"title": "Echo Bot"}
|
34 |
|
35 |
@app.post("/webhook")
|
36 |
-
async def webhook(request: Request
|
|
|
37 |
body = await request.body()
|
38 |
try:
|
39 |
-
|
40 |
except InvalidSignatureError:
|
41 |
-
raise HTTPException(status_code=400, detail="
|
42 |
-
|
|
|
43 |
|
44 |
@line_handler.add(MessageEvent, message=TextMessage)
|
45 |
def handle_message(event):
|
|
|
26 |
line_bot_api = LineBotApi(os.environ["line_bot_api"])
|
27 |
line_handler = WebhookHandler(os.environ["line_handler"])
|
28 |
|
29 |
+
working_status = os.getenv("DEFALUT_TALKING", default = "true").lower() == "true"
|
30 |
|
31 |
@app.get("/")
|
32 |
def root():
|
33 |
return {"title": "Echo Bot"}
|
34 |
|
35 |
@app.post("/webhook")
|
36 |
+
async def webhook(request: Request):
|
37 |
+
signature = request.headers['X-Line-Signature']
|
38 |
body = await request.body()
|
39 |
try:
|
40 |
+
handler.handle(body.decode(),signature)
|
41 |
except InvalidSignatureError:
|
42 |
+
raise HTTPException(status_code=400, detail="SignatureError")
|
43 |
+
|
44 |
+
return "ok"
|
45 |
|
46 |
@line_handler.add(MessageEvent, message=TextMessage)
|
47 |
def handle_message(event):
|