fix: Call popup modal
This commit is contained in:
parent
824d0ecc48
commit
39a4d59cf6
@ -12,9 +12,10 @@ def handle_incoming_call(*args, **kwargs):
|
|||||||
employee_email = kwargs.get('AgentEmail')
|
employee_email = kwargs.get('AgentEmail')
|
||||||
status = kwargs.get('Status')
|
status = kwargs.get('Status')
|
||||||
|
|
||||||
if status == 'free' and get_call_status(kwargs.get('CallSid')) == ['ringing', 'in-progress']:
|
if status == 'free':
|
||||||
# redirected to other agent number
|
# call disconnected for agent
|
||||||
frappe.publish_realtime('terminate_call_popup', user=employee_email)
|
# "and get_call_status(kwargs.get('CallSid')) in ['in-progress']" - additional check to ensure if the call was redirected
|
||||||
|
frappe.publish_realtime('call_disconnected', user=employee_email)
|
||||||
return
|
return
|
||||||
|
|
||||||
call_log = get_call_log(kwargs)
|
call_log = get_call_log(kwargs)
|
||||||
@ -29,9 +30,6 @@ def handle_incoming_call(*args, **kwargs):
|
|||||||
if call_log.call_status in ['ringing', 'in-progress']:
|
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)
|
||||||
|
|
||||||
def get_last_communication(phone_number, contact):
|
|
||||||
# frappe.get_all('Communication', filter={})
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def get_call_log(call_payload):
|
def get_call_log(call_payload):
|
||||||
communication = frappe.get_all('Communication', {
|
communication = frappe.get_all('Communication', {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class CallPopup {
|
class CallPopup {
|
||||||
constructor({ call_from, call_log, call_status_method }) {
|
constructor({ call_from, call_log, call_status_method }) {
|
||||||
this.number = call_from;
|
this.caller_number = call_from;
|
||||||
this.call_log = call_log;
|
this.call_log = call_log;
|
||||||
this.call_status_method = call_status_method;
|
this.call_status_method = call_status_method;
|
||||||
this.make();
|
this.make();
|
||||||
@ -11,17 +11,16 @@ class CallPopup {
|
|||||||
'static': true,
|
'static': true,
|
||||||
'minimizable': true,
|
'minimizable': true,
|
||||||
'fields': [{
|
'fields': [{
|
||||||
'fieldname': 'customer_info',
|
'fieldname': 'caller_info',
|
||||||
'fieldtype': 'HTML'
|
'fieldtype': 'HTML'
|
||||||
}, {
|
}, {
|
||||||
'label': 'Last Interaction',
|
|
||||||
'fielname': 'last_interaction',
|
'fielname': 'last_interaction',
|
||||||
'fieldtype': 'Section Break',
|
'fieldtype': 'Section Break',
|
||||||
// 'hidden': true
|
|
||||||
}, {
|
}, {
|
||||||
'fieldtype': 'Small Text',
|
'fieldtype': 'Small Text',
|
||||||
'label': "Last Communication",
|
'label': "Last Communication",
|
||||||
'fieldname': 'last_communication',
|
'fieldname': 'last_communication',
|
||||||
|
'read_only': true
|
||||||
}, {
|
}, {
|
||||||
'fieldname': 'last_communication_link',
|
'fieldname': 'last_communication_link',
|
||||||
'fieldtype': 'HTML',
|
'fieldtype': 'HTML',
|
||||||
@ -29,12 +28,12 @@ class CallPopup {
|
|||||||
'fieldtype': 'Small Text',
|
'fieldtype': 'Small Text',
|
||||||
'label': "Last Issue",
|
'label': "Last Issue",
|
||||||
'fieldname': 'last_issue',
|
'fieldname': 'last_issue',
|
||||||
|
'read_only': true
|
||||||
}, {
|
}, {
|
||||||
'fieldname': 'last_issue_link',
|
'fieldname': 'last_issue_link',
|
||||||
'fieldtype': 'HTML',
|
'fieldtype': 'HTML',
|
||||||
}, {
|
}, {
|
||||||
'label': 'Enter Call Summary',
|
'fieldtype': 'Column Break',
|
||||||
'fieldtype': 'Section Break',
|
|
||||||
}, {
|
}, {
|
||||||
'fieldtype': 'Small Text',
|
'fieldtype': 'Small Text',
|
||||||
'label': 'Call Summary',
|
'label': 'Call Summary',
|
||||||
@ -65,10 +64,13 @@ class CallPopup {
|
|||||||
this.dialog.set_value('call_summary', '');
|
this.dialog.set_value('call_summary', '');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}]
|
}],
|
||||||
|
on_minimize_toggle: () => {
|
||||||
|
this.set_call_status();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.set_call_status(this.call_log.call_status);
|
this.set_call_status(this.call_log.call_status);
|
||||||
this.make_customer_contact();
|
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.set_secondary_action(() => {
|
this.dialog.set_secondary_action(() => {
|
||||||
@ -78,19 +80,19 @@ class CallPopup {
|
|||||||
this.dialog.show();
|
this.dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
make_customer_contact() {
|
make_caller_info_section() {
|
||||||
const wrapper = this.dialog.fields_dict["customer_info"].$wrapper;
|
const wrapper = this.dialog.fields_dict['caller_info'].$wrapper;
|
||||||
wrapper.append('<div class="text-muted"> Loading... </div>');
|
wrapper.append('<div class="text-muted"> Loading... </div>');
|
||||||
frappe.xcall('erpnext.crm.doctype.utils.get_document_with_phone_number', {
|
frappe.xcall('erpnext.crm.doctype.utils.get_document_with_phone_number', {
|
||||||
'number': this.number
|
'number': this.caller_number
|
||||||
}).then(contact_doc => {
|
}).then(contact_doc => {
|
||||||
wrapper.empty();
|
wrapper.empty();
|
||||||
const contact = this.contact = contact_doc;
|
const contact = this.contact = contact_doc;
|
||||||
if (!contact) {
|
if (!contact) {
|
||||||
wrapper.append(`
|
wrapper.append(`
|
||||||
<div class="customer-info">
|
<div class="caller-info">
|
||||||
<div>Unknown Number: <b>${this.number}</b></div>
|
<div>Unknown Number: <b>${this.caller_number}</b></div>
|
||||||
<a class="contact-link" href="#Form/Contact/New Contact?phone=${this.number}">
|
<a class="contact-link text-medium" href="#Form/Contact/New Contact?phone=${this.caller_number}">
|
||||||
${__('Create New Contact')}
|
${__('Create New Contact')}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@ -99,7 +101,7 @@ class CallPopup {
|
|||||||
const link = contact.links ? contact.links[0] : null;
|
const link = contact.links ? contact.links[0] : null;
|
||||||
const contact_link = link ? frappe.utils.get_form_link(link.link_doctype, link.link_name, true): '';
|
const contact_link = link ? frappe.utils.get_form_link(link.link_doctype, link.link_name, true): '';
|
||||||
wrapper.append(`
|
wrapper.append(`
|
||||||
<div class="customer-info flex">
|
<div class="caller-info flex">
|
||||||
<img src="${contact.image}">
|
<img src="${contact.image}">
|
||||||
<div class='flex-column'>
|
<div class='flex-column'>
|
||||||
<span>${contact.first_name} ${contact.last_name}</span>
|
<span>${contact.first_name} ${contact.last_name}</span>
|
||||||
@ -108,27 +110,32 @@ class CallPopup {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
|
this.set_call_status();
|
||||||
this.make_last_interaction_section();
|
this.make_last_interaction_section();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
set_indicator(color) {
|
set_indicator(color, blink=false) {
|
||||||
this.dialog.header.find('.indicator').removeClass('hidden').addClass('blink').addClass(color);
|
this.dialog.header.find('.indicator').removeClass('hidden').toggleClass('blink', blink).addClass(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_call_status(call_status) {
|
set_call_status(call_status) {
|
||||||
let title = '';
|
let title = '';
|
||||||
call_status = this.call_log.call_status;
|
call_status = call_status || this.call_log.call_status;
|
||||||
if (call_status === 'busy') {
|
if (['busy', 'completed'].includes(call_status)) {
|
||||||
title = __('Incoming call');
|
title = __('Incoming call from {0}',
|
||||||
this.set_indicator('blue');
|
[this.contact ? `${this.contact.first_name} ${this.contact.last_name}` : this.caller_number]);
|
||||||
|
this.set_indicator('blue', true);
|
||||||
} else if (call_status === 'in-progress') {
|
} else if (call_status === 'in-progress') {
|
||||||
title = __('Call Connected');
|
title = __('Call Connected');
|
||||||
this.set_indicator('yellow');
|
this.set_indicator('yellow');
|
||||||
} else if (call_status === 'missed') {
|
} else if (call_status === 'missed') {
|
||||||
this.set_indicator('red');
|
this.set_indicator('red');
|
||||||
title = __('Call Missed');
|
title = __('Call Missed');
|
||||||
|
} else if (call_status === 'disconnected') {
|
||||||
|
this.set_indicator('red');
|
||||||
|
title = __('Call Disconnected');
|
||||||
} else {
|
} else {
|
||||||
this.set_indicator('blue');
|
this.set_indicator('blue');
|
||||||
title = call_status;
|
title = call_status;
|
||||||
@ -155,16 +162,14 @@ class CallPopup {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
terminate_popup() {
|
disconnect_call() {
|
||||||
|
this.set_call_status('disconnected');
|
||||||
clearInterval(this.updater);
|
clearInterval(this.updater);
|
||||||
this.dialog.hide();
|
|
||||||
delete erpnext.call_popup;
|
|
||||||
frappe.msgprint('Call Forwarded');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
make_last_interaction_section() {
|
make_last_interaction_section() {
|
||||||
frappe.xcall('erpnext.crm.doctype.utils.get_last_interaction', {
|
frappe.xcall('erpnext.crm.doctype.utils.get_last_interaction', {
|
||||||
'number': this.number,
|
'number': this.caller_number,
|
||||||
'reference_doc': this.contact
|
'reference_doc': this.contact
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
if (data.last_communication) {
|
if (data.last_communication) {
|
||||||
@ -180,7 +185,8 @@ class CallPopup {
|
|||||||
// this.dialog.set_df_property('last_interaction', 'hidden', false);
|
// this.dialog.set_df_property('last_interaction', 'hidden', false);
|
||||||
const issue_field = this.dialog.fields_dict["last_issue"];
|
const issue_field = this.dialog.fields_dict["last_issue"];
|
||||||
issue_field.set_value(issue.subject);
|
issue_field.set_value(issue.subject);
|
||||||
issue_field.$wrapper.append(frappe.utils.get_form_link('Issue', issue.name, true));
|
issue_field.$wrapper
|
||||||
|
.append(`<a class="text-medium" href="#Form/Issue/${issue.name}">View ${issue.name}</a>`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -191,15 +197,14 @@ $(document).on('app_ready', function () {
|
|||||||
if (!erpnext.call_popup) {
|
if (!erpnext.call_popup) {
|
||||||
erpnext.call_popup = new CallPopup(data);
|
erpnext.call_popup = new CallPopup(data);
|
||||||
} else {
|
} else {
|
||||||
console.log(data);
|
|
||||||
erpnext.call_popup.update(data);
|
erpnext.call_popup.update(data);
|
||||||
erpnext.call_popup.dialog.show();
|
erpnext.call_popup.dialog.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frappe.realtime.on('terminate_call_popup', () => {
|
frappe.realtime.on('call_disconnected', () => {
|
||||||
if (erpnext.call_popup) {
|
if (erpnext.call_popup) {
|
||||||
erpnext.call_popup.terminate_popup();
|
erpnext.call_popup.disconnect_call();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
.customer-info {
|
.call-popup {
|
||||||
|
.caller-info {
|
||||||
|
padding: 0 15px;
|
||||||
|
}
|
||||||
img {
|
img {
|
||||||
width: auto;
|
width: auto;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user