Zenaight commited on
Commit
b8fae5f
Β·
verified Β·
1 Parent(s): a265de0

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -21
main.py CHANGED
@@ -61,31 +61,37 @@ async def forward_to_rumas(b64_str: str, wa_id: str, task_id: str):
61
  print(f"[RUMAS] βœ” {resp.status_code}")
62
  pretty_print_dict(body)
63
 
64
- # ── send parsed ID back to WhatsApp ──
65
- if wa_id and data.get("status") == "success" and task_id in active_tasks:
66
- print(f"[TASK] Sending response for active task {task_id}")
67
- det = data["results"][0]["detections"][0]
68
- reply = (
69
- "βœ… *ID processed*\n"
70
- f"*Name*: {det.get('name','?')} {det.get('surname','')}\n"
71
- f"*ID No.*: {det.get('id_num','?')}\n"
72
- f"*DOB*: {det.get('date_of_birth','?')}\n"
73
- f"*Gender*: {det.get('gender','?')}\n"
74
- f"*ID Type*: {det.get('id_type','?')}\n"
75
- f"*Country of Birth*: {det.get('cob','?')}\n"
76
- f"*Citizen*: {det.get('citizen','?')}\n"
77
- f"*Citizen Status*: {det.get('citizen_status','?')}\n"
78
- f"*Date Issued*: {det.get('date_issued','?')}\n"
79
- f"*Age*: {det.get('age','?')}"
80
- )
81
- send_whatsapp_message(wa_id, reply)
 
 
 
 
 
 
 
 
 
82
  # Remove task from active list
83
  active_tasks.pop(task_id, None)
84
- print(f"[TASK] Completed and removed task {task_id}")
85
  elif task_id not in active_tasks:
86
  print(f"[TASK] Ignoring response for inactive task {task_id}")
87
- else:
88
- print(f"[TASK] RUMAS response not successful for task {task_id}")
89
 
90
  except Exception as e:
91
  print(f"[RUMAS] ✘ error while sending '{short}…' β†’", e)
 
61
  print(f"[RUMAS] βœ” {resp.status_code}")
62
  pretty_print_dict(body)
63
 
64
+ # ── send parsed ID back to WhatsApp or error message ──
65
+ if wa_id and task_id in active_tasks:
66
+ if data.get("status") == "success":
67
+ print(f"[TASK] Sending response for active task {task_id}")
68
+ det = data["results"][0]["detections"][0]
69
+ reply = (
70
+ "βœ… *ID processed*\n"
71
+ f"*Name*: {det.get('name','?')} {det.get('surname','')}\n"
72
+ f"*ID No.*: {det.get('id_num','?')}\n"
73
+ f"*DOB*: {det.get('date_of_birth','?')}\n"
74
+ f"*Gender*: {det.get('gender','?')}\n"
75
+ f"*ID Type*: {det.get('id_type','?')}\n"
76
+ f"*Country of Birth*: {det.get('cob','?')}\n"
77
+ f"*Citizen*: {det.get('citizen','?')}\n"
78
+ f"*Citizen Status*: {det.get('citizen_status','?')}\n"
79
+ f"*Date Issued*: {det.get('date_issued','?')}\n"
80
+ f"*Age*: {det.get('age','?')}"
81
+ )
82
+ send_whatsapp_message(wa_id, reply)
83
+ print(f"[TASK] Completed and removed task {task_id}")
84
+ elif "error" in data:
85
+ error_msg = data["error"]
86
+ print(f"[TASK] RUMAS error for task {task_id}: {error_msg}")
87
+ send_whatsapp_message(wa_id, f"❌ {error_msg}")
88
+ else:
89
+ print(f"[TASK] RUMAS response not successful for task {task_id}")
90
+ send_whatsapp_message(wa_id, "❌ Sorry, we could not process your ID. Please try again with a clearer image.")
91
  # Remove task from active list
92
  active_tasks.pop(task_id, None)
 
93
  elif task_id not in active_tasks:
94
  print(f"[TASK] Ignoring response for inactive task {task_id}")
 
 
95
 
96
  except Exception as e:
97
  print(f"[RUMAS] ✘ error while sending '{short}…' β†’", e)