Using Google Voice and Google Chat for free calls

This posting is an almagamation of this which, itself, references plugpbx and doozan, along with my own commentary and configuration and code.

Until recently you could use SIP providers to talk to Google Voice, and thus it was quite simple to use a phone analog terminal adapter (ATA) to work with the service. But now this has died, google has bought and shut down one service, others are overloaded or not taking new subscriptions.

You might ask, "why do I care? I can use google voice's web site to initiate calls", and the answer would be "but what if you want to _replace_ a voice line, or treat google voice like a real voice line - pick up your phone, dial a number, receive calls directly on the phone and so on".

Fortunately you can use Google Chat to make outgoing calls (you might have seen the link on your gmail site), and google voice can direct incoming calls to Google Chat.

So we need 4 things to make this work.
1) A google voice account
2) A Google Chat account
3) An ATA
4) Asterisk software to glue it all together.

Get a Google Voice account

Now asterisk needs to log into your Google Chat account (via Jabber) to do its magic. If you're using Google Chat for normal chatting then this might end up confusing people you talk with (permanently online with an odd status message). To avoid this, it's probably a good idea to create a new google account dedicated for your voice purposes. Fortunately they're free. So logout of your existing google session, create a new account. At this point you can ensure it's configured for Google Chat.

You can also add google voice to this. You no longer need to be invited by someone else; anyone can add google voice to their google account. Pick a number that'll be convenient for you. This will be your new phone number.

IMPORTANT: you need to configure google voice to forward calls to Google Chat. It can also forward to other phones (eg your cellphone) as normal, if you wish it to.

Build asterisk

Now we need Asterisk to talk to it. I have a Seagate Dockstar, which I've hacked to run Debian. This is currently my IPv6 tunnel endpoint. I've also plugged in a 300Gb disk and run NFS and Samba exporting it. I tested using transmission as a torrent client, but didn't really like it that much, so it's installed but not running. I figured this machine would be perfect to act as my asterisk server. With the configurations I list below Asterisk only takes around 18Mb of memory (RES).

So get and build asterisk. The posting at plugpbx is pretty much all you need to do.

In summary:
Step 1: Ensure your system has all the pre-req libraries:
  # apt-get update
  # apt-get -y install make gcc g++ libxml2 libxml2-dev ssh libncurses5 libncursesw5 libncurses5-dev libncursesw5-dev linux-libc-dev sqlite libnewt-dev libusb-dev zlib1g-dev libmysqlclient15-dev libsqlite0 libsqlite0-dev bison openssl libssl-dev libeditline0 libeditline-dev libedit-dev mc sox libedit2 libedit-dev curl libcurl4-gnutls-dev apache2 libapache2-mod-php5 php-pear openssh-server build-essential openssh-client zlib1g zlib1g-dev libtiff4 libtiff4-dev libnet-telnet-perl mime-construct libipc-signal-perl libmime-types-perl libproc-waitstat-perl mpg123 libiksemel-dev

Step 2: Get Asterisk
  # cd /usr/src
  # 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.*
When I did this, 1.8.3.2 was the latest version. I wasn't sure if asterisk actually needed to be in /usr/src so I actually did this on the 300Gb disk and symlinked from /usr/src to the untarred directory. This worked.

Step 3: Fix a minor "ARM" related bug in main/utils.c
(a) Under the line:   #include asterisk/config.h
add the following line:
  #define __arm__ 1

(b) Search for "__sparc__" and replace the line
  #ifdef __sparc__
with:
  #if defined(__sparc__) || defined(__arm__)
for the two instances it appears in

(c) Set proper compilation for ARM platform. In makeopts.in search for the line
  PROC=
and change it to
  PROC=arm

4) Configure the build environment:
  # ./configure

5) Configure the application:
  # make menuconfig
In the item "Channel Drivers" make sure "chan_gtalk" is selected
In the item "Resource Modules" make sure "res_jabber" and "res_rtp_asterisk" are selected
In the item "Music On Hold File Package" select "MOH-OPSOUND-G729"
Exit and save. The only setting I had to change was the "MOH" value, but you should verify the rest all work.

6) Now we're at the stage of compiling and installing
  # make
  # make install
  # make samples
  # make config
