Home » Posts tagged 'python'

Tag Archives: python

The Most Versatile VoIP Provider: FREE PORTING

The Wedding Is On: Asterisk and Google Voice Tie the Knot

Lips from Google Well, it was another painful week on the Google Voice front for Asterisk® lovers. We would hasten to add that none of the pain was induced by Google. This time around it was Gizmo5 initiating the daily gear shifting. What started out last Monday as a free, unlimited Google Voice service quickly morphed into a 20 minute call, and then a 3 minute call, and then 2¢ per minute for Google Voice calls. No notice to the early adopters, of course. So they'd only learn about all of this when the funds in their Gizmo5 accounts were exhausted. Ouch! We have gotten an explanation from Michael Robertson at Gizmo5 as have others. But we're not in a position to verify any of the information so we're not inclined to just pass it on again. Burn me once, shame on you. Burn be twice, shame on me.

So let's turn the page today. There were security issues with the Gizmo5 solution last week, and you can read all about it in last week's article if you're interested. Suffice it to say, it appears there was no business relationship between Google and Gizmo5 so it was a really bad idea to be providing your gMail credentials to Gizmo5 since they also are tied to Google Checkout and other Google services.

Aug. 4 Update: The solution outlined below works reliably. But it has a couple of limitations which have been alluded to in the comments. Specifically, there is not a simple way to terminate a call to either an answering machine or an unanswered call. In addition, two dedicated DIDs are required to get inbound and outbound calls working through Google Voice. Based upon user suggestions and a few new tricks of our own, we now have a tweaked solution that requires only a single DID and that properly terminates calls when either party hangs up. Please read the updated article here. Our apologies... recalling the Wild West adage: "Pioneers are the ones with the arrows in their backs."

Today's solution is much more secure. Your Google Voice credentials are stored on your Asterisk server and are only used to make HTTP requests to Google Voice to initiate calls. If you're just getting started with Google Voice, be aware that you do not have to use your gMail address to set up your Google Voice account, but it's a good idea particularly if you plan to use other Google services. For example, if you get an Android cellphone (as we did last week), the entire phone setup is configured around your gMail address and password. And, to integrate Google Voice into the phone, you need a gMail address that's tied to your Google Voice account. Once you make that link, all U.S. calls on your Android phone are free if they're routed out through Google Voice. Very slick!

Let's get down to business now. We promised you a secure Google Voice interface to Asterisk this week, and we've got it. As this is written, the only restrictions on use to make free U.S. calls are those set forth in the Google Voice Terms of Service. When we're finished today, you'll be able to pick up any Asterisk phone and dial GV-678-123-4567 to make a free call to anywhere in the United States and Canada. The call will go directly from your Asterisk server, through Google Voice, to the destination number you specify. In short, there is no intermediary in completing the calls. Google obviously can change the terms of service but, until they do, you should have a stable and free provider for making and receiving calls within the United States.

Special Thanks. At the outset, we want to express our sincere appreciation to Jacob Feisley and Paul Marks for their pioneering work on a Python interface to Google Voice. We also stumbled upon another Python development project, Google Voice for Python. While we originally had planned to rely upon Jacob and Paul's script, we ultimately decided to implement pygooglevoice because of the additional flexibility it provided for down the road. With pygooglevoice, you not only can make Google Voice calls, but you also can send SMS messages with no muss or fuss. Jacob Feisley has now joined that project as well. So, our special tip of the hat goes to the entire Google Voice for Python development team. It's a terrific product as you will see.

Prerequisites. Today's setup requires a CentOS-based Asterisk aggregation with a current version of FreePBX. Be aware that today's solution requires Python 2.4 and reportedly will not work with Python 2.5 found in some Linux distributions. We've tested everything with PBX in a Flash and, on that platform, you're good to go. The install script should work equally well with the other CentOS-based Asterisk aggregations, but we haven't tested them. Be our guest, and let us know if you encounter any problems. Finally, a word of caution. We don't ordinarily distribute solutions using development tools we don't use. Our knowledge of Python wouldn't fill a thimble. We've made an exception today because of the extraordinary interest in Google Voice by the Asterisk community. But, if something comes unglued, we can't fix it. So have a backup plan in place just in case. 🙂

Today's New Design. Here's the new design. You obviously still need a free Google Voice account. If you don't have one, you can request an invite here. At last report, it's only taking about a week from application to invite which is really great news! Once you have a Google Voice account and phone number (Google has reserved a million of them so... not to worry!), then we'll set up a couple of forwarding phone numbers in your Google Voice account. You aren't actually going to use one of them, but it does have to be registered as one of your GV forwarding numbers. We'll explain in a minute. Unlike the previous SIP approach, you no longer have to configure your Google Voice account to forward all incoming calls to voicemail. As you may recall, this allowed you to call your Google Voice number and press a few keys to make an outbound call instead of listening to your voicemails. The new Python approach simulates the Google Voice click-to-dial web interface to place calls so it won't disturb the normal use of your Google Voice phone number. But you need a RingBack number for the calls.

