Menu

Expand
Rate this page:

Modify Calls In Progress with Ruby

In this guide we’ll show you how to manipulate live phone calls using Ruby. We’ll also cover how to retrieve information about in progress and completed calls from your Twilio account.

We’ll use Twilio’s Ruby SDK in these examples to interact with the Twilio REST API’s Calls endpoint.

Modifying Twilio phone calls in progress with Ruby

The simplest way to control the flow of a Twilio phone call is with TwiML itself.

You can use the "action" parameters of verbs like <Gather> and <Record> to tell Twilio to get new instructions from your applications during a call. You can also use the <Redirect> verb to explicitly tell Twilio to fetch new TwiML.

But sometimes you need to change a live phone call outside of Twilio’s normal request-response cycle. For those cases you can update the Call to tell Twilio to immediately change the TwiML it’s using in a phone call.

        
        
        

        In order to update the call you will need to use the CallSid. Twilio returns this when you initiate an outgoing call, and also includes the CallSid in its request to your application for an incoming call's initial TwiML.

        As an alternative to updating your call with TwiML directly, you may also redirect a Call to a new URL that responds with your requested TwiML.

              
              
              

              Hanging up a call in progress

              Twilio will end phone calls for you when it encounters a <Hangup> verb or when it runs out of TwiML to process. But you can also end phone calls whenever you like by passing a "completed" status to a CallSid in progress.

                    
                    
                    

                    Check out Modifying Live Calls in the reference docs for more details.

                    Where to next?

                    Check out our tutorials to see full implementations of Twilio Voice in Ruby with Sinatra and Rails.

                    Hector Ortega Rob Spectre Ricky Robinett David Prothero Kevin Whinnery Kat King Craig Dennis Andrew Baker
                    Rate this page:

                    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 by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.

                          
                          
                          

                          Thank you for your feedback!

                          We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

                          Sending your feedback...
                          🎉 Thank you for your feedback!
                          Something went wrong. Please try again.

                          Thanks for your feedback!

                          Refer us and get $10 in 3 simple steps!

                          Step 1

                          Get link

                          Get a free personal referral link here

                          Step 2

                          Give $10

                          Your user signs up and upgrade using link

                          Step 3

                          Get $10

                          1,250 free SMSes
                          OR 1,000 free voice mins
                          OR 12,000 chats
                          OR more