Asterisk 101: Some CallerID Tips & Tricks

If you're relatively new to Internet Telephony and VoIP, then it may come as a bit of a surprise when CallerID for incoming calls shows the phone number for both the name and number of the incoming caller or when names that popped up using your plain old telephone's CallerID service no longer do. The problem is that most telephone providers only deliver a CallerID number when sending calls. Thus it is left to your service provider to look up the incoming number in a directory and supply the matching name. To put it another way, CallerID numbers are pushed to recipients, but CallerID names must be pulled from in-house databases. With Ma Bell and siblings, this was easy because they had all of the records. With some Internet Telephony Hosting Providers, it's a different story. The reverse is also problematic. Even though you may provide a CallerID name and number, most telephone companies throw the supplied CallerID name in the bit bucket and do their own lookups. So... if you're not in their directory, your number or nothing will be supplied instead of your actual name. Just another last vestige of monopoly preservation. With Asterisk®, the simplest solution to this mess is to do your own lookups. And today we have an updated CallerID directory lookup service to assist: the CallerID Superfecta.

NOTE: This article has been superseded. Continue reading the latest article here.

We have a second utility as well. Since moving to PBX in a Flash and Asterisk 1.4 and 1.6, we haven't provided a simple way to block or screen anonymous calls, i.e. those that show up in CallerID as either blank, anonymous, unknown, private, restricted, or toll free number. As they say, those are the usual suspects when it comes to weeding out unwanted callers. And today we'll provide several solutions from which you can choose. Our personal preference is to never answer these calls and route them straight to voicemail. You may be more curious than we are so we'll show you an option to screen calls using the Asterisk Parking Lot feature. Still others may hate these callers so much that you send them into IVR hell for hours at a time. And we've got some suggestions on that one, too.

Introducing CallerID Superfecta. We've dusted off an oldie but goodie today and reworked it a bit for newer versions of PHP. We also want to thank taiter and M Joyner for their whitepages.ca contribution to what used to be our CallerID Trifecta. The CallerID Superfecta now lets you choose up to four CallerID lookup sources for your incoming calls. The sources include the Google Phonebook, AnyWho, WhitePages, and our very own AsteriDex address book and robodialer. Complete installation instructions are available from our Best of Nerd Vittles site.

Installation and setup is a snap on all of the FreePBX-based aggregations including PBX in a Flash, Elastix, and trixbox. First, download and unzip the callerid.zip file into the root directory of the web server on your Asterisk system. Next, configure the sources you wish to use in callerid.php by setting the desired sources to 1 instead of 0 on the second page of the file. Then define the new CallerID Lookup Source in FreePBX. And finally, select the CallerID Superfecta as the lookup source for each of your Inbound Routes. The whole setup should take you less than two minutes. Now sit back and enjoy a much enhanced CallerID experience when incoming calls arrive on your Asterisk server.

Introducing the Creep Detector. Well, not so fast. The CallerID Superfecta doesn't get rid of the creeps that call wanting to sell you something or urging you to vote for your favorite Coroner. For that, you'll need a couple of tools. FreePBX includes an excellent web-based implementation of the Asterisk Blacklist. It allows you to specify the phone numbers of calls that should be blocked. You also can do this with a phone on your system by dialing *32 to blacklist the last caller or *30 to blacklist a specific phone number.

But, what about blacklisting all of those anonymous callers. Well, there's not an existing function in FreePBX to do it. Our preferred method goes like this. When an incoming call arrives, a message plays saying "Thanks for calling the Mundy's. Please hold a moment while I connect your call." During this message, a Stealth AutoAttendant will allow family members to press various buttons to be connected to various extensions. See the previous article for details. Once the IVR times out (in about 5 seconds), the call is passed to a Privacy Checker which screens the calls for creeps. If the call isn't identified as such, it is sent to a ring group. If a creep is detected, the system first plays a message that says: "Press 8 to be connected." If no key is pressed, we hang up. If 8 is pressed, the call goes to voicemail 704. If 4 is pressed, the call is passed to the ring group. This lets friends calling from phones with CallerID blocked still get through the maze.

