Skip to content

Instantly share code, notes, and snippets.

@phobeo
Created September 30, 2011 22:53
Show Gist options
  • Save phobeo/1255233 to your computer and use it in GitHub Desktop.
Save phobeo/1255233 to your computer and use it in GitHub Desktop.
twilio sample
require 'sinatra'
class Main < Sinatra::Base
enable :static
set :public, 'public'
get '/' do
content_type 'application/xml'
twiml = %{<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/process" method="GET">
<Say>
Welcome to Bletchley Park! Please enter the number of the item you want to hear about, then press the hash key
</Say>
</Gather>
<Say>We didn't receive any input. Goodbye!</Say>
</Response>}
puts twiml
twiml
end
get '/process' do
number = params['Digits']
content_type 'application/xml'
found = Dir.foreach("public").find {|x|
x.split(' ')[0] == number
}
if(found == nil)
twiml = %{<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman">I'm sorry, there's no entry with number #{number}</Say>-->
<Gather action="/process" method="GET">
<Say>
Please enter the number of another item and press the hash key, or hang up if you're done
</Say>
</Gather>
</Response>}
else
twiml = %{<?xml version="1.0" encoding="UTF-8"?>
<Response>
<!--<Say voice="woman">number #{number}</Say>-->
<Play>http://bletchley-test.heroku.com/#{found}</Play>
<Gather action="/process" method="GET">
<Say>
Please enter the number of another item and press the hash key, or hang up if you're done
</Say>
</Gather>
</Response>}
end
puts twiml
twiml
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment