devZenaight commited on
Commit
4e18bd8
·
verified ·
1 Parent(s): e130000

Upload 5 files

Browse files
Files changed (1) hide show
  1. main.py +6 -15
main.py CHANGED
@@ -25,21 +25,12 @@ async def test_post():
25
  return {"detail": "POST method working"}
26
 
27
  @app.get("/webhook")
28
- def verify(
29
- hub_mode: Optional[str] = Query(None, alias="hub.mode"),
30
- hub_challenge: Optional[str] = Query(None, alias="hub.challenge"),
31
- hub_verify_token: Optional[str] = Query(None, alias="hub.verify_token"),
32
- ):
33
- # 1) Initial probe
34
- if hub_mode is None and hub_challenge is None and hub_verify_token is None:
35
- return PlainTextResponse(status_code=200, content="")
36
-
37
- # 2) Real handshake: echo back challenge (temporarily ignore token)
38
- if hub_mode == "subscribe":
39
- return PlainTextResponse(content=hub_challenge or "", media_type="text/plain")
40
-
41
- # 3) Everything else → forbidden
42
- raise HTTPException(status_code=403, detail="Invalid verify token")
43
 
44
  @app.post("/webhook")
45
  async def receive_webhook(request: Request):
 
25
  return {"detail": "POST method working"}
26
 
27
  @app.get("/webhook")
28
+ async def verify(hub_mode: str = Query(..., alias="hub.mode"),
29
+ hub_token: str = Query(..., alias="hub.verify_token"),
30
+ hub_challenge: str = Query(..., alias="hub.challenge")):
31
+ if hub_mode == "subscribe" and hub_token == os.getenv("VERIFY_TOKEN"):
32
+ return PlainTextResponse(hub_challenge)
33
+ raise HTTPException(status_code=403)
 
 
 
 
 
 
 
 
 
34
 
35
  @app.post("/webhook")
36
  async def receive_webhook(request: Request):