From ec41f8efcac5b68b774f5001fc18f68f340c4aed Mon Sep 17 00:00:00 2001 From: Adrian Fretwell Date: Sat, 18 May 2019 12:21:33 +0100 Subject: [PATCH] Update cidlookup.lua Added and optional parameter, argv[2], to take a domain_uuid. This is to fix an issue where if two contact records exist with the same phone number, but in different domains, the CID lookup would always pick the same contact record irrespective of which domain the inbound number belonged to. --- resources/install/scripts/cidlookup.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/resources/install/scripts/cidlookup.lua b/resources/install/scripts/cidlookup.lua index 6dd990b85a..eaeea3b7dc 100644 --- a/resources/install/scripts/cidlookup.lua +++ b/resources/install/scripts/cidlookup.lua @@ -22,9 +22,10 @@ -- Contributor(s): -- Luis Daniel Lucio Quiroz -- Riccardo Granchi +-- Adrian Fretwell -- -- add this in Inbound Routes before transfer to use it: --- action set caller_id_name=${luarun cidlookup.lua ${uuid}} +-- action set caller_id_name=${luarun cidlookup.lua ${uuid} ${domain_uuid}} --define the trim function require "resources.functions.trim" @@ -35,6 +36,7 @@ --create the api object api = freeswitch.API(); uuid = argv[1]; + domain_uuid = argv[2]; if not uuid or uuid == "" then return end; caller = api:executeString("uuid_getvar " .. uuid .. " caller_id_number"); callee = api:executeString("uuid_getvar " .. uuid .. " destination_number"); @@ -86,8 +88,15 @@ end sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid "; sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid "; - sql = sql .. "WHERE v_contact_phones.phone_number = :caller " - local params = {caller = caller} + + local params; + if ((not domain_uuid) or (domain_uuid == "")) then + sql = sql .. "WHERE v_contact_phones.phone_number = :caller "; + params = {caller = caller}; + else + sql = sql .. "WHERE v_contacts.domain_uuid = :domain_uuid and v_contact_phones.phone_number = :caller "; + params = {caller = caller, domain_uuid = domain_uuid}; + end if (debug["sql"]) then freeswitch.consoleLog("notice", "[cidlookup] SQL: "..sql.."; params:" .. json.encode(params) .. "\n");