TwiML™ Voice: <Sip> - Twilio
Register for SIGNAL by 8/31 for $250 off. Register now.

TwiML™ Voice: <Sip>

The <Dial> verb's <Sip> noun lets you set up VoIP sessions by using SIP -- Session Initiation Protocol. With this feature, you can send a call to any SIP endpoint. Set up your TwiML to use the <Sip> noun within the <Dial> verb whenever any of your Twilio phone numbers are called. If you are unfamiliar with SIP, or want more information on how Twilio works with your SIP endpoint, please see the SIP overview.

The SIP session

The SIP INVITE message includes the API version, the AccountSid and CallSid for the call. Also, configure Twilio to pass custom SIP headers in the INVITE message. Optionally, provide a set of parameters to manage signaling transport and authentication.

Once the SIP session completes, Twilio requests the <Dial> action URL, passing along the SIP CallID header, the response code of the invite attempt, any X-headers passed back on the final SIP response, as well as the standard Twilio <Dial> parameters.

Currently, only one <Sip> noun may be specified per <Dial>, and the INVITE message may be sent to only one SIP endpoint. Also, you cannot add any other nouns (eg <Number>, <Client>) in the same <Dial> as the SIP. If you want to use another noun, set up a callback on the <Dial> to use alternate methods.

The region parameter

To specify the geographic region from which Twilio will send SIP-out traffic towards your communication infrastructure, you must include the region parameter in your SIP URI. For example, if the region=ie1 parameter is included in your SIP URI, Twilio will send the SIP traffic from the Europe Ireland region:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>sip:alice@example.com;region=ie1</Sip>
    </Dial>
</Response>
Region Location
us1 North America Virginia
us2 North America Oregon
ie1 Europe Ireland
de1 Europe Frankfurt
sg1 Asia Pacific Singapore
jp1 Asia Pacific Tokyo
br1 South America São Paulo
au1 Asia Pacific Sydney

If the region parameter is not specified, Twilio will send SIP-out traffic from the North America Virginia region.

Use the Sip noun

All of the existing <Dial> parameters work with the <Sip> noun (record, timeout, hangupOnStar, etc). For SIP calls, the callerId attribute does not need to be a validated phone number. Enter any alphanumeric string. Optionally include the following chars: +-_., but no whitespace.

Within the <Sip> noun, you must specify a URI for Twilio to connect to. The URI should be a valid SIP URI under 255 characters. For example:

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com');

console.log(response.toString());
using System;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "jack");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:jack@example.com')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:jack@example.com").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
    <Sip>
        sip:jack@example.com
    </Sip>
</Dial>
</Response>
Use the <Sip> noun

Authentication

Send username and password attributes for authentication to your SIP infrastructure as attributes on the <Sip> noun.

Attribute Name Values
username Username for SIP authentication
password Password for SIP authentication

For example:

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip(
  {
    username: 'admin',
    password: '1234',
  },
  'sip:kate@example.com'
);

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "admin", "1234");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:kate@example.com', ['username' => 'admin',
    'password' => '1234']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:kate@example.com', username: 'admin', password: '1234')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:kate@example.com', username='admin', password='1234')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:kate@example.com").username("admin")
            .password("1234").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
    <Sip username="admin" password="1234">sip:kate@example.com</Sip>
</Dial>
</Response>
Authentication with your <Sip>

Custom headers

Send custom headers by appending them to the SIP URI -- just as you'd pass headers in a URI over HTTP. For example:

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar');

console.log(response.toString());
using System;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(
            new Uri("http://example.com?mycustomheader=foo&myotherheader=bar"),
            "jack");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip
            .Builder("sip:jack@example.com?mycustomheader=foo&myotherheader=bar").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>
            sip:jack@example.com?mycustomheader=foo&amp;myotherheader=bar
        </Sip>
    </Dial>
</Response>
Custom headers with <Sip>

While the SIP URI itself must be under 255 chars, the headers must be under 1024 characters.

Transport

