Asterisk 1.8.x and FreePBX users: How to NOT answer Google Voice calls UNTIL the called extension answers


This is an edited version of a post that originally appeared on a blog called The Michigan Telephone Blog, which was written by a friend before he decided to stop blogging. It is reposted with his permission. Comments dated before the year 2013 were originally posted to his blog.

EDIT (May, 2018): FreePBX and Asterisk users that wish to continue using Google Voice after Google drops XMPP support should go here: How to use Google Voice with FreePBX and Asterisk without using XMPP or buying new hardware.

This article was originally published in December, 2010 and may contain out-of-date information.

Many folks are experimenting with Asterisk 1.8.x and Google Voice.  In most cases the way it’s set up is that when a Google Voice call arrives, Asterisk answers the call, then sends a touch-tone digit “1” to Google Voice to answer the call, then proceeds to ring the destination extension.  This is necessary because when you configure Google Voice to use a Gtalk destination, they require you to press “1” to accept the call, even if you’ve configured Google Voice not to require that.  I don’t know if this is a bug in Google Voice or if they did it that way deliberately for some reason, but answering the call and accepting it upon arrival at the PBX has a few unintended side effects:

  • If your callers pay for long distance by the minute, they get charged from the moment the called extension begins ringing – even if you never answer the call.
  • You can’t use Google Voice’s Voicemail, nor their transcription service, because you’ve already answered the call.
  • Callers may hear a confusing double ringing tone at the start of ringing — one ring from Google Voice and the rest from Asterisk.

On the other hand, there are some advantages to doing it that way:

  • Because you’ve answered the call, you can let the extension ring as long as you like before sending it to voicemail, and Google Voice won’t snatch it away in 25 seconds and send it to their voicemail.
  • You can use Asterisk’s voicemail, if that’s what you prefer.

For those who’d prefer to let Google Voice handle their voicemail, or who object to making callers pay to listen to up to 25 seconds of ringing, there is a way to not answer the call and send the touch tone “1” until  after the destination extension has actually picked up the call.  If you are using plain vanilla Asterisk, all you have to do is make sure your Dial() command contains two additional options.  Consider this example line of Asterisk dialplan:

exten => gvoicein,n,Dial(SIP/1004,35,rTWtwaD(:1))

The important part here is the aD(:1) — the other options can be whatever you’d normally use, if any, but it’s the aD(:1) that does the magic. Now at this point, if you’re a FreePBX user you may be wondering how on earth you can modify the Dial() string, since the code that generates it is buried deep within the bowels of FreePBX. Fortunately, there is a way. Consider the following piece of code that might be used in extensions_custom.conf to bring in Google Voice calls:

exten => _[0-9a-z].,1,Noop(Incoming Google Voice call for ${EXTEN})
exten => _[0-9a-z].,n,Set(CALLERID(name)=${CUT(CALLERID(name),@,1)})
exten => _[0-9a-z].,n,GotoIf($["${CALLERID(name):0:2}" != "+1"]?notrim)
exten => _[0-9a-z].,n,Set(CALLERID(name)=${CALLERID(name):2})
exten => _[0-9a-z].,n(notrim),Set(CALLERID(number)=${CALLERID(name)})
exten => _[0-9a-z].,n,Wait(1)
exten => _[0-9a-z].,n,Answer
exten => _[0-9a-z].,n,Wait(1)
exten => _[0-9a-z].,n,SendDTMF(1)
exten => _[0-9a-z].,n,Goto(from-trunk,gv-incoming-${CUT(EXTEN,@,1)},1)
exten => h,1,Macro(hangupcall,)

With this context you’d use gv-incoming-username (where username is the part of the associated gmail address before the @) as the DID in your inbound route — a DID doesn’t have to be numeric even if FreePBX whines about it, and the advantage is you only need one context to handle incoming calls for all your Google Voice accounts.  This particular context is slightly modified from one found in the PBX in a Flash forum, but note that it contains these four lines that wait ONE second, answer the call, wait ONE second (you do NOT have to wait two seconds, despite what any other article may say, and in fact the one second wait might be unnecessary), and then send the touch tone digit 1:

