How to connect the incoming call after accepting a reservation through Twilio Task Router?

200 Views Asked by At

I'm able to follow Twilio TaskRouter example to accept reservations:

import { Worker } from 'twilio-taskrouter'


const worker = new Worker(token);

worker.on("reservationCreated", async function (reservation) {
  console.log('reserved', reservation)
  await reservation.dequeue()
});

The incoming call reservation comes through and reaches the agent properly. But I'm not clear how to actually answer the incoming call after this. The documentation says calling dequeue() will perform telephony but seems like there are more needs to be done to actually answer the call?

I also tried to create a Twilio Device. But based on my understanding, that requires a TwiML app, but I'm also not sure how to hook up the TwiML with the TaskRouter; nor I'm not sure I'm in the right path.

1

There are 1 best solutions below

1
On

I actually figured it out by trying many diff SDK and code examples as the docs's not super clear.

Apparently we'd need to create a Device with its access token having the identity of the worker's contact_uri's client id.

"contact_uri":"client:a_worker_user_name"

When creating device access token:

const token = new AccessToken(
  twilioAccountSid,
  twilioApiKey,
  twilioApiSecret,
  { identity: "a_worker_user_name" }
);