Set a parameter on your SIP URI to specify what transport protocol you want to use. Currently, this is limited to UDP, TCP and TLS. By default, Twilio sends your SIP INVITE over UDP. Change this by using the transport parameter:

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com;transport=tcp');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com;transport=tcp"), "jack");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com;transport=tcp');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:jack@example.com;transport=tcp')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com;transport=tcp')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:jack@example.com;transport=tcp").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>
            sip:jack@example.com;transport=tcp
        </Sip>
    </Dial>
</Response>
Transport with <Sip>

Alternatively, you may customize it to use TLS for SIP signaling. When using TLS, the default port will be 5061 however, a different one may be specified.

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com;transport=tls');

console.log(response.toString());
using System;
using Twilio.Converters;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "jack");

        dial.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com;transport=tls');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:jack@example.com;transport=tls')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com;transport=tls')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:jack@example.com;transport=tls").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>
            sip:jack@example.com;transport=tls
        </Sip>
    </Dial>
</Response>
TLS Transport with <Sip>

Attributes

The <Sip> noun supports the following attributes that modify its behavior:

Attribute Name Allowed Values Default Value
url call screening url none
method GET, POST POST
statusCallbackEvent initiated, ringing, answered, completed none
statusCallback any url none
statusCallbackMethod GET, POST POST

url

The url attribute allows you to specify a url for a TwiML document that runs on the called party's end, after they answer, but before the two parties are connected. You can use this TwiML to privately <Play> or <Say> information to the called party, or provide a chance to decline the phone call using <Gather> and <Hangup>. The current caller continues to hear ringing while the TwiML document executes on the other end. TwiML documents executed in this manner cannot contain the <Dial> verb.

method

The method attribute allows you to specify which HTTP method Twilio should use when requesting the URL specified in the url attribute. The default is POST.

Call Screening HTTP parameters

When a call is answered, Twilio passes the following parameters with its request to your screening URL (in addition to the standard TwiML Voice request parameters):

Attribute Name Values
SipCallId The SIP call ID header of the request made to the remote SIP infrastructure.
SipHeader The name/value of any X-headers returned in the 200 response to the SIP INVITE request.

Dial Action HTTP parameters

Use the action callback parameters to modify your application based on the results of the SIP dial attempt:

Attribute Name Values
DialSipCallId The SIP call ID header of the request made to the remote SIP infrastructure.
DialSipResponseCode The SIP response code as a result of the INVITE attempt.
DialSipHeader_ The name/value of any X-headers returned in the final response to the SIP INVITE request.

statusCallbackEvent

When dialing out to a number using <Dial>, an outbound call is initiated. The call transitions from the initiated state to the ringing state when the phone starts ringing. It transitions to the answered state when the call is picked up, and finally to the completed state when the call is over. With statusCallbackEvent, you can subscribe to receive webhooks for the different call progress events: initiated, ringing, answered, or completed for a given call.

The statusCallbackEvent attribute allows you to specify which events Twilio should webhook on. To specify multiple events separate them with a space: initiated ringing answered completed. If a statusCallback is provided and no status callback events are specified the completed event will be sent by default.

As opposed to creating an outbound call via the API, outbound calls created using <Dial> are initiated right away and never queued. The following shows a timeline of possible call events that can be returned and the different call statuses that a <Dial> leg may experience:

Outbound Dial call events diagram

Event Description
initiated The initiated event is fired when Twilio starts dialing the call.
ringing The ringing event is fired when the call starts ringing.
answered The answered event is fired when the call is answered.
completed The completed event is fired when the call is completed, regardless of the termination status: busy, canceled, completed, failed, or no-answer. If no StatusCallbackEvent is specified, completed will be fired by default.

statusCallback

The statusCallback attribute allows you to specify a URL for Twilio to send webhook requests to on each event specified in the statusCallbackEvent attribute. Non-relative URLs must contain a valid hostname (underscores are not permitted).

statusCallbackMethod

