phplaraveltwiliotwilio-twimltwilio-taskrouter

Twilio TaskRouter: Unable to connect Reservation to Call


I am using TaskRouter Twilio with Laravel.

Here is what I am doing right now

  1. I have attached a twiml app to a phone number.

  2. Added a webhook to that twiml app.

  3. On that webhook I am hitting this code $response = new VoiceResponse();

    $taskAttributes = [
        'channel' => 'voice', // Specify that it's a voice call
    
    ];
    
    $enqueue = $response->enqueue('WSDSupport',['workflowSid' => $workflowSid,
                                                'action' => url('ivr/testQueue')]);
    $enqueue->task(json_encode($taskAttributes),['timeout' => 200]);
    return response($response)->header('Content-Type', 'text/xml');
    
  4. Now on frontend I received the reservation created event (reservation.created)

  5. I get a prompt to accept the reservation. When I do.

    if (confirm('Incoming call. Accept?')) {
                           reservation.accept();
                       } else {
                           reservation.reject();
                       }
    

Worker is selected but nothing happens. On the Workflow callback URL I am running this code.

 return response()->json([
                 "instruction"=> "dequeue",
                 "from"=> $taskAttributes['from'],
                 "post_work_activity_sid"=> config('services.twilio')['postWorkActivitySid']
             ]);

I need to connect my agent via a call to the customer. I have searched everwhere but did not find any help.


Solution

  • I figured it out

    return response()->json([
                "instruction"=> "dequeue"
            ]);
    

    Just return this. This will look for the worker who has accepted the reservation and call that worker contact_uri,

    contact_uri: '' // This can be the client id which you have used to created the token on client side.
    

    which is set in his/her profile on Twilio. It can be a phone number or browser client id.