From 3a042b234e09c2660dc7add94db9cfb403d6a209 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Thu, 11 Jan 2024 15:10:11 +0530 Subject: [PATCH] fix: strip special characters while checking phone number while calling or receiving --- crm/twilio/twilio_handler.py | 7 +++++-- frontend/src/stores/contacts.js | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crm/twilio/twilio_handler.py b/crm/twilio/twilio_handler.py index 71a64461..66dd82cb 100644 --- a/crm/twilio/twilio_handler.py +++ b/crm/twilio/twilio_handler.py @@ -156,6 +156,9 @@ def get_twilio_number_owners(phone_number): 'owner2': {....} } """ + # remove special characters from phone number and get only digits also remove white spaces + # keep + sign in the number at start of the number + phone_number = ''.join([c for c in phone_number if c.isdigit() or c == '+']) user_voice_settings = frappe.get_all( 'Twilio Agents', filters={'twilio_number': phone_number}, @@ -200,8 +203,8 @@ class TwilioCallDetails: self.application_sid = call_info.get('ApplicationSid') self.call_sid = call_info.get('CallSid') self.call_status = self.get_call_status(call_info.get('CallStatus')) - self._call_from = call_from - self._call_to = call_to + self._call_from = call_from or call_info.get('From') + self._call_to = call_to or call_info.get('To') def get_direction(self): if self.call_info.get('Caller').lower().startswith('client'): diff --git a/frontend/src/stores/contacts.js b/frontend/src/stores/contacts.js index 4f5dcead..b8298d8a 100644 --- a/frontend/src/stores/contacts.js +++ b/frontend/src/stores/contacts.js @@ -13,6 +13,9 @@ export const contactsStore = defineStore('crm-contacts', () => { auto: true, transform(contacts) { for (let contact of contacts) { + // remove special characters from phone number to make it easier to search + // also remove spaces but keep + sign at the start + contact.mobile_no = contact.mobile_no.replace(/[^0-9+]/g, '') contactsByPhone[contact.mobile_no] = contact contactsByName[contact.name] = contact } @@ -26,6 +29,7 @@ export const contactsStore = defineStore('crm-contacts', () => { }) function getContact(mobile_no) { + mobile_no = mobile_no.replace(/[^0-9+]/g, '') return contactsByPhone[mobile_no] } function getContactByName(name) {