Receive calls from 2 different Google Voice Accounts

Now that I have google Voice setup and working well (me=very happy), I’m now looking at using 2 different google voice accounts. I’ve setup the account details etc and have the calls being received for both numbers over to the Asterisk box.

However, the challenge is with my extensions_custom.conf. I believe that I need to route the calls to the correct incoming route based on the DID.

My configuration prior to adding a second account was (note 1617XXXXXXX is account Number 1 and 1617YYYYYYY is account number 2):

[from-google]
exten => s,1,Answer()
exten => s,n,Wait(2)
exten => s,n,SendDTMF(1)
exten => s,n,Set(TRXNUM=${CALLERID(name)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,@,1)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,+,2)})
exten => s,n,Set(CALLERID(num)=${TRXNUM})
exten => s,n,Goto(from-trunk,1617XXXXXXX,1)
exten => s,h,Hangup

Now, I figured that I need to use a GotoIf statement to route to the correct trunk:

[from-google]
exten => s,1,Answer()
exten => s,n,Wait(2)
exten => s,n,SendDTMF(1)
exten => s,n,Set(TRXNUM=${CALLERID(name)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,@,1)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,+,2)})
exten => s,n,Set(CALLERID(num)=${TRXNUM})
exten => s,n,GotoIf(???= 1617XXXXXXX]?from-trunk,1617XXXXXXX,1)
exten => s,n,GotoIf(???= 1617YYYYYYY]?from-trunk,1617YYYYYYY,1)
}
exten => s,h,Hangup

The question I have is what clause do I need to use / variable need to check in order to validate the DID? (represented by ???.

Also, thinking about this a little bit more, I probably could actually do something a little different as well:

[from-google]
exten => s,1,Answer()
exten => s,n,Wait(2)
exten => s,n,SendDTMF(1)
exten => s,n,Set(TRXNUM=${CALLERID(name)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,@,1)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,+,2)})
exten => s,n,Set(CALLERID(num)=${TRXNUM})
exten => s,n,Goto(from-trunk,${???},1)
exten => s,h,Hangup

This would set the DID when performing the Goto, however, again I still need to know what variable to use to determine the DID ( ${???} above).

Thanks guys

Andrew

So I followed the directions described in this wordpress blog
http://michigantelephone.wordpress.com/2010/12/21/how-to-use-google-voice-for-free-calls-on-an-asterisk-1-8freepbx-2-8-system-the-easy-way/

Which look to be what skippy76 did as well, but the call never comes in to my freepbx box. The necessary modules show to be installed in the make menuconfig screen; however when I do

asterisx*CLI> module show like gtalk
Module Description Use Count
0 modules loaded

The same for jabber.so.

Both of these also appear in /usr/lib/asterisk/modules/

I have the DID set to connect to a conference but the call never answers and just goes to google voice mail.

Any suggestions?

Sir_SIP, thanks for the help and advice.

I have inbound calling working and have followed the instruction for outbound calling. I seem to have some issues though with the outbound route to select the trunk.

Assume I have three Extensions, 1000, 1001, 1002 and I have two trunks, TrunkA and TrunkB which are both GVoice trunks.

I’ve then created two outbound routes, Domestic_TrunkA and Domestic_TrunkB. the objective is to route domestic (US) calls out either TrunkA or TrunkB depending on which extension placed the call.

  • 1000 should have all calls routed to TrunkA
  • 1001 and 1002 should have all calls routed to TrunkB

Domestic_TrunkA and Domestic_TrunkB both have 3 Dial Patterns:

        1NXXNXXXXXX

1 NXXNXXXXXX
1617 NXXXXXX

Based on reading, I believe I’m to route based on originator using the CallerID field of the Dial pattern (4th Field). However, inserting the originating extension number did not result in the desired effect.

After further analysis I fond that I was forcing the CID for the extensions to the DID. As such, when I had added 1001 to the Outbound Routes the call call was not being routed as I did not have the correct CID in there… D’Oh.

That said I’m still faced with another challenge.

  • Call is received into an IVR over TrunkA.
  • Caller selects an option (2) which routes to a Call Group
  • Call Group includes a single entry with a Cell Phone in

In routing this call, the Caller ID is that of the originator which obviously could be anyone or anything… How do i instruct this call to be placed over a specific trunk?

Yeech… why are they using two second waits after answering? And, why are they setting the same variable three times in a row, overwriting the previous value each time? This is an example of how NOT to write Asterisk dial plan code!

The best context I’ve found for Google Voice inbound is this - you only need to use it ONCE (do not duplicate it for additional accounts!). This assumes that in your gtalk.conf file you have context=googlein, so you might need to change that (or the context name below) so the two context names are the same for it to work:

[googlein] exten => _[@Xa-z].,1,Noop(Incoming Google Voice call for ${EXTEN}) exten => _[@Xa-z].,n,Set(CALLERID(number)=${CALLERID(name):2:10}) exten => _[@Xa-z].,n,Set(CALLERID(name)=${CALLERID(number)}) exten => _[@Xa-z].,n,Answer exten => _[@Xa-z].,n,Wait(1) exten => _[@Xa-z].,n,SendDTMF(1) exten => _[@Xa-z].,n,Goto(from-trunk,gv-incoming-${CUT(EXTEN,@,1)},1) exten => h,1,Macro(hangupcall,)

The above is from this page, which notes:

“Inbound calls will come in on inbound routes, the same as calls from DID’s or VoIP providers. The only difference is that instead of specifying a DID number, you’ll use gv-incoming-username as the DID, with the usual substitution for username. FreePBX will give you a hard time about it when you try to save it:”

(Here it shows a screenshot of a box that FreePBX pops up that says: “DID information is normally just an incoming telephone number or for advanced users, a valid Asterisk Dial Pattern You have entered a non standard DID pattern. Are you sure this is correct?”)

“Just click OK and you should be fine.”

What they mean by “the usual substitution for username” is the part of the gmail address associated with the account that is before the @ symbol - thus if the associated email account were [email protected], the username would be johndoe, and the inbound route DID would be gv-incoming-johndoe.

I’ve found that the above context will handle all your Google Voice accounts no matter how many you may have, and all you have to do is create an inbound route for each one.

Ok, figured it out… a couple of cups of coffee and google did the trick.

The info is here at: http://pbxinaflash.com/forum/showthread.php?t=8625

The changes needed were to the extensions_custom.conf:

[from-google]
exten => _.,1,GotoIf($["${EXTEN}" = "[email protected]"]?from-google-home,s,1:from-google-work,s,1])

[from-google-home]
exten => s,1,Answer()
exten => s,n,Wait(2)
exten => s,n,SendDTMF(1)
exten => s,n,Set(TRXNUM=${CALLERID(name)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,@,1)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,+,2)})
exten => s,n,Set(CALLERID(num)=${TRXNUM})
exten => s,n,Goto(from-trunk,1617XXXXXXX,1)
exten => s,h,Hangup

[from-google-work]
exten => s,1,Answer()
exten => s,n,Wait(2)
exten => s,n,SendDTMF(1)
exten => s,n,Set(TRXNUM=${CALLERID(name)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,@,1)})
exten => s,n,Set(TRXNUM=${CUT(TRXNUM,+,2)})
exten => s,n,Set(CALLERID(num)=${TRXNUM})
exten => s,n,Goto(from-trunk,1617YYYYYYY,1)

So, the way in which the traffic is routed is based on the Google Account details.