04 June 2011
This article was updated May 2013 with new instructions for Asterisk 11.
Inspired by a recent Maximum PC article, I recently set up a land line telephone that supports both incoming and outgoing calls from my Google Voice number. I opted to use an installation of Asterisk in on an Arch Linux server instead of using one of the pre-built PBX Linux distributions. The process involved enough fiddling and Google searching that I thought a summary of how my setup works could be helpful for others.
I compiled this setup by following the official Asterisk guide to enabling Google Voice and by mixing in a few other tips.
In Arch, Asterisk is available in the AUR.
There a few Asterisk configuration files to change:
/etc/asterisk/motif.conf
Add this to the end of the file:
[google]
context=incoming-motif
disallow=all
allow=ulaw
connection=google
transport=google
/etc/asterisk/modules.conf
Add this to the end of the file:
load => chan_motif.so
load => res_xmpp.so
/etc/asterisk/extensions.conf
Find the [local]
section of this file and add this to set up outgoing calls:
exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
At the end of the file, add this new incoming-motif
section. Replace
asterisk-username
with your user account in Asterisk. This enables incoming
calls and corrects the Caller ID.
[incoming-motif]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(all)=${stripcrazysuffix})
same => n,Dial(SIP/asterisk-username,20,D(:1))
/etc/asterisk/sip.conf
Replace asterisk-username
with your desired Asterisk username and
asterisk-password
with your desired password - you’ll use this account
information to log in to your Asterisk server from a SIP phone.
[asterisk-username]
type=peer
secret=asterisk-password
host=dynamic
context=local
/etc/asterisk/xmpp.conf
Replace [email protected]
with your actual Gmail address
and your-google-voice-password
with your Google account password. If you use
Google’s two-factor authentication, you will need to create an
application-specific password.
[google]
type=client
serverhost=talk.google.com
username=[email protected]
secret=your-google-voice-password
priority=1
port=5222
usetls=yes
usesasl=yes
status=available
statusmessage="Asterisk Server - Not a Human"
timeout=5
There are a few known issues with this setup.
The Google account you use will appear logged into Google Talk anytime the server is running. Messages sent to the server will just get lost in the ether. I set up a separate Google account with my Voice number so this wouldn’t be an issue. If you already have an established Voice number that you don’t want to change, another option is to create a second Google account for chat only - although then you lose the ability to use the inlined chat in Gmail. If anyone has a better solution for this, I’d love to know about it.
Incoming calls are not bulletproof - occasionally the phone will ring, but after picking it up you just get dead air. My cell phone keeps ringing when this happens so I’m still able to pick up the call. It’s annoying, however, and I’d love to find the root cause.
Other times, if you accidentally logged into Google Talk somewhere else, the local SIP phone won’t ring at all. My current workaround is to reboot Asterisk via a cronjob every night, so at least it gets back to normal fairly quickly.
Otherwise, outgoing calls work quite well. The only issue I’ve ever had is if I’m using all of my upstream bandwidth doing something else, but that’s not unique to Asterisk. Some QoS controls in your router should help out with that.
When I originally set up Asterisk, I wrote a Chef cookbook that did most of this configuration automatically. I no longer use Chef to manage my system configuration (nothing against Chef, it was just overkill for my setup and Arch Linux moves too quickly), so I’m not actively maintaining that cookbook anymore. If you use Chef, it may be a good starting point, and I’d be happy to transfer control of the cookbook over to you.