Queue calls
Learn to manage high call volumes with Twilio Programmable Voice by using the <Enqueue> verb to place callers in a wait state and the <Dial> verb to connect them to agents. To queue a call, your server must return TwiML containing the <Enqueue> verb in response to Twilio's webhook request. You can use this guide to create inbound contact centers and self-service automation.
See Related reference documentation to learn more about the TwiML and API resources used in this guide.
Info
This guide uses two Twilio phone numbers. If you'd like to try the code out live, you need to buy two phone numbers. For more help getting setup with Voice, see Programmable Voice quickstart.
When our first number is called, Twilio will make a request to our server to place the caller in the Queue.
1const VoiceResponse = require('twilio').twiml.VoiceResponse;23const response = new VoiceResponse();4response.enqueue(5{6waitUrl: 'wait-music.xml',7},8'support'9);1011console.log(response.toString());
Output
1<?xml version="1.0" encoding="UTF-8"?>2<Response>3<Enqueue waitUrl="wait-music.xml">support</Enqueue>4</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.
When our second number is called, Twilio will make a request to our server to connect the agent to the Queue.
1const VoiceResponse = require('twilio').twiml.VoiceResponse;23const response = new VoiceResponse();4const dial = response.dial();5dial.queue(6{7url: 'about_to_connect.xml',8},9'support'10);1112console.log(response.toString());
Output
1<?xml version="1.0" encoding="UTF-8"?>2<Response>3<Dial>4<Queue url="about_to_connect.xml">support</Queue>5</Dial>6</Response>
To connect to the first caller in the Queue all we do is Dial the Queue by name.
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.
1// Download the Node helper library from twilio.com/docs/node/install2const VoiceResponse = require('twilio').twiml.VoiceResponse;3const twiml = new VoiceResponse();45twiml.say('You will now be connected to the first caller in the queue.');6const dial = twiml.dial();7dial.queue('Queue Demo');8twiml.redirect();910console.log(twiml.toString());
Output
1<?xml version="1.0" encoding="UTF-8"?>2<Response>3<Say>You will now be connected to the first caller in the queue.</Say>4<Dial>5<Queue>Queue Demo</Queue>6</Dial>7<Redirect></Redirect>8</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.
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.
This guide teaches the basics required for the following use cases:
You can use this guide to build the foundation of an inbound contact center by holding callers in a queue until an agent is available to assist them. This ensures no calls are dropped during peak traffic hours.
To learn more advanced features that you can use with inbound contact centers, see Voice inbound contact center.
You can use this guide to manage callers as they navigate automated menus before being placed in a queue for specific departmental support. This allows for organized routing and reduced wait times through automated sorting.
To learn more advanced features that you can use with self-service automation, see Voice self-service automation.
After following this guide, you can successfully place incoming callers into a named queue and connect them to a live agent. You can test this by calling your Twilio number to enter the queue and then dialing your second Twilio number to act as the agent and pull the caller out of the queue.
Explore the following guides to build on what you've learned in this guide:
- Respond to incoming phone calls: Learn the basics of handling inbound telephony with Twilio.
- Record phone calls: Securely record the conversations between your agents and queued callers.
- Create conference calls: Move callers from a queue into a multi-party conference environment.