Zenaight commited on
Commit
ccbc960
ยท
verified ยท
1 Parent(s): c5b6eaa

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -55
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") == "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
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":