Zenaight commited on
Commit
3a4fdc8
Β·
verified Β·
1 Parent(s): a1009d6

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -8
main.py CHANGED
@@ -43,14 +43,11 @@ async def forward_to_rumas(b64_str: str, wa_id: str):
43
  # ── send parsed ID back to WhatsApp ──
44
  if wa_id and data.get("status") == "success":
45
  det = data["results"][0]["detections"][0]
46
- reply = (
47
- "βœ… *ID processed*\n"
48
- f"*Name*: {det.get('name','?')} {det.get('surname','')}\n"
49
- f"*ID No.*: {det.get('id_num','?')}\n"
50
- f"*DOB*: {det.get('date_of_birth','?')}\n"
51
- f"*Gender*: {det.get('gender','?')}"
52
- )
53
- send_whatsapp_message(wa_id, reply)
54
 
55
  except Exception as e:
56
  print(f"[RUMAS] ✘ error while sending '{short}…' β†’", e)
@@ -113,6 +110,10 @@ async def receive_update(req: Request):
113
  print("Malformed webhook payload:", e)
114
  return JSONResponse({"status": "ignored", "reason": "malformed payload"})
115
 
 
 
 
 
116
  # IMAGE: if user sent an image, convert to Base64 preview
117
  if msg["type"] == "image":
118
  media_id = msg["image"]["id"]
 
43
  # ── send parsed ID back to WhatsApp ──
44
  if wa_id and data.get("status") == "success":
45
  det = data["results"][0]["detections"][0]
46
+ lines = ["βœ… *ID processed*"]
47
+ for key, val in det.items():
48
+ pretty = key.replace("_", " ").title()
49
+ lines.append(f"*{pretty}*: {val or ''}")
50
+ send_whatsapp_message(wa_id, "\n".join(lines))
 
 
 
51
 
52
  except Exception as e:
53
  print(f"[RUMAS] ✘ error while sending '{short}…' β†’", e)
 
110
  print("Malformed webhook payload:", e)
111
  return JSONResponse({"status": "ignored", "reason": "malformed payload"})
112
 
113
+ # ── ignore updates from our own bot to prevent echo loops ──
114
+ if msg.get("from") == PHONE_NUMBER_ID:
115
+ return JSONResponse({"status": "ignored", "reason": "bot message"})
116
+
117
  # IMAGE: if user sent an image, convert to Base64 preview
118
  if msg["type"] == "image":
119
  media_id = msg["image"]["id"]