Resurrecting Google SMS Search Using Twilio

May 13, 2013
Written by
Jonathan Gottfried
Contributor
Opinions expressed by Twilio contributors are their own

Twilio Bug Logo

Join the discussion on Hacker News!

Twilio Google SMS
Like many of you, I was sad to hear on Friday that Google decided to shut down their service that let you search via SMS. Luckily, a basic version of the service is not difficult to create on your own using Twilio SMS and Google’s Custom Search API!

This is a very bare-bones implementation, but it should provide a decent framework for you to expand it with additional filters and more intelligent queries.

We are going to use Sinatra (my favorite lightweight Ruby web framework), the google-api-client gem, Heroku, and Twilio-Ruby to deploy a basic Google SMS app.

To begin, we need to go over to the Google API Console and create a new application. Once you have created the application, make sure to enable the Google Custom Search Service, then head to the API Access tab and get your API key. We do not need OAuth 2.0 for this project.

Next we need to create a new Custom Search Engine:

  1. In the Sites to Search field feel free to enter any domain, we will delete it later
  2. Head to the Setup tab under ‘Edit search engine’ – under the Sites to Search dropdown select “Search the entire web but emphasize included sites”
  3. Select the domain name you entered on the list below and Delete it

Now you have a Custom Search Engine that searches the entire web.

Be sure to copy down the CX parameter from your URL – we will be using this later.

Coding the SMS

Now that our setup is complete, we can proceed to the code. For this project, we only have one route – /receivesms. Create a file named app.rb with the following contents:
Make sure you go back in and enter your Google API key on line 7 and your Custom Search Engine ID (CX) on line 15. You’ll also notice that we are only returning the top 3 results at this point, you can customize this number or add additional filters as per the API documentation for Custom Search. To finish up, we will need a Gemfile and a config.ru file (to deploy on Heroku)

Then you can deploy this to Heroku or your favorite hosting service, set up your Twilio number’s SMS URL to be http://yourapp.com/receivesms – and then you can get back to sending your search queries to Google via SMS!

If you have any questions or comments, feel free to e-mail jonmarkgo@twilio.com or tweet @jonmarkgo!