Guest Post: David Czarnecki's Twilio GitHub Hook

David Czarnecki is a Lead Engineer at Agora Games and an avid Ruby/Rails/Scala/Java developer. One Sunday evening he started playing with Twilio and ended up writing a GitHub service hook. This is how it happened:

If you think it’s hard to integrate Voice, VoIP or SMS into your application, you couldn’t be more wrong. In this blog post, I’ll show you how easily I integrated Twilio into a GitHub Service hook. It started out as a late Sunday evening exploration. I’m honestly not sure why I decided to play around with GitHub services or decided that GitHub push notification via SMS would (or would not be) useful, but it’s out there now.

In case you’re not familiar, GitHub Services are a collection of open source integrations for various services such as Bugzilla,  HipChat, Jabber, Twitter and more. When a GitHub Service is enabled for your GitHub repository, it can perform an action like notifying you via chat that someone committed a piece of code with a link to view the diff. I got the idea that it  could be useful to get an SMS notification when someone commits code to a  repository.  And that’s where Twilio comes in.

This is my first experience integrating Twilio into an application and Twilio makes it really easy to do so by offering libraries to interact with the Twilio API in some of the most popular languages like Java, Python and .NET. You can find them all on the Twilio site here: http://www.twilio.com/docs/libraries/. My  language of choice these days is Ruby. Thankfully both the GitHub Services project AND the Twilio Ruby API are well-documented, to the point that it was almost cut-and-paste in terms of writing the Twilio GitHub Service. You can find the code for the Twilio GitHub Service here: https://github.com/github/github-services/blob/master/services/twilio.rb.

The flow is as follows:

  • First, we check to make sure we have all the configuration settings available for interacting with Twilio such as our authorization token, account SID, Twilio phone number where messages are sent from and the phone number that will be notified of new commits via SMS to the GitHub repository.
  • Next, we create a client with our Twilio credentials.
  • Finally, we create a new SMS message by piecing together some of the data we get from a GitHub push event such as the committer’s name, the # of commits and the repository that was committed to.

4 lines of code and I had a working service that does exactly that! Now that the Twilio GitHub Service has been officially integrated, it is available for every single one of the over 1 million projects hosted on GitHub.

Integrating Twilio into your application is so simple, it’s almost magical. The Twilio API works as advertised due in large part to libraries that work as expected and are well documented. This goes a long way to maximizing developer productivity when you don’t have to fight the API to figure out the correct bits that need to be twiddled to get a prototype or full-fledged application off the ground.

The next time you’re thinking of integrating Voice, VoIP or SMS into your application–do it with Twilio.