Ruby Quickstart: Say a Message

We'll start with greeting people who call your Twilio phone number.

Setting Up Your Server

This tutorial assumes you have a Ruby development environment with Sinatra and the twilio-ruby helper library. If you don't have these yet, please see our post on setting up your environment.

Create a new Sinatra application with code below. We're using the twilio-ruby helper library to generate TwiML, Twilio's Markup XML:

require 'rubygems'
require 'sinatra'
require 'twilio-ruby'

get '/hello-monkey' do do |r|
    r.say 'Hello Monkey'

Save the file and start your local server:

$ ruby twiml-quickstart.rb
== Sinatra has taken the stage ...
>> Listening on

Go to your browser at http://localhost:4567/hello-monkey. You should see TwiML that looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
    <Say>Hello Monkey</Say>

If you do, great. You're ready to move on to the next step.

Let Twilio Find Your Server

At this point in the tutorial, you will need to find a way to expose your server to the public Internet.

Here are some tutorials that may be able to help you:

For the rest of the tutorial, we will assume your server is available at

Try it out

Copy and paste the URL of your servlet into the "Voice" URL of a number listed on the Numbers page of your Twilio Account. On the page for that number, change the Method from "POST" to "GET".

Now call your Twilio number! You should hear a voice say "Hello Monkey" in response. When you call, Twilio will fetch your URL, and execute the XML instructions listed above. Then, Twilio will hang up, because there are no more instructions.

Next: Greet callers by name »

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.