$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:
Property | Type | Description |
---|---|---|
botState | String | The state from which the playback data was sent. |
reply | Object | Bot reply data. Object content depends on the bot reactions in which the playback data was sent. |
cause | String | Phrase playback result. Possible values: |
durationSeconds | Number | Phrase 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 thetext
type, the object will contain the following properties:text
andssml
— 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 theaudio
type, the object will contain theaudioSrc
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:
- Call
getBotSpeech
to receive the bot playback data. - If this data is defined, loop through all replies and construct a comment text.
- 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 Analytics → Dialogs → Phrases 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.