Twilio TaskRouter: Need Help in Conference Call

49 Views Asked by At

I use task router enqueue and dequeue instructions to connect the caller to the worker. Everything is working perfectly fine. Now I want to add another agent in the same call. For that purpose, I need to convert that call into a conference. I am using Laravel. Here is I am enqueuing the call

$taskAttributes = [
        'channel' => 'voice', // Specify that it's a voice call
        'type' => $deptName,
        'departmentId' => $department_id,
    ];
    $enqueue->task(json_encode($taskAttributes),['timeout' => 60]);
    return response($response)->header('Content-Type', 'text/xml');

That is how I am dequeuing it

return response()->json([
            "instruction" => "dequeue",
            "status_callback_events" => "initiated,ringing,answered,completed",
            "record" => "record-from-answer",
            "status_callback_url" => url('ivr/statuseventCallback'),
        ]);

What I need is to convert the in progress call to conference so I can add another person to the same call.

2

There are 2 best solutions below

0
Yasir Ijaz On BEST ANSWER

I managed to do that. Sharing here for information.

When the Call is attended and in progress. I trigger an API to update the task

$task = $twilio->taskrouter->v1->workspaces($workspaceSid)
                            ->tasks($taskSid)->fetch()->toArray();

        $existing = json_decode($task['attributes'],true);
        $new = [
            "conference" => "redirect"
        ];
        $updated = array_merge($existing,$new);
        // dd($task['attributes']);
        $task = $twilio->taskrouter->v1->workspaces($workspaceSid)
                            ->tasks($taskSid)
                            ->update([
                                    "attributes" => json_encode($updated)
                                ]
                            );

Now every event in my webhook call will have this attribute in Task Detail. I am updating first the child leg of the call then the parent leg.

if(isset($taskAttributes['conference'])){
   $task = isset($postDate['TaskSid']) ? $postDate['TaskSid'] : '';
   $twilio = new Client($accountSid, $authToken);
   $twilio->calls($callData['call_sid'])->update([
      "method" => "POST",
       "url" => url('api/phone/addConf?tsid='.$task),
   ]);
   $twilio->calls($taskAttributes['call_sid'])->update([
       "method" => "POST",
       "url" => url('api/phone/addConf?tsid='.$task),
   ]);
} catch (Exception $e) {
  setErrorLogs('Twilio callIsNotUpdating'.$e->getMessage());
}             
exit;}

on this addconf just return the twiml conference.

2
jassent On

Skip the "dequeue" and use the Conference Instruction:

Conference instruction is the recommended way to connect calls between customer and agents. This should be used in almost all cases instead of dequeue or call for call center scenarios

The documentation for the POST Parameters:

Conference instruction uses the Conference Participants API . All values valid for that API can be provided as part of the conference instruction. Note that those parameter names are not replicated here. Please refer to linked documentation for valid values.

I added the bolded part about "all values valid" because this isn't super clear in the documentation.

Your code would look something like this:

return response()->json([
            "instruction" => "conference",
            "conference_status_callback_event" => "start,end,join,leave,mute,hold",
            "conference_record" => "record-from-start",
            "conference_status_callback_url" => url('ivr/statuseventCallback'),
        ]);

This stackoverflow post has some additional tips.