The statusCallbackMethod attribute allows you to specify which HTTP method Twilio should use when requesting the URL in the statusCallback attribute. The default is POST.

Status Callback HTTP Parameters

The parameters Twilio passes to your application in its asynchronous request to the StatusCallback URL include all parameters passed in a synchronous request to retrieve TwiML when Twilio receives a call to one of your Twilio numbers. The full list of parameters and descriptions of each are in the TwiML Voice Request documentation.

When the call progress events are fired, the Status Callback request also passes these additional parameters:

Parameter Description
CallSid A unique identifier for this call, generated by Twilio. You can use the CallSid to modify the child call by POSTing to Calls/{CallSid} with a new TwiML URL.
ParentCallSid A unique identifier for the parent call.
CallStatus A descriptive status for the call. The value is one of queued, initiated, ringing, in-progress, busy, failed, or no-answer. See the CallStatus section for more details.
CallDuration The duration in seconds of the just-completed call. Only present in the completed event.
RecordingUrl The URL of the phone call's recorded audio. This parameter is included only if record is set on the <Dial> and does not include recordings initiated in other ways. RecordingUrl is only present in the completed event.
RecordingSid The unique ID of the Recording from this call. RecordingSid is only present in the completed event.
RecordingDuration The duration of the recorded audio (in seconds). RecordingDuration is only present in the completed event. To get a final accurate recording duration after any trimming of silence, use recordingStatusCallback.
Timestamp The timestamp when the event was fired, given as UTC in RFC 2822 format.
CallbackSource A string that describes the source of the webhook. This is provided to help disambiguate why the webhook was made. On Status Callbacks, this value is always call-progress-events.
SequenceNumber The order in which the events were fired, starting from 0. Although events are fired in order, they are made as separate HTTP requests and there is no guarantee they will arrive in the same order.

Examples

Example 1: Dialing to a SIP endpoint

In this example, we want to connect to kate@example.com. To connect the call to Kate, use a <Dial> verb with a <Sip> noun nested inside.

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('kate@example.com');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "kate");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('kate@example.com');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('kate@example.com')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('kate@example.com')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("kate@example.com").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>kate@example.com</Sip>
    </Dial>
</Response>
Dialing to a SIP endpoint

Example 2: Dial a SIP endpoint, protected by authentication

In this example, you are still dialing Kate, but you need to pass authentication credentials to reach her.

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip({
    username: 'admin',
    password: '1234'
}, 'kate@example.com');

console.log(response.toString());
using System;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "kate", "1234");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('kate@example.com', ['username' => 'admin', 'password' => '1234']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.sip('kate@example.com', username: 'admin', password: '1234')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('kate@example.com', username='admin', password='1234')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("kate@example.com").username("admin")
            .password("1234").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip username="admin" password="1234">kate@example.com</Sip>
    </Dial>
</Response>
Dial a SIP endpoint, protected by authentication

Example 3: Passing headers

In this example, pass custom headers along with the SIP address.

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("example.com?mycustomheader=foo&myotherheader=bar", "kate", ));

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip
            .Builder("sip:kate@example.com?mycustomheader=foo&myotherheader=bar").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>sip:kate@example.com?mycustomheader=foo&amp;myotherheader=bar</Sip>
    </Dial>
</Response>
Passing headers

Example 4: Dial with several attributes

A more complex Dial, specifying custom settings as attributes on <Dial>, including call screening and setting the protocol to TCP.

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial({
    record: 'record-from-answer',
    timeout: 10,
    hangupOnStar: true,
    callerId: 'bob',
    method: 'POST',
    action: '/handle_post_dial'
});
dial.sip({
    method: 'POST',
    url: '/handle_screening_on_answer'
}, 'sip:kate@example.com?customheader=foo');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using Twilio.Http;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial(
            record: "record-from-answer",
            timeout: 10,
            hangupOnStar: true,
            callerId: "bob",
            method: HttpMethod.Post,
            action: new Uri("http://example.com/handle_post_dial")
        );

        var sip = new Sip(
            new Uri("http://example.com?customheader=foo"),
            "kate",
            url: new Uri("http://example.com/handle_screening_on_answer"),
            method: HttpMethod.Post
        );

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString()); ;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial(['record' => 'record-from-answer', 'timeout' => 10,
    'hangupOnStar' => 'true', 'callerId' => 'bob', 'method' => 'POST',
    'action' => '/handle_post_dial']);