With a little dialplan voodoo and pygooglevoice, we'll tell Asterisk to place a click-to-dial call using one of your Google Voice forwarding numbers. Then we'll stuff in the destination U.S. phone number. When you dial GV-678-1234567 from any of your Asterisk phones, Asterisk will connect both your extension and the called party to an Asterisk MeetMe Conference where you can chat as long as you like. The entire procedure is totally transparent both to the caller and the callee. And the sound quality is still great.

To use Asterisk for inbound calls through Google Voice, you can designate a second forwarding number in Google Voice that connects to one or more extensions on your Asterisk system. All you really need for this is any DID, but you'll need separate DIDs to handle inbound and outbound calls. We'd recommend free IPkall and SIPgate DIDs. For outbound calls, we'll point one of your DIDs that's registered with Google Voice to a special Google Voice MeetMe conference line on your PBX. For inbound calls, point the other DID registered with Google Voice to an extension or ring group on your Asterisk server. Since all of these calls are free, the area code of the two DIDs really doesn't matter because you're never going to publish the fact that they exist.

Update: See the comments to this article for a one-DID solution that can handle both inbound and outbound calls.

To get everything working today, there are four steps: (1) configuring two Google Voice forwarding numbers to manage your outbound and inbound calls, (2) configuring FreePBX to route all outbound calls with a GV prefix to your special Google Voice dialplan context, (3) setting up a reserved MeetMe conference to manage your outbound Google Voice calls, and (4) running our install script which adds the dialplan code for Google Voice outbound dialing with your credentials and puts the Python application into place on your server. It sounds more complicated than it is. So hang on to your hat. Here we go!

Getting Two DIDs. Before you can use Google Voice with Asterisk, you'll need a couple of DIDs. As we indicated, we'll use one of the DIDs to handle the GV RingBack process when it places outbound calls. The other DID will be used to route incoming calls from Google Voice to your Asterisk server when people call your GV number. To get started, use the links above to obtain and configure the two DIDs. Then point each of them to an extension on your Asterisk system that can be used to verify your requests for the numbers.

The easiest method for setting these DIDs up is to create SIP URIs for the two DIDs on your Asterisk system. Then point each DID to a separate SIP URI on your server. Route each SIP URI to an Inbound Route in FreePBX where you can manage the destination for that DID's calls.

HINT: The entry in extensions_override_freepbx.conf would look something like this for a SIP URI called ipkall-1:

exten => ipkall-1,1,Goto(from-trunk,${DID},1)

Then you would create an inbound route named ipkall-1 using FreePBX and designate some existing extension on your server as the destination for these inbound calls.

When you set up the SIP forwarding for the DID at ipkall.com, you'd specify the SIP URI as:


We've previously covered in detail how to do this so read the article if you need a refresher course. To reiterate, the area codes of these DIDs really don't matter because you're never going to give out either number. So use the free sources and save yourself some money. The real trick is you want to use DIDs with unlimited, free inbound calls. Both IPkall and SIPgate provide that functionality at no cost.

Google Voice Setup. Log into your Google Voice account and click Settings, Phones, Add Another Phone. Add the area code and phone number of both DIDs: the RingBack DID for outbound calls and the Destination DID for incoming calls. Remember, you'll need to be sure both DIDs are pointed to extensions on your PBX that you can answer since you have to go through Google's confirmation drill to successfully register each number. After the RingBack DID is confirmed, be sure you uncheck this Google Voice destination. You do not want incoming Google Voice calls routed to this DID because it is going to land in a MeetMe conference on your Asterisk system. We're only setting it up as a destination number in Google Voice so that we can use it for click-to-dial ringbacks.

The RingBack DID will ring whenever you place a GV-routed Outbound Call from any phone on your Asterisk system. Remember, we're using click-to-dial technology to make these calls. You just won't see it. So, once this DID has been set up in Google Voice and you've confirmed that it works, we're going to alter the destination of this DID's inbound route and redirect it to a dedicated MeetMe conference number to manage these calls. Whenever you place an outbound call through Google Voice, pygooglevoice will initiate the click-to-dial process and then our dialplan code will transfer both the caller and the called party to the same dedicated MeetMe conference. When the other party answers, you both can begin talking. The MeetMe conference will be transparent to both parties except you'll get music on hold if either party hangs up.

Integrating Google Voice into Asterisk and FreePBX. This setup lets you place a call through Google Voice from any Asterisk phone by dialing the GV prefix plus a 10-digit number. So, to place a call to President Obama in Washington through Google Voice, you'd dial 48-202-456-1111.

First, open FreePBX with a web browser and choose Setup, Trunks, Add Custom Trunk. Insert the following Custom Dial String on the form and Submit Changes and reload the dialplan:


