Zenaight commited on
Commit
7f30324
Β·
verified Β·
1 Parent(s): 498f30c

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -8
main.py CHANGED
@@ -12,7 +12,7 @@ PHONE_NUMBER_ID = os.getenv("PHONE_NUMBER_ID", "")
12
  WHATSAPP_API_TOKEN = os.getenv("WHATSAPP_API_TOKEN", "")
13
  RUMAS_API_URL = os.getenv("RUMAS_API_URL", "")
14
 
15
- async def forward_to_rumas(b64_str: str):
16
  """Fire-and-forget call to RUMAS /api/process_id."""
17
  payload = {
18
  "data": [b64_str],
@@ -40,13 +40,17 @@ async def forward_to_rumas(b64_str: str):
40
  print(f"[RUMAS] βœ” {resp.status_code}")
41
  pretty_print_dict(body)
42
 
43
- # OPTIONAL: notify user (comment out if you prefer silent)
44
- wa_id = body.get("wa_id") # supply wa_id if backend echoes it
45
- if wa_id:
46
- send_whatsapp_message(
47
- wa_id,
48
- "βœ… ID processed, results ready."
 
 
 
49
  )
 
50
 
51
  except Exception as e:
52
  print(f"[RUMAS] ✘ error while sending '{short}…' β†’", e)
@@ -129,7 +133,7 @@ async def receive_update(req: Request):
129
  preview = full_b64[:10]
130
 
131
  # 4) forward full string to RUMAS (non-blocking)
132
- asyncio.create_task(forward_to_rumas(full_b64))
133
 
134
  # 5) echo preview to the user
135
  send_whatsapp_message(wa_id, f"Base64: {preview}")
 
12
  WHATSAPP_API_TOKEN = os.getenv("WHATSAPP_API_TOKEN", "")
13
  RUMAS_API_URL = os.getenv("RUMAS_API_URL", "")
14
 
15
+ async def forward_to_rumas(b64_str: str, wa_id: str):
16
  """Fire-and-forget call to RUMAS /api/process_id."""
17
  payload = {
18
  "data": [b64_str],
 
40
  print(f"[RUMAS] βœ” {resp.status_code}")
41
  pretty_print_dict(body)
42
 
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)
 
133
  preview = full_b64[:10]
134
 
135
  # 4) forward full string to RUMAS (non-blocking)
136
+ asyncio.create_task(forward_to_rumas(full_b64, wa_id))
137
 
138
  # 5) echo preview to the user
139
  send_whatsapp_message(wa_id, f"Base64: {preview}")