How to play sound instead of dial tones

82 views Asked by At

I have a bot in Dialogflow CX with Voximplant. I want to play a typing sound while my customer is waiting for response. How do I do it?

1

There are 1 answers

0
Ksenia Cherkasova On

To do this:

require(Modules.Player);
let typing = false;
var typingPlayer = VoxEngine.createURLPlayer(
  "https://staging.crmsuite.com/media/typing.trimmed.mp3",
  { loop: true, progressivePlayback: true }
);

conversationParticipant.addEventListener(
  CCAI.Events.Participant.Response,
  function (e) {
    var res = e.response || {};

    if (
      !typing &&
      res.recognitionResult?.messageType === "TRANSCRIPT" &&
      res.recognitionResult?.isFinal
    ) {
      typingPlayer.sendMediaTo(call);
      typing = true;
    }

    if (res.automatedAgentReply?.responseMessages) {
      res.automatedAgentReply.responseMessages.forEach((response) => {
        if (response.liveAgentHandoff) transfer = true;
        if (response.endInteraction && res.replyText) hangup = true;
        else if (response.endInteraction) endConversation();
      });
    }
  }
);

conversationParticipant.addEventListener(
  CCAI.Events.Participant.PlaybackReady,
  (e) => {
    if (typing) {
      conversationParticipant.sendMediaTo(call);
      typing = false;
    }
  }
);