In this recipe, we're going to set up a simple call queue. We're going to have this work with two separate numbers: one number is the number that the callers will call on and a second number will handle the agents who call in.
Callers will get placed in a queue, and when an agent calls the agent number, they will be connected to the first caller who is waiting to speak to someone.
OK, let's set up our listener.php
file to place all incoming calls in a queue and agent.php
to connect our agents to callers by performing the following steps:
Services/
folder to your website.config.php
to your web server using the following code:<?php $accountsid = ''; // YOUR TWILIO ACCOUNT SID $authtoken = ''; // YOUR TWILIO AUTH TOKEN $callqueue = 'Twilio Cookbook'; // YOUR CALL QUEUE ?>
listener.php
to your web server using the following code:<?php include("config.php"); # Include Twilio PHP helper library. require('Services/Twilio.php'), # Tell Twilio to expect some XML header('Content-type: text/xml'), # Create response object. $response = new Services_Twilio_Twiml(); $response->enqueue( $callqueue ); # Print TwiML print $response;
agent.php
using the following code:<?php include("config.php"); # Include Twilio PHP helper library. require('Services/Twilio.php'), # Tell Twilio to expect some XML header('Content-type: text/xml'), # Create response object. $response = new Services_Twilio_Twiml(); # Dial into the Queue we placed the caller into to connect agent to # first person in the Queue. $dial = $response->dial(); $dial->queue( $callqueue ); # Print TwiML print $response;
listener.php
, as shown in the following screenshot:listener.php
.agent.php
as shown in the following screenshot:agent.php
.In steps 1 and 2, we downloaded and set up our Twilio PHP library.
In step 3, we set up our config.php
file with our Twilio settings.
In step 4, we uploaded listener.php
, which handles calls from our customers and places them into a call queue.
In step 5, we uploaded agent.php
, which handles calls from agents and connects them to customers waiting in the call queue.
In step 6, we set up our Twilio phone number that receives incoming calls and adds them to a queue.
Finally, in steps, 7, 8, and 9, we added agent.php
to a phone number to connect our agents to any callers waiting in a queue.
This is a two-prong system. Firstly, any incoming caller is placed inside a call queue. Secondly, any agent who calls is connected to the first caller waiting to talk to an agent.