Bio

Christopher Flynn

Webdeveloper, husband, dad, surfer, ameteur photographer, tinkerer, 2nd amendment advocate, brewer, chef, libertarian, atheist, UNIX Geek, troublemaker.


Using Google Voice with Asterisk

I've been playing with Google Voice and there's one main problem with it, how to initiate a call. Traditional VOIP services offer ways to connect using an ATA or a softphone. Currently google does not offer such functionality, you have to initiate the call using an existing phone.

Some cell phone companies allow you to pick one or more numbers to send or receive calls for free. If your provider does this, be sure to add your google voice number. You may have to change the way calls are presented but it's a good way to make/receive unlimited calling for free. I do not currently have such a plan so I needed to find another way.

At home I've been playing with asterisk. I do not use it for my main number but it is something I've been playing with. There is also a python project called pygooglevoice. This allows you to have google voice initiate a call much like using the web interface, you give it your login credentials, the phone number you wish to call and the phone number you want to use. So now we just need a phone number that allows free incoming.

To get a free incoming number you can signup for one using ipkall or sipgate. There are a ton of tutorials on how to install asterisk, I'm not going to cover that. You'll also need to configure at least one softphone at least for testing purposes. Finally you'll need to configure your phone number. Now you should be able to receive calls on your new number to your softphone.

Once all this is done and you've installed pygooglevoice you can test it. To test it, from the command line, run the command: "gvoice -e youremail@gmail.com" it will ask you for your password and then you should end up at a 'gvoice>' prompt. Type call and it will prompt you for the outgoing number and the forwarding number (the number you want to call). Try out your new number and see how it works.

Now this way it's not much better than using the web interface, we need to automate it. Fortunately asterisk let's us do some really powerful stuff, including executing external applications. First we'll need to edit the extensions.conf file and add a gv-outbound section. It should be before [default] and look something like the following:

[gv-outbound]
exten => _X.,1,Wait(1)
exten => _X.,n,Set(ACCTNAME=username@gmail.com)
exten => _X.,n,Set(ACCTPASS=password)
exten => _X.,n,Set(RINGBACK=15555555555) ; number you want to ring (ipkall/sipgate number)
exten => _X.,n,System(gvoice -e ${ACCTNAME} -p ${ACCTPASS} call ${EXTEN} ${RINGBACK})
exten => _X.,n,Set(DB(gv_dialout/channel)=${CHANNEL})
exten => _X.,n,Wait(5)
exten => _X.,n,Hangup

This basically uses the gvoice program to call your number like we did above, just using asterisk. Now we need to have it execute this block, we'll do this in the default block like so:

exten => _54NXXNXXXXXX,1,playback(vm-dialout)
exten => _54NXXNXXXXXX,n,Dial(local/${EXTEN:2}@gv-outbound,300)

This is a dialplan rule in asterisk, it's basic format is the extension, priority and then the command. In this case, the extension is what we dial to initiate the call. The _ character denotes this as a pattern to match, 54 is what I chose to prefix google voice numbers. You could remove this and it would be like dialing a normal number. The second parameter is the priority. You used to have to number each one but now you can use 'n' for next, you still have to have the first one numbered 1. Finally is the command we are going to execute. The first line plays back a recording saying "please wait while we connect your call..." The second line is where the call is placed. We are using the Dial() command to dial a local number, in this case using the gv-outbound block we created above. The ${EXTEN:2} bit will take the matched pattern and remove the first 2 digits (the 54). If you remove the prefix from the pattern, be sure to remove the :2 or it will remove the first two digits of the number.

Now you should be able to dial this pattern ('54' + 10 digit phone number) and your softphone should prompt you to answer a call (this is google voice calling). Take the call and then the person you are calling's phone should ring as well. The ipkall/sipgate number you get doesn't matter because you don't need to give it to anyone, you just need to give them your google voice number. However you might want to add your ipkall/sipgate number to your phones list on google voice so if someone calls, it should ring your softphone. (It will need to be running for this) Alternatively, you can setup an ATA to interface with asterisk much in the same way that you configured the softphone. You could then plug this ATA into the phone wiring in your house. The downside is you lose 911 calling. To gain it back, you can sign up for a VOIP provider that provides E911. I currently use vitelity which I get for $3.79/month and it's a pay per minute. I found this deal from nerdvittles.com and if you look, I think they are still running the deal. Nerdvittles.com also has info on setting up something similar to the above using trixbox or their Orgasmatron installer script.

If you configure your router properly, you can connect your softphone from outside your local network. Basically, port forward UDP on ports 10000-20000 to your asterisk machine as well as port 5060. Then, if you have a dynamic IP address, like most residential services offer, sign up for a service like dyndns.org. It's free and most routers will work with it. This allows you to map your dynamic IP address to something like whatever.dyndns.org. (Or others, they have multiple domain names you can choose from now) no-ip.com is another similar service. Now you can use this address in your softphone and connect from outside your local network.

Finally, how can you get this to work with your iPhone? Well, there are a number of softphones available for the iPhone. For testing purposes, I would try fring since it's free. (Though if you try testing on your local network, it won't work because fring uses their servers to make the connection. Therefore you need to setup the dynamic dns thing in the previous paragraph) The downside is that once you initiate the call there's no keypad for automated systems. If you really need this, other softphones should have it.

I had a hard time putting all the pieces together, I hope this helps you. Sorry I glossed over some items, this would just be a really long post otherwise. If there's a lot of demand for it, maybe I'll cover things like installing asterisk and configuring ipkall/sipgate, etc... However I've found there are a lot of tutorials out there already, just none on integrating google voice outside of trixbox.

Comments

show comment form

 
Christopher Flynn