fix: Get available employees from communication medium
This commit is contained in:
parent
44c0e9d549
commit
87645e98ad
@ -79,4 +79,18 @@ def add_call_summary(docname, summary):
|
||||
call_log.call_summary += '<br>' + content
|
||||
call_log.save(ignore_permissions=True)
|
||||
|
||||
def get_employee_emails_for_popup():
|
||||
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)
|
||||
|
||||
for group in available_employee_groups:
|
||||
employee_emails += [e.user_id for e in frappe.get_doc('Employee Group', group.employee_group).employee_list]
|
||||
|
||||
return employee_emails
|
||||
|
@ -1,5 +1,5 @@
|
||||
import frappe
|
||||
from erpnext.crm.doctype.utils import get_document_with_phone_number
|
||||
from erpnext.crm.doctype.utils import get_document_with_phone_number, get_employee_emails_for_popup
|
||||
import requests
|
||||
|
||||
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call
|
||||
@ -9,39 +9,34 @@ def handle_incoming_call(*args, **kwargs):
|
||||
exotel_settings = get_exotel_settings()
|
||||
if not exotel_settings.enabled: return
|
||||
|
||||
employee_email = kwargs.get('AgentEmail')
|
||||
status = kwargs.get('Status')
|
||||
|
||||
if status == 'free':
|
||||
# call disconnected for agent
|
||||
# "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
|
||||
|
||||
call_log = get_call_log(kwargs)
|
||||
|
||||
data = frappe._dict({
|
||||
'call_from': kwargs.get('CallFrom'),
|
||||
'agent_email': kwargs.get('AgentEmail'),
|
||||
'call_type': kwargs.get('Direction'),
|
||||
'call_log': call_log,
|
||||
'call_status_method': 'erpnext.erpnext_integrations.exotel_integration.get_call_status'
|
||||
})
|
||||
|
||||
frappe.publish_realtime('show_call_popup', data, user=data.agent_email)
|
||||
employee_emails = get_employee_emails_for_popup()
|
||||
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):
|
||||
close_call_log(kwargs)
|
||||
frappe.publish_realtime('call_disconnected', data=kwargs.get('CallSid'))
|
||||
update_call_log(kwargs, 'Completed')
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def handle_missed_call(*args, **kwargs):
|
||||
close_call_log(kwargs)
|
||||
frappe.publish_realtime('call_disconnected', data=kwargs.get('CallSid'))
|
||||
update_call_log(kwargs, 'Missed')
|
||||
|
||||
def close_call_log(call_payload):
|
||||
call_log = get_call_log(call_payload)
|
||||
def update_call_log(call_payload, status):
|
||||
call_log = get_call_log(call_payload, False)
|
||||
if call_log:
|
||||
call_log.status = 'Closed'
|
||||
call_log.call_status = status
|
||||
call_log.call_duration = call_payload.get('DialCallDuration') or 0
|
||||
call_log.save(ignore_permissions=True)
|
||||
frappe.db.commit()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user