From 03c3bd5f4a2f61361a0ae6511ae01e5a01cdf7bf Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Thu, 16 May 2019 13:39:50 +0530 Subject: [PATCH] feat: Open modal in realtime for incoming call --- erpnext/crm/call_summary/call_summary_utils.py | 6 ++++-- erpnext/crm/call_summary/exotel_call_handler.py | 12 ++++++++++++ erpnext/public/js/call_summary_dialog.js | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 erpnext/crm/call_summary/exotel_call_handler.py diff --git a/erpnext/crm/call_summary/call_summary_utils.py b/erpnext/crm/call_summary/call_summary_utils.py index 822fb3e038e..0b6131ffd89 100644 --- a/erpnext/crm/call_summary/call_summary_utils.py +++ b/erpnext/crm/call_summary/call_summary_utils.py @@ -2,8 +2,10 @@ import frappe @frappe.whitelist() def get_contact_doc(phone_number): - contacts = frappe.get_all('Contact', filters={ - 'phone': phone_number + phone_number = phone_number[-10:] + contacts = frappe.get_all('Contact', or_filters={ + 'phone': ['like', '%{}%'.format(phone_number)], + 'mobile_no': ['like', '%{}%'.format(phone_number)] }, fields=['*']) if contacts: diff --git a/erpnext/crm/call_summary/exotel_call_handler.py b/erpnext/crm/call_summary/exotel_call_handler.py new file mode 100644 index 00000000000..82c925de064 --- /dev/null +++ b/erpnext/crm/call_summary/exotel_call_handler.py @@ -0,0 +1,12 @@ +import frappe + +@frappe.whitelist(allow_guest=True) +def handle_request(*args, **kwargs): + r = frappe.request + + payload = r.get_data() + + print(r.args.to_dict()) + print(payload) + + frappe.publish_realtime('incoming_call', r.args.to_dict()) \ No newline at end of file diff --git a/erpnext/public/js/call_summary_dialog.js b/erpnext/public/js/call_summary_dialog.js index c4c6d483eb7..17bf7b97666 100644 --- a/erpnext/public/js/call_summary_dialog.js +++ b/erpnext/public/js/call_summary_dialog.js @@ -1,6 +1,6 @@ -frappe.call_summary_dialog = class { +class CallSummaryDialog { constructor(opts) { - this.number = '+91234444444'; + this.number = opts.number; this.make(); } @@ -15,10 +15,18 @@ frappe.call_summary_dialog = class { if (!res) { this.$modal_body.html('Unknown Contact'); } else { - this.$modal_body.html(`${res.first_name}`); + this.$modal_body.append(`${frappe.utils.get_form_link('Contact', res.name, true)}`) } }); d.show(); } +} -}; \ No newline at end of file +$(document).on('app_ready', function() { + frappe.realtime.on('incoming_call', data => { + const number = data.CallFrom; + frappe.call_summary_dialog = new CallSummaryDialog({ + number + }); + }); +});