From b0f56fbeb49d04fabc58ee14b0c1329c609ec7bb Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sat, 11 Jan 2025 18:07:56 +0530 Subject: [PATCH] fix: updated status based on direction --- crm/integrations/exotel/handler.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crm/integrations/exotel/handler.py b/crm/integrations/exotel/handler.py index 77d8f077..741c2588 100644 --- a/crm/integrations/exotel/handler.py +++ b/crm/integrations/exotel/handler.py @@ -158,7 +158,18 @@ def get_call_log(call_payload): return frappe.get_doc("CRM Call Log", call_log_id) -def get_call_log_status(call_payload): +def get_call_log_status(call_payload, direction): + if direction == "outbound-api" or direction == "outbound-dial": + status = call_payload.get("Status") + if status == "completed": + return "Completed" + elif status == "busy": + return "Ringing" + elif status == "no-answer": + return "No Answer" + elif status == "failed": + return "Failed" + status = call_payload.get("DialCallStatus") call_type = call_payload.get("CallType") dial_call_status = call_payload.get("DialCallStatus") @@ -178,13 +189,14 @@ def get_call_log_status(call_payload): def update_call_log(call_payload, status="Ringing", call_log=None): + direction = call_payload.get("Direction") call_log = call_log or get_call_log(call_payload) - status = get_call_log_status(call_payload) + status = get_call_log_status(call_payload, direction) try: if call_log: call_log.status = status # resetting this because call might be redirected to other number - call_log.to = call_payload.get("DialWhomNumber") + call_log.to = call_payload.get("DialWhomNumber") or call_payload.get("To") call_log.duration = ( call_payload.get("DialCallDuration") or call_payload.get("ConversationDuration") or 0 )