Asterisk 11 + Google Voice

*** Update ***

Unfortunately, Google has decided to end support for the XMPP protocol in May of 2014. I will keep the post here in the hope that Google releases a new API, but also to share that information with any searchers. As of April 2016, the service is still operational, but there’s no telling for how long that will be the case.

Introduction: History

Earlier this year, the company I work for, Laird Technologies, converted their phone system to Cisco IP phones. In the process they threw out all of their old IP phones which were used with their Asterisk system. I acquired these, all Grandstream products (mostly GXP2020’s, 1 or 2 GXP2000’s and even a HandyTone-286!) and I had some ideas about what I could do with these, but I mostly just wanted to play around: set up phones around the house, make a doorbell/intercom system, etc. After I started reading and Asterisk and how people are using it, I got the idea to set up my own “land-line” service using Google Voice.

I think the first thing to understand about Asterisk is that it is a hugely powerful tool; you can run a call-center or office phone system on it. The second thing to understand is that it is Free and Open Source Software (FOSS)! These two factors combined mean that you can do almost anything Voice over IP (VoIP) related, but you end up reading a lot of blogs and documentation in order to really make it happen.

In my reading, I found that there are basically two different ways to accomplish my goal:

  1. Set up Asterisk in conjunction with another Private Branch Exchange (PBX) and let the other PBX handle the GV transactions.
  2. Take advantage of a new Google Voice engine in an upcoming version of Asterisk: Asterisk 11.

When presented with these two options, I really wanted to make a pure Asterisk system to reduce the complexity (Asterisk is complex enough as-is) and to really get to know Asterisk.

It took me quite a few tries to get this right. Setting up a PBX with calling inside of our home network was a piece of cake given how simple that configuration is. After I set up the Motif channel for Google Voice, I could see that it was connected (through Gmail Chat) and I could even make the phone ring by calling my Google Voice Number, but when I answered, I either got no audio or the call wouldn’t connect (this was because of how Motif answers a call, using a DTMF tone) so I figured it had to be a problem with my networking configuration. After checking and double-checking all of my port-forwarding through my NAT, I finally broke down and installed FreePBX to get it up and running more easily. Once I got that configuration working, I took all of the useful stuff out their generated configuration files and finally, I had a working system! Next, I’ll walk you through how to set up your own!

Walk-Through: Do it yourself

This walkthrough is based very heavily on these pages, I’ve just compiled the information for you:

My set-up is as follows:

  • I have an Ubuntu 12.04 server on a LAN behind a NAT.
  • The router is a WRT54G running DD-WRT and I use that to assign reserved IPs to the server and the phones.
  • I have the following external ports forwarded through my NAT: 5060-5082 (SIP), 5222 (XMPP), 10000-12000 (RTP – note this for rtp.conf).

Currently, the Ubuntu Repository has the last Long-Term Support (LTS) version of Asterisk (1.8) so we need to download and compile Asterisk from source:

I’m going skip the DAHDI instructions in the link because I don’t have any Digium Hardware installed in my server.

# apt-get update && apt-get upgrade -y && reboot
# apt-get install build-essential wget libssl-dev libncurses5-dev libnewt-dev  libxml2-dev linux-headers-$(uname -r) libsqlite3-dev libiksemel-dev

Next, get the source files that we need

# cd /usr/src/
# wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz

Extract the files we’ll need to compile

# tar zxvf libpri*
# tar zxvf asterisk*

Install PRI (for ISDN, you may or may not need this as well):

# cd /usr/src/libpri*
# make && make install

Install Asterisk:

# cd /usr/src/asterisk*
# ./configure && make menuselect && make && make install && make config && make samples

When the “Asterisk Module and Build Option Selection” window pops up, navigate to “Channel Drivers” and ensure “chan_motif” is selected and navigate to “Resource Modules” and ensure “res_xmpp” is selected. Then you can select “Save & Exit” and finish the install. Start Asterisk to ensure it installed properly:

# /etc/init.d/asterisk start

Next, let’s look at configuration. All of the configuration files are located in /etc/asterisk. Let’s navigate there:

# cd /etc/asterisk
# ls

The files we’ll need to change are: extensions.conf, motif.conf, rtp.conf, sip.conf, and xmpp.conf. I trust that you know how to edit files in Linux so I’ll just post the relevant bits below.

extensions.conf: All of your dialing information goes here

[general]

static = yes
writeprotect = no
clearglobalvars = yes

[home]
exten => 200,1,Dial(SIP/200,20)
// Other local extensions go here

// These two expose Google Voice outbound calling with no extension prefix
exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)

[incoming-motif] // This is verbatim from the second link I showed above.
exten => s,1,NoOp()
 same => n,Wait(1)
 same => n,Set(crazygooglecid=${CALLERID(name)})
 same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
 same => n,Set(CALLERID(all)=${stripcrazysuffix})
 same => n,Dial(SIP/205&SIP/204,20,D(:1))

