If you are using Twilio TaskRouter SDK version 1, it's critical that you update to version 2 to ensure that your systems stay current, robust, and well-supported with the latest improvements and developments. TaskRouter SDK version 2 is not just the newer version, but it is the platform that Twilio will provide long-term support for.
Please note that updates and support for TaskRouter SDK version 1 will be discontinued, and only version 2 will continue to be updated.
accepted
,
canceled
,
rejected
,
rescinded
, and
timed out
.
Performance enhancements: Version 2 reduces the need for multiple round-trips to the API by:
As a result of these updates, a hard refresh is required to re-fetch from the API in version 2.
When you migrate to TaskRouter SDK version 2, you'll need to make updates for the following changes:
Complete the following steps to upgrade to TaskRouter SDK version 2 and address any breaking changes.
The main changes from v1 to v2 are the migration of callbacks to promises and different organization of the worker's activity and event handling. The SDK is now more efficient, accomplished by sending the entire Task and Reservation payload down the JS SDK and listing all active Tasks and Reservations for the Worker in memory.
Use the information in this section to update your workers, events, and reservations for version 2.
Version 2 uses promises instead of callbacks.
1worker.on("ready", function(worker) {2updateWorker(worker);3});
1worker.on('ready', () => {2updateWorker(worker);3});
In version 1, the activity was defined by properties. In version 2, the worker has an activity object instead.
1function updateWorker(worker) {2console.log(worker.activityName);3console.log(worker.available);4}
1function updateWorker(worker) {2console.log(worker.activity.name);3console.log(worker.activity.available);4}
Version 1 used a fetchActivityList
function call to fetch the API workspace activity list. In version 2, you can simply loop through worker.activities
.
1worker.fetchActivityList(2function(error, activityList) { //body} );
1worker.activities.forEach((activity) => {2console.log(activity.name);3});
worker.updateActivity(onlineActivitySid);
1worker.activities.forEach((activity) => {2if (activity.name === 'Idle') {3activity.setAsCurrent().then(() => {4console.log(worker.activity.name);5});6}7});
1worker.on("activity.update", function(worker) {2updateWorker(worker);3});
1worker.on("activityUpdated",2function(worker) {3updateWorker(worker);4});
In version 2, you must have an event handler for reservation before you can listen for reservation events (accepted, canceled, rejected, rescinded, and timed out).
1worker.on("reservation.accepted", function(reservation) {2console.log(reservation.task.attributes);3});
1worker.on(“reservationCreated”, function(reservation) {2reservation.on(“accepted”, function(reservation) {3console.log(reservation.task.attributes);4});5});