Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Queue Calls



Overview

overview page anchor

This guide will explain how to use Twilio's Queue feature(link takes you to an external page) to create a simple call queueing system. A Queue stores incoming calls in order. You can then connect the first call in the queue to another call easily. The complete code sample will show you how to accept an incoming call, place it into a queue and then connect a live agent to the first call in the queue.

For this demonstration we'll be using two Twilio phone numbers, so if you'd like to try the code out live, you'll need to buy two phone numbers(link takes you to an external page). For more help getting setup with Voice be sure to read our Getting Started guide.


Putting the Caller in a Queue

caller page anchor

When our first number is called, Twilio will make a request to our server to place the caller in the Queue.

Simple Enqueue

simple-enqueue 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-music.xml'
_10
}, 'support');
_10
_10
console.log(response.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Enqueue waitUrl="wait-music.xml">support</Enqueue>
_10
</Response>

We start by creating a TwiML response that uses the Enqueue verb to create a new Queue and place the caller into it.

You can learn more about how to serve TwiML from your own application in our webhook guides. You can explore all the available TwiML functionality in our TwiML reference docs.


Connecting the Agent to the Queue

agent page anchor

When our second number is called, Twilio will make a request to our server to connect the agent to the Queue.

Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
const dial = response.dial();
_10
dial.queue({
_10
url: 'about_to_connect.xml'
_10
}, 'support');
_10
_10
console.log(response.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Dial>
_10
<Queue url="about_to_connect.xml">support</Queue>
_10
</Dial>
_10
</Response>

To connect to the first caller in the Queue all we do is Dial the Queue by name.


Automatically Connecting to the next Caller

redirect page anchor

By default the call will end when the Agent or Caller hang up, but in most cases we'll want to connect to the next Caller automatically.

Automatically Connect to the Next Caller

automatically-connect-to-the-next-caller page anchor
Node.js
Python
Java
PHP
Ruby

_10
// Download the Node helper library from twilio.com/docs/node/install
_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
const twiml = new VoiceResponse();
_10
_10
twiml.say('You will now be connected to the first caller in the queue.');
_10
const dial = twiml.dial();
_10
dial.queue('Queue Demo');
_10
twiml.redirect();
_10
_10
console.log(twiml.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Say>You will now be connected to the first caller in the queue.</Say>
_10
<Dial>
_10
<Queue>Queue Demo</Queue>
_10
</Dial>
_10
<Redirect></Redirect>
_10
</Response>

An empty <Redirect> verb will redirect the caller to the beginning of the TwiML, which will then Dial and connect to the next person in the Queue. As a final touch we add a <Say> verb to tell the agent that they are being connected to another caller.


More sophisticated workflows

taskrouter page anchor

With Twilio's TaskRouter you can implement very sophisticated call-center workflows like:

  • assigning available Agents to the next caller in the Queue
  • offering tiered support plans, that allow premium customers to skip the queue
  • routing certain callers to different teams based on business logic

Hopefully this guide got you up and running with Twilio Queues. Email us and let us know what features of Queue you would like to know more about.


Rate this page: