Invoking a VoiceXML application from a Java application

The Call.invokeVoiceXML2() method allows you to invoke a VoiceXML 2.1 application from a Java application.

It is easy to create a dialog with the caller using VoiceXML, but there are currently some things you cannot do from VoiceXML because the VoiceXML specification does not support them. For example, you can't make an outbound call from a VoiceXML dialog. To augment the capabilities of VoiceXML, you can create a Java application that makes the outbound call and then invokes the Call.invokeVoiceXML2() method to transfer control to a VoiceXML application dialog. At the end of the dialog, you return control to the Java application.

  1. To invoke a VoiceXML 2.1 application from a Java application, use the Call.invokeVoiceXML2() method. In the first parameter, which is the URI property, specify the URI of the VoiceXML application.
  2. Optionally, to pass data to the VoiceXML application, specify a second parameter, which is the applicationData property, the name of a serializable Java object. The data is put into a session variable called session.ibm.application_data, which the VoiceXML application can access. To pass data back to the Java application, use the expr= attribute on the VoiceXML <exit>tag. In this example, response is a VoiceXML variable that contains a value indicating the called party's response to a question they have been asked, which you want to return to the Java application:
    <exit expr=”response” />
     

    The value passed using the expr= attribute is returned by the Call.invokeVoiceXML2() method as an object when the method has finished executing.

To pass the telephone call to a VoiceXML 2.1 application, create an instance of the Call object and within the try– catch block dealing with the call handling, use the Call.invokeVoiceXML2() method. For example:
  try {
    // Invoke a VoiceXML application and transfer data
    Object appData = new Object();
    call.invokeVoiceXML2("\\http:\mydir\myapp.vxml",appData);
   }

This gives you the start of a generic outbound calling solution where the Web or application server not only delivers the VoiceXML pages to the browser but controls the outbound dialing numbers. You can then extend this further to deal with errors such as no answer, fax or answering machine detection, and so on.

For performance reasons you should always run Java applications that invoke VoiceXML applications within a node: in other words, you must define the Java application in an AppName entry in the default.cff configuration file.