Really, do read the plugpbx article on compiling for full details.

Configure Asterisk

We need to replace a few of the provided configuration files to talk to google. There are 4 files that need updating:
  sip.conf
  extensions.conf
  gtalk.conf
  jabber.conf
In addition we can edit modules.conf to minimise the footprint by only loading required modules. At this stage I'm cargo-culting 'cos I'm not 100% sure what I'm doing! The basis of these files are from superm1, but I've made some changes. In particular I've made a change to do callerID to name lookups using 411.com. This is because Google Voice incoming calls have callerID numbers, but not names. I created a kludge script that uses 411.com to look up the number to get the name, and if we find something then we store the results in the asterisk configuration so repeated calls don't result in multiple lookups.

My files can be found here. The conf files need to go into /etc/asterisk/ and the agi file needs to go into /var/lib/asterisk/agi-bin/

You need to edit extensions.conf and gtalk.conf to replace YOURGVOICE with your Google Voice login name
You need to edit jabber.conf with your Google Voice username and password.
Finally you need to edit sip.conf, replacing PASSWORD and YOUR NAME values. We only actually use user 101 in the following; a second user can use 102.

Some things I've learned: originally the "102" user had transport and allow/disallow lines - this prevented it from bridging to Gtalk and failed. Also I removed the "7 digit" and "free call" sections; my area code doesn't work with 7 digit dialling and gtalk works fine for free call numbers. Also if you want to make both 101 and 102 ring at the same time for incoming calls you need to to modify the line that reads
  exten => YOURGVOICE@gmail.com, n, Dial(SIP/101, 180, D(:1))
to read
  exten => YOURGVOICE@gmail.com, n, Dial(SIP/101&SIP/102, 180, D(:1))

Caller ID

As previously mentioned, Google Voice incoming calls list the callers number, but not the name. I created a simple "agi" script to do this. If you don't want to do 411.com look ups for incoming calls then just comment out the line in extensions.conf that references the script. Basically it's a fragile little "screen scraper"; if 411.com output changes format then this script will break and need updating.

You can also do manual addition of entries to the asterisk number lookup database by connecting to the running asterisk instance:
  /usr/sbin/asterisk -r -x 'database put cidname +19875551234 "Fred Bloggs"'
You can remove entries with:
  /usr/sbin/asterisk -r -x 'database del cidname +19875551234'
You can see the database with:
  /usr/sbin/asterisk -r -x 'database show cidname'
And, of course, you can always use your phone's built in phonebook and let it do the lookup based on that. But one nice feature of having 411.com and asterisk do the lookup is that the number is stored in /var/log/asterisk/cds-csv/ files.

Start Asterisk

You should now be able to do /etc/init.d/asterisk start and it should all work! Check the logs in /var/log/asterisk for errrors. I typically see three warnings, that can be ignored:
[Mar 28 22:11:12] NOTICE[17275] cdr.c: CDR simple logging enabled.
[Mar 28 22:11:12] NOTICE[17275] loader.c: 25 modules will be loaded.
[Mar 28 22:11:12] NOTICE[17275] chan_sip.c: The 'username' field for sip peers has been deprecated in favor of the term 'defaultuser'

Configure the ATA

As with many before me, I use the Grandstream HandyTone HT286. This is a very simple device. Costs around $30 and they're easy to get ahold of. Almost any SIP ATA should work. Softphones should probably work as well.

For the ATA, pretty much all you need to do is configure it to point to your asterisk server as the SIP server, with username "101" and the password you configured. The HT286 has these settings on "Advanced Settings 1"; set both the SIP User ID and Authenticate ID to "101". Save. Reboot.

If you've configured the ATA correctly the admin screens should show it's registered with the SIP server.

The posting that started me off has more details on the HT286; again I suggest you read that

And that's it!

You should now be able to pick up the phone plugged into the ATA and dial numbers as if it was a real phone, and they'll go out with your Google Voice number associated with them, and people calling your Google Voice number will cause that phone to ring.

Just like a real phone!

But with the advantages of having Google Voice's web page to handle voicemail, to log calls, to provide cheap international calls, to block spammers and so on.


Last modified: Tuesday, 12-Apr-2011 21:19:02 EDT