Relay.Calling.PromptAction

View as Markdown

Relay.Calling.PromptAction

This object returned from one of asynchronous prompt methods that represents a prompt attempt that is currently active on a call.

Methods-submenu

GetResult

Returns the final result of the prompt attempt.

Parameters

None

Returns

Relay.Calling.PromptResult - Final result of the prompt attempt.

Examples

Start the attempt and grab the result when it’s completed.

1resultDial.Call.OnPrompt = func(promptaction *signalwire.PromptAction) {
2 // we could do something here and this gets called when the Prompt Action finishes.
3}
4
5playAudioParams := signalwire.PlayAudioParams{
6 URL: "https://www.pacdv.com/sounds/voices/can-you-keep-a-secret.wav",
7}
8
9playTTSParams := signalwire.PlayTTSParams{
10 Text: "Hello from Signalwire!",
11}
12
13playRingtoneParams := signalwire.PlayRingtoneParams{
14 Duration: 5,
15 Name: "us",
16}
17
18play := []signalwire.PlayStruct{{
19 Type: "audio",
20 Params: playAudioParams,
21}, {
22 Type: "tts",
23 Params: playTTSParams,
24}, {
25 Type: "ringtone",
26 Params: playRingtoneParams,
27}}
28
29collectDigits := new(signalwire.CollectDigits)
30collectDigits.Max = 3
31
32collectSpeech := new(signalwire.CollectSpeech)
33collectSpeech.EndSilenceTimeout = 1
34collectSpeech.SpeechTimeout = 10
35collectSpeech.Hints = []string{"top", "well"}
36
37collect := signalwire.CollectStruct{
38 Speech: collectSpeech,
39 Digits: collectDigits,
40}
41
42promptAction, err := resultDial.Call.PromptAsync(&play, &collect)
43if err != nil {
44 signalwire.Log.Error("Error occurred while trying to start Prompt Action\n")
45
46 if err := consumer.Stop(); err != nil {
47 signalwire.Log.Error("Error occurred while trying to stop Consumer. Err: %v\n", err)
48 }
49
50 return
51}
52if !promptAction.GetCompleted() {
53 promptAction.Stop()
54}
55
56for {
57 time.Sleep(1 * time.Second)
58
59 if promptAction.GetCompleted() {
60 break
61 }
62}
63myResult := promptAction.GetResultType()
64switch myResult {
65case signalwire.CollectResultSpeech:
66 signalwire.Log.Info("Speech text: \"%s\" Confidence: %f\n", promptAction.GetCollectResult(), promptAction.GetConfidence())
67case signalwire.CollectResultDigit:
68 signalwire.Log.Info("Digits: \"%s\" Terminator: %s\n", promptAction.GetCollectResult(), promptAction.GetTerminator())
69default:
70 signalwire.Log.Info("Result was: %s\n", myResult.String())
71}

GetCompleted

Return true if the prompt attempt has finished, false otherwise.

Parameters

None

Returns

Boolean - True/False accordingly to the state.

Examples

Start the attempt and check if it has finished.

1promptAction, err := resultDial.Call.PromptAsync(&play, &collect)
2for {
3 time.Sleep(1 * time.Second)
4 if promptAction.GetCompleted() {
5 break
6 }
7}

Stop

Stop the action immediately.

Parameters

None

Returns

error

Examples

Start the attempt and then stop it.

1if !promptAction.GetCompleted() {
2 promptAction.Stop()
3}

Volume

Control the volume of the playback.

Parameters

PropertyTypeDescription
volumenumberrequired

Returns

error

Examples

Start the prompt and increase the playback volume with 5 dB

1promptAction, err := resultDial.Call.PromptAsync(&play, &collect)
2promptAction.Volume(5)

GetControlID

Return the UUID to identify the action.

Parameters

None

Returns

string - UUID to identify the action.