Call Whisper with Selective Audio Controls

Nexmo’s been a well-liked selection for contact centre solutions for a very long time, but with in the present day’s launch of Selective Audio Controls we’re taking it to the subsequent degree. Selective audio controls remedy a standard use case – a supervisor listening to a name but only being heard by their employee and not the client – in an intuitive means.

Each participant in a conversation on the Nexmo platform is assigned an ID. Using these IDs and the dialog motion you’ll be able to build an software that controls which individuals someone new to the dialog can hear. In this submit, we’re going to construct the supervisor listening to an employee use case.

The code for this software is obtainable on Github

Bootstrapping an Software

To construct this name move we need to write a small node.js software. Let’s create a brand new undertaking and install categorical to serve our answer_url.

Once you’ve accomplished this, you’ll have to create an occasion of categorical, register an answer_url and pay attention on a port. To do this, create index.js with the next contents:

Creating Your Answer URL

Now that we have now an software bootstrapped, it’s time to start out adding our business logic. There are three individuals in our call:

  • Alice, the contact centre supervisor
  • Bob, the contact centre agent
  • Charlie, the client

In the actual world we’d use a database to store all the info needed to make this occur, however for this submit let’s simply use an object in reminiscence. The secret is the participant’s telephone number, and that maps to an object containing information about them. For now, it’s just their position. Add the following code after app.use(bodyParser.json());, ensuring to replace the code under, changing the keys with your real telephone numbers.

Once you’ve completed that, you have to replace your /webhooks/answer URL in order that it returns a legitimate NCCO. As we’ll need a unique NCCO for each sort of caller, let’s add a change statement and name a way which returns an NCCO for every caller sort:

This code calls createSupervisorNcco, createAgentNcco or createCustomerNcco relying on the caller sort offered. We need to go ahead and create those features and return NCCO.

The Buyer NCCO

Let’s start with the client NCCO. When the client joins, we would like them to have the ability to hear the agent but not the supervisor, and to be able to converse to both the agent and the supervisor. As well as, when the client calls we would like them to be positioned on hold till an agent joins the dialog.

Add the following to the bottom of your file to generate the client NCCO. We use the conversation motion, give the dialog a name, specify that the decision shouldn’t begin routinely and that the consumer ought to be positioned on maintain. These are all present parameters for the Nexmo Voice API.

What makes this NCCO fascinating, are the canSpeak and canHear parameters. These two parameters settle for an inventory of UUIDs that determine different individuals, and controls who the individual connecting to the call can converse to and listen to from. If the UUID of a participant isn’t offered, the connecting consumer will be unable to speak to or hear that participant.

On this example, our buyer can converse to the agent and their supervisor, but can solely hear the audio from the agent. Add the following to the underside of your file:

The Agent NCCO

Next up is the agent NCCO. Brokers should be capable of converse to all members and be heard by all members. They’re the proprietor of this conference call, so we set startOnEnter to true to indicate that the conference turns into lively once they be a part of. In addition, we set document to true in order that the call is recorded.

As the agent can converse to and listen to everybody, we discover all clients and all supervisors and supply their UUIDs to the conversation action.

In this case we might omit canSpeak and canHear from the NCCO because the default values are to permit audio between all members. Within the pursuits of full management over individuals, I’ve chosen to provide them anyway

The Supervisor NCCO

Lastly, we’ve the supervisor NCCO. The supervisor can hear everybody, however only converse to the agent (that is the other of the client). As earlier than, they don’t own the decision so startOnEnter is about to false.

We offer canSpeak and canHear with an inventory of UUIDs like our previous NCCOs, and this ensures that the supervisor can solely converse to the agent, however will hear each the agent and the client.

Making it All Work

We’re virtually there! There are just two things left to do before our software will work. The first is to implement our findParticipants technique. Add the next perform to the bottom of your file:

This searches via all members for the offered position. If the position matches, the leg UUID is pushed in to an array and returned.

The second factor to do is to ensure we retailer the caller’s leg UUID when a request is made to /webhooks/reply. Update your code to retailer the leg ID after we examine if the current caller might be discovered:

At this level, your software should work. Ensure that your answer_url is accessible (perhaps using ngrok if it’s on your native machine) and call a quantity that factors to the appliance you just built. If you could create a Nexmo software and lease a quantity, take a look at our software concepts on our developer portal.