Caller ID Lookup (cidlookup) from Contacts.

EasyBB

Active Member
Time and time again those who are new to FusionPBX find it difficult to get cidlookup working from their contact list.

Inbound Route:
upload_2016-10-24_17-44-5.png



upload_2016-10-24_17-55-48.png

Now navigate to Advanced > XML Editor > autoload_configs > cidlookup.conf.xml and modify existing lines with these:

HTML:
<!--<param name="odbc-dsn" value="$${dsn_system}"/>-->
    <param name="odbc-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=fusionpbx user=fusionpbx password=your_db_password"/>
Code:
<param name="sql" value="
SELECT concat_ws(' ',v_contacts.contact_name_given,v_contacts.contact_name_family) AS name, v_contact_phones.phone_number AS number
FROM v_contacts, v_contact_phones
WHERE v_contact_phones.contact_uuid = v_contacts.contact_uuid AND (v_contact_phones.phone_number LIKE '%' || '${caller_id_number}')
LIMIT 1
      "/>
Once you've finished the edits, goto Status > SIP Status and hit 'Reload XML' and 'Flush Memcache'.
 
Last edited:

EasyBB

Active Member
Isn't this already part of the dialplan? You should have just have to enable it in the dialplan, right?
Yes and No :)

The cidlookup in the default dialplan is only good if your entry in the contact db matches exactly with the incoming caller id. I use multiple providers and the caller id formatting is all over the place. I store numbers in international format, e.g. 0061312341234 and using my method all below caller id formats will give you a positive match:
0061312341234
+61312341234
61312341234
0312341234
12341234

I've also seen different formats with the same provider as well; I think this happens when they accept calls from different upstream providers.
 
Hi, I've a strange behaviour. I created my own rest api to reply to fusionbx and it works great! The problem is when I receive calls from number starting with 0 (the number arrive without international prefix), it is striped when it is sent to my API.

So if the number is 02123456, fusionpbx try to make a cid of 2123456. I don't understand where the leading zero is striped!

Thanks a lot
 
If you have problems with imports use COALESCE and if you have spaces in phone number use regexp_replace and right in sql

You can play with this sql

SELECT trim( COALESCE(v_contacts.contact_name_given, ' ' ) || ' ' || COALESCE(v_contacts.contact_name_family, ' ' ) || ' (' || COALESCE(v_contacts.contact_organization, ' ' ) || ')') AS name, v_contact_phones.phone_number AS number
FROM v_contacts, v_contact_phones
WHERE v_contact_phones.contact_uuid = v_contacts.contact_uuid AND RIGHT(regexp_replace(v_contact_phones.phone_number , '[^0-9]*', '', 'g'), 9) LIKE RIGHT('%' || '${caller_id_number}',9)
LIMIT 1
 
Hi, I used this method for lookup the incoming number and all works well if I transfer the number directly to a telephone.
If i transfer the call to a call center and then to a telephone I lose the name of the caller and I see only the number.
How can I pass also the name to a call center?
Thank you.
 
I am trying to get all incoming calls to reference the Contacts for the Caller ID before displaying a caller ID

I believe I have everything as above but I must be off somewhere as it displays "UNKNOWN" on the sip device. Where did I go wrong?



<configuration name="cidlookup.conf" description="cidlookup Configuration">
<settings>
<!-- comment out url to not setup a url based lookup -->
<!--<param name="url" value="http://query.voipcnam.com/query.php?api_key=MYAPIKEY&number=${caller_id_number}"/>-->

<!-- comment out whitepages-apikey to not use whitepages.com, you must
get an API key from http://developer.whitepages.com/ -->
<!-- <param name="whitepages-apikey" value="MYAPIKEY"/>-->

<!-- set to false to not cache (in memcache) results from the url query -->
<param name="cache" value="true"/>
<!-- expire is in seconds -->
<param name="cache-expire" value="86400"/>

<param name="odbc-dsn" value="$${dsn_system}"/>
<!--<param name="odbc-dsn" value="/var/www/fusionpbx/secure/fusionpbx.db"/>-->

<!-- comment out sql to not setup a database (directory) lookup -->
<param name="sql" value="pgsql://hostaddr=127.0.0.1 dbname=fusionpbx user=fusionpbx password=iputdatabasepwhere"/>
<param name="sql" value="
SELECT concat_ws(' ',v_contacts.contact_name_given,v_contacts.contact_name_family) AS name, v_contact_phones.phone_number AS number
FROM v_contacts, v_contact_phones
WHERE v_contact_phones.contact_uuid = v_contacts.contact_uuid AND (v_contact_phones.phone_number LIKE '%' || '${caller_id_number}')
LIMIT 1
<!-- comment out citystate-sql to not setup a database (city/state)
lookup -->
<!--
<param name="citystate-sql" value="
SELECT ratecenter||' '||state as name
FROM npa_nxx_company_ocn
WHERE npa = ${caller_id_number:1:3} AND nxx = ${caller_id_number:4:3}
LIMIT 1
"/>
-->
</settings>
</configuration>
 

Attached Files:

ad5ou

Active Member
There were changes recently to cidlookup in master branch. The script as well as dial plan changed.
You might want to try upgrading, deleting the existing cidlookup dial plan then run app defaults to restore new “improved” dial plan.
 
I tried your suggestion and I thank you for it. Still no luck - It just passes the DID through as the Caller ID name and does not seem to reference the contact (Donald Duck for example in my attachment). Any guidance would be greatly appreciated. I attached 3 screenshots
 

Attached Files:

@Andrew Byrd I think the cidlookup method you are using uses the mod_cidlookup Freeswitch module. I have no experience with that.

I use the cidlookup.lua script provided by the FusionPBX distribution. This also had a small bug, have a look at:
https://github.com/fusionpbx/fusionpbx/pull/5134

I use cidlookup.lua in the inbound route, see the screenshot below, I'm not saying this is the correct way to do it but it works for me:
Screenshot from 2020-02-07 10-14-49.png