alanchen1115 commited on
Commit
0a52d39
1 Parent(s): 8efacf7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -10
main.py CHANGED
@@ -33,18 +33,12 @@ 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
-
39
- body = request.get_data(as_text=True)
40
- app.logger.info("Request body: " + body)
41
  try:
42
- print(body, signature)
43
- line_handler.handle(body, signature)
44
-
45
  except InvalidSignatureError:
46
- abort(400)
47
-
48
  return 'OK'
49
 
50
  @line_handler.add(MessageEvent, message=TextMessage)
 
33
  return {"title": "Echo Bot"}
34
 
35
  @app.post("/webhook")
36
+ async def webhook(request: Request, x_line_signature: str = Header(None)):
37
+ body = await request.body()
 
 
 
38
  try:
39
+ handler.handle(body.decode("utf-8"), x_line_signature)
 
 
40
  except InvalidSignatureError:
41
+ raise HTTPException(status_code=400, detail="chatbot handle body error.")
 
42
  return 'OK'
43
 
44
  @line_handler.add(MessageEvent, message=TextMessage)