TwiML™ Voice: <Leave>

The <Leave> verb transfers control of a call that is in a queue so that the caller exits the queue and execution continues with the next verb after the original <Enqueue>.

Verb Attributes

The <Leave> verb doesn't support any attributes.

Example: Leaving a Queue

In this example, we have a number of people who are waiting in a queue for a support line. Unfortunately the support line closes at 9PM and the callers will have to be notified that they are out of the queue and will have to try again tomorrow.

The original call TwiML might look like this:

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();
response.enqueue(
  {
    waitUrl: 'wait.xml',
  },
  'support'
);
response.say(
  'Unfortunately, the support line has closed. Please call again tomorrow.'
);

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Enqueue("support", waitUrl: new Uri("wait.xml"));
        response
            .Say("Unfortunately, the support line has closed. Please call again tomorrow.");

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

$response = new Twiml();
$response->enqueue('support', ['waitUrl' => 'wait.xml']);
$response->say('Unfortunately, the support line has closed. Please call again tomorrow.');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.enqueue(name: 'support', wait_url: 'wait.xml')
response
  .say('Unfortunately, the support line has closed. ' \
       'Please call again tomorrow.')

puts response
from twilio.twiml.voice_response import Enqueue, VoiceResponse, Say

response = VoiceResponse()
response.enqueue('support', wait_url='wait.xml')
response.say(
    'Unfortunately, the support line has closed. Please call again tomorrow.')

print(response)
import com.twilio.twiml.voice.Enqueue;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Enqueue enqueue = new Enqueue.Builder().waitUrl("wait.xml")
            .name("support").build();
        Say say = new Say
            .Builder("Unfortunately, the support line has closed. Please call again tomorrow.").build();
        VoiceResponse response = new VoiceResponse.Builder().enqueue(enqueue)
            .say(say).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Enqueue waitUrl="wait.xml">support</Enqueue>
    <Say>Unfortunately, the support line has closed. Please call again tomorrow.</Say>
</Response>
Enqueue call in a closed line

Configure wait.xml to play hold music before 9pm:

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();
response.play('http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3');

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

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response
            .Play(new Uri("http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3"));

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

$response = new Twiml();
$response->play('http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.play(url: 'http://com.twilio.sounds.music.'\
                   's3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3')

puts response
from twilio.twiml.voice_response import Play, VoiceResponse

response = VoiceResponse()
response.play(
    'http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3'
)

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


public class Example {
    public static void main(String[] args) {
        Play play = new Play
            .Builder("http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3").build();
        VoiceResponse response = new VoiceResponse.Builder().play(play).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Play>http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3</Play>
</Response>
Play audio

After 9PM, wait.xml will dequeue the user and return control to the <Say> block in the original call TwiML:

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();
response.leave();

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Leave();

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

$response = new Twiml();
$response->leave();

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.leave

puts response
from twilio.twiml.voice_response import Leave, VoiceResponse

response = VoiceResponse()
response.leave()

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


public class Example {
    public static void main(String[] args) {
        Leave leave = new Leave.Builder().build();
        VoiceResponse response = new VoiceResponse.Builder().leave(leave)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Leave />
</Response>
Leave a call

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();
response.enqueue(
  {
    waitUrl: 'wait.xml',
  },
  'support'
);
response.say(
  'Unfortunately, the support line has closed. Please call again tomorrow.'
);

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Enqueue("support", waitUrl: new Uri("wait.xml"));
        response
            .Say("Unfortunately, the support line has closed. Please call again tomorrow.");

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

$response = new Twiml();
$response->enqueue('support', ['waitUrl' => 'wait.xml']);
$response->say('Unfortunately, the support line has closed. Please call again tomorrow.');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.enqueue(name: 'support', wait_url: 'wait.xml')
response
  .say('Unfortunately, the support line has closed. ' \
       'Please call again tomorrow.')

puts response
from twilio.twiml.voice_response import Enqueue, VoiceResponse, Say

response = VoiceResponse()
response.enqueue('support', wait_url='wait.xml')
response.say(
    'Unfortunately, the support line has closed. Please call again tomorrow.')

print(response)
import com.twilio.twiml.voice.Enqueue;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Enqueue enqueue = new Enqueue.Builder().waitUrl("wait.xml")
            .name("support").build();
        Say say = new Say
            .Builder("Unfortunately, the support line has closed. Please call again tomorrow.").build();
        VoiceResponse response = new VoiceResponse.Builder().enqueue(enqueue)
            .say(say).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Enqueue waitUrl="wait.xml">support</Enqueue>
    <Say>Unfortunately, the support line has closed. Please call again tomorrow.</Say>
</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();
response.play('http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3');

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

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response
            .Play(new Uri("http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3"));

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

$response = new Twiml();
$response->play('http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.play(url: 'http://com.twilio.sounds.music.'\
                   's3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3')

puts response
from twilio.twiml.voice_response import Play, VoiceResponse

response = VoiceResponse()
response.play(
    'http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3'
)

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


public class Example {
    public static void main(String[] args) {
        Play play = new Play
            .Builder("http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3").build();
        VoiceResponse response = new VoiceResponse.Builder().play(play).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Play>http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3</Play>
</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();
response.leave();

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Leave();

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

$response = new Twiml();
$response->leave();

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.leave

puts response
from twilio.twiml.voice_response import Leave, VoiceResponse

response = VoiceResponse()
response.leave()

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


public class Example {
    public static void main(String[] args) {
        Leave leave = new Leave.Builder().build();
        VoiceResponse response = new VoiceResponse.Builder().leave(leave)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Leave />
</Response>