Hello World

Jean-Philippe Gariépy edited this page Oct 19, 2018 · 4 revisions

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:

Dialogue.java:

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 for VoiceXmlDialogueServlet
  • an <init-param> specifying which dialogue class to instantiate
  • a <servlet-mapping> entry

web.xml:

<?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.


Running this example

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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.