-
Notifications
You must be signed in to change notification settings - Fork 5
Invoking a subdialogue
This example shows how to invoke a VoiceXML subdialogue as defined in the VoiceXML specification.
The output turn required to invoke a subdialogue is a SubdialogueCall
. We pass the URL of the
subdialogue in the constructor:
SubdialogueCall subdialogueCall = new SubdialogueCall("invoke-subdialogue", "subdialogue.vxml");
The HTTP request to get the subdialogue will use the POST method:
subdialogueCall.setMethod(SubmitMethod.post);
The turn will be executed:
VoiceXmlInputTurn inputTurn = DialogueUtils.doTurn(subdialogueCall, context);
The subdialogue return values will be placed in the value
property of the InputTurn
. Let's assume here
that our dialogue returned multiple named values. This will be available in the dialogue as a JsonObject
:
if (inputTurn.getJsonValue() != null) {
JsonObject subdialogueReturnValues = (JsonObject) inputTurn.getJsonValue();
Each property of the JSON object correspond to the return value:
for (Entry<String, JsonValue> returnValue : subdialogueReturnValues.entrySet()) {
context.getLogger().info("Subdialogue return value:"
+ returnValue.getKey()
+ "="
+ returnValue.getValue());
}
}
The sample comes with a sample VoiceXML subdialogue:
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
<form id="test">
<field name="numberField" type="number">
<prompt>Say a number</prompt>
</field>
<filled>
<var name="number" expr="numberField" />
<var name="status" expr="'success'" />
<return namelist="number status" />
</filled>
</form>
</vxml>
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-invocation [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.