<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/en/2171/18/9/_/styles/combined.css?spaceKey=AST&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/AST/Calling+using+Google">Calling using Google</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://wiki.asterisk.org/wiki/display/~mdavenport">Malcolm Davenport</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{warning} <br>Note that Google&#39;s changes to their Google Voice system have rendered much of these capabilities inoperable, in many cases, or unreliable, in most cases.  As such, building a business based on Google Voice calling using Asterisk is not something that would be recommended.  Additionally, ongoing maintenance of Google Talk integration with Asterisk is not provided by Digium and is instead in the charge of the community. <br>{warning} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Prerequisites <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Note that Google's changes to their Google Voice system have rendered much of these capabilities inoperable, in many cases, or unreliable, in most cases.  As such, building a business based on Google Voice calling using Asterisk is not something that would be recommended.  Additionally, ongoing maintenance of Google Talk integration with Asterisk is not provided by Digium and is instead in the charge of the community.</td></tr></table></div>

<h2><a name="CallingusingGoogle-Prerequisites"></a>Prerequisites</h2>

<p>Asterisk communicates with Google Voice and Google Talk using the chan_gtalk Channel Driver and the res_jabber Resource module.  Before proceeding, please ensure that both are compiled and part of your installation.  Compilation of res_jabber and chan_gtalk for use with Google Talk / Voice are dependant on the iksemel library files as well as the OpenSSL development libraries presence on your system.</p>

<p>Calling using Google Voice or via the Google Talk web client requires the use of Asterisk 1.8.1.1 or greater.  The 1.6.x versions of Asterisk only support calls made using the legacy GoogleTalk external client.</p>

<p>For basic calling between Google Talk web clients, you need a Google Mail account.</p>

<p>For calling to and from the PSTN, you will need a Google Voice account.</p>

<p>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."</p>

<p>IPv6 is currently not supported.  Use of IPv4 is required.</p>

<p>Google Voice can now be used with Google Apps accounts.</p>

<h2><a name="CallingusingGoogle-Gtalkconfiguration"></a>Gtalk configuration</h2>

<p>The chan_gtalk Channel Driver is configured with the gtalk.conf configuration file, typically located in /etc/asterisk.  What follows is the minimum required configuration for successful operation.</p>

<h5><a name="CallingusingGoogle-MinimumGtalkConfiguration"></a>Minimum Gtalk Configuration</h5>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>[general]
context=local
allowguest=yes
bindaddr=0.0.0.0
externip=216.208.246.1

[guest]
disallow=all
allow=ulaw
context=local
connection=asterisk
</pre>
</div></div>

<p>This general section of this configuration specifies several items.</p>
<ol>
        <li>That calls will terminate to or originate from the <b>local</b> context; context=local</li>
        <li>That guest calls are allowd; allowguest=yes</li>
        <li>That RTP sessions will be bound to a local address (an IPv4 address must be present); bindaddr=0.0.0.0</li>
        <li>(optional) That your external (the one outside of your NAT) IP address is defined; externip=216.208.246.1</li>
</ol>


<p>The guest section of this configuration specifies several items.</p>
<ol>
        <li>That no codecs are allowed; disallow=all</li>
        <li>That the ulaw codec is explicitly allowed; allow=ulaw</li>
        <li>That calls received by the guest user will be terminated into the <b>local</b> context; context=local</li>
        <li>That the Jabber connection used for guest calls is called "asterisk;" connection=asterisk</li>
</ol>


<h2><a name="CallingusingGoogle-JabberConfiguration"></a>Jabber Configuration</h2>

<p>The res_jabber Resource is configured with the jabber.conf configuration file, typically located in /etc/asterisk.  What follows is the minimum required configuration for successful operation.</p>

<h5><a name="CallingusingGoogle-MinimumJabberConfiguration"></a>Minimum Jabber Configuration</h5>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>[general]
autoregister=yes

[asterisk]
type=client
serverhost=talk.google.com
username=your_google_username@gmail.com/Talk
secret=your_google_password
port=5222
usetls=yes
usesasl=yes
statusmessage="I am an Asterisk Server"
timeout=100
</pre>
</div></div>

<p>The general section of this configuration specifies several items.</p>
<ol>
        <li>Debug mode is enabled, so that XMPP messages can be seen on the Asterisk CLI; debug=yes</li>
        <li>Automated buddy pruning is disabled, otherwise buddies will be automatically removed from your list; autoprune=no</li>
        <li>Automated registration of users from the buddy list is enabled; autoregister=yes</li>
</ol>


<p>The asterisk section of this configuration specifies several items.</p>
<ol>
        <li>The type is set to client, as we're connecting to Google as a service; type=client</li>
        <li>The serverhost is Google's talk server; serverhost=talk.google.com</li>
        <li>Our username is configured as your_google_username@gmail.com/resource, where our resource is "Talk;" username=your_google_username@gmail.com/Talk</li>
        <li>Our password is configured using the secret option; secret=your_google_password</li>
        <li>Google's talk service operates on port 5222; port=5222</li>
        <li>TLS encryption is required by Google; usetls=yes</li>
        <li>Simple Authentication and Security Layer (SASL) is used by Google; usesasl=yes</li>
        <li>We set a status message so other Google chat users can see that we're an Asterisk server; statusmessage="I am an Asterisk Server"</li>
        <li>We set a timeout for receiving message from Google that allows for plenty of time in the event of network delay; timeout=100</li>
</ol>



<h2><a name="CallingusingGoogle-Phoneconfiguration"></a>Phone configuration</h2>

<p>Now, let's place a phone into the same context as the Google calls.  The configuration of a SIP device for this purpose would, in sip.conf, typically located in /etc/asterisk, look something like:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>[malcolm]
type=peer
secret=my_secure_password
host=dynamic
context=local
</pre>
</div></div>

