ariansyahdedy commited on
Commit
9569b7d
·
1 Parent(s): 77ac737

Change webhook

Browse files
Files changed (1) hide show
  1. app/main.py +16 -0
app/main.py CHANGED
@@ -1,5 +1,7 @@
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import JSONResponse
 
 
3
 
4
  app = FastAPI()
5
 
@@ -8,3 +10,17 @@ app = FastAPI()
8
  async def whatsapp_webhook(request: Request):
9
  data = await request.json()
10
  print("Webhook received:", data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import JSONResponse
3
+ from fastapi.responses import Response
4
+ from fastapi.exceptions import HTTPException
5
 
6
  app = FastAPI()
7
 
 
10
  async def whatsapp_webhook(request: Request):
11
  data = await request.json()
12
  print("Webhook received:", data)
13
+
14
+
15
+ @app.get("/webhook")
16
+ async def verify_webhook(request: Request):
17
+ mode = request.query_params.get('hub.mode')
18
+ token = request.query_params.get('hub.verify_token')
19
+ challenge = request.query_params.get('hub.challenge')
20
+
21
+ # Replace 'your_verification_token' with the token you set in Facebook Business Manager
22
+ if mode == 'subscribe' and token == 'test':
23
+ # Return the challenge as plain text
24
+ return Response(content=challenge, media_type="text/plain")
25
+ else:
26
+ raise HTTPException(status_code=403, detail="Verification failed")