title: How do I get twilio to call the agent to connect them to callers in the queue?
body: <p>From the twilio documentation and <a href="http://www.twilio.com/docs/howto/callqueue" rel="nofollow">tutorial</a> 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.</p>
  
  <p><strong>Objective:</strong></p>
  
  <p><strong>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.</strong></p>
  
  <p>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:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;Response&gt;
       &lt;Enqueue waitUrl="contactagent.php"&gt;myqueue&lt;/Enqueue&gt;
  &lt;/Response&gt; 
  </code></pre>
  
  <p><strong>contactagent.php:</strong></p>
  
  <pre><code>&lt;?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-&gt;account-&gt;calls-&gt;create($_REQUEST['the caller that's in the queue'], "(the agent's phone number)", "connectagent.xml", array());
  echo "&lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt;
  &lt;Response&gt;
     &lt;Say&gt;Your are number ".$_REQUEST['QueuePosition']." in line for a representative.&lt;/Say&gt;
     &lt;Play&gt;http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3&lt;/Play&gt;
  &lt;/Response&gt;"
  ?&gt;
  </code></pre>
  
  <p><strong>connectAgent.xml</strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8' ?&gt;
  &lt;Response&gt;
     &lt;Dial&gt;myqueue&lt;/Dial&gt;
  &lt;/Response&gt;
  </code></pre>