Skip to contentSkip to navigationSkip to topbar
On this page

TwiML™ Voice: <Leave>


The <Leave> verb is used in conjunction with <Enqueue> to manage control of a call that is in a queue.

When Twilio executes the <Leave> verb on a call, the call is removed from the queue and Twilio executes the next TwiML verb after the original <Enqueue>.


Verb Attributes

attributes page anchor

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

Example: Leaving a Queue

examples-1 page anchor

Consider the following scenario: There are several calls waiting in a call queue for a customer support agent. The customer support line closes at 9PM and the callers must be notified that they have been removed from the queue and will have to try again tomorrow.

The original call TwiML might look like this:

Enqueue call in a closed lineLink to code sample: Enqueue call in a closed line
1
const VoiceResponse = require('twilio').twiml.VoiceResponse;
2
3
4
const response = new VoiceResponse();
5
response.enqueue({
6
waitUrl: 'wait.xml'
7
}, 'support');
8
response.say('Unfortunately, the support line has closed. Please call again tomorrow.');
9
10
console.log(response.toString());

Output

1
<?xml version="1.0" encoding="UTF-8"?>
2
<Response>
3
<Enqueue waitUrl="wait.xml">support</Enqueue>
4
<Say>Unfortunately, the support line has closed. Please call again tomorrow.</Say>
5
</Response>

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

1
const VoiceResponse = require('twilio').twiml.VoiceResponse;
2
3
4
const response = new VoiceResponse();
5
response.play('http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3');
6
7
console.log(response.toString());

Output

1
<?xml version="1.0" encoding="UTF-8"?>
2
<Response>
3
<Play>http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3</Play>
4
</Response>

After 9PM, wait.xml dequeues the call and returns call control to the <Say> block in the original call TwiML:

1
const VoiceResponse = require('twilio').twiml.VoiceResponse;
2
3
4
const response = new VoiceResponse();
5
response.leave();
6
7
console.log(response.toString());

Output

1
<?xml version="1.0" encoding="UTF-8"?>
2
<Response>
3
<Leave />
4
</Response>