Google Voice and Custom Contexts

So I have Google Voice integration working pretty well with Asterisk 1.8 and 2.9, both incoming and outgoing. I have a google voice incoming line for each extension, I would like to set it up so that each extension dials out using its own trunk.

So I installed custom-contexts and configured one to restrict the outbound route to the associated GV Trunk. I assigned this to the device and tried, and no go. The log shows me that when the context is from-internal, the steps asterisk is taking is completely different from the custom context. While this makes sense, how do I make the custom context behave like from-internal?

Here are the two log entry sets, 1st from the custom context, second from Allow All

[Jun 4 13:44:32] VERBOSE[58625] netsock2.c: == Using SIP RTP TOS bits 184
[Jun 4 13:44:32] VERBOSE[58625] pbx.c: – Executing [##########@1002:1] Dial(“SIP/1002-00000079”, "Gtalk/1002@.com/+##########@voice.google.com") in new stack
[Jun 4 13:44:32] VERBOSE[58625] chan_gtalk.c: OOOOH domain = 1002
[Jun 4 13:44:32] VERBOSE[58625] app_dial.c: – Called 1002@
.com/+##########@voice.google.com
[Jun 4 13:44:32] WARNING[58625] acl.c: Cannot connect
[Jun 4 13:44:32] VERBOSE[58625] app_dial.c: – Gtalk/+##########@voice.google.com-61bf is ringing
[Jun 4 13:44:32] NOTICE[58625] chan_gtalk.c: Remote peer reported an error, trying to establish the call anyway
[Jun 4 13:44:32] NOTICE[58625] chan_gtalk.c: Remote peer reported an error, trying to establish the call anyway
[Jun 4 13:44:52] VERBOSE[58625] pbx.c: == Spawn extension (1002, ##########, 1) exited non-zero on ‘SIP/1002-00000079’
[Jun 4 13:44:52] VERBOSE[58625] pbx.c: – Executing [h@1002:1] Macro(“SIP/1002-00000079”, “hangupcall,”) in new stack
[Jun 4 13:44:52] VERBOSE[58625] pbx.c: – Executing [s@macro-hangupcall:1] GotoIf(“SIP/1002-00000079”, “1?theend”) in new stack
[Jun 4 13:44:52] VERBOSE[58625] pbx.c: – Goto (macro-hangupcall,s,3)
[Jun 4 13:44:52] VERBOSE[58625] pbx.c: – Executing [s@macro-hangupcall:3] Hangup(“SIP/1002-00000079”, “”) in new stack
[Jun 4 13:44:52] VERBOSE[58625] app_macro.c: == Spawn extension (macro-hangupcall, s, 3) exited non-zero on ‘SIP/1002-00000079’ in macro ‘hangupcall’
[Jun 4 13:44:52] VERBOSE[58625] pbx.c: == Spawn extension (1002, h, 1) exited non-zero on ‘SIP/1002-00000079’
[Jun 4 13:44:53] NOTICE[58625] chan_gtalk.c: Remote peer reported an error, trying to establish the call anyway
[Jun 4 13:44:53] NOTICE[58625] chan_gtalk.c: Whoa, didn’t find call during hangup!
[Jun 4 13:45:07] VERBOSE[58625] netsock2.c: == Using SIP RTP TOS bits 184
[Jun 4 13:45:07] VERBOSE[58625] pbx.c: – Executing [1##########@1002:1] Dial(“SIP/1002-0000007a”, “Gtalk/1002@*******.com/+1##########@voice.google.com”) in new stack
[Jun 4 13:45:07] VERBOSE[58625] chan_gtalk.c: OOOOH domain = 1002

[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [##########@from-internal:1] Macro(“SIP/1002-0000007b”, “user-callerid,LIMIT,”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:1] Set(“SIP/1002-0000007b”, “AMPUSER=1002”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:2] GotoIf(“SIP/1002-0000007b”, “0?report”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:3] ExecIf(“SIP/1002-0000007b”, “1?Set(REALCALLERIDNUM=1002)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:4] Set(“SIP/1002-0000007b”, “AMPUSER=1002”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:5] Set(“SIP/1002-0000007b”, “AMPUSERCIDNAME=ramarnat”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:6] GotoIf(“SIP/1002-0000007b”, “0?report”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:7] Set(“SIP/1002-0000007b”, “AMPUSERCID=1002”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:8] Set(“SIP/1002-0000007b”, “CALLERID(all)=“ramarnat” <1002>”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:9] GotoIf(“SIP/1002-0000007b”, “0?limit”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:10] ExecIf(“SIP/1002-0000007b”, “1?Set(GROUP(concurrency_limit)=1002)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:11] GotoIf(“SIP/1002-0000007b”, “1?continue”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-user-callerid,s,24)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:24] Set(“SIP/1002-0000007b”, “CALLERID(number)=1002”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:25] Set(“SIP/1002-0000007b”, “CALLERID(name)=ramarnat”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-user-callerid:26] Set(“SIP/1002-0000007b”, “CHANNEL(language)=en”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [##########@from-internal:2] Set(“SIP/1002-0000007b”, “MOHCLASS=default”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [##########@from-internal:3] Set(“SIP/1002-0000007b”, “_NODEST=”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [##########@from-internal:4] Macro(“SIP/1002-0000007b”, “record-enable,1002,OUT,”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-record-enable:1] GotoIf(“SIP/1002-0000007b”, “1?check”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-record-enable,s,4)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-record-enable:4] ExecIf(“SIP/1002-0000007b”, “0?MacroExit()”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-record-enable:5] GotoIf(“SIP/1002-0000007b”, “0?Group:OUT”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-record-enable,s,14)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-record-enable:14] GotoIf(“SIP/1002-0000007b”, “0?IN”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-record-enable:15] ExecIf(“SIP/1002-0000007b”, “1?MacroExit()”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [##########@from-internal:5] Macro(“SIP/1002-0000007b”, “dialout-trunk,6,1##########,”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:1] Set(“SIP/1002-0000007b”, “DIAL_TRUNK=6”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:2] GosubIf(“SIP/1002-0000007b”, “0?sub-pincheck,s,1”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:3] GotoIf(“SIP/1002-0000007b”, “0?disabletrunk,1”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:4] Set(“SIP/1002-0000007b”, “DIAL_NUMBER=1##########”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:5] Set(“SIP/1002-0000007b”, “DIAL_TRUNK_OPTIONS=tr”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:6] Set(“SIP/1002-0000007b”, “OUTBOUND_GROUP=OUT_6”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:7] GotoIf(“SIP/1002-0000007b”, “1?nomax”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-dialout-trunk,s,9)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:9] GotoIf(“SIP/1002-0000007b”, “0?skipoutcid”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:10] Set(“SIP/1002-0000007b”, “DIAL_TRUNK_OPTIONS=”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:11] Macro(“SIP/1002-0000007b”, “outbound-callerid,6”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:1] ExecIf(“SIP/1002-0000007b”, “0?Set(CALLERPRES()=)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:2] ExecIf(“SIP/1002-0000007b”, “0?Set(REALCALLERIDNUM=1002)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:3] GotoIf(“SIP/1002-0000007b”, “1?normcid”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-outbound-callerid,s,6)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:6] Set(“SIP/1002-0000007b”, “USEROUTCID=##########”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:7] Set(“SIP/1002-0000007b”, “EMERGENCYCID=”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:8] Set(“SIP/1002-0000007b”, “TRUNKOUTCID=##########”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:9] GotoIf(“SIP/1002-0000007b”, “1?trunkcid”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-outbound-callerid,s,12)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:12] ExecIf(“SIP/1002-0000007b”, “1?Set(CALLERID(all)=##########)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:13] ExecIf(“SIP/1002-0000007b”, “1?Set(CALLERID(all)=##########)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:14] ExecIf(“SIP/1002-0000007b”, “0?Set(CALLERID(all)=)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-outbound-callerid:15] ExecIf(“SIP/1002-0000007b”, “0?Set(CALLERPRES()=prohib_passed_screen)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:12] GosubIf(“SIP/1002-0000007b”, “1?sub-flp-6,s,1”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@sub-flp-6:1] ExecIf(“SIP/1002-0000007b”, “0?Set(TARGET_FLP_6=11##########)”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@sub-flp-6:2] GotoIf(“SIP/1002-0000007b”, “0?match”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@sub-flp-6:3] ExecIf(“SIP/1002-0000007b”, “1?Return()”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:13] Set(“SIP/1002-0000007b”, “OUTNUM=1##########”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:14] Set(“SIP/1002-0000007b”, “custom=AMP”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:15] ExecIf(“SIP/1002-0000007b”, “0?Set(DIAL_TRUNK_OPTIONS=M(setmusic^default))”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:16] ExecIf(“SIP/1002-0000007b”, “0?Set(DIAL_TRUNK_OPTIONS=M(confirm))”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:17] Macro(“SIP/1002-0000007b”, “dialout-trunk-predial-hook,”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk-predial-hook:1] MacroExit(“SIP/1002-0000007b”, “”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:18] GotoIf(“SIP/1002-0000007b”, “0?bypass,1”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:19] GotoIf(“SIP/1002-0000007b”, “1?customtrunk”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-dialout-trunk,s,23)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:23] Set(“SIP/1002-0000007b”, “pre_num=AMP:gtalk/1002/+”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:24] Set(“SIP/1002-0000007b”, “the_num=OUTNUM”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:25] Set(“SIP/1002-0000007b”, "[email protected]") in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:26] GotoIf(“SIP/1002-0000007b”, “1?outnum:skipoutnum”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Goto (macro-dialout-trunk,s,27)
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:27] Set(“SIP/1002-0000007b”, “the_num=1##########”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] pbx.c: – Executing [s@macro-dialout-trunk:28] Dial(“SIP/1002-0000007b”, “gtalk/1002/+1##########@voice.google.com,300,”) in new stack
[Jun 4 13:47:03] VERBOSE[58625] app_dial.c: – Called 1002/+1##########@voice.google.com

Not sure if this is the best way to do it. And wondering if there a way to set it so that it just dials the googleout without needing a separate section for every extension.

In any case to make it work, I changed the extensions_custom.conf to the following:

[googlein]
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,${CUT(EXTEN,@,1)},1)
exten => _[0-9a-z].,h,hangup

[googleout]
exten => _1NXXNXXXXXX,1,Macro(user-callerid,LIMIT,)
exten => _1NXXNXXXXXX,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _1NXXNXXXXXX,n,Set(_NODEST=)
exten => _1NXXNXXXXXX,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _1NXXNXXXXXX,n,Macro(dialout-trunk,6,${EXTEN},)
exten => _1NXXNXXXXXX,n,Macro(outisbusy,)
exten => _NXXNXXXXXX,1,Macro(user-callerid,LIMIT,)
exten => _NXXNXXXXXX,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _NXXNXXXXXX,n,Set(_NODEST=)
exten => _NXXNXXXXXX,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _NXXNXXXXXX,n,Macro(dialout-trunk,6,1${EXTEN},)
exten => _NXXNXXXXXX,n,Macro(outisbusy,)
exten => _NXXXXXX,1,Macro(user-callerid,LIMIT,)
exten => _NXXXXXX,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _NXXXXXX,n,Set(_NODEST=)
exten => _NXXXXXX,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _NXXXXXX,n,Macro(dialout-trunk,6,1646${EXTEN},)
exten => _NXXXXXX,n,Macro(outisbusy,)

[1002]
include => googleout

[1003]
include => googleout

I’ve not tried to do what you’re attempting, but why not have an outbound route for each of the GV lines and match the CallerID for each of the extensions to their respective route?

Maybe you’ve tried that?

Peter,

I dont have the freepbx/asterisk skills to do the matching. Point me in the right direction and I will figure it out though. Are you saying I could do this without custom contexts?

Right now I have

  1. GV Outbound Routes configured as custom routes pointing to its own google voice trunks as described by the asterisk 1.8/gvoice integration docs out there.
  2. The trunks have a custom dial string: “gtalk/####/[email protected]” where #### is the extension
  3. The custom contexts restrict the outbound calling from a particular extension to its custom outbound route

If there was a way for me to pass the extension in the custom dial string, that might allow me to have only one custom GV trunk, which would appropriately pick the right outgoing jabber channel. I have tried setting it to $AMPUSER$, but the macro takes the literal “AMPUSER” rather than the extension it is coming from.

Note that I changed the workaround I posted in my last reply, by modifying the extensions_custom.conf to include the from-internal instead of googleout

[1002]
include => from-internal

Yes, skip custom contexts and be sure to set the caller id on each of the extensions or users. Create a trunk for each of you GV accounts (as you probably already have?) and then jump into the Outbound Routes.

Create a route for EACH of GV accounts using the ‘9’ and ‘.’ (or whatever you’re using for outbound calling) but put only one extension’s callerid then also into the box where the red arrow points. (You can hover over the text noted by the purple arrow for more information.)

Then only select the right trunk for each of the extensions you put in each of the routes.

In the end you’ll have at least one trunk entry for each GV number and then at least one route entry for each Extension/User. It’s okay to have them all match the 9+. as noted above. Only if the callerid matches will the route get used.

If you have a couple extensions that should all use the same GV number, put that one last.

Yes, skip custom contexts and be sure to set the caller id on each of the extensions or users. Create a trunk for each of you GV accounts (as you probably already have?) and then jump into the Outbound Routes.

Create a route for EACH of GV accounts using the ‘9’ and ‘.’ (or whatever you’re using for outbound calling) but put only one extension’s callerid then also into the box where the red arrow points. (You can hover over the text noted by the purple arrow for more information.)

Then only select the right trunk for each of the extensions you put in each of the routes.

In the end you’ll have at least one trunk entry for each GV number and then at least one route entry for each Extension/User. It’s okay to have them all match the 9+. as noted above. Only if the callerid matches will the route get used.

If you have a couple extensions that should all use the same GV number, put that one last.

Awesome, it works! That made the configuration a lot easier!

I too like it when simpler = easier = better.