$dial->sip('sip:kate@example.com?customheader=foo', ['method' => 'POST',
    'url' => '/handle_screening_on_answer']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial(
  record: 'record-from-answer', timeout: 10, hangup_on_star: true,
  caller_id: 'bob', method: 'POST', action: '/handle_post_dial'
) do |dial|
  dial.sip(
    'sip:kate@example.com?customheader=foo',
    method: 'POST', url: '/handle_screening_on_answer'
  )
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial(
    record='record-from-answer',
    timeout=10,
    hangup_on_star=True,
    caller_id='bob',
    method='POST',
    action='/handle_post_dial')
dial.sip(
    'sip:kate@example.com?customheader=foo',
    method='POST',
    url='/handle_screening_on_answer')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;
import com.twilio.http.HttpMethod;

public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:kate@example.com?customheader=foo")
            .method(HttpMethod.POST).url("/handle_screening_on_answer").build();
        Dial dial = new Dial.Builder().record(Dial.Record.RECORD_FROM_ANSWER)
            .timeout(10).hangupOnStar(true).callerId("bob").method(HttpMethod.POST)
            .action("/handle_post_dial").sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial
     record="record-from-answer"
     timeout="10"
     hangupOnStar="true"
     callerId="bob"
     method="POST"
     action="/handle_post_dial">

        <Sip
         method="POST"
         url="/handle_screening_on_answer">
            sip:kate@example.com?customheader=foo
        </Sip>
    </Dial>
</Response>
Dial with several attributes

Example 5: Call Progress Events

In this example, we want to receive a webhook for each call progress event when dialing a SIP endpoint using <Dial>.

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip({
    statusCallbackEvent: 'initiated ringing answered completed',
    statusCallback: 'https://myapp.com/calls/events',
    statusCallbackMethod: 'POST'
}, 'sip:kate@example.com');

console.log(response.toString());
using static Twilio.TwiML.Voice.Sip;
using System;
using System.Collections.Generic;
using Twilio.Converters;
using Twilio.Http;
using Twilio.TwiML;
using Twilio.TwiML.Voice;

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(
            new Uri("http://example.com"),
            "kate",
            statusCallbackEvent: new List<Sip.EventEnum>(
                new EventEnum[] {
                    EventEnum.Initiated,
                    EventEnum.Ringing,
                    EventEnum.Answered,
                    EventEnum.Completed
                }
            ),
            statusCallback: new Uri("https://myapp.com/calls/events"),
            statusCallbackMethod: HttpMethod.Post
        );

        dial.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:kate@example.com',
    ['statusCallbackEvent' => 'initiated ringing answered completed',
    'statusCallback' => 'https://myapp.com/calls/events',
    'statusCallbackMethod' => 'POST']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.sip('sip:kate@example.com',
           status_callback_event: 'initiated ringing answered completed',
           status_callback: 'https://myapp.com/calls/events',
           status_callback_method: 'POST')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip(
    'sip:kate@example.com',
    status_callback_event='initiated ringing answered completed',
    status_callback='https://myapp.com/calls/events',
    status_callback_method='POST'
)
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.voice.Sip.Event;
import com.twilio.http.HttpMethod;
import java.util.Arrays;

public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:kate@example.com")
            .statusCallback("https://myapp.com/calls/events")
            .statusCallbackMethod(HttpMethod.POST).statusCallbackEvents(Arrays
            .asList(Event.INITIATED, Event.RINGING, Event.ANSWERED, Event
            .COMPLETED)).build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip
         statusCallbackEvent='initiated ringing answered completed'
         statusCallback='https://myapp.com/calls/events'
         statusCallbackMethod='POST'>
            sip:kate@example.com
        </Sip>
    </Dial>
</Response>
Call Progress Events

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.

Loading Code Samples...
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com');

console.log(response.toString());
using System;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "jack");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:jack@example.com')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:jack@example.com").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
    <Sip>
        sip:jack@example.com
    </Sip>
</Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip(
  {
    username: 'admin',
    password: '1234',
  },
  'sip:kate@example.com'
);

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "admin", "1234");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:kate@example.com', ['username' => 'admin',
    'password' => '1234']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:kate@example.com', username: 'admin', password: '1234')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:kate@example.com', username='admin', password='1234')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:kate@example.com").username("admin")
            .password("1234").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
    <Sip username="admin" password="1234">sip:kate@example.com</Sip>
</Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar');

console.log(response.toString());
using System;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(
            new Uri("http://example.com?mycustomheader=foo&myotherheader=bar"),
            "jack");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com?mycustomheader=foo&myotherheader=bar')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip
            .Builder("sip:jack@example.com?mycustomheader=foo&myotherheader=bar").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>
            sip:jack@example.com?mycustomheader=foo&amp;myotherheader=bar
        </Sip>
    </Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com;transport=tcp');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com;transport=tcp"), "jack");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com;transport=tcp');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:jack@example.com;transport=tcp')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com;transport=tcp')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:jack@example.com;transport=tcp").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>
            sip:jack@example.com;transport=tcp
        </Sip>
    </Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:jack@example.com;transport=tls');

console.log(response.toString());
using System;
using Twilio.Converters;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "jack");

        dial.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:jack@example.com;transport=tls');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:jack@example.com;transport=tls')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:jack@example.com;transport=tls')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:jack@example.com;transport=tls").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>
            sip:jack@example.com;transport=tls
        </Sip>
    </Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('kate@example.com');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "kate");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('kate@example.com');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('kate@example.com')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('kate@example.com')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("kate@example.com").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>kate@example.com</Sip>
    </Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip({
    username: 'admin',
    password: '1234'
}, 'kate@example.com');

console.log(response.toString());
using System;
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("http://example.com"), "kate", "1234");

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('kate@example.com', ['username' => 'admin', 'password' => '1234']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.sip('kate@example.com', username: 'admin', password: '1234')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('kate@example.com', username='admin', password='1234')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("kate@example.com").username("admin")
            .password("1234").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip username="admin" password="1234">kate@example.com</Sip>
    </Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(new Uri("example.com?mycustomheader=foo&myotherheader=bar", "kate", ));

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip('sip:kate@example.com?mycustomheader=foo&myotherheader=bar')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip
            .Builder("sip:kate@example.com?mycustomheader=foo&myotherheader=bar").build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip>sip:kate@example.com?mycustomheader=foo&amp;myotherheader=bar</Sip>
    </Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial({
    record: 'record-from-answer',
    timeout: 10,
    hangupOnStar: true,
    callerId: 'bob',
    method: 'POST',
    action: '/handle_post_dial'
});
dial.sip({
    method: 'POST',
    url: '/handle_screening_on_answer'
}, 'sip:kate@example.com?customheader=foo');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using Twilio.Http;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial(
            record: "record-from-answer",
            timeout: 10,
            hangupOnStar: true,
            callerId: "bob",
            method: HttpMethod.Post,
            action: new Uri("http://example.com/handle_post_dial")
        );

        var sip = new Sip(
            new Uri("http://example.com?customheader=foo"),
            "kate",
            url: new Uri("http://example.com/handle_screening_on_answer"),
            method: HttpMethod.Post
        );

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString()); ;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial(['record' => 'record-from-answer', 'timeout' => 10,
    'hangupOnStar' => 'true', 'callerId' => 'bob', 'method' => 'POST',
    'action' => '/handle_post_dial']);