motif.conf: Connections using the Motif channel, if you had multiple Google Voice numbers, you would replicate these connections

[google]
context=incoming-motif
disallow=all
allow=ulaw
connection=google

rtp.conf: These are the ports used for UDP transmission, note that these must be forwarded through your NAT

[general]
rtpstart=10000
rtpend=12000
icesupport=yes

sip.conf: This is the most important file, it specifies how all of the calls are set up

[general]
context=home
callerid=Unknown
notifyringing=yes
notifyhold=yes
tos_sip=cs3
tos_audio=ef
tos_video=af41
alwaysauthreject=yes
disallow=all
allow=ulaw
allow=alaw
allow=gsm
callevents=no
jbenable=no
maxcallbitrate=384
maxexpiry=3600
minexpiry=60
notifyhold=yes
notifyringing=yes
registerattempts=0
registertimeout=20
rtpholdtimeout=300
rtpkeepalive=0
rtptimeout=30
srvlookup=no
t38pt_udptl=no
checkmwi=10
videosupport=no
canreinvite=no
allowguest=yes
defaultexpiry=120
g726nonstandard=no
nat=force_rport,comedia
// I have a dynamic IP I use dyndns.org for this service
externhost=<yourinternethostname>
externrefresh=120
localnet=192.168.1.1/255.255.255.0

[200]
deny=0.0.0.0/0.0.0.0
secret = <extensionpassword>
dtmfmode = rfc2833
canreinvite=no
context = home
host = dynamic
trustrpid=yes
sendrpid=no
type = friend
nat=no
port=5060
qualify=yes
qualifyfreq=60
transport=udp
encryption=no
callgroup=
pickupgroup=
dial=SIP/200
mailbox=200@home
permit=0.0.0.0/0.0.0.0
callerid = Master Bedroom
callcounter=yes
faxdetect=no

xmpp.conf: Where all of your Google account settings are stored

[google]
type=client
serverhost=talk.google.com
username=<gmailusername>
secret=<gmailpassword>
// Set Priority to at least 25 if you use this account for GMail/Chat
priority=25
port=5222
usetls=yes
usesasl=yes
status=available
statusmessage=Asterisk Phone
timeout=5

This is how I have mine configured. I have tried to highlight the settings which should be specific to your setup, but also keep in mind this is a pretty basic configuration.

Asterisk is still running with the base configuration, so let’s reload that:

# asterisk -rvvv
CLI> reload

Conclusion

This project was a lot of fun and I would recommend my approach to Asterisk: Start with simple tasks and add more complex features bit by bit. For example, my next post is about how to set up multiple Google Accounts on one server.

One of the coolest things about this, is you don’t even have to have your own server. If you ran this configuration on a Raspberry Pi, you could even have a standalone Google Voice phone!

One final thought, as of writing Google Voice provides free calling to the U.S. and Canada until at least the end of 2013. After that, I’m sure the rates will be cheap, but there’s no information about that.

Let me know if you try this and how far it gets you!

Join the Conversation

