Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A small Rails plugin that sets up a mime type for Twilio responses
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
tasks
test
.project
MIT-LICENSE
README
Rakefile
init.rb
install.rb
uninstall.rb

README

TwilioMime
==========

twilio_mime is a simple Rails plugin that adds a mime type for Twilio responses (http://www.twilio.com). Using twilio_mime you can respond to Twilio requests using TwiML in the same way you'd handle other mime types

For Example
=======

Lets say we have a blog and on our Posts controller we have a show action

	def show
    	  @posts = Post.find :all

          respond_to do |format|
            format.html
            format.twiml
            format.xml { render :xml => @posts.to_xml }
          end

	end

In our views we could have a file that holds the Twilio response called show.twiml.erb that might contain something like this

	<?xml  version="1.0" encoding="UTF-8" ?>  
	<Response>
	  <% @posts.each do |post| %>
  	    <Say><%= post.title </Say>
    <% end %>
	</Response>


Installation
=======

Install as a plugin using 

	./script/plugin install git://github.com/dalecook/twilio-mime.git


Set Up and Security
=======

twilio_mime tries to determine if the request is actually coming from Twilio. The safest way to do this is to set your Twilio Account GUID as a constant in your application. To do this, in config/environment.rb set a constant TWILIO_ACCOUNT_GUID and set it to your Twilio Account GUID. If you don't have a Twilio account you can sign up at https://www.twilio.com/try-twilio. 

For example in config/environment.rb
TWILIO_ACCOUNT_GUID = "AC000000xx332541df93d8d685c2331111"

Incoming requests from Twilio always provide this so you can be reasonably sure the request is coming from Twilio. If the constant is present then twilio_mime will check this before deciding if the request is valid. 
In addition, if this constant is set then it will override the explicit mime format URL request, such that a request like http://yourapp.com/foo/show/1.twiml would not return the Twilio response but would return the default HTML response instead, since the AccountGuid is missing from this request. 

If you don't wish to do that then twilio_mime will attempt to work out if the request is coming from Twilio by looking for certain parameters. In this case an explit mime format request would return the TwiML response even if the parameters were non present. To see how this is actually done take a look at the is_twilio_request? function in vendor/plugins/twilio_mime/lib/twilio_mime.rb

Copyright (c) 2010 Dale John Cook, released under the MIT license
Something went wrong with that request. Please try again.