Prerequisites
Asterisk communicates with Google Voice and Google Talk using the chan_motif Channel Driver and the res_xmpp Resource module. Before proceeding, please ensure that both are compiled and part of your installation. Compilation of res_xmpp and chan_motif for use with Google Talk / Voice are dependant on the iksemel library files as well as the OpenSSL development libraries presence on your system.
Calling using Google Voice or via the Google Talk web client requires the use of Asterisk 11.0 or greater. Older versions of Asterisk will not work.
For basic calling between Google Talk web clients, you need a Google Mail account.
For calling to and from the PSTN, you will need a Google Voice account.
In your Google account, you'll want to change the Chat setting from the default of "Automatically allow people that I communicate with often to chat with me and see when I'm online" to the second option of "Only allow people that I've explicitly approved to chat with me and see when I'm online."
IPv6 is currently not supported. Use of IPv4 is required.
Google Voice can now be used with Google Apps accounts.
RTP configuration
ICE support is required for chan_motif to operate. It is disabled by default and must be explicitly enabled in the RTP configuration file rtp.conf as follows.
[general] icesupport=yes
If this option is not enabled you will receive the following error message.
Unable to add Google ICE candidates as ICE support not available or no candidates available
Motif configuration
The Motif channel driver is configured with the motif.conf configuration file, typically located in /etc/asterisk. What follows is an example configuration for successful operation.
Example Motif Configuration
[google] context=incoming-motif disallow=all allow=ulaw connection=google
This general section of this configuration specifies several items.
- That calls will terminate to or originate from the incoming-motif context; context=incoming-motif
- That all codecs are first explicitly disallowed
- That G.711 ulaw is allowed
- The an XMPP connection called "google" is to be used
Google lists supported audio codecs on this page - https://developers.google.com/talk/open_communications
Per section, 5, the supported codecs are:
- PCMA
- PCMU
- G.722
- GSM
- iLBC
- Speex
Our experience shows this not to be the case. Rather, the codecs, supported by Asterisk, and seen in an invite from Google Chat are:
- PCMA
- PCMU
- G.722
- iLBC
- Speex 16kHz
- Speex 8kHz
It should be noted that calling using Google Voice requires the G.711 ulaw codec. So, if you want to make sure Google Voice calls work, allow G.711 ulaw, at a minimum.
XMPP Configuration
The res_xmpp Resource is configured with the xmpp.conf configuration file, typically located in /etc/asterisk. What follows is an example configuration for successful operation.
Example XMPP Configuration
[general] [google] type=client serverhost=talk.google.com username=example@gmail.com secret=examplepassword priority=25 port=5222 usetls=yes usesasl=yes status=available statusmessage="I am available" timeout=5
The default general section does not need any modification.
The google section of this configuration specifies several items.
- The type is set to client, as we're connecting to Google as a service; type=client
- The serverhost is Google's talk server; serverhost=talk.google.com
- Our username is configured as your_google_username@gmail.com; username=your_google_username@gmail.com
- Our password is configured using the secret option; secret=your_google_password
- Google's talk service operates on port 5222; port=5222
- Our priority is set to 25; priority=25
- TLS encryption is required by Google; usetls=yes
- Simple Authentication and Security Layer (SASL) is used by Google; usesasl=yes
- We set a status message so other Google chat users can see that we're an Asterisk server; statusmessage="I am available"
- We set a timeout for receiving message from Google that allows for plenty of time in the event of network delay; timeout=5
More about Priorities
As many different connections to Google are possible simultaneously via different client mechanisms, it is important to understand the role of priorities in the routing of inbound calls. Proper usage of the priority setting can allow use of a Google account that is not otherwise entirely dedicated to voice services.
With priorities, the higher the setting value, the more any client using that value is preferred as a destination for inbound calls, in deference to any other client with a lower priority value. Known values of commonly used clients include the Gmail chat client, which maintains a priority of 20, and the Windows GTalk client, which uses a priority of 24. The maximum allowable value is 127. Thus, setting one's priority option for the XMPP peer in res_xmpp.conf to a value higher than 24 will cause inbound calls to flow to Asterisk, even while one is logged into either Gmail or the Windows GTalk client.
Outbound calls are unaffected by the priority setting.
Phone configuration
Now, let's create a phone. The configuration of a SIP device for this purpose would, in sip.conf, typically located in /etc/asterisk, look something like:
[malcolm] type=peer secret=my_secure_password host=dynamic context=local
Dialplan configuration
Incoming calls
Next, let's configure our dialplan to receive an incoming call from Google and route it to the SIP phone we created. To do this, our dialplan, extensions.conf, typically located in /etc/asterisk, would look like:
[incoming-motif] exten => s,1,NoOp() same => n,Wait(1) same => n,Answer() same => n,SendDTMF(1) same => n,Dial(SIP/malcolm,20)
This example uses the "s" unmatched extension, because we're only configuring one client connection in this example.
In this example, we're Waiting 1 second, answering the call, sending the DTMF "1" back to Google, and then dialing the call.
We do this, because inbound calls from Google enable, even if it's disabled in your Google Voice control panel, call screening.
Without this SendDTMF event, you'll have to confirm with Google whether or not you want to answer the call.
Outgoing calls
Outgoing calls to Google Talk users take the form of:
exten => 100,1,Dial(Motif/google/mybuddy@gmail.com,,r)
Where the technology is "Motif," the dialing peer is "google" as defined in xmpp.conf, and the dial string is the Google account name.
We use the Dial option "r" because Google doesn't provide ringing indications.
Outgoing calls made to Google Voice take the form of:
exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
Where the technology is "Motif," the dialing peer is "google" as defined in motif.conf, and the dial string is a full E.164 number, sans the plus character.
Again, we use Dial option "r" because Google doesn't provide ringing indications.