0

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?

Ken White
  • 123,280
  • 14
  • 225
  • 444

1 Answers1

0

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;
    }
  }
);

Harsh Mangalam
  • 1,116
  • 1
  • 10
  • 19