fix: Handle end call
diff --git a/erpnext/erpnext_integrations/exotel_integration.py b/erpnext/erpnext_integrations/exotel_integration.py
index 39d43b3..5b24e7c 100644
--- a/erpnext/erpnext_integrations/exotel_integration.py
+++ b/erpnext/erpnext_integrations/exotel_integration.py
@@ -27,11 +27,19 @@
'call_log': call_log,
'call_status_method': 'erpnext.erpnext_integrations.exotel_integration.get_call_status'
})
- if call_log.call_status in ['ringing', 'in-progress']:
- frappe.publish_realtime('show_call_popup', data, user=data.agent_email)
+
+ frappe.publish_realtime('show_call_popup', data, user=data.agent_email)
+
+@frappe.whitelist(allow_guest=True)
+def handle_end_call(*args, **kwargs):
+ call_log = get_call_log(kwargs)
+ if call_log:
+ call_log.status = 'Closed'
+ call_log.save(ignore_permissions=True)
+ frappe.db.commit()
-def get_call_log(call_payload):
+def get_call_log(call_payload, create_new_if_not_found=True):
communication = frappe.get_all('Communication', {
'communication_medium': 'Phone',
'call_id': call_payload.get('CallSid'),
@@ -39,7 +47,8 @@
if communication:
communication = frappe.get_doc('Communication', communication[0].name)
- else:
+ return communication
+ elif create_new_if_not_found:
communication = frappe.new_doc('Communication')
communication.subject = frappe._('Call from {}').format(call_payload.get("CallFrom"))
communication.communication_medium = 'Phone'
@@ -49,15 +58,11 @@
communication.sent_or_received = 'Received'
communication.communication_date = call_payload.get('StartTime')
communication.call_id = call_payload.get('CallSid')
-
- status = get_call_status(communication.call_id)
- communication.call_status = status or 'failed'
- communication.status = 'Closed' if status in ['completed', 'failed', 'no-answer'] else 'Open'
- communication.call_duration = call_payload.get('Duration') if status in ['completed', 'failed', 'no-answer'] else 0
- communication.content = 'call_payload'
- communication.save(ignore_permissions=True)
- frappe.db.commit()
- return communication
+ communication.status = 'Open'
+ communication.content = frappe._('Call from {}').format(call_payload.get("CallFrom"))
+ communication.save(ignore_permissions=True)
+ frappe.db.commit()
+ return communication
@frappe.whitelist()
def get_call_status(call_id):
diff --git a/erpnext/public/js/call_popup/call_popup.js b/erpnext/public/js/call_popup/call_popup.js
index f203c8e..3fa5fa6 100644
--- a/erpnext/public/js/call_popup/call_popup.js
+++ b/erpnext/public/js/call_popup/call_popup.js
@@ -73,6 +73,7 @@
this.make_caller_info_section();
this.dialog.get_close_btn().show();
this.setup_call_status_updater();
+ this.dialog.$body.addClass('call-popup');
this.dialog.set_secondary_action(() => {
clearInterval(this.updater);
this.dialog.hide();
@@ -123,7 +124,7 @@
set_call_status(call_status) {
let title = '';
call_status = call_status || this.call_log.call_status;
- if (['busy', 'completed'].includes(call_status)) {
+ if (['busy', 'completed'].includes(call_status) || !call_status) {
title = __('Incoming call from {0}',
[this.contact ? `${this.contact.first_name} ${this.contact.last_name}` : this.caller_number]);
this.set_indicator('blue', true);