Relay.Calling.PromptResult

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-submenu

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.

1promptAction, err := resultDial.Call.PromptAsync(&play, &collect)
2for {
3 time.Sleep(1 * time.Second)
4 if promptAction.GetCompleted() {
5 break
6 }
7}
8myResult := promptAction.GetResultType()
9switch myResult {
10case signalwire.CollectResultSpeech:
11 signalwire.Log.Info("Speech text: \"%s\" Confidence: %f\n", promptAction.GetCollectResult(), promptAction.GetConfidence())
12case signalwire.CollectResultDigit:
13 signalwire.Log.Info("Digits: \"%s\" Terminator: %s\n", promptAction.GetCollectResult(), promptAction.GetTerminator())
14default:
15 signalwire.Log.Info("Result was: %s\n", myResult.String())
16}

GetEvent

Returns the last Relay Event arrived for this operation.

Parameters

None

Returns

Relay.Event - Last Relay Event.

Examples

Stop the prompt and then inspect last Relay event payload.

1promptAction.Stop()
2lastEvent := promptAction.GetEvent()
3
4ev := struct {
5 Params *json.RawMessage `json:"params"`
6}{Params: lastEvent}
7
8b, err := json.MarshalIndent(&ev, "", "\t")
9if err != nil {
10 signalwire.Log.Error("error:", err)
11}
12signalwire.Log.Info("Last event: %s\n", b)

GetResult

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

Parameters

None

Returns

signalwire.CollectResult

Examples

Show CollectResult.

1myResult := promptAction.GetResultType()
2switch myResult {
3case signalwire.CollectResultSpeech:
4 signalwire.Log.Info("Result: \"%v\" Confidence: %f\n", promptAction.GetResult(), promptAction.GetConfidence())
5case signalwire.CollectResultDigit:
6 signalwire.Log.Info("Result: \"%v\" Terminator: %s\n", promptAction.GetResult(), promptAction.GetTerminator())
7default:
8}

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

Show the terminator digit.

1myResult := promptAction.GetResultType()
2switch myResult {
3case signalwire.CollectResultSpeech:
4 signalwire.Log.Info("Result: \"%v\" Confidence: %f\n", promptAction.GetResult(), promptAction.GetConfidence())
5case signalwire.CollectResultDigit:
6 signalwire.Log.Info("Result: \"%v\" Terminator: %s\n", promptAction.GetResult(), promptAction.GetTerminator())
7default:
8}

GetSuccessful

Return true if the prompt attempt succeeded, false otherwise.

Parameters

None

Returns

boolean - True/False accordingly to the state.

Examples

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

1promptAction, err := resultDial.Call.PromptAsync(&play, &collect)
2for {
3 time.Sleep(1 * time.Second)
4 if promptAction.GetCompleted() {
5 break
6 }
7}
8signalwire.Log.Info("Success: %v\n", promptAction.GetSuccessful())