Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

TwiML templates for Rails and Tilt.

License

Notifications You must be signed in to change notification settings

vippetcare/twiml_template

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TwimlTemplate

TwiML templates for Tilt.

An easy way to work with TwiML for responding to Twilio webhooks in Rails or Sinatra applications using template files.

Build Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'twiml_template'

And then execute:

$ bundle

Or install it yourself as:

$ gem install twiml_template

Usage

Rails

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>

Sinatra

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>

Contributing

  1. Fork it ( https://github.com/philnash/twiml_template/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Packages

No packages published

Languages

  • Ruby 100.0%