Hack46.Selectively Forward Calls

Hack 46. Selectively Forward Calls

You can pass caller ID signals into Asterisk, and have them acted on appropriatelyincluding auto-ignoring the people you don't want to speak to.

By making some clever use of Asterisk's built-in caller ID channel variable and a little workflow logic, it's easy to turn your call-forwarding project from the previous hack into something even more useful. In this hack, we'll make Asterisk forward calls to your cell phone only if they're from a certain caller ID. That way, you need only be bothered with answering your cell phone if dear old Mom is calling (or your boss).

Asterisk refers to the one or more voice communication links of a phone call as channels. So, when a call-forwarding setup that uses two SIP peers is active, it's said to use two channels. Each channel has with it a number of channel-specific variables that contain information about the ongoing call. When the call ends, the channels, and these channel-specific variables, disappear. One of these variables is ${CALLERIDNUM}, which contains the phone number of the calling party, as signaled by the calling peer. (On the PSTN, caller ID signals originate from the exchange switch of the calling party.) We can use this variable to figure out whether we want to forward a call.

Unless you're paying for caller ID service, your Asterisk server won't receive caller ID signals, and this hack won't work. Some phone companies (and just about all VoIP service providers) include caller ID for free.

Consider the following:

 [incoming] ; Priority 1: Check to see if the call is Mom's home phone. ; If so, go to priority 5; if not, continue to priority 2. exten => s,1,GotoIf($["${CALLERIDNUM}" = "3138853352"]?5:2) ; Priority 2: See if the call is Mom's cell phone. ; If so, go to priority 5; if not, continue to priority 3. exten => s,2,GotoIf($["${CALLERIDNUM}" = "3132981848"]?5:3) ; Priority 3 and 4: This call's not Mom, so just drop it. exten => s,3,Playback(carried-away-by-monkeys) exten => s,4,Hangup ; Priority 5: Dial my cell phone for 30 seconds to connect Mom. exten => s,5,Dial(${MYCELLPHONE},30) ; Priority 6 and 7: If not answered in time, drop the call. exten => s,6,Playback(carried-away-by-monkeys) exten => s,7,Hangup 

Note the syntax of the GotoIf command. If you're familiar with logic control structures in programming, the ? should look like a "then" in an if-then workflow statement. A colon (:) separates the then-target from the else-target. The targets correspond to the step numbers in each of the exten directives, of course.

If you think Asterisk dial-plan syntax is atrocious, well, you're right. Don't get too hung up on it now, though. There are some good references out there for Asterisk dial-plan commands, including http://www.voip-info.org/ and the unforgettable classic, Switching to VoIP (O'Reilly). For now, just keep hacking, and you'll get comfy.

4.7.1. Hacking the Hack

With a little modification, you should be able to forward incoming calls to different numbers, depending on their caller ID values. Just rearrange the previous example so that each GotoIf numbered target step contains a Dial command with a different phone numberone for Mom, one for Dad, etc. You can even forward calls with no caller ID signals (like those from telemarketers) to a fun destination [Hack #48].

VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net