TwiML templates for Tilt.
An easy way to work with TwiML for responding to Twilio webhooks in Rails or Sinatra applications using template files.
Add this line to your application's Gemfile:
gem 'twiml_template'
And then execute:
$ bundle
Or install it yourself as:
$ gem install twiml_template
By including the twiml_template
gem in your Rails project Gemfile you will be able to write TwiML templates easily.
Create a controller, like below:
class VoiceController < ApplicationController
def index
@name = "World"
end
end
Add a route:
Rails.application.routes.draw do
get 'voice' => 'voice#index'
# Other routes...
end
And then add your TwiML view:
twiml.Say "Hello #{@name}"
Save the file as #{RAILS_ROOT}/app/views/voice/index.twiml
.
Run the app using rails s
and visit http://localhost:3000/voice and you will see:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello World!</Say>
</Response>
Create your application file like below:
require 'sinatra'
require 'sinatra/twiml'
helpers Sinatra::TwiML
get '/voice' do
@name = "World!"
twiml :voice
end
And then add your TwiML view:
twiml.Say "Hello #{@name}"
Save the file as #{APP_ROOT}/views/voice.twiml
.
Start the app with ruby app.rb
and visit http://localhost:4567/voice and you will see:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello World!</Say>
</Response>
- Fork it ( https://github.com/philnash/twiml_template/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request