I am trying to set up outgoing calls through Twilio task router. I am creating tasks through PHP with the all the necessary attributes (instruction, to , from, post_work_activity_sid ) but the created task doesn't set up a call between the twilio client and the external phone number. I was hoping that tasks created by the program would create a conference call between worker(browser) and external client. I keep getting an error that is shown below. I have a assignment php on my application server which de-queues calls to my workers (Browser clients). Currently, incoming calls from external number to browser clients through task router is working as expected. However, outbound calls generates a task and a reservation is assigned but Twilio is not able to dequeue the call to a worker. Is there a way to create a task for voice call such that the task is created using Twiml Enqueue verb? Or is there a better way of handling outbound calls using the Twilio taskrouter so that calls are assigned successfully to the workers using Browser client ?
As per this thread: Can outbound calls be made through Twilio TaskRouter, I tried using instruction call.I have also gone through the documentation and another stack overflow post about assignment callback URL but it's not clear and am not sure what I could be potentially doing wrong.
Error message: The dequeue instruction can only be issued on a task that was created using the TwiML verb
<?php
require_once('TwilioVendor/autoload.php'); // Loads the library
use Twilio\Rest\Client;
$sid = "ACxxxxxxxxxxxxxxxxxxxxxxx";
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
try{
$twilio = new Client($sid, $token);
$task = $twilio->taskrouter->v1-
>workspaces("WSxxxxxxxxxxxxxxxxxxxxxxxxxxxx")->tasks-
>create(array("attributes" => json_encode(array(
//"instruction"=>"accept",
//"instruction"=>"conference",
"instruction"=>"call",
"to"=> "client:Bob",
"from"=> "+61123456789",
"post_work_activity_sid"=> "WAxxxxxxxxxxxxxxxxxxxx"
)),
"workflowSid" => "WWxxxxxxxxxxxxxxxxxx"
)
);
}catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
print($task->sid);
**Assignment Callback code**
<?php
$assignment_instruction = [
'instruction' => 'call','to'=> 'client:Bob',
'from' => '+61xxxxx','url'=>'CRM REST END POINT'
];
header('Content-Type: application/json');
echo json_encode($assignment_instruction);
**CRM REST END POINT TWIML**
<?php
require __DIR__ . '/vendor/autoload.php';
require_once 'TwilioVendor/autoload.php';
use Twilio\Twiml;
$reservationSid= $_REQUEST['rsid']
header('Content-Type: text/xml');
?>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman">You will now be connected to the customer</Say>
<Dial>
<Queue reservationSid="<?$reservationSid?>"/>
</Dial>
</Response>