Skip to main content

Google Voice API

Click here to expand Table of Contents

Error rendering macro 'toc'

null

Adding Google Voice as an outgoing destination

Create yourself a Google Voice account (or reconfigure an existing one)

a) Go to www.google.com/voice 
b) Login to Google voice, creating a new Google voice number if you don't have one yet
c) Add a destination number which would be a DID inbound to your PBX (this will be the number google voice calls back on when establishing the outbound call)

Install pygooglevoice API utility

a) Install python, python-setuptools and mercurial system packages
b) easy_install simplejson
c) hg clone https://pygooglevoice.googlecode.com/hg/ pygooglevoice
d) cd pygooglevoice/
e) sudo python setup.py install
f) sudo -u freeswitch HOME=/opt/freeswitch gvoice # this will create /opt/freeswitch/.gvoice
g) Setup your email and password in /opt/freeswitch/.gvoice
h) Setup the forwardingNumber to be the DID inbound number, with the appropriate phoneType

Create the outbound dialplan

a) Create freeswitch/conf/dialplan/default/02_googlevoice.xml with the following contents (replacing DIDNUMBER with the number above):

<!-- dial via googlevoice callback -->
<extension name="googlevoice">
<condition field="destination_number" expression="^33(\d+)$">
<action application="hash" data="insert/googlevoice/uuidDIDNUMBER/${uuid}" />
<action application="set" data="tts_engine=flite"/>
<action application="set" data="tts_voice=rms"/>
<action application="speak" data="Please wait while we connect you via Google Voice"/>
<!-- do gvoice call here -->
<action application="system" data="HOME=/opt/freeswitch gvoice call $1" />
<action application="park" />
</condition>
</extension>

Modification: nttranbao on Nov 21 2011 Thanks for the great tutorial. Based on this, I can do multi trunks of google voices properly. Below is a nicer outbound dialplan that generates connecting tone for caller, and explicitly specify all required parameters for gvoice script. (Note that a "&" at the end of gvoice command is to let Freeswich continue IMMEDIATELY without having to wait for the SYSTEM() command to finish)

<condition field="destination_number" expression="^33(\d+)$">
<!-- dial via googlevoice callback -->
<action application="hash" data="insert/googlevoice/uuidDIDNUMBER/${uuid}" />
<!-- do gvoice call here -->
<action application="system" data="gvoice -e google-voice-email -p google-voice-password call $1 10-digit-callback-No &" />
<action application="playback" data="tone_stream://%(50,50,350);loops=-1" />
</condition>


Modify your DID inbound extension to add the intercept call

a) Replace DIDNUMBER with your configured Google Voice callback number
b) Replace GOOGLEVOICEEXT with the extension to answer any google voice calls to the DIDNUMBER that don't have an attached outgoing call.

<extension name="DIDNUMBER">
<condition field="destination_number" expression="^DIDNUMBER$">
<action application="intercept" data="${hash(select/googlevoice/uuidDIDNUMBER)}" />
<action application="transfer" data="GOOGLEVOICEEXT XML default"/>
</condition>
</extension>