SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

How Do You Make the Browser Ring When a Flex Call Comes In?

The best option for making the browser ring when an incoming Flex call arrives is to listen for the reservationCreated event, and then play back audio. Here's an example of what plugin code for this might look like:

let alertSound = new Audio("https://mysite.com/sounds/alert.mp3");
alertSound.loop = true;

const resStatus = ["accepted","canceled","rejected","rescinded","timeout"];

manager.workerClient.on("reservationCreated", function(reservation) {
  if (
reservation.task.taskChannelUniqueName === "voice" &&
reservation.task.attributes.direction === "inbound"
) {
alertSound.play();
} resStatus.forEach((e) => { reservation.on(e, () => { alertSound.pause() }); }); });

This code will play a repeated audio file (alert.mp3 in this example), until the task is accepted by the worker in Flex, and the call is answered.

To make this code work, you'll only need to update the audio file URL in line 1, and then add your code to the the init() function of your plugin. For help adding this code to your hosted Flex instance, please see Creating Plugins for Twilio Flex.

Notice: The audio file must be accessible by Twilio's proxy servers. Local files on your desktop are likely unaccessible via these methods, but your audio file may be uploaded to Twilio Assets for use here.

How Does the Browser Know Which Audio Device to Ring?

The MediaDevices interface allows you to request a list of available audio output devices with enumerateDevices():

navigator.mediaDevices.enumerateDevices();

Once you identify the desired device ID, pass it off with using the HTMLMediaElement.setSinkId() method.

Notice: These methods are officially supported in Chrome 49+ and Edge 17+. Support for additional browsers cannot be guaranteed at this time.

Have more questions? Submit a request
Powered by Zendesk