Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 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
|
|
@@ -13,5 +15,19 @@ async def verify_webhook(request: Request):
|
|
| 13 |
challenge = params.get("hub.challenge")
|
| 14 |
|
| 15 |
if mode == "subscribe" and token == VERIFY_TOKEN:
|
| 16 |
-
return PlainTextResponse(content=challenge)
|
| 17 |
return PlainTextResponse(content="Verification failed", status_code=403)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.responses import PlainTextResponse
|
| 3 |
+
from datetime import datetime, timezone, timedelta
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
VERIFY_TOKEN = "my_secure_token"
|
| 8 |
|
| 9 |
+
# Verification (GET)
|
| 10 |
@app.get("/webhook")
|
| 11 |
async def verify_webhook(request: Request):
|
| 12 |
params = request.query_params
|
|
|
|
| 15 |
challenge = params.get("hub.challenge")
|
| 16 |
|
| 17 |
if mode == "subscribe" and token == VERIFY_TOKEN:
|
| 18 |
+
return PlainTextResponse(content=challenge)
|
| 19 |
return PlainTextResponse(content="Verification failed", status_code=403)
|
| 20 |
+
|
| 21 |
+
# Lead delivery (POST)
|
| 22 |
+
@app.post("/webhook")
|
| 23 |
+
async def receive_lead(request: Request):
|
| 24 |
+
payload = await request.json()
|
| 25 |
+
print("📥 Webhook payload received:")
|
| 26 |
+
|
| 27 |
+
# Print with timestamps
|
| 28 |
+
gmt_plus_3 = timezone(timedelta(hours=3))
|
| 29 |
+
print("Timestamp:", datetime.now(gmt_plus_3).strftime("%Y-%m-%d %H:%M:%S"))
|
| 30 |
+
|
| 31 |
+
print(payload)
|
| 32 |
+
|
| 33 |
+
return {"status": "ok"}
|