$dial->sip('sip:kate@example.com?customheader=foo', ['method' => 'POST',
    'url' => '/handle_screening_on_answer']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial(
  record: 'record-from-answer', timeout: 10, hangup_on_star: true,
  caller_id: 'bob', method: 'POST', action: '/handle_post_dial'
) do |dial|
  dial.sip(
    'sip:kate@example.com?customheader=foo',
    method: 'POST', url: '/handle_screening_on_answer'
  )
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial(
    record='record-from-answer',
    timeout=10,
    hangup_on_star=True,
    caller_id='bob',
    method='POST',
    action='/handle_post_dial')
dial.sip(
    'sip:kate@example.com?customheader=foo',
    method='POST',
    url='/handle_screening_on_answer')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;
import com.twilio.http.HttpMethod;

public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:kate@example.com?customheader=foo")
            .method(HttpMethod.POST).url("/handle_screening_on_answer").build();
        Dial dial = new Dial.Builder().record(Dial.Record.RECORD_FROM_ANSWER)
            .timeout(10).hangupOnStar(true).callerId("bob").method(HttpMethod.POST)
            .action("/handle_post_dial").sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial
     record="record-from-answer"
     timeout="10"
     hangupOnStar="true"
     callerId="bob"
     method="POST"
     action="/handle_post_dial">

        <Sip
         method="POST"
         url="/handle_screening_on_answer">
            sip:kate@example.com?customheader=foo
        </Sip>
    </Dial>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.sip({
    statusCallbackEvent: 'initiated ringing answered completed',
    statusCallback: 'https://myapp.com/calls/events',
    statusCallbackMethod: 'POST'
}, 'sip:kate@example.com');

console.log(response.toString());
using static Twilio.TwiML.Voice.Sip;
using System;
using System.Collections.Generic;
using Twilio.Converters;
using Twilio.Http;
using Twilio.TwiML;
using Twilio.TwiML.Voice;

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        var sip = new Sip(
            new Uri("http://example.com"),
            "kate",
            statusCallbackEvent: new List<Sip.EventEnum>(
                new EventEnum[] {
                    EventEnum.Initiated,
                    EventEnum.Ringing,
                    EventEnum.Answered,
                    EventEnum.Completed
                }
            ),
            statusCallback: new Uri("https://myapp.com/calls/events"),
            statusCallbackMethod: HttpMethod.Post
        );

        dial.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$dial = $response->dial();
$dial->sip('sip:kate@example.com',
    ['statusCallbackEvent' => 'initiated ringing answered completed',
    'statusCallback' => 'https://myapp.com/calls/events',
    'statusCallbackMethod' => 'POST']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.sip('sip:kate@example.com',
           status_callback_event: 'initiated ringing answered completed',
           status_callback: 'https://myapp.com/calls/events',
           status_callback_method: 'POST')
end

puts response
from twilio.twiml.voice_response import Dial, VoiceResponse, Sip

response = VoiceResponse()
dial = Dial()
dial.sip(
    'sip:kate@example.com',
    status_callback_event='initiated ringing answered completed',
    status_callback='https://myapp.com/calls/events',
    status_callback_method='POST'
)
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Sip;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.voice.Sip.Event;
import com.twilio.http.HttpMethod;
import java.util.Arrays;

public class Example {
    public static void main(String[] args) {
        Sip sip = new Sip.Builder("sip:kate@example.com")
            .statusCallback("https://myapp.com/calls/events")
            .statusCallbackMethod(HttpMethod.POST).statusCallbackEvents(Arrays
            .asList(Event.INITIATED, Event.RINGING, Event.ANSWERED, Event
            .COMPLETED)).build();
        Dial dial = new Dial.Builder().sip(sip).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Sip
         statusCallbackEvent='initiated ringing answered completed'
         statusCallback='https://myapp.com/calls/events'
         statusCallbackMethod='POST'>
            sip:kate@example.com
        </Sip>
    </Dial>
</Response>