0
votes

in the basic Twilio outgoing call, there is one parameter to be set which is the url, like this example:

call = client.calls.create(to="+14085551234",  # Any phone number
                       from_="+12125551234", # Must be a valid Twilio number
                       url="TwiML-app-url")

Here is the TwiML file that is being passed in my url:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="**my-ruby-script**" method="get">
        <Say>Please choose a number then press the pound sign</Say>
    </Gather>
</Response>

How can I handle the action with a ruby script? The ruby script needs to get the digit that is inputed by the user, then generate a new TwiML response based on that input.

1

1 Answers

0
votes

Ricky from Twilio here.

In order to do this you'll want to make sure your ruby script is available via publicly accessible URL. Since you specified GET as the method for your action Twilio will send the digits the user pressed in the query string in the parameter named Digits. Then you can use the Ruby helper library to generate the TwiML you want to respond with.

You didn't mention if you were using a framework so I'll show a snippet using Sinatra but the general idea would apply in other frameworks as well.

require 'twilio-ruby'
require 'sinatra'

get '/process_gather' do
  # params['Digits'] <- here is where the button the user pressed will be stored. 
  # You can do a conditional check here as you see fit.
  response = Twilio::TwiML::Response.new do |r|
    r.Say 'hello there', voice: 'alice'
  end

  response.text
end

Hope that helps!