VoIPowering Your Office with Asterisk: Dealing with Wanted and Unwanted Callers

We’re rolling right along here with our hotrod customized Asterisk PBX server.
Today we’re going to harness the power of Caller ID to configure Asterisk to
forward calls based on who is trying to call us. Then we’ll have a little fun
with callers we don’t want to talk to, like telemarketers and bossy older siblings.

Asterisk comes with a lot of fun soundfiles for getting your point across,
like carried-away-by-monkeys, busy-hangovers, abandon-all-hope,
go-away1 and go-away2, and something-terribly-wrong. Or
have even more fun and record your own custom kiss-offs. (See VoIPowering
Your Office with Asterisk: SOHO VoIP, Part 6
to learn how to record custom

Restarting after making changes
Any time a configuration file is changed the changes have to be reloaded. The simple way is to restart the whole server:

# /etc/init.d/asterisk restart

See VoIPowering Your Office With Asterisk: Moving to the Grownup Version for more Asterisk and Linux administration tips.

Selective forwarding
First of all you need Caller ID service. You might have to pay for it, or you might have a great service provider who throws it in for free. These days it seems that all VoIP providers provide it for free, but you still get stuck paying extra for it on PSTN lines.

Then you need to open up our old friend extensions.conf and go to work. First of all we’re going to learn about setting variables. Asterisk has both built-in variables and user-defined variables. Asterisk’s built-in variables are documented here.

User-defined variables can be set either globally, or limited to a single channel. (Yes, more of Asterisk’s famous infinite flexibility in action.) Setting global variables is done in the [globals] section of extensions/conf. This example shows how to create variables for your cell phone number and Mom’s home phone:

ALRACCELL = 4445556677
ALRACMOM = 2223334455

Using variables reduces both hair loss and blood pressure, because it means making one change instead of having to hunt down and change many individual entries.

Now let’s set up an example context that forwards Mom’s call to Alrac’s personal secret cell phone. Mom’s number is specified in the context and is forwarded to Alrac’s cell phone, while all other callers get routed to Alrac’s office phone.

exten => s,1,GotoIf($["${CALLERID(num)}" = "${ALRACMOM}"]?4:2)
exten => s,2,Dial(SIP/alrac,10,r)
exten => s,3,VoiceMail([email protected])
exten => s,4,Dial(${ALRACCELL},30)
exten => s,5,Hangup

We set up voicemail way back in VoIPowering Your Office with Asterisk: SOHO VoIP, Part 4 if you need a refresher.

What if your bossy big brother calls to deliver his usual ration of unsolicited bad advice? Create another variable (ALRACBRO), play the message of your choice and then hangup by adding a second GotoIf line. Remember to change your priorities accordingly:

exten => s,1,GotoIf($["${CALLERID(num)}" = "${ALRACMOM}"]?5:3)
exten => s,2,GotoIf($["${CALLERID(num)}" = "${ALRACBRO}"]?6:3)
exten => s,3,Dial(SIP/alrac,10,r)
exten => s,4,VoiceMail([email protected])
exten => s,5,Dial(${ALRACCELL},30)
exten => s,6,Playback(you-are-not-the-boss-of-me)
exten => s,7,Hangup

Zapping telemarketers
I’m not really a vindictive person. Not very, anyway. So if the following instructions aren’t your cup of tea it won’t hurt my feelings for you to ignore them, even if they are extremely mild compared to last week’s Telemarketer Torture.

Asterisk comes with a neat little application called Zapateller, which is like the Telezapper on the infomercials. It plays a tone to fool auto-dialers into believing your line has been disconnected. Usually this causes them to hang up, and to mark your line as being out of service. If an incoming call has no caller ID, Zapateller swings into action. You might use it on all of your incoming calls, like this modified [default] context from VoIPowering Your Office with Asterisk: SOHO VoIP, Part 5 shows:

exten => s,1,Zapateller(answer|nocallerid)
exten => s,2,DigitTimeout,5
exten => s,3,ResponseTime,10
exten => s,4,Background(local/foo-main-greeting)

This is a pretty big club because a lot of people block their phone numbers for privacy reasons, so use Zapateller carefully. An alternative is to use the Privacy Manager application. If an incoming call has its number blocked, the caller is requested to enter their 10-digit number. If they don’t, they suffer such consequences as you deem fitting. Best of all, your phone never rings until approved calls are routed through; you won’t hear ringing on rejected calls.

This example answers incoming calls, requests the caller’s number, then routes it normally when a 10-digit number is entered, or plays our custom “Sorry, we’re dead” greeting and hangs up. Note the priority numbering; Privacy Manager routes rejected calls to the current priority + 100. This is a bit confusing; just remember that the current priority is the next one in line. So in this example it is 102, not 101.

exten => s,1,PrivacyManager
exten => s,2,DigitTimeout,5
exten => s,3,ResponseTime,10
exten => s,4 Background(local/foo-main-greeting)
exten => s,102,Playback(sorry-we're-dead)
exten => s,103,Hangup

Relax and enjoy
Now that Asterisk is vigilantly guarding your phone system, kick back and have a nice cup of tea. The come back next week to learn how to do conferencing. Conferencing is something that Asterisk does exceptionally well, and for a fraction of the cost of commercial conferencing services.

Your Office with Asterisk: Mastering Dialplan Basics

Index to the entire Asterisk series

Previous articleTinker for Freedom
Next articleUnder the Hood with IPv6

Latest Articles

Follow Us On Social Media

Explore More