-
Notifications
You must be signed in to change notification settings - Fork 5
Reading subdialogue VoiceXML parameters
First, make sure you understand the Implementing a subdialogue example. The following example will show you
how to read the parameters sent to a subdialogue using the <param>
VoiceXML element:
<subdialog name="twoNumbers" src="dialogue">
<param name="promptText1" value="Enter a number" />
<param name="promptText2" value="Enter another number" />
We are going the obtain the subdialogue parameters by declaring variables in the first output turn of the dialogue:
VariableList parameters = new VariableList();
parameters.add("promptText1");
parameters.addWithString("promptText2", "Enter a number");
Note that the variable declaration can contain an initial expression. In this case, the expression will act as the
default value of the parameters. This is shown above with the promptText2
parameter.
Those declaration must be included in a Script
turn:
Script script = new Script("get-parameters");
script.setVariables(parameters);
This turn is then executed and the subdialogue parameters are available as properties of the jsonValue
:
VoiceXmlInputTurn inputTurn = DialogueUtils.doTurn(script, context);
JsonObject parameterValues = (JsonObject) inputTurn.getJsonValue();
String promptText1 = parameterValues.getString("promptText1");
String promptText2 = parameterValues.getString("promptText2");
You can download or browse the complete code for this example at GitHub.This is a complete working application that you can build and run for yourself.
You can also clone the Rivr Cookbook repository and checkout this example:
git clone -b subdialogue-implementation-voicexml-parameter [email protected]:nuecho/rivr-cookbook.git
Then, to build and run it:
cd rivr-cookbook
./gradlew jettyRun
The VoiceXML dialogue should be available at http://localhost:8080/rivr-cookbook/dialogue
To stop the application, press Control-C in the console.