Upload main.py
Browse files
main.py
CHANGED
|
@@ -161,6 +161,26 @@ async def receive_update(req: Request):
|
|
| 161 |
return JSONResponse({"status": "duplicate", "id": msg_id})
|
| 162 |
processed_message_ids.add(msg_id)
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
# IMAGE: if user sent an image, convert to Base64 preview
|
| 165 |
if msg["type"] == "image":
|
| 166 |
media_id = msg["image"]["id"]
|
|
@@ -186,16 +206,6 @@ async def receive_update(req: Request):
|
|
| 186 |
# 5) echo preview to the user
|
| 187 |
return JSONResponse({"status": "image_preview_sent", "preview": preview})
|
| 188 |
|
| 189 |
-
# TEXT: instruct user how to pick/send an ID image
|
| 190 |
-
if msg["type"] == "text":
|
| 191 |
-
send_whatsapp_message(
|
| 192 |
-
wa_id,
|
| 193 |
-
"Welcome to RUMAS! 📋\n\n"
|
| 194 |
-
"Please tap the 📎 (attachment) icon below, select \"Photo & Video Library,\" "
|
| 195 |
-
"and choose a clear image of your South African ID."
|
| 196 |
-
)
|
| 197 |
-
return JSONResponse({"status": "instructions_sent"})
|
| 198 |
-
|
| 199 |
# OTHER: ignore
|
| 200 |
return JSONResponse({"status": "ignored", "type": msg["type"]})
|
| 201 |
|
|
|
|
| 161 |
return JSONResponse({"status": "duplicate", "id": msg_id})
|
| 162 |
processed_message_ids.add(msg_id)
|
| 163 |
|
| 164 |
+
# ① Handle button-reply taps first
|
| 165 |
+
if msg.get("type") == "button":
|
| 166 |
+
payload = msg["button"]["payload"]
|
| 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":
|
| 181 |
+
send_welcome_buttons(wa_id)
|
| 182 |
+
return JSONResponse({"status": "buttons_sent"})
|
| 183 |
+
|
| 184 |
# IMAGE: if user sent an image, convert to Base64 preview
|
| 185 |
if msg["type"] == "image":
|
| 186 |
media_id = msg["image"]["id"]
|
|
|
|
| 206 |
# 5) echo preview to the user
|
| 207 |
return JSONResponse({"status": "image_preview_sent", "preview": preview})
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
# OTHER: ignore
|
| 210 |
return JSONResponse({"status": "ignored", "type": msg["type"]})
|
| 211 |
|