Resurrecting Google SMS Search Using Twilio
Time to read: 2 minutes
Join the discussion on Hacker News!
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.
Setting up Custom Search
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:
- In the Sites to Search field feel free to enter any domain, we will delete it later
- Head to the Setup tab under ‘Edit search engine’ – under the Sites to Search dropdown select “Search the entire web but emphasize included sites”
- 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!
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.