Skip to main content

$dialer.getBotSpeech

This method returns data on bot phrase playback in the phone channel.

Syntax

The method is called without arguments:

$dialer.getBotSpeech();

Return value

The method returns an array of objects with the following properties:

PropertyTypeDescription
botStateStringThe state from which the playback data was sent.
replyObjectBot reply data. Object content depends on the bot reactions in which the playback data was sent.
causeStringPhrase playback result. Possible values:
  • OK — the user has finished listening to the phrase.
  • FAIL — a synthesis or playback error occurred.
  • CANCEL — the phrase was not played.
  • INTERRUPTED_BY_BARGEIN — the playback was interrupted by barge-in.
  • INTERRUPTED_BY_HANGUP — the playback was interrupted by the hangup event.
durationSecondsNumberPhrase playback duration in seconds.

Reply object format

The reply object with bot reply data contains string properties. If the reply is sent via:

  • The a tag, the $reactions.answer method, or a reply with the text type, the object will contain the following properties: text and ssml — a phrase text and a text with speech synthesis markup if it is used.
  • The audio tag, the $reactions.audio method, or a reply with the audio type, the object will contain the audioSrc property — an audio link.
  • The $reactions.ttsWithVariables method, the object will contain the following properties: text — a phrase text, template — a text of the speech synthesis template, audio — a link to the audio with a phrase template.

Return value example

[
{
"botState": "/Start",
"reply": {
"text": "Hi!"
},
"cause": "OK",
"durationSeconds": 0.68
},
{
"botState": "/Intro",
"reply": {
"text": "I am calling you from Just AI."
},
"cause": "OK",
"durationSeconds": 2.17
},
{
"botState": "/Promo",
"reply": {
"text": "I am sure you will be interested in our offer."
},
"cause": "INTERRUPTED_BY_HANGUP",
"durationSeconds": 2.35
}
]

How to use

Let’s assume that during the call the bot informs users about current promotions. The bot says a phrase using the a tag and then plays a voice recording using the audio tag.

To record the phrase playback data as a comment in analytics:

  1. Call getBotSpeech to receive the bot playback data.
  2. If this data is defined, loop through all replies and construct a comment text.
  3. Record this comment to analytics using $analytics.setComment.
state: Promo
q!: * (promo*/campaign*/offer*) *
a: We have a special offer now!
audio: https://example.com/audio.wav
script:
var botSpeech = $dialer.getBotSpeech();
if (botSpeech !== undefined) {
var comment = "";
botSpeech.forEach(function(speech) {
if (speech.reply.text !== undefined) {
comment += "Bot phrase “" + speech.reply.text + "” from the " + speech.botState + " state completed with the " + speech.cause + " result in " + speech.durationSeconds + " seconds." + "\n";
}
if (speech.reply.audioSrc != undefined) {
comment += "Audio " + speech.reply.audioSrc + " from the " + speech.botState + " state completed with the " + speech.cause + " result in " + speech.durationSeconds + " seconds." + "\n";
}
});
$analytics.setComment(comment);
}

If the user listened to the phrase, but ended the call while the audio was playing, you will see the following comment in the AnalyticsDialogsPhrases section:

Bot phrase “We have a special offer now!” from the /Promo state completed with the OK result in 1.58 seconds.
Audio https://example.com/audio.wav from the /Promo state completed with the INTERRUPTED_BY_HANGUP result in 5.38 seconds.