Free Calling with Google Voice and Asterisk
I've been playing with Asterisk and Google Voice for the better part of a year now, and just recently was finally able to get it all working the way I wanted it to. When Google started letting you make phone calls using Voice from Gmail, they opened up the ability to make phone calls over gtalk, their XMPP/Jabber based IM/Voice/Video service. When I heard that, I thought it would be a piece of cake to get Voice working with Asterisk's Jabber/Jingle channel... nope! In fact, Voice didn't start working with Asterisk until 1.8.1 which is what I was waiting to finally become stable enough to use. Then after a few more problems with Asterisk breaking support for my Cisco 7960 (SIP) which was finally fixed in 1.8.4.4. Now that you've heard my life story, here's how I got that working.
Prerequisites
- A modern Linux box, I'm running OpenSUSE 11.4 Kernel 2.6.37.1
- Asterisk 1.8.1.1 or newer, I'm running 1.8.4.4 (to get support for my Cisco 7960 SIP)
- Some sort of VoIP phone connected to your Asterisk box, soft or hard
Google Voice Setup
You need to, of course, have a Google account, with Voice enabled, and Gmail calling turned on as well. Once you have that setup, make sure that you change the Chat setting from the default of "Automatically allow people that I communicate with often to chat with me and see when I'm online" to the second option of "Only allow people that I've explicitly approved to chat with me and see when I'm online."
Asterisk Setup
On the Asterisk side, things aren't quite as easy. You'll want to make sure you have at least the chan_gtalk and the res_jabber modules compiled and installed before proceeding or else none of this will work. I of course needed things like chan_sip as well to work with my Cisco 7960. In your Asterisk configuration directory (usually /etc/asterisk) you'll need these conf files to look at least like this:
/etc/asterisk/gtalk.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [general] context=local ; Context to dump call into bindaddr=10.8.2.5 ; Address to bind to ;externip=1.2.3.4 ; Set your external ip if you are behind a NAT. ;stunaddr=mystunserver.com ; Get your external ip from a STUN server. ; Note, if the STUN query is successful, this will ; replace any value placed in externip; allowguest=yes ; Allow calls from people not in list of peers [guest] ; special account for options on guest account disallow=all allow=ulaw context=local connection=asterisk |
/etc/asterisk/jabber.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | [general] debug=no ; Enable debugging (disabled by default). autoprune=no ; Auto remove users from buddy list. Depending on your ; setup (ie, using your personal Gtalk account for a test) ; you might lose your contacts list. Default is 'no'. autoregister=yes ; Auto register users from buddy list. ;collection_nodes=yes ; Enable support for XEP-0248 for use with ; distributed device state. Default is 'no'. ;pubsub_autocreate=yes ; Whether or not the PubSub server supports/is using ; auto-create for nodes. If it is, we have to ; explicitly pre-create nodes before publishing them. ; Default is 'no'. ;auth_policy=accept ; Auto accept users' subscription requests (default). ; Set to deny for auto denial. [asterisk] type=client ; Client or Component connection serverhost=talk.google.com ; Route to server for example, talk.google.com ;pubsub_node=pubsub.astjab.org ; Node to use for publishing events via PubSub username=butters08@gmail.com/Talk ; Username with optional resource. (must be /Talk for Voice) secret=XXXXXXXXXXXXXXXX ; Google Password ;priority=1 ; Resource priority port=5222 ; Port to use defaults to 5222 usetls=yes ; Use tls or not usesasl=yes ; Use sasl or not ;buddy=mogorman@astjab.org ; Manual addition of buddy to list. ; For distributed events, these buddies are ; automatically added in the whitelist as ; 'owners' of the node(s). ;distribute_events=yes ; Whether or not to distribute events using ; this connection. Default is 'no'. status=away ; One of: chat, available, away, xaway, or dnd statusmessage="I'm an Asterisk Server!" ; Have custom status message for Asterisk timeout=100 ; Timeout (in seconds) on the message stack, defaults to 5. ; Messages stored longer than this value will be deleted by Asterisk. ; This option applies to incoming messages only, which are intended to ; be processed by the JABBER_RECEIVE dialplan function. |
/etc/asterisk/extensions.conf
Now obviously not all of this is required, this is just how I have my dial plan setup. To receive incoming calls from Voice you must have a exten => s,1,Answer() though as Voice doesn't say where it's coming from.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [general] static=yes writeprotect=yes autofallthough=yes clearglobalvars=no priorityjumping=no [local] exten => s,1,Answer() exten => s,n,Set(crazygooglecid=${CALLERID(name)}) ; Get rid of crazy Google incoming CID exten => s,n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)}) exten => s,n,Set(CALLERID(name)="${CURL(http://cnam.bulkCNAM.com/?id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&did=${CALLERID(num)})}") ; Set Caller ID from bulkCNAM exten => s,n,Wait(2) exten => s,n,Dial(SIP/102&SIP/103,20,D(:1)) ; This sends the 1 after you answer, otherwise it'll fall back on Google Voice-mail ; It also dials my SIP phones (7960 and Android 2.3 Phone) ; Internal Calling exten => _1XX,1,Dial(SIP/${EXTEN}) ; External Calling exten => _1XXXXXXXXXX,1,Dial(gtalk/asterisk/+${EXTEN}@voice.google.com) exten => _XXXXXXXXXX,1,Dial(gtalk/asterisk/+1${EXTEN}@voice.google.com) |
Final Thoughts
I know this isn't the most in depth guide on getting Asterisk working on your machine, but there are enough guides out there for that. Hope my article helped you get Voice working with Asterisk, happy calling!


