Zenaight commited on
Commit
c5b6eaa
Β·
verified Β·
1 Parent(s): ad72c76

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +52 -10
main.py CHANGED
@@ -164,18 +164,60 @@ async def receive_update(req: Request):
164
  # β‘  Handle button-reply taps first
165
  if msg.get("type") == "button":
166
  payload = msg["button"]["payload"]
167
- # Small delay to prevent reply behavior
168
- await asyncio.sleep(0.5)
169
  if payload == "open_gallery":
170
- send_whatsapp_message(
171
- wa_id,
172
- "πŸ‘ Please tap the πŸ“Ž icon below and select \"Photo & Video Library\" to pick your ID image."
173
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  elif payload == "open_camera":
175
- send_whatsapp_message(
176
- wa_id,
177
- "πŸ“Έ Please tap the πŸ“· icon next to the text box to take a photo of your ID now."
178
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  return JSONResponse({"status":"handled_button"})
180
 
181
  # TEXT: prompt with Quick-Reply buttons
 
164
  # β‘  Handle button-reply taps first
165
  if msg.get("type") == "button":
166
  payload = msg["button"]["payload"]
 
 
167
  if payload == "open_gallery":
168
+ # Send as interactive message to force new message behavior
169
+ url = f"https://graph.facebook.com/v23.0/{PHONE_NUMBER_ID}/messages"
170
+ headers = {
171
+ "Authorization": f"Bearer {WHATSAPP_API_TOKEN}",
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
+ # Send as interactive message to force new message behavior
196
+ url = f"https://graph.facebook.com/v23.0/{PHONE_NUMBER_ID}/messages"
197
+ headers = {
198
+ "Authorization": f"Bearer {WHATSAPP_API_TOKEN}",
199
+ "Content-Type": "application/json"
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