fix: strip special characters while checking phone number while calling or receiving

This commit is contained in:
Shariq Ansari 2024-01-11 15:10:11 +05:30
parent 5d09a046d3
commit 3a042b234e
2 changed files with 9 additions and 2 deletions

View File

@ -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'):

View File

@ -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) {