feat(exotel): make use of `CustomField` in API (#33338)
* feat(exotel): pass kwargs for `make_a_call`
https://developer.exotel.com/api/make-a-call-api#call-agent
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* feat(exotel): map custom field to doctype
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
diff --git a/erpnext/erpnext_integrations/exotel_integration.py b/erpnext/erpnext_integrations/exotel_integration.py
index fd0f783..0d40667 100644
--- a/erpnext/erpnext_integrations/exotel_integration.py
+++ b/erpnext/erpnext_integrations/exotel_integration.py
@@ -72,6 +72,24 @@
return frappe.get_doc("Call Log", call_log_id)
+def map_custom_field(call_payload, call_log):
+ field_value = call_payload.get("CustomField")
+
+ if not field_value:
+ return call_log
+
+ settings = get_exotel_settings()
+ target_doctype = settings.target_doctype
+ mapping_enabled = settings.map_custom_field_to_doctype
+
+ if not mapping_enabled or not target_doctype:
+ return call_log
+
+ call_log.append("links", {"link_doctype": target_doctype, "link_name": field_value})
+
+ return call_log
+
+
def create_call_log(call_payload):
call_log = frappe.new_doc("Call Log")
call_log.id = call_payload.get("CallSid")
@@ -79,6 +97,7 @@
call_log.medium = call_payload.get("To")
call_log.status = "Ringing"
setattr(call_log, "from", call_payload.get("CallFrom"))
+ map_custom_field(call_payload, call_log)
call_log.save(ignore_permissions=True)
frappe.db.commit()
return call_log
@@ -93,10 +112,10 @@
@frappe.whitelist()
-def make_a_call(from_number, to_number, caller_id):
+def make_a_call(from_number, to_number, caller_id, **kwargs):
endpoint = get_exotel_endpoint("Calls/connect.json?details=true")
response = requests.post(
- endpoint, data={"From": from_number, "To": to_number, "CallerId": caller_id}
+ endpoint, data={"From": from_number, "To": to_number, "CallerId": caller_id, **kwargs}
)
return response.json()