<h2><a name="CallingusingGoogle-Dialplanconfiguration"></a>Dialplan configuration</h2>

<h5><a name="CallingusingGoogle-Incomingcalls"></a>Incoming calls</h5>

<p>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:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>exten =&gt; s,1,Answer()
exten =&gt; s,n,Wait(2)
exten =&gt; s,n,SendDTMF(1)
exten =&gt; s,n,Dial(SIP/malcolm,20)
</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Note that you might have to adjust the "Wait" time from 2 (in seconds) to something larger, like 8, depending on the current mood of Google.  Otherwise, your incoming calls might not be successfully picked up.</td></tr></table></div>

<p>This example uses the "s" unmatched extension, because Google does not forward any DID when it sends the call to Asterisk.</p>

<p>In this example, we're Answering the call, Waiting 2 seconds, sending the DTMF "1" back to Google, and <b>then</b> dialing the call.<br/>
We do this, because inbound calls from Google enable, even if it's disabled in your Google Voice control panel, call screening.<br/>
Without this SendDTMF event, you'll have to confirm with Google whether or not you want to answer the call.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using Google's voicemail</b><br />Another method for accomplishing the sending of the DTMF event is to use the D dial option.  The D option tells Asterisk to send a specified DTMF string after the called party has answered.  DTMF events specified before a colon are sent to the <b>called</b> party.  DTMF events specified after a colon are sent to the <b>calling</b> party.

<p>In this example then, one does not need to actually answer the call first.  This means that if the called party doesn't answer, Google will resort to sending the call to one's Google Voice voicemail box, instead of leaving it at Asterisk.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">exten =&gt; s,1,Dial(SIP/malcolm,20,D(:1))</pre>
</div></div></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Filtering Caller ID</b><br />The inbound CallerID from Google is going to look a bit nasty, e.g.:

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>+15555551212@voice.google.com/srvres-MTAuMjE4LjIuMTk3Ojk4MzM=
</pre>
</div></div>

<p>Your VoIP client (SIPDroid) might not like this, so let's simplify that Caller ID a bit, and make it more presentable for your phone's display.  Here's the example that we'll step through:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>exten =&gt; s,1,Set(crazygooglecid=${CALLERID(name)})
exten =&gt; s,n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
exten =&gt; s,n,Set(CALLERID(all)=${stripcrazysuffix})
exten =&gt; s,n,Dial(SIP/malcolm,20,D(:1))
</pre>
</div></div>

<p>First, we set a variable called <b>crazygooglecid</b> to be equal to the name field of the CALLERID function.  Next, we use the CUT function to grab everything that's before the @ symbol, and save it in a new variable called <b>stripcrazysuffix.</b>  We'll set this new variable to the CALLERID that we're going to use for our Dial.  Finally, we'll actually Dial our internal destination.</p></td></tr></table></div>

<h5><a name="CallingusingGoogle-Outgoingcalls"></a>Outgoing calls</h5>

<p>Outgoing calls to Google Talk users take the form of:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>exten =&gt; 100,1,Dial(gtalk/asterisk/mybuddy@gmail.com)
</pre>
</div></div>

<p>Where the technology is "gtalk," the dialing peer is "asterisk" as defined in jabber.conf, and the dial string is the Google account name.</p>

<p>Outgoing calls made to Google Voice take the form of:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>exten =&gt; _1XXXXXXXXXX,1,Dial(gtalk/asterisk/+${EXTEN}@voice.google.com)
</pre>
</div></div>

<p>Where the technology is "gtalk," the dialing peer is "asterisk" as defined in jabber.conf, and the dial string is a full E.164 number (plus character followed by country code, followed by the rest of the digits).</p>

<h3><a name="CallingusingGoogle-InteractiveVoicewithTextResponse%28IVTR%29"></a>Interactive Voice with Text Response (IVTR)</h3>

<p>Because the Google Talk web client provides both audio and text interface, you can use it to provide a text-based way of traversing Interactive Voice Response (IVR) menus.  This is necessary since the client does not have any DTMF inputs.</p>

<p>In the following dialplan example, we will answer the call, wait a bit, send some text that will show up in the caller's Google Talk client, play back a prompt, capture the caller's text-based response, and then dial the appropriate SIP device.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">exten =&gt; s,1,Answer()
exten =&gt; s,n,SendText("If you know the extension of the party you wish to reach, dial it now.")
exten =&gt; s,n,Background(if-u-know-ext-dial)
exten =&gt; s,n,Set(OPTION=${JABBER_RECEIVE(asterisk,${CALLERID(name)::15},5)})
exten =&gt; s,n,Dial(SIP/${OPTION},20)</pre>
</div></div>

<p>Note that with the JABBER_RECEIVE function, we're receiving the text from <b>asterisk</b> which we defined earlier in this page as our connection to Google.  We're also specifying with <b>${CALLERID(name)::15}</b> that we want to strip off the last 15 characters from the CallerID name string - which is the number of characters that Google is appending, as of this writing, to represent an internal call ID number, and that we want to wait <b>5</b> seconds for a response.</p>

<h3><a name="CallingusingGoogle-Webinar"></a>Webinar</h3>

<p>A Webinar was conducted on Tuesday, March 24, 2011 detailing Asterisk configuration for calling using Google as well as several usage cases.  A copy of the slides, in PDF format, is available here - <a href="/wiki/download/attachments/5996698/Google+Calling+Webinar+-+Public.pdf?version=1&amp;modificationDate=1300994576490">Google Calling Webinar - Public.pdf</a></p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://wiki.asterisk.org/wiki/display/AST/Calling+using+Google">View Online</a>
        |
        <a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=5996698&revisedVersion=39&originalVersion=38">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/display/AST/Calling+using+Google?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>