SIGN UP

Step-by-step call center tutorial part 5

Step-by-step call center tutorial part 5

Waiting in a queue

Having a full control over an incoming and outgoing calls allows to implement any business needs. By default, a user will hear nothing while waiting in the queue, since we have not instructed VoxEngine to produce any audio. Good practice is to inform the user about his or her queue position and play some music to indicate the call in progress.

Let’s start by adding the background music by using the call object’s startPlayback method. In order to start background music, add the following source code:

inc.addEventListener(CallEvents.Connected, () => {
  const isLoop = true;
  inc.startPlayback("https://cdn.voximplant.com/bb_remix.mp3", isLoop);
  request = VoxEngine.enqueueACDRequest('main', incId);
  ...
});

Important note: outside of conference rooms, any call object can have only one audio source. So if you are using startPlayback and then say, the say method call will detach startPlayback audio and attach it’s own audio. After say finishes, audio from startPlayback will not be automatically attached back. Music automatically stops after operator answers and new audio source is connected to call via sendMediaBetween. One more thing to do is queue position notification. This is done by periodically calling a getStatus method of the queue request object and subscribing to the the ACDEvents.Waiting event. The event receives queue position info as position and ewt (estimated wait time) properties of an event handler parameter:

// This event only fired if request was queued without errors.
request.addEventListener(ACDEvents.Queued, () => request.getStatus());
request.addEventListener(ACDEvents.Waiting, e => {
  inc.say(`Queue position is ${e.position}`);
  inc.addEventListener(CallEvents.PlaybackFinished, () => {
    // Note that say() changes audio source, so we need to change it back,
    // but only if operator is not yet connected.
    if (!out) {
      const isLoop = false;
      inc.startPlayback("https://cdn.voximplant.com/bb_remix.mp3", isLoop);
    }
  });
  setTimeout(function() { request.getStatus(); }, 30000);
});

While that setup will work in most situations, where are so-called “edge cases” what can be gracefully handled. For example, if no operators are connected, it’s definitely not possible to queue a request. For such “error cases” ACD module fires a number of events:

It will be a good idea to handle such events and provide the caller with a meaningful way to reach an operator, like asking a permission for callback and passing phone number to your backend, so an operator can call back manually or automatically later. Complete source code for this step:

require(Modules.ACD);

VoxEngine.addEventListener(AppEvents.CallAlerting, e => {
  const inc = e.call;
  const incId = e.callerid;
  let request = null;
  let out = null;
  inc.answer();
  inc.addEventListener(CallEvents.Connected, () => {
    const isLoop = true;
    inc.startPlayback("https://cdn.voximplant.com/bb_remix.mp3", isLoop);
    request = VoxEngine.enqueueACDRequest('main', incId);
    // This event only fired if request was queued without errors.
    request.addEventListener(ACDEvents.Queued, () => request.getStatus());
    request.addEventListener(ACDEvents.Waiting, e => {
      inc.say(`Queue position is ${e.position}`);
      inc.addEventListener(CallEvents.PlaybackFinished, () => {
        // Note that say() changes audio source, so we need to change it back,
        // but only if operator is not yet connected.
        if (!out) {
          inc.startPlayback("https://cdn.voximplant.com/bb_remix.mp3", isLoop);
        }
      });
      setTimeout(() => request.getStatus(), 30000);
    });
    request.addEventListener(ACDEvents.OperatorReached, e => {
      out = e.operatorCall;
      VoxEngine.sendMediaBetween(inc, out);
      out.addEventListener(CallEvents.Disconnected, () => {
        inc.hangup();
        // Some logic can be performed instead of session termination
        VoxEngine.terminate();
      });
    });
  });
  inc.addEventListener(CallEvents.Disconnected, () => {
    // If operator already connected, this also hangs up operator's call.
    // Also cancels all events like ACDEvents.Waiting
    request.cancel();
    // Some logic can be performed instead of session termination
    VoxEngine.terminate();
  });
});
Tags:call center
B6A24216-9891-45D1-9D1D-E7359CEB8282 Created with sketchtool.

Comments(0)

Add your comment

To leave a comment, first confirm that you are not a robot. It's free

Recommend

Get your free developer account or talk with our sales team to learn more about Voximplant solutions
SIGN UP
Contact sales

Please complete this field.

Please complete this field.

Please complete this field.

Choose the solution

Please complete this field.

Please complete this field.