Spaces:
Sleeping
Sleeping
Upload main.py
Browse files
main.py
CHANGED
|
@@ -162,63 +162,19 @@ async def receive_update(req: Request):
|
|
| 162 |
processed_message_ids.add(msg_id)
|
| 163 |
|
| 164 |
# โ Handle button-reply taps first
|
| 165 |
-
if msg.get("type") == "
|
| 166 |
-
payload = msg["
|
| 167 |
if payload == "open_gallery":
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
"Content-Type": "application/json"
|
| 173 |
-
}
|
| 174 |
-
gallery_payload = {
|
| 175 |
-
"messaging_product": "whatsapp",
|
| 176 |
-
"to": wa_id,
|
| 177 |
-
"type": "interactive",
|
| 178 |
-
"interactive": {
|
| 179 |
-
"type": "button",
|
| 180 |
-
"body": {
|
| 181 |
-
"text": "๐ Please tap the ๐ icon below and select \"Photo & Video Library\" to pick your ID image."
|
| 182 |
-
},
|
| 183 |
-
"action": {
|
| 184 |
-
"buttons": [
|
| 185 |
-
{
|
| 186 |
-
"type": "reply",
|
| 187 |
-
"reply": {"id": "got_it", "title": "Got it!"}
|
| 188 |
-
}
|
| 189 |
-
]
|
| 190 |
-
}
|
| 191 |
-
}
|
| 192 |
-
}
|
| 193 |
-
httpx.post(url, headers=headers, json=gallery_payload)
|
| 194 |
elif payload == "open_camera":
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
}
|
| 201 |
-
camera_payload = {
|
| 202 |
-
"messaging_product": "whatsapp",
|
| 203 |
-
"to": wa_id,
|
| 204 |
-
"type": "interactive",
|
| 205 |
-
"interactive": {
|
| 206 |
-
"type": "button",
|
| 207 |
-
"body": {
|
| 208 |
-
"text": "๐ธ Please tap the ๐ท icon next to the text box to take a photo of your ID now."
|
| 209 |
-
},
|
| 210 |
-
"action": {
|
| 211 |
-
"buttons": [
|
| 212 |
-
{
|
| 213 |
-
"type": "reply",
|
| 214 |
-
"reply": {"id": "got_it", "title": "Got it!"}
|
| 215 |
-
}
|
| 216 |
-
]
|
| 217 |
-
}
|
| 218 |
-
}
|
| 219 |
-
}
|
| 220 |
-
httpx.post(url, headers=headers, json=camera_payload)
|
| 221 |
-
return JSONResponse({"status":"handled_button"})
|
| 222 |
|
| 223 |
# TEXT: prompt with Quick-Reply buttons
|
| 224 |
if msg.get("type") == "text":
|
|
|
|
| 162 |
processed_message_ids.add(msg_id)
|
| 163 |
|
| 164 |
# โ Handle button-reply taps first
|
| 165 |
+
if msg.get("type") == "interactive" and msg["interactive"]["type"] == "button_reply":
|
| 166 |
+
payload = msg["interactive"]["button_reply"]["id"]
|
| 167 |
if payload == "open_gallery":
|
| 168 |
+
send_whatsapp_message(
|
| 169 |
+
wa_id,
|
| 170 |
+
"๐ Great! Tap the ๐ (paper-clip) icon below and choose \"Photo & Video Library\" to select your ID image."
|
| 171 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
elif payload == "open_camera":
|
| 173 |
+
send_whatsapp_message(
|
| 174 |
+
wa_id,
|
| 175 |
+
"๐ธ Okayโtap the ๐ท (camera) icon next to the text box to take and send a photo of your ID now."
|
| 176 |
+
)
|
| 177 |
+
return JSONResponse({"status":"handled_button", "payload":payload})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
# TEXT: prompt with Quick-Reply buttons
|
| 180 |
if msg.get("type") == "text":
|