fix: Decouple call popup from exotel

This commit is contained in:
Suraj Shetty 2019-06-17 08:46:38 +05:30
parent 3fdeffff7a
commit 5ea6a5e33a
3 changed files with 19 additions and 13 deletions

View File

@ -3,8 +3,17 @@
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
import frappe
from frappe.model.document import Document
from erpnext.crm.doctype.utils import get_employee_emails_for_popup
class CallLog(Document):
pass
def after_insert(self):
employee_emails = get_employee_emails_for_popup(self.medium)
for email in employee_emails:
frappe.publish_realtime('show_call_popup', self, user=email)
def on_update(self):
doc_before_save = self.get_doc_before_save()
if doc_before_save.status in ['Ringing'] and self.status in ['Missed', 'Completed']:
frappe.publish_realtime('call_{id}_disconnected'.format(id=self.id), self)

View File

@ -1,5 +1,4 @@
import frappe
from erpnext.crm.doctype.utils import get_employee_emails_for_popup
import requests
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call
@ -17,14 +16,9 @@ def handle_incoming_call(*args, **kwargs):
call_log = get_call_log(kwargs)
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):
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):

View File

@ -2,6 +2,7 @@ class CallPopup {
constructor(call_log) {
this.caller_number = call_log.from;
this.call_log = call_log;
this.setup_listener();
this.make();
}
@ -187,6 +188,13 @@ class CallPopup {
}
});
}
setup_listener() {
frappe.realtime.on(`call_${this.call_log.id}_disconnected`, call_log => {
this.call_disconnected(call_log);
// Remove call disconnect listener after the call is disconnected
frappe.realtime.off(`call_${this.call_log.id}_disconnected`);
});
}
}
$(document).on('app_ready', function () {
@ -198,9 +206,4 @@ $(document).on('app_ready', function () {
erpnext.call_popup.dialog.show();
}
});
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);
}
});
});