Google Voice and Asterisk

Google Voice & Asterisk

There are numerous guides about setting up Google Voice and an incoming sip number for free outgoing calling. Sadly, all of the guides I found were written for FreePBX or some other Asterisk bundle, and also used a shell script to do much of the work (scary!). I have compiled the minimal amount that you need to put in your asterisk conf files to make things work, GUI-free and variant-independent.


sipgate logo

First off, you need a sip number. I recommend sipgate or ipkall (I use sipgate, it’s much more user-friendly). If you google around, you’ll find out how to set up your sipgate/ipkall number as an incoming number in asterisk, I won’t waste time covering it here.

Secondly, you need a google voice number. Once you get said number, turn off call presentation. Also, assign the account a password that you don’t mind having plaintext in a conf file. In addition, you must add your incoming sip number as a phone in google voice. I’d recommend connecting a softphone to your sip number to set this up with google’s verification call, or redirect all incoming calls in Asterisk to your extension.

Thirdly, you need pygooglevoice. Download and install it, or use python’s easy_install command.

The outgoing rule

Now for the actual configuration. First you need to set up an outgoing call rule, so all calls to the outside world (in this case, 10-digit numbers preceded with a “9”) are directed though google voice.

exten = _9XXXXXXXXXX,1,Goto(custom-gv,${EXTEN:-10},1)

Explanation: Any outgoing 10-digit number prefixed with a 9 will match this rule and go to the custom-gv section which we will set up later. The number that was dialed is passed (the “-10” excludes the 9 prefix from this) at the first dialplan rule.

The GV dialer

Now we need to set up the custom-gv section:

exten => _X.,1,Verbose(0, Custom-GV Preparing to call and park call at number ${EXTEN})
exten => _X.,n,Wait(1)
exten => _X.,n,Playback(pls-wait-connect-call)
exten => _X.,n,System(gvoice -e -p GVPassword call ${EXTEN} IncomingNum &)
exten => _X.,n,Set(PARKINGEXTEN=701)
exten => _X.,n,Park()

Explanation: After you dial an outgoing number, you’ll be dropped in here. The Verbose() function tosses some output in debug level 0 and up (see the console for this output). The System() command dials the number with google voice. Make sure you change the items in strikethrough to your own personal information. The call is then parked on extension 701 (70X extensions for parking are default. Switch to your parking extension range if you are using non-default options).

Routing GV callbacks

Now you need to set up an incoming call rule. Direct all incoming calls from your sip number at this rule.

exten = s,1,NoOp(CIDredirect)
exten = s,2,Verbose(0, Got incoming CID ${CALLERID(num)}, redirecting…)
exten = s,3,GotoIf($[“${CALLERID(num)}” == “GVNumber“]?custom-park,s,1)
exten = s,4,Goto(section-to-route-normal-incoming-calls,s,1)

Explanation: If your google voice number rings your PBX, you know that it’s connecting you to the call you just dialed, so we need to reconnect it to the extension you dialed from. We’ll handle linking of the incoming GV call and your outgoing call (which is now parked) in the next section (custom-park).

Bringing it all together

The custom-park section links a google voice incoming call (which is actually ringing the person you originally dialed) with your original outgoing call (which is parked).

exten => s,1,Verbose(0, Got incoming GV Callback! Connecting to your original outgoing call…)
exten => s,2,ParkedCall(701)

Explanation: After you dialed your external number, your call was parked as google voice started dialing the other number. This section joins your outgoing call with google voice’s incoming call, so you are connected to the party you originally dialed.

You’re done!

[pullquote]Have comments, questions, or need clarification? Leave a comment![/pullquote]

Well that turned out to be a bit longer than I expected, but if you know what you’re doing, you can just ignore the italicized text.

Ethan is a computer engineer and open source hardware/software developer from Michigan. He enjoys AVR and linux development, photography, mountain biking, and drinking significant amounts of home-roasted coffee. Find out more at

Tagged with: , ,
Posted in Linux, Technology
4 comments on “Google Voice and Asterisk
  1. Lorenzo Z says:

    There is any way to make asterisk not spell “7-0-1” every time i start a call?

    • I did some research, the fix is a bit more complicated than I would like. If you installed asterisk from source, edit the app_parkandannounce.c file and comment out this line:

      ast_say_digits(dchan, lot, “”, dchan->language);

      Then recompile and reinstall.

      I might try doing this change myself and compiling, then I can post the compiled 32/64-bit .so files here, although I’m not sure how much app_parkandannnounce.c has changed between asterisk versions.

  2. Twinclouds says:

    I am also very interested to know what can be done with minimum implementation of GV over asterisk. I don’t have problem of sip.conf and features.conf. The only part I don’t know if what is the needed minimum implementation of extensions.conf. Can you provide more information? For example, what will the minimum needed for your “section-to-route-normal-incoming-calls”? I have been using freepbx for some time for GV and other voip calls but don’t know much about Asterisk programming.
    Hope you can provide me more clue. Thanks.

    • “section-to-route-normal-incoming-calls” is wherever you want normal incoming calls routed to (that are not Google Voice’s callback). If you are only using one extension to pick up incoming calls, you can just Goto(default,1000,1) where “1000” is your extension number.

Leave a Reply

Your email address will not be published. Required fields are marked *