4

From the twilio documentation and tutorial an agent would have no idea that someone was in the queue, so this only works if there is always someone in the queue and agents just sit there and field calls all day.

Objective:

When someone calls I would like to connect the call to the agent. If the agent isn't available, add the caller to a queue. If a second or third person calls, keep adding them to the queue. When the agent finishes their first call and hangs up, let the next in line call and actually ring the agent's phone to speak with the agent.

I'm really new to twilio so this twiml is bad and I already know this doesn't work, but here's what I'm trying so far:

<?xml version="1.0" encoding="UTF-8" ?>
<Response>
     <Enqueue waitUrl="contactagent.php">myqueue</Enqueue>
</Response> 

contactagent.php:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('../callapp/Services/Twilio.php'); // Loads the library

$sid = "(MYID)";
$token = "(MyToken)";
$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create($_REQUEST['the caller that's in the queue'], "(the agent's phone number)", "connectagent.xml", array());
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<Response>
   <Say>Your are number ".$_REQUEST['QueuePosition']." in line for a representative.</Say>
   <Play>http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3</Play>
</Response>"
?>

connectAgent.xml

<?xml version='1.0' encoding='utf-8' ?>
<Response>
   <Dial>myqueue</Dial>
</Response>
Altimus Prime
  • 2,207
  • 2
  • 27
  • 46

1 Answers1

3

I think you should put all of your client calls to the queue (no matter first client or not). Do it using Enqueue. That is good then.

Next, you need to initiate a call to an agent. You can instruct Twilio to call agent's phone number. In that instruction define a callback url "dial_agent_callback" and a status callback url "dial_agent_status_callback". Once the "dial_agent_callback" callback occurs (indicating that agent has picked up), you instruct Twilio to dial your queue:

<Response>
   <Dial>
      <Queue url="dial_queue_callback">
         myqueue
      </Queue>
   </Dial>
<Response>

You can know when an agent has finished talking to a client in a dial_queue_status_callback (or if agent has not picked up, or if any problems occurred). The callback Status will indicate what has happened.

Finally, you need to figure out when to trigger calls to the agent. I suggest triggering an event when a client call occurs. Call your next available agent, if there is one. In case there are more clients than agents you can check the Queue Size using Twilio API. Then you can trigger a new call to an agent when a new agent joins, or when a busy agent finishes handling client call.

I hope that helps.

Alvis
  • 3,543
  • 5
  • 36
  • 41
  • Thanks for offering an answer. Somehow I thought there would be some simple built in way, but I realize that it's a bit too involved for you to actually lay out what I'm trying to do. I'll post later what my final solution is. – Altimus Prime Aug 26 '13 at 20:09
  • @AuntJamaima -- what was your final solution? – Andrew Bucklin Aug 15 '15 at 20:35
  • Sorry I didn't post it. I set it up so that when there's a caller in the queue, it will call the agent every 30 seconds until she answers. It's a little annoying for the agent if they're on a cell phone. I don't have the script I wrote for it as it was a long time back. – Altimus Prime Aug 15 '15 at 21:16