Upload main.py
Browse files
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 |
-
#
|
| 44 |
-
wa_id
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"
|
|
|
|
|
|
|
|
|
|
| 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}")
|