Twilio API and Rails 3 example

Posted by Andrew on November 8, 2010

I recently created a simple Rails app based on the Twilio API (which is awesome) and the Twilio "appointment reminder" demo. Twilio allows developers to incorporate telephony into their web apps. You can use it to allow users to make phone calls or send SMS to your app or have your app call or SMS users, plus features such as audio playback and recording. Twilio has a Ruby on Rails specific tutorial on their site but it is not written for Rails 3 and so there were some small changes that had to be made. One of the changes is that the url that Twilio calls for the TwiML file needs a .xml extension:

redirect_to BASE_URL + "/goodbye"


redirect_to BASE_URL + "/goodbye.xml"

The full controller is shown here:

The other change was to the routing. The routes need to be able to access the xml.builder files at callme/goodbye.xml which looks like this in a Rails 3 routes.rb:

match ':controller(/:action(.:format))'

shown here:

Here is index.html.erb file:

The xml.builder files are placed into the views/callme folder: