-
Notifications
You must be signed in to change notification settings - Fork 5
Hello World
This example shows how to implement a simple dialogue. It only plays a single message and then hang-up.
First step is to provide an implementation of VoiceXmlDialogue and code the dialogue in the run method:
public class Dialogue implements VoiceXmlDialogue {
@Override
public VoiceXmlLastTurn run(VoiceXmlFirstTurn firstTurn, VoiceXmlDialogueContext context)
throws Timeout, InterruptedException {
Message message = new Message("message", new SpeechSynthesis("Hello World!"));
doTurn(message, context);
return new Exit("exit");
}
}Next, the web.xml must contain:
- a
<servlet>entry forVoiceXmlDialogueServlet - an
<init-param>specifying which dialogue class to instantiate - a
<servlet-mapping>entry
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>Dialogue Engine</display-name>
<servlet>
<servlet-name>Dialogue</servlet-name>
<servlet-class>com.nuecho.rivr.voicexml.servlet.VoiceXmlDialogueServlet</servlet-class>
<init-param>
<param-name>com.nuecho.rivr.voicexml.dialogue.class</param-name>
<param-value>com.nuecho.rivr.cookbook.dialogue.Dialogue</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Dialogue</servlet-name>
<url-pattern>/dialogue/*</url-pattern>
</servlet-mapping>
</web-app>Once compiled and deployed, the dialogue is ready to be called by the VoiceXML platform.
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 hello-world git@github.com: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.