Spaces:
Running
Running
axeronis commited on
Commit Β·
d04de93
1
Parent(s): 2294473
fix: add default verify token for Meta webhook verification
Browse files
backend/app/api/meta_webhooks.py
CHANGED
|
@@ -34,16 +34,26 @@ async def verify_webhook(
|
|
| 34 |
session: AsyncSession = Depends(get_async_session)
|
| 35 |
):
|
| 36 |
"""Handle Meta Webhook Verification Challenge."""
|
|
|
|
|
|
|
| 37 |
tenant = await session.get(Tenant, tenant_id)
|
| 38 |
if not tenant:
|
|
|
|
| 39 |
raise HTTPException(status_code=404, detail="Tenant not found")
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
if mode == "subscribe" and token == wa_verify:
|
| 44 |
logger.info(f"β
Webhook Verified for Tenant {tenant_id}")
|
| 45 |
return int(challenge)
|
| 46 |
|
|
|
|
| 47 |
raise HTTPException(status_code=403, detail="Verification failed")
|
| 48 |
|
| 49 |
|
|
|
|
| 34 |
session: AsyncSession = Depends(get_async_session)
|
| 35 |
):
|
| 36 |
"""Handle Meta Webhook Verification Challenge."""
|
| 37 |
+
logger.info(f"π Webhook verification attempt: tenant={tenant_id}, mode={mode}, token={token[:10]}...")
|
| 38 |
+
|
| 39 |
tenant = await session.get(Tenant, tenant_id)
|
| 40 |
if not tenant:
|
| 41 |
+
logger.error(f"β Tenant {tenant_id} not found")
|
| 42 |
raise HTTPException(status_code=404, detail="Tenant not found")
|
| 43 |
|
| 44 |
+
# Get verify token from config or use default
|
| 45 |
+
wa_verify = None
|
| 46 |
+
if tenant.meta_wa_config:
|
| 47 |
+
wa_verify = tenant.meta_wa_config.get("verify_token")
|
| 48 |
+
|
| 49 |
+
# Fallback to default token for initial setup
|
| 50 |
+
default_token = "microfunnel_webhook_2024"
|
| 51 |
|
| 52 |
+
if mode == "subscribe" and (token == wa_verify or token == default_token):
|
| 53 |
logger.info(f"β
Webhook Verified for Tenant {tenant_id}")
|
| 54 |
return int(challenge)
|
| 55 |
|
| 56 |
+
logger.error(f"β Verification failed: expected={wa_verify or default_token}, got={token}")
|
| 57 |
raise HTTPException(status_code=403, detail="Verification failed")
|
| 58 |
|
| 59 |
|