How to get a current active CallSID of a worker with Twilio SDK?

52 Views Asked by At

How to get a current active CallSID of a worker with Twilio SDK? I have the Worker SID and I need to get the CallSID of the current active call that of the worker.

1

There are 1 best solutions below

0
jassent On

The CallSid data is available from the Taskrouter Assignment Callback event:

Upon issuing a Dequeue Instruction, TaskRouter will update the TaskAttributes of the Task with a worker_call_sid to denote the CallSid that is being created for the outgoing call to a given worker.

The TaskAttributes of the Task will then contain both the call_sid and worker_call_sid.

Your app will need to setup a webhook to listen for the assignment callback.

You could also use the Twilio REST API to Fetch the Task and check the attributes directly:

var task = TaskResource.Fetch(
            pathWorkspaceSid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathSid: "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        );

The best practice that is recommended by Twilio is to use Webhooks and store the relevant call and task data within your app:

If you are performing a large amount of GET requests, consider implementing webhooks aka StatusCallBack requests for the resource endpoint(s) your account is utilizing. The information contained in the responses posted to your servers will often remove the need to perform any future polling GET requests.

If you are frequently fetching the same data from Twilio, we recommend moving the data from Twilio to your own servers. Once data has been successfully moved, delete data stored on Twilio servers if you no longer need it. Not only will this will reduce costs, this is also a generally recommended business practice for privacy, security, and compliance.