fix: Change call log fieldname and some cleanups
This commit is contained in:
parent
97780613ad
commit
c8c17422f7
@ -1,71 +1,71 @@
|
||||
{
|
||||
"autoname": "field:call_id",
|
||||
"autoname": "field:id",
|
||||
"creation": "2019-06-05 12:07:02.634534",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"call_id",
|
||||
"call_from",
|
||||
"id",
|
||||
"from",
|
||||
"column_break_3",
|
||||
"received_by",
|
||||
"to",
|
||||
"section_break_5",
|
||||
"call_status",
|
||||
"call_duration",
|
||||
"call_summary"
|
||||
"status",
|
||||
"duration",
|
||||
"summary"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "call_id",
|
||||
"fieldtype": "Data",
|
||||
"label": "Call ID",
|
||||
"read_only": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "call_from",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Call From",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "received_by",
|
||||
"fieldtype": "Data",
|
||||
"label": "Received By",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_5",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "call_status",
|
||||
"fieldname": "id",
|
||||
"fieldtype": "Data",
|
||||
"label": "ID",
|
||||
"read_only": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "from",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "From",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "to",
|
||||
"fieldtype": "Data",
|
||||
"label": "To",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Call Status",
|
||||
"label": "Status",
|
||||
"options": "Ringing\nIn Progress\nCompleted\nMissed",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"description": "Call Duration in seconds",
|
||||
"fieldname": "call_duration",
|
||||
"fieldname": "duration",
|
||||
"fieldtype": "Int",
|
||||
"in_list_view": 1,
|
||||
"label": "Call Duration",
|
||||
"label": "Duration",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "call_summary",
|
||||
"fieldname": "summary",
|
||||
"fieldtype": "Data",
|
||||
"label": "Call Summary",
|
||||
"label": "Summary",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"modified": "2019-06-06 07:41:26.208109",
|
||||
"modified": "2019-06-07 09:49:07.623814",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Communication",
|
||||
"name": "Call Log",
|
||||
@ -86,6 +86,6 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "ASC",
|
||||
"title_field": "call_from",
|
||||
"title_field": "from",
|
||||
"track_changes": 1
|
||||
}
|
@ -78,17 +78,17 @@ def add_call_summary(docname, summary):
|
||||
call_log.call_summary += '<br>' + content
|
||||
call_log.save(ignore_permissions=True)
|
||||
|
||||
def get_employee_emails_for_popup():
|
||||
def get_employee_emails_for_popup(communication_medium):
|
||||
employee_emails = []
|
||||
now_time = frappe.utils.nowtime()
|
||||
weekday = frappe.utils.get_weekday()
|
||||
|
||||
available_employee_groups = frappe.db.sql("""SELECT `parent`, `employee_group`
|
||||
FROM `tabCommunication Medium Timeslot`
|
||||
WHERE `day_of_week` = %s AND
|
||||
%s BETWEEN `from_time` AND `to_time`
|
||||
""", (weekday, now_time), as_dict=1)
|
||||
|
||||
WHERE `day_of_week` = %s
|
||||
AND `parent` = %s
|
||||
AND %s BETWEEN `from_time` AND `to_time`
|
||||
""", (weekday, communication_medium, now_time), as_dict=1)
|
||||
for group in available_employee_groups:
|
||||
employee_emails += [e.user_id for e in frappe.get_doc('Employee Group', group.employee_group).employee_list]
|
||||
|
||||
|
@ -3,6 +3,8 @@ from erpnext.crm.doctype.utils import get_document_with_phone_number, get_employ
|
||||
import requests
|
||||
|
||||
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call
|
||||
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_end_call
|
||||
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_missed_call
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def handle_incoming_call(*args, **kwargs):
|
||||
@ -18,41 +20,43 @@ def handle_incoming_call(*args, **kwargs):
|
||||
|
||||
call_log = get_call_log(kwargs)
|
||||
|
||||
employee_emails = get_employee_emails_for_popup()
|
||||
employee_emails = get_employee_emails_for_popup(kwargs.get('To'))
|
||||
for email in employee_emails:
|
||||
frappe.publish_realtime('show_call_popup', call_log, user=email)
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def handle_end_call(*args, **kwargs):
|
||||
update_call_log(kwargs, 'Completed')
|
||||
frappe.publish_realtime('call_disconnected', kwargs.get('CallSid'))
|
||||
call_log = update_call_log(kwargs, 'Completed')
|
||||
frappe.publish_realtime('call_disconnected', call_log)
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def handle_missed_call(*args, **kwargs):
|
||||
update_call_log(kwargs, 'Missed')
|
||||
frappe.publish_realtime('call_disconnected', kwargs.get('CallSid'))
|
||||
call_log = update_call_log(kwargs, 'Missed')
|
||||
frappe.publish_realtime('call_disconnected', call_log)
|
||||
|
||||
def update_call_log(call_payload, status):
|
||||
call_log = get_call_log(call_payload, False)
|
||||
if call_log:
|
||||
call_log.call_status = status
|
||||
call_log.call_duration = call_payload.get('DialCallDuration') or 0
|
||||
call_log.status = status
|
||||
call_log.duration = call_payload.get('DialCallDuration') or 0
|
||||
call_log.save(ignore_permissions=True)
|
||||
frappe.db.commit()
|
||||
return call_log
|
||||
|
||||
|
||||
def get_call_log(call_payload, create_new_if_not_found=True):
|
||||
call_log = frappe.get_all('Call Log', {
|
||||
'call_id': call_payload.get('CallSid'),
|
||||
'id': call_payload.get('CallSid'),
|
||||
}, limit=1)
|
||||
|
||||
if call_log:
|
||||
return frappe.get_doc('Call Log', call_log[0].name)
|
||||
elif create_new_if_not_found:
|
||||
call_log = frappe.new_doc('Call Log')
|
||||
call_log.call_id = call_payload.get('CallSid')
|
||||
call_log.call_from = call_payload.get('CallFrom')
|
||||
call_log.id = call_payload.get('CallSid')
|
||||
call_log.to = call_payload.get('To')
|
||||
call_log.status = 'Ringing'
|
||||
setattr(call_log, 'from', call_payload.get('CallFrom'))
|
||||
call_log.save(ignore_permissions=True)
|
||||
frappe.db.commit()
|
||||
return call_log
|
||||
|
@ -1,6 +1,6 @@
|
||||
class CallPopup {
|
||||
constructor(call_log) {
|
||||
this.caller_number = call_log.call_from;
|
||||
this.caller_number = call_log.from;
|
||||
this.call_log = call_log;
|
||||
this.make();
|
||||
}
|
||||
@ -20,17 +20,11 @@ class CallPopup {
|
||||
'label': "Last Communication",
|
||||
'fieldname': 'last_communication',
|
||||
'read_only': true
|
||||
}, {
|
||||
'fieldname': 'last_communication_link',
|
||||
'fieldtype': 'HTML',
|
||||
}, {
|
||||
'fieldtype': 'Small Text',
|
||||
'label': "Last Issue",
|
||||
'fieldname': 'last_issue',
|
||||
'read_only': true
|
||||
}, {
|
||||
'fieldname': 'last_issue_link',
|
||||
'fieldtype': 'HTML',
|
||||
}, {
|
||||
'fieldtype': 'Column Break',
|
||||
}, {
|
||||
@ -44,26 +38,23 @@ class CallPopup {
|
||||
const values = this.dialog.get_values();
|
||||
if (!values.call_summary) return
|
||||
frappe.xcall('erpnext.crm.doctype.utils.add_call_summary', {
|
||||
'docname': this.call_log.call_id,
|
||||
'docname': this.call_log.id,
|
||||
'summary': values.call_summary,
|
||||
}).then(() => {
|
||||
this.dialog.set_value('call_summary', '');
|
||||
});
|
||||
}
|
||||
}],
|
||||
on_minimize_toggle: () => {
|
||||
this.set_call_status();
|
||||
}
|
||||
});
|
||||
this.set_call_status();
|
||||
this.make_caller_info_section();
|
||||
this.dialog.get_close_btn().show();
|
||||
this.dialog.$body.addClass('call-popup');
|
||||
this.dialog.set_secondary_action(() => {
|
||||
clearInterval(this.updater);
|
||||
delete erpnext.call_popup;
|
||||
this.dialog.hide();
|
||||
});
|
||||
frappe.utils.play_sound("incoming_call");
|
||||
this.dialog.show();
|
||||
}
|
||||
|
||||
@ -112,7 +103,7 @@ class CallPopup {
|
||||
|
||||
set_call_status(call_status) {
|
||||
let title = '';
|
||||
call_status = call_status || this.call_log.call_status;
|
||||
call_status = call_status || this.call_log.status;
|
||||
if (['Ringing'].includes(call_status) || !call_status) {
|
||||
title = __('Incoming call from {0}',
|
||||
[this.contact ? `${this.contact.first_name || ''} ${this.contact.last_name || ''}` : this.caller_number]);
|
||||
@ -120,7 +111,7 @@ class CallPopup {
|
||||
} else if (call_status === 'In Progress') {
|
||||
title = __('Call Connected');
|
||||
this.set_indicator('yellow');
|
||||
} else if (call_status === 'missed') {
|
||||
} else if (call_status === 'Missed') {
|
||||
this.set_indicator('red');
|
||||
title = __('Call Missed');
|
||||
} else if (['Completed', 'Disconnected'].includes(call_status)) {
|
||||
@ -137,9 +128,10 @@ class CallPopup {
|
||||
this.call_log = call_log;
|
||||
this.set_call_status();
|
||||
}
|
||||
disconnect_call() {
|
||||
this.set_call_status('Disconnected');
|
||||
clearInterval(this.updater);
|
||||
|
||||
call_disconnected(call_log) {
|
||||
frappe.utils.play_sound("call_disconnect");
|
||||
this.update_call_log(call_log);
|
||||
}
|
||||
|
||||
make_last_interaction_section() {
|
||||
@ -147,12 +139,14 @@ class CallPopup {
|
||||
'number': this.caller_number,
|
||||
'reference_doc': this.contact
|
||||
}).then(data => {
|
||||
const comm_field = this.dialog.fields_dict["last_communication"];
|
||||
if (data.last_communication) {
|
||||
const comm = data.last_communication;
|
||||
// this.dialog.set_df_property('last_interaction', 'hidden', false);
|
||||
const comm_field = this.dialog.fields_dict["last_communication"];
|
||||
comm_field.set_value(comm.content);
|
||||
comm_field.$wrapper.append(frappe.utils.get_form_link('Communication', comm.name));
|
||||
} else {
|
||||
comm_field.$wrapper.hide();
|
||||
}
|
||||
|
||||
if (data.last_issue) {
|
||||
@ -176,9 +170,9 @@ $(document).on('app_ready', function () {
|
||||
erpnext.call_popup.dialog.show();
|
||||
}
|
||||
});
|
||||
frappe.realtime.on('call_disconnected', id => {
|
||||
if (erpnext.call_popup && erpnext.call_popup.call_log.call_id === id) {
|
||||
erpnext.call_popup.disconnect_call();
|
||||
frappe.realtime.on('call_disconnected', call_log => {
|
||||
if (erpnext.call_popup && erpnext.call_popup.call_log.id === call_log.id) {
|
||||
erpnext.call_popup.call_disconnected(call_log);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user