So here's how to get it installed and working. Log into your server as root and add the following code snippet to the bottom of /etc/asterisk/extensions_custom.conf:

[custom-privacy-check]
exten => s,1,SetMusicOnHold(default)
exten => s,2,GotoIf($["${CALLERID(num)}" = ""]?s,16)
exten => s,3,GotoIf($["foo${CALLERID(num)}" = "foo"]?s,16)
exten => s,4,GotoIf($["${CALLERID(name):1:8}" = "nonymous"]?s,16)
exten => s,5,GotoIf($["${CALLERID(name):1:6}" = "nknown"]?s,16)
exten => s,6,GotoIf($["${CALLERID(num):1:6}" = "rivate"]?s,16)
exten => s,7,GotoIf($["${CALLERID(name):1:6}" = "rivate"]?s,16)
exten => s,8,GotoIf($["${CALLERID(num):1:9}" = "estricted"]?s,16)
exten => s,9,GotoIf($["${CALLERID(num):0:4}" = "PSTN"]?s,16)
exten => s,10,GotoIf($["${CALLERID(num):1:3}" = "oll"]?s,16)
exten => s,11,GotoIf($["${CALLERID(name):1:2}" = "--"]?s,16)
exten => s,12,GotoIf($["${CALLERID(name):0:1}" = ","]?s,16)
exten => s,13,GotoIf($["${CALLERID(name):1:3}" = "oll"]?s,16)
exten => s,14,GotoIf($["${CALLERID(num):0:3}" = "000"]?s,16)
exten => s,15,Dial(Local/777@from-internal)
exten => s,16,Playback(custom/nv-press8)
exten => s,17,Set(TIMEOUT(digit)=10)
exten => s,18,WaitExten(10)
exten => s,19,Hangup
exten => 4,1,Dial(Local/777@from-internal)
exten => 4,2,Hangup
exten => 8,1,VoiceMail(704@default)
exten => 8,2,Hangup

You'll need to make a couple of changes in the code above before using it. In lines s,14 and 4,1, modify extension 777 to reflect an extension or ring group on your phone system that you want to call after incoming calls are screened for creeps. In line 8,1, modify 704 to reflect a voicemail box that is active on your system and that should be used for recording messages from unwanted callers.

The next step is to add the "Press 8 to be connected" message to your system. While still logged in as root, issue the following commands:

cd /var/lib/asterisk/sounds/custom
wget http://bestof.nerdvittles.com/applications/callerid/nv-press8.wav
chown asterisk:asterisk nv-press8.wav
chmod +x nv-press8.wav

Now we need to configure your FreePBX setup to use the code above. The easiest way is to modify your Stealth AutoAttendant IVR and simply change the timeout destination (t) to a Custom App: custom-privacy-check,s,1. Save your changes and reload your dialplan, and you're all set.

Some additional ideas have also been floated on the PBX in a Flash Forum for handling anonymous callers. If you'd prefer to park these calls and announce them, see this thread. And here's an embellished version that gives you options to accept the call, send it to voicemail, or banish the caller. Enjoy!


