Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,49 +1,17 @@
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
-
from
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
-
|
| 7 |
-
async def verify_webhook(hub_mode: str = "", hub_verify_token: str = "", hub_challenge: str = ""):
|
| 8 |
-
VERIFY_TOKEN = "my_secure_token" # Match this to your subscription
|
| 9 |
-
if hub_mode == "subscribe" and hub_verify_token == VERIFY_TOKEN:
|
| 10 |
-
return int(hub_challenge)
|
| 11 |
-
return {"status": "verification failed"}
|
| 12 |
-
|
| 13 |
-
@app.post("/webhook")
|
| 14 |
-
async def receive_webhook(request: Request):
|
| 15 |
-
payload = await request.json()
|
| 16 |
-
print("📥 Webhook received:")
|
| 17 |
-
|
| 18 |
-
gmt_plus_3 = timezone(timedelta(hours=3))
|
| 19 |
-
|
| 20 |
-
print(f"Object: {payload.get('object')}")
|
| 21 |
-
print("----")
|
| 22 |
-
|
| 23 |
-
for entry in payload.get('entry', []):
|
| 24 |
-
entry_id = entry.get("id")
|
| 25 |
-
timestamp = entry.get("time")
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
value = change.get("value", {})
|
| 38 |
-
|
| 39 |
-
print(f"🔔 Change Field: {field}")
|
| 40 |
-
if field == "leadgen":
|
| 41 |
-
print("📌 Lead Details:")
|
| 42 |
-
print(f"• Lead ID: {value.get('leadgen_id')}")
|
| 43 |
-
print(f"• Form ID: {value.get('form_id')}")
|
| 44 |
-
print(f"• Ad ID: {value.get('ad_id')}")
|
| 45 |
-
print(f"• Page ID: {value.get('page_id')}")
|
| 46 |
-
print(f"• Created Time: {value.get('created_time')}")
|
| 47 |
-
|
| 48 |
-
print("----")
|
| 49 |
-
return {"status": "ok"}
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import PlainTextResponse
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
+
VERIFY_TOKEN = "my_secure_token"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
@app.get("/webhook")
|
| 9 |
+
async def verify_webhook(request: Request):
|
| 10 |
+
params = request.query_params
|
| 11 |
+
mode = params.get("hub.mode")
|
| 12 |
+
token = params.get("hub.verify_token")
|
| 13 |
+
challenge = params.get("hub.challenge")
|
| 14 |
+
|
| 15 |
+
if mode == "subscribe" and token == VERIFY_TOKEN:
|
| 16 |
+
return PlainTextResponse(content=challenge) # 👈 this is key
|
| 17 |
+
return PlainTextResponse(content="Verification failed", status_code=403)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|