Asterisk and Called ID

We’re all familiar with Caller ID, when the phone rings you can see the name and number of the party who’s calling you. Recently I’ve dabbled a bit in getting the name of the Called party to show up on the phone when I dial a number. When calling extensions local to my PBX (peers configured in local sip.conf) it’s as simple as making sure sendrpid=pai in the general section of sip.conf

What about outgoing calls through the SIP trunk to my provider or out to Google Voice? Well first we need a reliable way to do the Caller ID Name lookup (CNAM), if you are in the US a service like OpenCnam may be of use however being in Canada I haven’t yet found a reliable lookup service. A few years ago I came across a script that searches etc to return the CNAM info, this was useful during a period when I was using a VoIP provider that didn’t forward reliable CNAM data for incoming calls. Now I can use this same script to show me the name data for whoever I’m calling (including businesses).

A copy of the latest iteration of the lookup script can be found here

Once the lookup script is working to your liking you’ll need to incorporate the following in extensions.conf:

exten => _NXXNXXXXXX,1,agi(callerid_shell.agi,${EXTEN})
exten => _NXXNXXXXXX,n,Set(CONNECTEDLINE(name,i)=${lookupname})
exten => _NXXNXXXXXX,n,Set(CONNECTEDLINE(name-pres,i)=allowed)
exten => _NXXNXXXXXX,n,Set(CONNECTEDLINE(num-pres)=allowed)
exten => _NXXNXXXXXX,n,Dial(Gtalk/googlevoice/+1${EXTEN},,I)

In the above example when I dial a number the lookup script is called, it returns the name associated with the number I dialed and I can see that name on my SIP phone when the line is connected.

Leave a Reply