Upload 5 files
Browse files
main.py
CHANGED
|
@@ -57,6 +57,7 @@ async def receive_update(req: Request):
|
|
| 57 |
"type": "text",
|
| 58 |
"text": {"body": reply}
|
| 59 |
}
|
|
|
|
| 60 |
resp = httpx.post(
|
| 61 |
f"https://graph.facebook.com/v23.0/{PHONE_NUMBER_ID}/messages",
|
| 62 |
headers={
|
|
@@ -65,7 +66,17 @@ async def receive_update(req: Request):
|
|
| 65 |
},
|
| 66 |
json=payload
|
| 67 |
)
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
return JSONResponse({"status": "image_preview_sent", "preview": preview})
|
| 70 |
# 2) Existing text handler
|
| 71 |
if msg["type"] != "text":
|
|
|
|
| 57 |
"type": "text",
|
| 58 |
"text": {"body": reply}
|
| 59 |
}
|
| 60 |
+
# send via WhatsApp Cloud API, capture response
|
| 61 |
resp = httpx.post(
|
| 62 |
f"https://graph.facebook.com/v23.0/{PHONE_NUMBER_ID}/messages",
|
| 63 |
headers={
|
|
|
|
| 66 |
},
|
| 67 |
json=payload
|
| 68 |
)
|
| 69 |
+
# log full request and response for debugging
|
| 70 |
+
print("Outgoing payload:", payload)
|
| 71 |
+
print("Response status code:", resp.status_code)
|
| 72 |
+
print("Response body:", resp.text)
|
| 73 |
+
# do not raise; return status
|
| 74 |
+
if resp.status_code != 200:
|
| 75 |
+
return JSONResponse({
|
| 76 |
+
"status": "error",
|
| 77 |
+
"code": resp.status_code,
|
| 78 |
+
"body": resp.text
|
| 79 |
+
}, status_code=500)
|
| 80 |
return JSONResponse({"status": "image_preview_sent", "preview": preview})
|
| 81 |
# 2) Existing text handler
|
| 82 |
if msg["type"] != "text":
|