Vitelity Special: Time Is Running Out. Remember, you only have one more week until July 15 to get your half-price DIDs and 60 free minutes from our special Vitelity sign-up link. If you're seeking the best flexibility in choosing an area code and phone number plus the lowest entry level pricing plus high quality calls, then Vitelity is the hands-down winner. Vitelity provides Tier A DID inbound service in over 3,000 rate centers throughout the US and Canada. And, when you use our special link to sign up, the Nerd Vittles and PBX in a Flash projects get a few shekels down the road while you get an incredible signup deal as well. The going rate for Vitelity's DID service is $7.95 a month which includes up to 4,000 incoming minutes on two simultaneous channels with terminations priced at 1.45¢ per minute. Not any more! For PBX in a Flash users, here's a deal you can't (and shouldn't) refuse! Sign up before the end of June, and you can purchase a Tier A DID with unlimited incoming calls for just $3.79 a month and you get a free hour of outbound calling to test out their call quality. To check availability of local numbers and tiers of service from Vitelity, click here. Do not use this link to order your DIDs, or you won't get the special pricing! After the free hour of outbound calling, Vitelity's rate is just 1.44¢ per minute for outbound calls in the U.S.


Some Recent Nerd Vittles Articles of Interest...

Be Sociable, Share!

9 Responses to “Asterisk 101: Some CallerID Tips & Tricks”

  1. Steve says:

    Thanks. As a home user, I’ve implemented this and would love to see it officially worked in to FreePBX. The only present GUI way is to catch them with the Privacy manager.

  2. Ryan says:

    Ward – Thanks this is great. I just moved over to PBX in a Flash yesterday and the one thing I could not get to work was the mySQL query source for callerid lookup. I installed this yesterday and now I am back in business – Thanks! Also about 6-8 months ago I exported my contacts from my MS Exchange server and used a little MS Access macro to dedup and then append to the Asteridex mySQL table using an ODBC connection. Since the contacts were the Global Contacts for the entire company everyone’s callerID shows the callers First Name, Last Name and Location (Office, Home, Mobile) as the CallerID. my entire company loves it. I cannot program but if you think this would be valuable I could explain in more detail how its done.

    [WM: Sounds terrific. By all means, tell us more. Or better yet, post it on the PBX in a Flash Forum.]

  3. Maxim says:

    check out http://www.whocalled.us – probably the most comprehensive telemarketer caller-ID database. there’s a junk_lookup.agi script on there I submitted to the owner of the web-site. With junk_lookup.agi and whocalled.us I have NEVER EVER had another call from a telemarketer again.

  4. vanDivX says:

    why remaind us of the great Vitelity deal when you need some ‘secret’ pass on the bottom of the form you get to when you click the link you provide, apparently it is a deal reserved only for your $199 EPC customers, at least that’s how it looks to me

    [WM: The code you need should be displayed just to the right of the prompt unless your browser is verrrrrrrrrry old and cannot display GIF images. It was only intended to keep the automated creeps away from the link.]

  5. Harold says:

    We have a PRI connected to our PIAF unit and it shows the caller id name as the number just as you spoke about in the article. BUT if I put the PRI into debug with “pri debug span” I see the name displayed in the debug “Smith, John” yet ${CALLERID(name)} returns “555-555-1212″.

    [WM: Post this in the forums. We have lots of PRI experts, but I'm not one of them.]

  6. Raoul says:

    Is there anyone out there who has modified this to search for Australian numbers from http://www.whitepages.com.au? If so, I would love to know how to do it :)

  7. mark says:

    Thanks for the tip, however I’m a newb and don’t understand what you mean by “simply change the timeout destination (t) to a Custom App: custom-privacy-check,s,1.” I know to put t as the destination, but I don’t see any option of “Custom App” as a destination.

    Thanks!!

  8. Dennis says:

    AnyWho is no longer working. The URL format have changed. format before was http://www.anywho.com/qry/wp_rl?npa=$npa&telephone=$telephone but now it has changed to

    http://whitepages.anywho.com/results.php?ReportType=33&qi=0&qk=10&qnpa=612&qnpanxx=612392&qnpanxx7=6123925&qnxx=392&qp=3925549&qstation=5549

    [WM: We're way ahead of you this time. Just download the update and replace /var/www/html/callerid.php.]

    http://bestof.nerdvittles.com/applications/callerid/callerid.zip

  9. Mark Cochenour says:

    We have a Grandstream GXP2000 and it is showing the incoming Caller ID information for blocked incoming calls. Any ideas on why this is happening and how to prevent it? the same SIP account on a PAP2 does NOT show the blocked calling party information. Since Callin Party Number Blocking is an FCC required service for Interstate calls we need to figure this out ASAP.

Leave a Reply

Ringbinder theme by Themocracy