41 Comments

  1. Very good read, enjoyed the whole article. Wish I had enough time in my day to “fiddle” with something like this! Very well put together also. Found this browsing for Michigan numbers in Google Voice, sadly no Michigan numbers seem to be available.

    1. Thanks Jeff! I remember searching for Flint numbers a little while ago and it was slim pickings. Do they let you search across the whole state or do you have to search area code by area code?

      By the way, be sure to check out some of the other articles on my blog; I think you would enjoy them as well.

      1. I was doing a Michigan search, but only came up with a town called Michigan something in CA. Anyway, I found some with my area code but not specific enough to my area. Not a big deal, really only want it for digital copies of voice mails.

  2. Ok, so I would set up multiple entries in Montif, for multipe GV accounts. I take it the label would have to be something like [google_1] [google_2] ect. ect. ect. How would that affect the incoming and outgoing routes?

    1. I am planning a post to this effect, but the basic idea is to duplicate all of the XMPP and Motif configurations and then set up different dial plans based on how you want to choose the outgoing line.

  3. Hello, I have been trying these instructions but am not getting anywhere after two days of work. I have read and configured based on this example/wiki.asterisk.org and am getting no luck here. Outgoing calls give the error as if I did not enable icesupport but in rtp.conf but I assure you I have.

    The message reads:
    “Unable to add Google ICE candidates as ICE support not available or no candidates available”

    Incoming calls give the error:
    “Received Google transport information on session ‘SIPXXXXXXXX@XX.XXX.XX.XX’ but ICE support not available”

    I have forwarded the ports from my NAT device (ubuntu server) to my device running asterisk, I also tried setting a stun server in rtp.conf and that did not help either…

    The only difference is I grabbed the latest release using subversion. Its late, I will try a tarball after work tomorrow if anything thinks it will make a difference.

    Thanks,

    1. Do you want to post/send me your rtp.conf? You’re definitely right, it’s like Asterisk doesn’t think the option is enabled.

      1. http://pastebin.com/0CrW2QSp

        I downloaded the -current tarball instead of using the svn and recompiled today, I am ssh’d in and working on it remotely at this time from my work office, so I will check for sure later, but modifying the dial plan to give me an echo sounded fine when calling the GV number. When I get home I will attempt to call out through it to verify.

        1. Great! I just compiled Asterisk 11.4.0 from source a couple of weeks ago and it worked like a charm. Do you know if you had any build errors?

          1. I can’t say the first go-around I paid huge attention to compile time warnings, etc, but if there was a compile time error, it wasn’t one that had aborted the build part way through.

            Also, just confirmed all features work at home now, my cisco 7905 desk phone + soft phones can receive/place calls through. Despite my initial issues I am now happy. Thanks for the write up!

          2. Congratulations, and thanks for sharing your success. Hopefully soon Asterisk 11 will be in the Ubuntu Repositories to avoid this whole compiling mess.

          3. David,
            I have exact same issue as you originally had. I’m on Asterisk 11.6.0 and tried enabling icesupport in rtp.conf but still get “Unable to add Google ICE candidates as ICE support not available or no candidates available”.
            I’ve tried recompiling asterisk couple of times and it seems to compile fine. Can you share the exact steps you took to resolve it?

            BTW, this is a great tutorial. Thanks!

          4. Thanks for the note Dan. Would you mind posting your (edited) sip.conf on Pastebin? I may be able to spot an issue. What is your connection to the internet? Do you have an internet IP address or are you in a private Subnet because of your ISP?

          5. I’m running it on Amazon EC2. I followed instructions for that setup on xda website (I can post the link if you don’t mind)
            sip.conf: http://pastebin.com/gWSjs3wG
            I beleive I have the ELASTIPIP, NAME, PASS set correctly.
            I aslo have the ports TCP: 22, 1723, 5060. UDP: 5060, 10000-20000) open on EC2 instance.

          6. I think I see the issue, you also need port 5222 open for XMPP communication between your server and Google Voice. Also, I have read that you should also open ports 5060-5082. Let me know if this works!

  4. Hi .. first thanks to the great writeup. I was able to setup GV with asterisk successfully. I am running asterisk on a pogoplug E02 box where I am also a host of other apps. For the ATA I picked up a Linksys PAP2 for $9 on ebay and then unlocked it. Everything works great. There is one nuance .

    When someone calls my google voice number , I am able to recieve the call to my landline. But if I try to ignore the call by dicsonnecting, nothing happens. My phone keeps ringing. Only if the caller disconnects the call, the phone stops ringing .

    But after I pickup the call, I am able to hangup immediatly.

    I believe its got to be something in the way my extensions.conf is setup for incoming calls. Any help is appreciated.

    Here is my extensions.conf . I have also try to include the Wait(1) and the Answer() commands before Dial. But that doesn’t help.

    [incoming-motif]
    exten => s,1,NoOp()
    same => n,Set(CALLERID(num)=${CUT(CALLERID(name),@,1)})
    same => n,Set(CALLERID(name)=External)
    same => n,Set(CALLERID(num)=${IF($[${LEN(${CALLERID(num)})}=1]?:${CALLERID(num)})})
    same => n,Set(CALLERID(name)=${IF($[${LEN(${CALLERID(num)})}=0]?Anonymous:${CALLERID(name)})})
    same => n,Dial(SIP/127356,20,D(:1))

    1. Thanks! That sounds like a good solution. I think your problem is related to your voicemail settings in Asterisk. Do you use Google Voice for Voicemail?

          1. Yes if I dont attend the call for 20 seconds it goes to google voicemail.

            But if I try to Ignore the call , by pressing the disconnect button on the handset before 20 seconds , the handset keeps ringing until 20 seconds , or the caller hangs up, whichever is earlier.

            Not a big deal, but keeps bugging me what could be wrong.

          2. One thing I don’t understand is the function of the “disconnect” button. Is this built in to the landline phone? I wonder if that would trigger something to Asterisk through the ATA and I also wonder if this is an unsupported feature on the PAP2?

  5. Apologize didn’t login for a couple of days ….. Yes I’m thinking the same too. I would assume the ‘Green’ phone button is to pickup a call, and the ‘Red’ one is to ignore a call in any handset. Just like a cell phone. Probably it does not sed signal back to the PAP2 until the call is answered.

  6. Someone might find this useful. To get a proper caller name we could lookup a free CNAM provider. Google forum says they are not going to provide this funationality anytime now. Below is my extensions.conf and it works great for most numbers.

    [incoming-motif] exten => s,1,NoOp()
    same => n,Set(CALLERID(name)=${CURL(https://api.opencnam.com/v2/phone/${CALLERID(num)}?format=pbx)})
    same => n,Set(CALLERID(num)=${CUT(CALLERID(num),+,2)})
    same => n,Dial(SIP/127356,20,D(:1))

    1. I briefly tried out a couple of numbers but it said they weren’t supported at the Hobbyist level. This would definitely be interesting for a small business use, though! Now it has me thinking, does Google have a contacts API that could be used in a similar fashion?

  7. That is correct. Its mentioned the hpbbyist level uses a cached DB Vs the realtime DB for the Professional. So far the numbers I have tried out comes up fine.

    When I call home from work it correctly reflects my company name. When I call from mobile it shows Minneapolis MN .

    Definitely good for something that is free 🙂

  8. Hello,

    Thank you for this tutorial.

    Everytime when I call from the Asterisk command line, through to google Voice to a USA Telephone #,
    +1-202-XXX-XXXX. whoever is answering can only hear continual ringing.

    Is this is Google Voice Issue?

    My dial string has ringing, ( r ) removed and despite any USA telephone that gets called, all the answering party hears is ringing upon answering their telephones.

    Any ideas would be greatly appreciated and the instruction above works other the Google Voice ” ringing upon answer issue “.

    1. Have you tried it in other configurations? For example, have you tried calling from a SIP phone? Have you tried calling the GV number directly from a POTS phone?

      At first blush, it sounds like a network port issue, but I don’t have many ideas. Can you check your NAT?

  9. DanTheMan2865,

    Since Asterisk 1.8.something, and per your guide listed above, though I still, from dialing
    191912345678 at the Asterisk command prompt, upon answering the call, all I or any callee hears
    is ringing, though the call is going through Google’s Voice network.

    So I hooked up a SDR device to the the laptop, ran OpenBTS whcih created the GSM (Um)interface, to a unlocked GSM phone which was able, upon dialing a USA telephone #, to get the call to ring through cleanly Asterisk to Google Voice with ZERO ringing issues to the called party.

    DanTheMan2865’s reputation lives on!

    1. It’s no problem Martin. It sounds like some really cool stuff you’re doing with SDRs!

      1. I’m still stuck on why, from the Asterisk command line, upon dialing any USA/Canada telephone # through Google Voice, upon answering the call, the ” Called Party ” hears ringing. Yet from OpenBTS through Asterisk to Google Voice, ZERO issues.

        So there is a mishap between my OpenBTS config files & Asterisk config files, but I can honestly say it is far more important for GSM to Google Voice calls then ” Command Line ” telephony ringing cleanly through Google Voice.

        Though being able to make a telephone call through from a Linux Command line has PLENTY of uses too !

        😉

        1. What syntax are you using to Dial? I briefly looked into it, but intuitively the command line would just connect one Asterisk endpoint to another. Can you post an example? I’ll try it out on my setup.

  10. Dan,

    Just dial by the following:

    console dial 13122222222

    console dial 1(and whatever USA/Canada #)

    And it’s not true dialing as you CAN dial OUT from the Asterisk Command Line to any properly configured VOIP provider successfully as I use to do all the time in Asterisk versions 1.8

    This might be a Asterisk 11.5 / Google Modules issue but I am more than satisfied at least in being able to make GSM to Asterisk to Google Voice calls successfully.

    Which for my situation, for the moment is most important.

    Thanks Dan!

  11. The world needs DantheMan …
    With google announcing it will end xmpp support on May 2014 , My guess is this setup wont work after that. Are there other alternative ways to setup GV with asterisk ? There are lots of discussions going around in OBI forums . I guess our setup is similar to OBI too …

    1. Thank you for sharing this sad news. I will definitely update my post and we can both hope that Google opens up another API that could be used. Unfortunately, I wouldn’t count on it….

      1. hello dear , is google stoping xmpp support for both ( google voice and google talk web based) or only google voice ; is it possible io use google talk to connect asterisk after 15 may 2014 ?????

        1. I believe the issue is that Google is rolling Google Talk and Google Voice into one application: Google Hangouts. They have notified the community that they will end support for XMPP when this happens. We can still hope that they bring in a replacement, though!

  12. Hi. I was just wondering if you had found a new way to do this?
    I heard this may still be possible without xmpp?

    1. Hi, unfortunately I have not seen any straight-forward way to do it. There are ways to get around it, like this gateway: https://simonics.com/gw/ but that’s still not free (although it is cheap).

Leave a comment

Leave a Reply to Jeff Cancel reply