Prompt Result

View as Markdown

Relay.Calling.PromptResult

This object returned from one of synchronous prompt methods that represents the final result of a prompting attempt.

Methods

getConfidence

In a prompt action of type speech, it returns the confidence of the result.

Parameters

None

Returns

number - Confidence of the result on a speech prompt.

Examples

Start prompt and then check the result confidence.

1<?php
2
3$collect = [
4 'type' => 'speech',
5 'end_silence_timeout' => 1,
6 'speech_language' => 'en-US',
7 'text' => 'Please, tell me who you want to talk to'
8];
9$call->promptTTS($collect)->done(function($result) {
10 if ($result->isSuccessful()) {
11 $confidence = $result->getConfidence(); // => 83.2
12 }
13});

getEvent

Returns the last Relay Event arrived for this operation.

Parameters

None

Returns

Relay.Event - Last Relay Event.

Examples

Start the prompt while playing TTS and then inspect last Relay event payload.

1<?php
2
3$collect = [
4 'type' => 'digits',
5 'digits_max' => 3,
6 'initial_timeout' => 10,
7 'text' => 'Please, enter your 3 digits PIN'
8];
9$call->promptTTS($collect)->done(function($result) {
10 $event = $result->getEvent();
11 // Inspect $event->payload ..
12});

getResult

Returns the user’s input in a prompt attempt. Could be both from speech or digits type.

Parameters

None

Returns

string - User’s input in a prompt attempt.

Examples

Start recording and print the result in a digits prompt.

1<?php
2
3$collect = [
4 'type' => 'digits',
5 'digits_max' => 3,
6 'initial_timeout' => 10,
7 'text' => 'Please, enter your 3 digits PIN'
8];
9$call->promptTTS($collect)->done(function($result) {
10 if ($result->isSuccessful()) {
11 $result = $result->getResult();
12
13 echo "User enter the PIN: " . $result;
14 }
15});

getTerminator

In a prompt action of type digits, it returns the digit that has terminated the attempt.

Parameters

None

Returns

string - Digit that has terminated the prompt attempt.

Examples

Start prompt and then check the terminator digit.

1<?php
2
3$collect = [ "initial_timeout" => 10, "digits" => [ "max" => 3, "digit_timeout" => 5, "terminators" => "#*" ] ];
4$tts = [ "text" => "Please, enter your 3 digits PIN" ];
5$call->promptTTS($collect)->done(function($result) {
6 if ($result->isSuccessful()) {
7 $terminator = $result->getTerminator(); // => "#"
8 }
9});

getType

Returns the type of the attempt: digits or speech.

Parameters

None

Returns

string - digits or speech.

Examples

Start prompt and then check the type of the prompt.

1<?php
2
3$collect = [
4 'type' => 'digits',
5 'digits_max' => 3,
6 'initial_timeout' => 10,
7 'text' => 'Please, enter your 3 digits PIN'
8];
9$call->promptTTS($collect)->done(function($result) {
10 if ($result->isSuccessful()) {
11 $type = $result->getType(); // => "digits"
12 }
13});

isSuccessful

Return true if the prompt attempt succeeded, false otherwise.

Parameters

None

Returns

boolean - True/False accordingly to the state.

Examples

Start the prompt while playing TTS and then check if it has ended successfully.

1<?php
2
3$collect = [
4 'type' => 'digits',
5 'digits_max' => 3,
6 'initial_timeout' => 10,
7 'text' => 'Please, enter your 3 digits PIN'
8];
9$call->promptTTS($collect)->done(function($result) {
10 if ($result->isSuccessful()) {
11 // Prompt completed with success..
12 }
13});