Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now

Menu

Expand
Rate this page:

Thanks for rating this page!

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

Outgoing Calls with Twilio Client

Outgoing Capability

In order for your client device to be allowed to connect to Twilio so it can make an outgoing call, you need to make sure that the Capability Token you've provided allows for it. To do this, you will need a TwiML App SID and have your server application provide this SID to the outgoing capability of the token generator.

        
        
        
        

        TwiML App Configuration

        Configure your TwiML App to connect to a URL that returns the following TwiML:

        <?xml version="1.0" encoding="UTF-8"?>
        <Response>
            <Say>Thanks for calling!</Say>
        </Response>
        

        See our server application guide for more details on how to set this up.

        Connecting a Call

        Once you've created a Device, you can call it's connect() method to connect to Twilio. Twilio will make a request to the voice URL configured on your TwiML App. Since this return the <Say> verb that simply thanks the caller, you should hear the thank you message in your browser or on your device.

              
              
              
              

              Passing Parameters for a Call

              Just getting a message played to you in your browser isn't all that interesting. What we really want to do is have the client make a call to a real live phone number. In order to do this, our client needs to pass a parameter to our TwiML App. The parameter can be anything you like, but we'll create a parameter named "To" to indicate the number we want to make a call to.

                    
                    
                    
                    

                    The "To" parameter (and anything else you specify in the params object) will be passed to your server application's TwiML handler. Your server code can check for those parameters and then generate and return the appropriate TwiML, for example a <Dial> verb to connect the call.

                          
                          
                          
                          

                          Hanging Up a Call

                          Once you're on a call, you will probably want a way to hang up. This can be accomplished (albeit with less satisfaction than slamming a real phone handset into the receiver) using the disconnect() method.

                                
                                
                                
                                
                                David Prothero Devin Rader
                                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 browsing the Twilio tag on Stack Overflow.