exten => _[0-9a-z].,n,Wait(1)
exten => _[0-9a-z].,n,Answer
exten => _[0-9a-z].,n,Wait(1)
exten => _[0-9a-z].,n,SendDTMF(1)

You will find those four lines, or some variation on them (sometimes just the last three), in just about every published method for using Google Voice with Asterisk and FreePBX.  But, in FreePBX at least, you can replace them with this:

exten => _[0-9a-z].,n,Set(DIAL_OPTIONS=${DIAL_OPTIONS}aD(:1))

This slides the aD(:1) into the options that will be used with the Dial command, so when the extension answers, the call will be answered and then the touch tone “1” will be immediately sent to Google Voice, and then the audio between Google Voice and the called extension will be bridged as usual.

Unfortunately, or maybe fortunately depending on your point of view, it appears that if the call should go to Asterisk’s voicemail, the call will not be answered and the DTMF 1 will never be sent.  This means that if, for whatever reason, you don’t answer the incoming call, after 25 seconds it will go to Google’s voicemail.  There are doubtless ways around that (and if anyone’s truly interested, leave a comment and I’ll suggest a way that may work, that involves routing the incoming call to a ring group first) but I suspect that the majority of people who want to do this will be doing it because they want to use Gmail’s voicemail.

I’ve tested this and it works for me, though I would not use it on a regular basis because I prefer Asterisk’s voicemail.  If it doesn’t work for you for some reason, the only suggestion I can offer is adding a w before the :1, so the added options look like aD(w:1) – that will add a one-half second delay before the “1” is sent, and more than likely it won’t help one bit, but may cause callers to not hear your “hello” or other greeting.  But, you can try it and see — at least one user has reported it to be necessary.  If that doesn’t work, I probably won’t be able to help you but if you leave a comment, maybe someone else can.

And, should anyone from Google Voice read this, it would be really helpful if you’d do two things:

  1. Give us a way to disable Google Voice’s voicemail so we don’t have to resort to hacks like this to discourage callers from leaving a message there.
  2. Fix the bug (or “feature”) so that when we turn off call screening, it’s off for ALL destinations, including Gtalk!

