Skip to contentSkip to navigationSkip to topbar
Rate this page:
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 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 line

enqueue-call-in-a-closed-line page anchor
Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
response.enqueue({
_10
waitUrl: 'wait.xml'
_10
}, 'support');
_10
response.say('Unfortunately, the support line has closed. Please call again tomorrow.');
_10
_10
console.log(response.toString());

Output

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

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

Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
response.play('http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3');
_10
_10
console.log(response.toString());

Output

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

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

Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
response.leave();
_10
_10
console.log(response.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Leave />
_10
</Response>


Rate this page: