Saturday, November 27, 2010

Google Voice Talk on Asterisk 1.8 (with FreePBX) and a flexible dialplan

Google Voice Talk on Asterisk 1.8 (with FreePBX) and a flexible dialplan [Updated 12-04-2012]
Ok so you’ve got a 1.4 or 1.6 Asterisk with FreePBX running somewhere? Now you wish to use GoogleVoice/Talk with Asterisk 1.8. Here’s how.
This guide is more for a Debian system, so if you are running other than, do a little google.
Firstly, get your FreePBX updated to v2.8, other versions apparently won’t support Asterisk 1.8.
After that, start the Asterisk upgrade process. (from Mikael Carlsson, FreePBX Development Team @ this article) and the necessary dependencies for Asterisk’s chan_gtalk and chan_jabber
  • cd /usr/src
  • wget http://iksemel.googlecode.com/files/iksemel-1.4.tar.gz
  • tar -zxvf iksemel-1.4.tar.gz
  • cd iksemel-1.4
  • ./configure
  • make && make all && make install
  • wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.8-current.tar.gz
  • tar xvfz asterisk-1.8-current.tar.gz
  • cd asterisk-1.8.0
  • contrib/scripts/get_mp3_source.sh
  • ./configure
  • make menuconfig
  • Goto Add-ons and select –> app_mysqp, app_saycountpl, cdr_mysql, format_mp3, res_config_mysql
  • Goto Extra-Sound-Packages and Select –> EXTRA-SOUNDS-<Yourlanguage>-GSM
  • Goto Channel Drivers and ensure that > chan_gtalk and chan_jingle are selected
  • Save and exit
  • ./configure
  • make && make install
  • amportal stop
  • amportal start
You’ve done your 1.8 setup which is ready for google voice/talk
Now, here are some configuration files you can simply copy paste in /etc/asterisk/. You can follow exactly the same as i have to make things work first.
Edit /etc/asterisk/gtalk.conf, paste the following, modify accordingly. Note, for newer versions of FreePBX, it supports inbound routes with names (typically it would be numbers). So you can actually send the call to for example from-pstn or from-dahdi or from-trunnk, then you can add this "inbound route to route to a specific extension” as you would do with a normal DID for instance.
;####start####
[general]
context=google-incoming ;;##use from-trunk if using newer FBX 2.8 or higher
allowguests=yes
bindaddr=<yourinternalIP>
[guest]
disallow=all
allow=ulaw
context=google-incoming ;;##use from-trunk if using newer FBX 2.8 or higher
connection=sanjay-ac1

;####end####
Save and exit.
Now, edit, /etc/asterisk/jabber.conf, paste the following, modify accordingly
;####start####
[general]
debug=yes
autoprune=no
autoregister=yes

[sanjay-ac1]
type=client
serverhost=talk.google.com
username=highsecurity@gmail.com/Talk
secret=mysecretPassword
port=5222
usetls=yes
usesasl=yes
statusmessage="higsecurity@asterisk.gmail"
timeout=100

[sanjay-ac2]
type=client
serverhost=talk.google.com
username=stunningsimplicity@gmail.com/Talk2
secret=mysecretPassword
port=5222
usetls=yes
usesasl=yes
statusmessage="stunningsimplicity@asterisk.gmail"
timeout=100

;####end###
And finally, edit your custom dialplan e.g. /etc/asterisk/extensions_custom.conf, paste the following, modify accordingly. Yo u only do this below if you are not using FreePBX latest version 2.8 or higher. For FreePBX 2.8 or higher, see below this dialplan.
;####start####
[from-internal-custom]
include => google-outgoing

[google-incoming]
;this for internal gmail user highsecurity@gmail.com, ring her 1001 extension
exten => highsecurity@gmail.com,1,Macro(user-callerid,)
exten => highsecurity@gmail.com,n,Answer()
exten => highsecurity@gmail.com,n,Wait(2)
exten => highsecurity@gmail.com,n,Set(Thiscallchan=${CALLERID(name)})
exten => highsecurity@gmail.com,n,Set(CALLERID(name)=${CUT(Thiscallchan,/,1)})
exten => highsecurity@gmail.com,n,Set(CALLERID(num)=g*${CUT(CALLERID(name),@,1)})
exten => highsecurity@gmail.com,n,SendDTMF(1)
exten => highsecurity@gmail.com,n,Goto(from-internal,1001,1) or ,n,DIAL(SIP/1001)
; end gmail user highsecurity@gmail.com