18 thoughts on “Asterisk 1.8.x and FreePBX users: How to NOT answer Google Voice calls UNTIL the called extension answers

  1. Timely posting, as I am having this same issue with wanting to automate the DTMF 1 part of answering a GV call. However, after having implemented your one line above in place of the SendDTMF line, all it does it cause the GV lady to say Press 1 to answer to 2 to send to voicemail. I cannot automate the pressing of the 1 this way.

    1. Did you replace all three lines with that one line? If you only replaced one line it won’t work!

  2. When I do, I get this:

    [Dec 21 14:23:30] NOTICE[20032]: pbx.c:4119 pbx_extension_helper: No such label ‘regcall’ in extension ‘s’ in context ‘googlein’
    [Dec 21 14:23:30] WARNING[20032]: pbx.c:10174 pbx_parseable_goto: Priority ‘regcall’ must be a number > 0, or valid label

    exten =>,1,Wait(1)
    exten =>,n,Set(
    exten =>,n,JABBERSend(asterisk,${ALERTNAME},Incoming Google Voice Call: ${CALLERID(name):2:10})
    exten =>,n,Set(CALLERID(number)=${CALLERID(name):2:10})
    exten =>,n,Set(CALLERID(name)=${CALLERID(number)})
    exten =>,n,GotoIf(${DB_EXISTS(gv_dialout_account1/channel)}?bridged)
    exten =>,n,Goto(s,regcall)
    exten =>,n(bridged),Bridge(${DB_DELETE(gv_dialout_account1/channel)})
    exten =>,1,Wait(1)
    exten =>,n,Set(
    exten =>,n,JABBERSend(asterisk2,${ALERTNAME},Incoming Google Voice Call: ${CALLERID(name):2:10})
    exten =>,n,Set(CALLERID(number)=${CALLERID(name):2:10})
    exten =>,n,Set(CALLERID(name)=${CALLERID(number)})
    exten =>,n,GotoIf(${DB_EXISTS(gv_dialout_account2/channel)}?bridged)
    exten =>,n,Goto(s,regcall)
    exten =>,n(bridged),Bridge(${DB_DELETE(gv_dialout_account2/channel)})
    exten => s,1,Wait(1)
    exten => s,n,Set(
    ;exten => _X.,n,Set(STATUS=${JABBER_STATUS(asterisk,${ALERTNAME})});
    ;exten => _X.,n,NoOp(Gvoice/Jabber Status: ${STATUS})
    exten => s,n,JABBERSend(asterisk,${ALERTNAME},Incoming Google Voice Call: ${CALLERID(name):2:10})
    exten => s,n,Set(CALLERID(number)=${CALLERID(name):2:10})
    exten => s,n,Set(CALLERID(name)=${CALLERID(number)})
    exten => s,n(regcall),Answer
    exten => s,n,Set(DIAL_OPTIONS=${DIAL_OPTIONS}D(:1))
    ;exten => s,n,SendDTMF(1)
    exten => s,n,Goto(from-trunk,gv-incoming-${CUT(ALERTNAME,@,1)},1)

    1. Where in Sam Hill did you get THAT context? That’s the most convoluted mishmash I’ve seen yet, and if it works at all I’m amazed. Delete that POS and replace it with the following context, which is ALL you need for incoming calls regardless of the number of Google Voice accounts coming into your system:

      exten => _[0-9a-z].,1,Noop(Incoming Google Voice call for ${EXTEN})
      exten => _[0-9a-z].,n,Set(CALLERID(name)=${CUT(CALLERID(name),@,1)})
      exten => _[0-9a-z].,n,GotoIf($[“${CALLERID(name):0:2}” != “+1”]?notrim)
      exten => _[0-9a-z].,n,Set(CALLERID(name)=${CALLERID(name):2})
      exten => _[0-9a-z].,n(notrim),Set(CALLERID(number)=${CALLERID(name)})
      exten => _[0-9a-z].,n,Set(DIAL_OPTIONS=${DIAL_OPTIONS}aD(:1))
      exten => _[0-9a-z].,n,Goto(from-trunk,gv-incoming-${CUT(EXTEN,@,1)},1)
      exten => h,1,Macro(hangupcall,)

      (Note that some of the lines wrap as displayed so use copy-and-paste to get them as they should be. Also, the above has been edited since originally posted to fix a bug that displayed wrong CallerID information under certain circumstances.)

      Make sure that in the general context of gtalk.conf you have this line:

      If you are using FreePBX, in your inbound routes, specify the DID Number(s) as gv-incoming-username where username is the part of the gmail address before the @ – in your example it would be gv-incoming-blah. Make an inbound route for each user following that pattern, using the front part of their e-mail address. When you go to save the route FreePBX will complain that the DID is usually a number, but click through that (oh, how I wish there were a way to turn off the “nanny” warnings in FreePBX) and save it anyway (after entering a description and selecting a destination, of course).

      And again, be aware of the one caveat with this: If the call goes to FreePBX’s voicemail, it won’t answer the Google Voice call and generate the DTMF 1 – but then I assume you’re doing this because you want to use Google Voice’s voicemail in the first place.

      I’m still somewhat in shock that anyone could make a dialplan that convoluted. It never ceases to amaze me how some people can take something simple and make it complicated (although there’s one site in the VoIP world where that kind of thing happens far too often, but I’m not naming any names).

  3. Well that context works fine…I pulled that from the pbiaf forum, so let it be known I did not come up with that on my own. It did work, but not as efficiently as yours. Many thanks…

  4. I’m sure there’s a way to do this, but I’m not smart enough to figure out how. I want my incoming GV to be routed to a ring group, don’t want it answered unless someone picks up the phone (since I may be having the GV number routed to my cell phone), but would rather not have to press 1 when I pick up. Can I add to the “Goto” command that sends the call to the ring group? I’m guessing not. If, as I suspect, I’m missing something very straightforward, I’d love some advice on how to implement what I’m looking for.


    Seth Green

    1. With the caveat that Google did something that’s caused problems with inbound calls for many Asterisk 1.8 users, so I don’t guarantee that anything relating to incoming calls will work correctly without some additional tweaking, my initial question would be whether you attempted to send the calls to your ring group from your inbound route, and if so, what was the result?

  5. OK, I’m an idiot. I hadn’t properly implemented your code so I’d been asked to dial one when the ring group picked up. Once I got your response, I double checked and found a mistake (in fixing it I managed to lose my original file so I can’t swear what I had gotten wrong). Now (with the correct code) everything seems to be working through the ring group. Thanks for the quick response though.

  6. I installed incredible pbx from nerd vittles, and google voice worked right away. I applied their patch (same as yours) to use google’s voicemail. In my limited testing, it takes a long time for my phone to start ringing when I call it, so that by the time it does start ringing I have to answer fast or google’s voicemail takes over. Any way to fix this? I do have my cell phone ringing from this google number as well, but my cell is usually off when I’m at home.

  7. Followup: It seems to be taking a good 20 seconds for asterisk to ring my extension after the first gv related item shows up in the log. Any tweaks I can do to shorten this?

  8. More followup, from the logs: The big delays appear to be here:

    [2011-04-01 18:22:43] VERBOSE[25829] pbx.c: — Executing [s@googlein:7] Wait(“Gtalk/+1xxxxxxxxxx-5c47”, “8”) in new stack
    [2011-04-01 18:22:51] VERBOSE[25829] pbx.c: — Executing [s@googlein:8] Goto(“Gtalk/+1xxxxxxxxxx-5c47”, “from-trunk,gv-incoming,1”) in new stac

    Is that an 8 second intentional wait? And here:

    [2011-04-01 18:22:52] VERBOSE[25829] file.c: — Playing ‘custom/nv-GenericWelcome.gsm’ (language ‘en’)
    [2011-04-01 18:22:57] VERBOSE[25829] pbx.c: — Executing [s@ivr-3:13] WaitExten(“Gtalk/+1xxxxxxxxxx-5c47”, “,”) in new stack
    [2011-04-01 18:23:02] VERBOSE[25829] pbx.c: — Timeout on Gtalk/+1xxxxxxxxxx-5c47, going to ‘t’

    I don’t hear any generic welcome. So there appears to be 18 seconds of unnecessary delay here. Can I do something about this?

  9. Yet more followup:

    I found the 8 second wait and turned it into a 1 second wait. I found the generic welcome and 5 second wait in the IVRmain setup and turned the greeting off and set the timeout from 5 to 0. Now my extension rings right away. So I guess I’m set.

  10. PS: Before I found the delays, I tried turning off the caller id name lookup. After I reduced the delays, I tried turning cid back on, and the phone didn’t ring before gv gave up, so maybe that 8 second delay was to give cid time to work? Anyway, I can live without the name lookup.

  11. hi

    thanks for your kind of help. i have a problem in editing of extensions_custom.conf in elastix for remove press 1.

    my google context is like this
    exten => s,1,Answer
    exten => s,n,Wait(1)
    exten => s,n,SendDTMF(1)
    exten => s,n,Set(CALLERID(num)=${CUT(CALLERID(name),@,1)})
    exten => s,n,Set(CALLERID(name)=${CUT(CALLERID(name),/,1)})
    exten => s,n,Goto(from-trunk,19494442522,1)
    exten => s,h,Hangup

    what part of this context should change?

  12. NOTICE: All comments above this one were imported from the original Michigan Telephone Blog and may or may not be relevant to the edited article above.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

Recent Comments




GiottoPress by Enrique Chavez