fix: Handle end call

This commit is contained in:
Suraj Shetty 2019-05-27 15:30:41 +05:30
parent 39a4d59cf6
commit bd03a51e8f
2 changed files with 20 additions and 14 deletions

View File

@ -27,11 +27,19 @@ def handle_incoming_call(*args, **kwargs):
'call_log': call_log, 'call_log': call_log,
'call_status_method': 'erpnext.erpnext_integrations.exotel_integration.get_call_status' '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 = frappe.get_all('Communication', {
'communication_medium': 'Phone', 'communication_medium': 'Phone',
'call_id': call_payload.get('CallSid'), 'call_id': call_payload.get('CallSid'),
@ -39,7 +47,8 @@ def get_call_log(call_payload):
if communication: if communication:
communication = frappe.get_doc('Communication', communication[0].name) communication = frappe.get_doc('Communication', communication[0].name)
else: return communication
elif create_new_if_not_found:
communication = frappe.new_doc('Communication') communication = frappe.new_doc('Communication')
communication.subject = frappe._('Call from {}').format(call_payload.get("CallFrom")) communication.subject = frappe._('Call from {}').format(call_payload.get("CallFrom"))
communication.communication_medium = 'Phone' communication.communication_medium = 'Phone'
@ -49,15 +58,11 @@ def get_call_log(call_payload):
communication.sent_or_received = 'Received' communication.sent_or_received = 'Received'
communication.communication_date = call_payload.get('StartTime') communication.communication_date = call_payload.get('StartTime')
communication.call_id = call_payload.get('CallSid') communication.call_id = call_payload.get('CallSid')
communication.status = 'Open'
status = get_call_status(communication.call_id) communication.content = frappe._('Call from {}').format(call_payload.get("CallFrom"))
communication.call_status = status or 'failed' communication.save(ignore_permissions=True)
communication.status = 'Closed' if status in ['completed', 'failed', 'no-answer'] else 'Open' frappe.db.commit()
communication.call_duration = call_payload.get('Duration') if status in ['completed', 'failed', 'no-answer'] else 0 return communication
communication.content = 'call_payload'
communication.save(ignore_permissions=True)
frappe.db.commit()
return communication
@frappe.whitelist() @frappe.whitelist()
def get_call_status(call_id): def get_call_status(call_id):

View File

@ -73,6 +73,7 @@ class CallPopup {
this.make_caller_info_section(); this.make_caller_info_section();
this.dialog.get_close_btn().show(); this.dialog.get_close_btn().show();
this.setup_call_status_updater(); this.setup_call_status_updater();
this.dialog.$body.addClass('call-popup');
this.dialog.set_secondary_action(() => { this.dialog.set_secondary_action(() => {
clearInterval(this.updater); clearInterval(this.updater);
this.dialog.hide(); this.dialog.hide();
@ -123,7 +124,7 @@ class CallPopup {
set_call_status(call_status) { set_call_status(call_status) {
let title = ''; let title = '';
call_status = call_status || this.call_log.call_status; 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}', title = __('Incoming call from {0}',
[this.contact ? `${this.contact.first_name} ${this.contact.last_name}` : this.caller_number]); [this.contact ? `${this.contact.first_name} ${this.contact.last_name}` : this.caller_number]);
this.set_indicator('blue', true); this.set_indicator('blue', true);