;this for internal gmail user stunningsimplicity@gmail.com, ring her 1002 extension
exten => stunningsimplicity@gmail.com,1,Answer()
exten => stunningsimplicity@gmail.com,n,Wait(2)
exten => stunningsimplicity@gmail.com,n,Set(Thiscallchan=${CALLERID(name)})
exten => stunningsimplicity@gmail.com,n,Set(CALLERID(name)=${CUT(Thiscallchan,/,1)})
exten => stunningsimplicity@gmail.com,n,Set(CALLERID(num)=g*${CUT(CALLERID(name),@,1)})
exten => stunningsimplicity@gmail.com,n,SendDTMF(1)
exten => stunningsimplicity@gmail.com,n,Goto(from-internal,1002,1) # or ,n,DIAL(SIP/1002)
; end gmail user stunningsimplicity@gmail.com

[google-outgoing]
; Set the outgoing account per jabber.conf
exten => _g*.,1,Macro(user-callerid,SKIPTTL)
; Add more users here
exten => _g*.,n,ExecIf($["${AMPUSER}" = "1001"]?Set(gmailoutaccount=sanjay-ac1))
exten => _g*.,n,ExecIf($["${AMPUSER}" = "1002"]?Set(gmailoutaccount=sanjay-ac2))
;
; Normal outbound calling, g is prefixed so it will call google talk,
; and call other places using google voice, like below, a US number
exten => _g*.,n,Dial(gtalk/${gmailoutaccount}/${EXTEN:2}@gmail.com)
exten => _1XXXXXXXXXX,n,Dial(gtalk/${gmailoutaccount}/${EXTEN}@voice.google.com)
;
;
; Dialplan for sending messages
exten => _t*.,1,Macro(user-callerid,SKIPTTL)
exten => _t*.,n,ExecIf($["${AMPUSER}" = "1001"]?Set(gmailoutaccount=sanjay-ac1))
exten => _t*.,n,ExecIf($["${AMPUSER}" = "1002"]?Set(gmailoutaccount=sanjay-ac2))
;
exten => _t*.,n,JABBERSend(${gmailoutaccount},sanjayws@gmail.com,"${EXTEN:2}")
exten => h,1,(Hangup)

;####end####
 
At this point be sure to stop and start Asterisk (amportal kill / amportal start). Infact most settings made on gtalk.conf needs to restart Asterisk, not just reload.
With FreePBX 
When using FreePBX 2.8 or higher, you don’t need to write manual dialplans for INBOUND (incoming) calls. You only need to customize the dialplan if you are planning to make outbound calls on Gtalk through Asterisk. Here below is a sample inbound route created in FreePBX.
Remember, this is for INCOMING only that will be handled by FreePBX, here any calls destined to highsecurity@gmail.com I will attempt to send to an extension (or anywhere as you please). As you can see below, if I set the context to from-trunk, I will see it like below in my cli
image
Notice the DID value there is highsecurity@gmail.com which mean, it is as simple as adding an Inbound Route in FreePBX like below;
image
 
Extra information manual dialplan creation
1) You must specify incoming and outgoing google accounts.
2) Incoming connections will dial internal extensions or just about anywhere you have designed in FreePBX, in this case, they are extensions.
3) Outgoing calls are matched based on the extension that is dialling (supports user/device mode as well) so that if extension 1001 is dialing out, the recipient will see highsecurity calling and if extension 1002 dialling, he/she will see stunningsimplicity
4) Anyone without that specific dialplan set for outbound can be limited to a failurecode (not defined in this sample here).
5) If someone wants to dial out, he/she dial g*<user> like for example gs*anjayws will dial the gmail user sanjayws. The g* is used as a prefix for dialling out so it is a clear path to dial google.  To make redials easier, when an incoming call comes through the dialplan, we’ve added the g* at the begining of the callerID(name) field so that when a person redials, it will engage the outbound route. Notice that we do a CUT in there and that is to remove certain characters through a delimiter character.
6) Of course, you can also specify calling to other google voice numbers if you have google voice credits to those outgoing accounts created in jabber.conf. This example above, does US calls as it is free for now. Feel free to add any other calling matches to use google voice.
Done.
Do send your feedback to sanjay@astiostech.com
Thank you.
Resources:
http://forums.digium.com/viewtopic.php?f=1&t=76250
https://wiki.asterisk.org/wiki/display/AST/Calling+using+Google
http://www.freepbx.org/forum/freepbx/installation/asterisk-1-8-installation







































Post a Comment