Twilio - best way to learn of a client disconnect to set task router worker to unavailable

22 Views Asked by At

Does anyone know a way to learn about a Twilio Voice Client register/unregister? There doesn't seem to be any webhooks associated with this. I would like to know when they disconnect so I can make sure to update their task router worked to unavailable.

1

There are 1 best solutions below

0
jassent On

It seems from your post that you are using Twilio Javascript SDK and making calls using the browser. If this is correct, then you can listen for the destroy or unregister events:

const device = new Device(token);

device.on('unregistered', () => 
    // Do something to update TaskWorker status
});

However, this will be fragile if the end-user loses Internet connectivity, quits the browser/closes the tab, or just powers off the computer. A more reliable method would be to the put the "ready" user into a Conference while they wait for calls. If the user hangs-up the conference will send a "participant-leave" webhook event that your Server can then use to update the Taskrouter worker status to unavailable.