VoIP Hacks: Tips & Tools for Internet Telephony
Hack 45. Forward Your Home Calls to Your Cell Phone
Using Asterisk, you can create a simple call forwarder, so calls to your home can follow you whenever you go. Asterisk is a programmable platform in the same way that the Apache Web Server is. There are many ways to program Asterisk, but all of them connect in some way to the core of Asterisk's functionalityits so-called "dial plan." The dial plan begins (and usually ends) in /etc/asterisk/extensions.conf. Using the dial plan, you can program how your softPBX should behave, which phones should ring when different digits are dialed, how long they should ring, and what to do if nobody answers when they ring. So, it's actually pretty straightforward to program the dial plan to forward all incoming calls from a certain line to another phone number via a second line. There are many uses for this, including having your phone calls follow you wherever you go, as well as using the Asterisk server as a screen so that you don't have to give people the number you are forwarding to. This is a great way to keep your cell phone or parents' home phone number private. The Asterisk server will dial the cell phone on the second line and then bridge (or conference) the two lines together for the duration of the call. The hardest part about setting up this configuration is connecting two lines (or two SIP peers acting as lines [Hack #43] to the Asterisk server. Once that's done, the forwarding part is simple. But before we get to that, let's check out the configuration for the two lines. Let's assume that two SIP peers are connected to the Asterisk server, vis-à-vis a media gateway with two SIP clients, like the Clipcomm used earlier [Hack #43]. The sip.conf configuration for these peers would look something like this: [7711] caller <200> canreinvite=no context=incoming dtmfmode=rfc2833 host=dynamic port=5060 type=friend username=7711 [7712] caller <201> canreinvite=no context=default dtmfmode=rfc2833 host=dynamic port=5060 type=friend username=7712 Line 1 is SIP peer 7711, and line 2 is SIP peer 7712. Let's say that the line we're going to receive calls on is line 1, and the line we're going to use to call the cell phone is line 2. Note context=incoming. This creates a context within Asterisk for incoming calls to arrive. Now, open up extensions.conf so that you can create a dial plana set of instructions that tell Asterisk what to do in this incoming contextto correspond to peer 7711's incoming context setting: [incoming] exten => s,1,Dial(SIP/7712/${CELL_PHONE},30) exten => s,2,Playback(abandon-all-hope) exten => s,3,Hangup
Since sip.conf indicates that all incoming calls from SIP peer 7711 should enter the incoming context, we've created that context in the dial plan (as shown in the previous code snippet). Using the special s extension, whose purpose is to incorporate into the context incoming calls that haven't been triggered by a user dialing an extension number (calls like those incoming from the outside world), we can specify three steps to deal with the call:
So, when an incoming call from SIP peer 7711 hits the server, SIP peer 7712 (the "second line") will be directed to call your cell phone and attempt to bridge the call. I know what you're thinking: "Why wouldn't I just use my phone line's built-in call-forwarding service to do this?" My answer is "Selectively Forward Calls" [Hack #46]. |
Категории