title: twilio how pick a call from queue with PHP and JavaScript
body: <p>Am creating a call queuing system with twiml everything is working like i can receive calls and enqueue calls but i can't pick a call from queue, i wrote this code but it is not working</p>
  
  <p>This is my twiml when there is an incoming call:</p>
  
  <p>I receive the first call the other following calls get queued but now after the first call ended i can't pick the queued calls. and when i hung up it put the first caller in a queue.</p>
  
  <pre><code>header("Content-type: text/xml");
  
  $name = $_POST['name'];
  $email = $_POST['email'];
  
  $message = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Response&gt;
      &lt;Say&gt;Please wait and one of our agents will be with you shortly.&lt;/Say&gt;
      &lt;Dial&gt;
          &lt;Client&gt;joey&lt;/Client&gt;
          &lt;Parameter name="name" value="'.$name.'" /&gt;
          &lt;Parameter name="email" value="'.$email.'" /&gt;
      &lt;/Dial&gt;
      &lt;Say&gt;Our agents are still busy please hold.&lt;/Say&gt;
      &lt;Enqueue waitUrl="waiting.php"&gt;Support&lt;/Enqueue&gt;
  &lt;/Response&gt;';
  
  echo $message;
  </code></pre>
  
  <p>So to pick a call from queue i found this Twilio PHP code:</p>
  
  <pre><code>use Twilio\TwiML\VoiceResponse;
  
  $support = $_REQUEST['To'];
  
  $response = new VoiceResponse();
  $response-&gt;say("You will now be connected to the first caller in the queue.");
  $dial = $response-&gt;dial('');
  $dial-&gt;queue($support, ['url' =&gt; 'about_to_connect.php']);
  
  echo $response;
  </code></pre>
  
  <p>With this JavaSCript code</p>
  
  <pre><code> queueButton.click(function() {
          Twilio.Device.connect({
              To: 'Support'
          });
      });
  </code></pre>
  
  <p>here i wanted to follow this answer <a href="https://stackoverflow.com/questions/51565109/twilio-connecting-an-agent-to-a-call-in-a-queue">Twilio connecting an agent to a call in a queue</a></p>
  
  <p>but when i click a button to pick a call nothing happens instead i get this js error</p>
  
  <pre><code>twilio.js:7100 Received an error from the gateway: {code: 31002, connection: Connection, message: "Connection Declined", twilioError: Error
  
  code: 31005
  description: "Connection error"
  explanation: "A connection error occurred during the call"
  </code></pre>
  
  <p>All in all i just need a solution on how to connect an agent to a queue,
  like see how many calls are in the queue and be able to pick them from queue</p>
  
  <p>Please help</p>
  
  <p>Thank in advanced</p>