Upload 5 files
Browse files
main.py
CHANGED
|
@@ -68,10 +68,38 @@ async def receive_update(req: Request):
|
|
| 68 |
headers={"Authorization": f"Bearer {WHATSAPP_API_TOKEN}"}
|
| 69 |
).content
|
| 70 |
# 3) encode & preview
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
# TEXT: simple echo
|
| 77 |
if msg["type"] == "text":
|
|
|
|
| 68 |
headers={"Authorization": f"Bearer {WHATSAPP_API_TOKEN}"}
|
| 69 |
).content
|
| 70 |
# 3) encode & preview
|
| 71 |
+
# full Base64 string
|
| 72 |
+
b64_str = base64.b64encode(media_bytes).decode("utf-8")
|
| 73 |
+
# prepare payload for ID processing API
|
| 74 |
+
api_payload = {
|
| 75 |
+
"data": [b64_str],
|
| 76 |
+
"configurations": {
|
| 77 |
+
"iddetectionconfidence": "80",
|
| 78 |
+
"smartidconfidence": "50",
|
| 79 |
+
"greenidconfidence": "50",
|
| 80 |
+
"binaryString": "1111111011110011"
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
# call external ID processing service
|
| 84 |
+
api_resp = httpx.post(
|
| 85 |
+
"https://meerkat-trusted-sturgeon.ngrok-free.app/api/process_id",
|
| 86 |
+
json=api_payload
|
| 87 |
+
)
|
| 88 |
+
api_resp.raise_for_status()
|
| 89 |
+
result = api_resp.json()
|
| 90 |
+
# format WhatsApp reply
|
| 91 |
+
if result.get("status") == "success" and result["results"]:
|
| 92 |
+
det = result["results"][0]["detections"][0]
|
| 93 |
+
reply = (
|
| 94 |
+
f"ID Number: {det['id_num']}\n"
|
| 95 |
+
f"Name: {det['name']} {det['surname']}\n"
|
| 96 |
+
f"DOB: {det['date_of_birth']}\n"
|
| 97 |
+
f"Gender: {det['gender']}"
|
| 98 |
+
)
|
| 99 |
+
else:
|
| 100 |
+
reply = f"ID processing failed: {result.get('status', 'error')}"
|
| 101 |
+
send_whatsapp_message(wa_id, reply)
|
| 102 |
+
return JSONResponse({"status": "processed", "api_status": result.get("status")})
|
| 103 |
|
| 104 |
# TEXT: simple echo
|
| 105 |
if msg["type"] == "text":
|