Twilio is a highly flexible and customizable cloud communication platform.
In this post, we'll see how to enable ringing for different types of incoming tasks to notify agents that someone needs attention.
First, create a new plugin, following Twilio guidelines here:
https://www.twilio.com/docs/flex/quickstart/getting-started-plugin
After that, prepare a sound sample, which can be hosted at a publicly available URL or within Twilio assets, and specify this within the plugin code.
Attention: be careful with the size of the audio file, as this may negatively impact agents with a slow internet connection.
let alertSound = new Audio("URL to your sound sample");
Then, within the plugin code, we need to add a listener to the Reservation created event, and in this case we'll show a notification and play an alert sound for an incoming chat task:
const resStatus = ["accepted","canceled","rejected","rescinded","timeout"];
manager.workerClient.on("reservationCreated", function(reservation) {
if (reservation.task.taskChannelUniqueName === 'chat') {
DefaultTaskChannels.Chat.notifications.override.IncomingTask = () => {
Notifications.showNotification(NotificationIds.IncomingTask, { task: reservation.task });
}
alertSound.play();
};
resStatus.forEach((e) => {
reservation.on(e, () => {
alertSound.pause()
});
});
});