Caller ID name from contact DB cross tenants

Status
Not open for further replies.

MTR

Member
Oct 25, 2017
181
9
18
46
Hi

I set it up in the inbound route for tenant BB it should lookup callerid name from the contacts

But now i see that if tenant AA has a contact listed that callerid name will show up at tenant BB
 

MTR

Member
Oct 25, 2017
181
9
18
46
will try to write more details here about the BUG

i have a multi Domain system
  1. abc.com
  2. efg.com
at Domain abc.com i add this action set caller_id_name=${luarun cidlookup.lua ${uuid}} so if the end user adds my number in the contact list as "MTR great guy" this will show up as the callerID name. this worked perfect.

now a person at domain efg.com had add it my number into the contact list and for my name he used "my best friend", now the phones at domain abc.com will see "my best friend" as the callerID name and not "MTR great guy"

can anyone guide me on this?
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,519
437
83
@MTR, I have just set this up as you describe and I can confirm, that on my system, if I create two contacts one on each domain with the same number, the CID lookup always picks the same contact record irrespective of which inbound number I call.

I don't know why it's happening, it certainly feels like a bug, but I will do some digging and see what I can find out.
 

MTR

Member
Oct 25, 2017
181
9
18
46
I am very new to freepbx i am coming from asterisk freepbx

But my first tough on this is

I will need to see on the table how they link a contact to a domain

And make sure that the SQL query that does the lookup has the where domain = $domain
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,519
437
83
@MTR I'm just looking at it , I will let you know if I find anything. The SQL that gets executed for me is:
Code:
SELECT
CASE WHEN contact_name_given = ''
  THEN v_contacts.contact_organization
  ELSE v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_label || ')' END
  AS name FROM v_contacts
INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid
INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid
WHERE  v_contact_phones.phone_number = '033012XXXXX'

The domain constraint should be achieved by the "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid" but for me the query is returning five rows, three with one CID name and two with the other, I just need to work out why...
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,519
437
83
@MTR I'm not familiar with lua so it took me a while to establish that the domain was not being made available in an environment variable.

It would appear that the SQL in cidlookup.lua does not take domain in to account when looking in contacts for the CID. I hope someone will show us a better way of doing this but I fixed it by adding another command line argument to cidlookup.lua. So I now call it with:
Code:
caller_id_name=${luarun cidlookup.lua ${uuid} ${domain_uuid}}

Added the line domain_uuid = argv[2]; under uuid = argv[1];

Altered the SQL and parameters from:

Code:
 sql = sql .. "WHERE  v_contact_phones.phone_number = :caller "
   local params = {caller = caller}
to
Code:
    sql = sql .. "WHERE  v_contacts.domain_uuid = :domain_uuid and v_contact_phones.phone_number = :caller "
   local params = {caller = caller, domain_uuid = domain_uuid}

I hope that is helpful.
 
  • Like
Reactions: DigitalDaz

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,519
437
83
It's certainly a quick fix, I think to be a bug fix would need a little more work. The domain argument should be optional for backward compatibility. We should then test for the domain argument being present and adjust the SQL accordingly if that makes sense.
 
Status
Not open for further replies.