Next, choose Setup, Outbound Routes, Add Route and fill in the following entries on the form:

Route Name: GoogleVoice
Dial Pattern: 48|NXXNXXXXXX
Trunk Seq: local/$OUTNUM$@custom-gv

Next, choose Admin, Setup, Conferences, Add Conference. For the conference number, make up an obscure 5-digit number. Name the conference GV. Leave both PINs blank. For Conference Options, use the following. Once you've completed all of the entries, click Submit Changes and then reload your dialplan.

  • Join Message: None
  • Leader Wait: No
  • Quiet Mode: Yes
  • User Count: No
  • User join/leave: No
  • Music on Hold: Yes
  • Allow Menu: No
  • Record Conference: No

Finally, for the inbound route of the DID that will handle the RingBacks, change the inbound route destination for this DID to the MeetMe conference number you created above.

Save your changes and reload the Asterisk dial plan one more time to complete the setup.

Integrating pygooglevoice. Now we're ready to complete the setup by running our little script which loads pygooglevoice and sets up your dialplan in extensions_custom.conf. You'll need 4 pieces of information to run the script so write them down before you begin:

1. Your Google Voice email address
2. Your Google Voice password
3. Your 11-digit RingBack DID (16781234567)
4. MeetMe Conference Number for Outbound Calls

A word of caution: If you used a gMail address to set up your Google Voice account, it's possible to have different gMail and Google Voice passwords. For this to work, you'll need to enter your gMail password, not your Google Voice password (assuming they're different).

Now log into your Asterisk server as root and issue the following commands:

cd /root
wget http://bestof.nerdvittles.com/applications/gv/install-gv
chmod +x install-gv

Google Voice Speed Dials. For frequently called numbers, you can add speed dials by inserting entries in the [from-internal-custom] context of extensions_custom.conf that look like the example below where 333 is the speed dial number and 6781234567 is the area code and number to call. Be sure to reload your Asterisk dialplan to activate them.

exten => 333,1,Dial(local/6781234567@custom-gv,300)

Congratulations! You now have free U.S. calling on your Asterisk system using Google Voice with no gimmicks and no strings. Enjoy!

If you happen to be running Asterisk 1.6, there's a simpler way to bridge your calls together without using the MeetMe conferencing trick. See this message thread in the PBX in a Flash Forum for details.

Finally, a word of caution. This transparent call design obviously only works for a single call at a time. There are no safeguards to prevent multiple calls, but that may violate the Google Voice terms of service anyway. And, even if Google Voice put the second call through, the end result would be that all four of you (2 callers + 2 destinations) would end up in the same conference. So much for privacy.

Need help with Asterisk? Visit the PBX in a Flash Forum.
Or Try the New, Free PBX in a Flash Conference Bridge.

whos.amung.us If you're wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what's happening. It's a terrific resource both for us and for you.


Special Thanks to Our Generous Sponsors

FULL DISCLOSURE: ClearlyIP, Skyetel, Vitelity, DigitalOcean, Vultr, VoIP.ms, 3CX, Sangoma, TelecomsXchange and VitalPBX have provided financial support to Nerd Vittles and our open source projects through advertising, referral revenue, and/or merchandise. As an Amazon Associate and Best Buy Affiliate, we also earn from qualifying purchases. We’ve chosen these providers not the other way around. Our decisions are based upon their corporate reputation and the quality of their offerings and pricing. Our recommendations regarding technology are reached without regard to financial compensation except in situations in which comparable products at comparable pricing are available from multiple sources. In this limited case, we support our sponsors because our sponsors support us.

BOGO Bonaza: Enjoy state-of-the-art VoIP service with a $10 credit and half-price SIP service on up to $500 of Skyetel trunking with free number porting when you fund your Skyetel account. No limits on number of simultaneous calls. Quadruple data center redundancy. $25 monthly minimum spend required. Tutorial and sign up details are here.

The lynchpin of Incredible PBX 2020 and beyond is ClearlyIP components which bring management of FreePBX modules and SIP phone integration to a level never before available with any other Asterisk distribution. And now you can configure and reconfigure your new Incredible PBX phones from the convenience of the Incredible PBX GUI.

VitalPBX is perhaps the fastest-growing PBX offering based upon Asterisk with an installed presence in more than 100 countries worldwide. VitalPBX has generously provided a customized White Label version of Incredible PBX tailored for use with all Incredible PBX and VitalPBX custom applications. Follow this link for a free test drive!

Special Thanks to Vitelity. Vitelity is now Voyant Communications and has halted new registrations for the time being. Our special thanks to Vitelity for their unwavering financial support over many years and to the many Nerd Vittles readers who continue to enjoy the benefits of their service offerings. We will keep everyone posted on further developments.

Some Recent Nerd Vittles Articles of Interest...