Browse DevX
Sign up for e-mail newsletters from DevX


Creating Voice Applications with Reusable Dialog Components : Page 2

Find out how J2EE, JSP, and Struts developers can use the Reusable Dialog Component (RDC) Open Source project along with VoiceXML to develop rich voice applications using standard Web progamming models.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The Sample Application
The sample application in this article is a simple voice application that uses RDCs to order pizzas. The application answers calls, asks customers for their telephone numbers to verify that they are already in the system, and takes their order. Customers are then given the choice of paying cash or by credit card. This application uses three existing RDCs:
  • The atomic digits RDC: collects the telephone number.
  • select1: lists the payment options.
  • The composite creditcardInfo RDC: collects the credit card information.
The application is designed using the Struts framework for a well-defined Model View Controller framework and to take advantage of the RDC's framework's Struts support. Each interaction with a customer has its own JSP file containing VoiceXML. The JSPs submit the user input to Struts Actions and Form Beans collect the data. Figure 1 shows the JSPs, Struts Actions, and Form Beans that make up the application.

Figure 1. The Sample Application: This diagram displays the JSPs, Struts Actions, and Form Beans that make up the pizza ordering voice application.

To keep it simple, concentrate on the JSPs that instantiate the RDCs: welcome.jsp, paymentType.jsp, and creditCardInfo.jsp. Listing 1 shows the welcome.jsp. This JSP defines a PizzaOrderBean with session scope. The bean holds all the current order information—amount owed, number and type of pizzas, payment type, delivery time, etc. This bean is updated throughout the call as input from the customer is processed.

Next in the JSP, notice a VoiceXML block containing a prompt to welcome the user. Inside the <vxml> block, and after the welcome prompt, the digits RDC is instantiated. Note that the config attribute is set to point to an XML file, where the default prompts are overwritten to give more relevant messages to the customer. Listing 2 is a partial listing of the configuration file. After the <vxml> block, the struts-submit tag submits the input from the user to the server-side struts Action. Note that the namelist attribute contains the id of the digits RDC, defined earlier. If there were multiple RDCs defined on this page, the namelist attribute would include the list of ids separated by a space. That is all that is needed and a rich dialog is created that handles no-input, no-match, and other error conditions to collect the customer input.

The JSP containing the select1 RDC is very similar to the welcome.jsp, except that the select1 RDC contains an additional attribute. optionList points to an .xml file that defines the options for the RDC. The following code shows the RDC that instantiates the select1 RDC.

<rdc:select1 id="paymentType" optionList="RDCConfigurationFiles/paymentType-Options.xml" confirm="true" minConfidence="0.4F" initial="cash" config="RDCConfigurationFiles/paymentType-Config.xml"/>

The paymentType-Options.xml is very simple and just lists the two options for payment. The code below shows the XML file listing the payment options for select1 RDC:

<?xml version="1.0" encoding="utf-8"?> <list> <option value="cash">cash</option> <option value="credit">credit card</option> </list>

The composite creditcardInfo RDC is defined in the same way as the atomics digits. However, the configuration file for the composite RDC points to the configuration files for the atomic digits RDCs it contains and that you wish to overwrite. In this case, only the creditcardExpiry configuration file is overwritten. All the other atomic RDCs contained in the creditcardInfo use the default configuration file:

<?xml version="1.0" encoding="utf-8"?> <config> <componentConfigList> <component id="creditcardExpiry" file="RDCConfigurationFiles/creditcard-expiry.xml"/> </componentConfigList> </config>

Of course, to make the pizza application complete, you need to create a grammar file and a JSP containing VoiceXML to collect the actual pizza order from customers, as well as all the server-side code. For reference, Listings 3 and 4 show the grammar and JSP, respectively, for this portion. A voice developer should be able to easily implement the grammar and VoiceXML portion to get the order from the customer. And a Web developer should implement the server-side code. But that is beyond the scope of this article.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date