VoiceXML Events
Welcome to First Words, VoiceXML Review's column that teaches you about VoiceXML and how you can use it. We hope you enjoy the lesson.
VoiceXML Events
Last issue, we had a look at events in VoiceXML. Over these many months, we've seen something about how events work, and how you can use them. In this column, we'll provide some details examples of how you can use events in your application.
All About Events - Part Two
As we discussed last column, VoiceXML events are similar to events or exceptions in other languages. They provide a way to generate and handle behavior related to normal or exceptional application execution.
Here are a few examples of where you might find events useful.
Tapered Promts
You're probably already very familiar with the use of the <noinput> and <nomatch> elements. These are used to deal with the case where the caller has provided either no response, or we weren't able to recognize the response. These are in fact syntactic shorthand for the noinput and nomatch event handlers.
<catch event="noinput">
You must say something
</catch>
and
<noinput>
You must say something
</noinput>
|
By using the count attribute, you can provide a better user interface using tapered prompts, or take more intelligent action is response to an event that has occurred multiple times.
In the case of tapered prompts, the response to a <noinput> or <nomatch> event changes to add or remove prompt detail based upon the number of times the user has been prompted (note this can be done with the prompt attribute of the <prompt> tag as well).
<prompt count="1">
What would you like to order?
We have pizza, drinks, salad or wings.
</prompt>
<nomatch count="1">
Say pizza, drinks, salad, or wings.
</nomatch>
<nomatch count="2">
Perhaps you should use your telephone keypad.
Press 1 for pizza; 2 for drinks; 3 for salad;
or 4 for wings.
</nomatch>
<noinput count="1">
Please say something.
<reprompt/>
</noinput>
<noinput count="2">
Anyone home?
<reprompt/>
</noinput>
<noinput count="3">
I surrender.
<disconnect/>
</noinput>
|
Call Post-Processing
You can make use of the telephone.disconnect.hangup (now connection.disconnect.hangup) event to perform post-call cleanup and processing. For example, in the case of disconnect during a recording, it is often desirable to save the recording (regardless of the fact that the caller hung up):
<record name="feedback">
<prompt bargein="true">
Please give us your feedback.
</prompt>
<filled>
<submit next="/cgi-bin/send_message.pl"
method="post" namelist="feedback"/>
</filled>
<catch event="telephone.disconnect.hangup">
<submit next="/cgi-bin/send_message.pl"
method="post" namelist="feedback"/>
</catch>
</record>
|
In the case of a <transfer>, it is useful to perform post-call processing when the inbound caller disconnects, or when the 'blind' transfer (in the case of a non-bridged transfer) is completed..
<catch event="telephone.disconnect.transfer">
<log>
DISCONNECT_TRANSFER event. DNIS is
<value expr="session.telephone.dnis"/>
<exit/>
</log>
</catch>
<catch event="telephone.disconnect.hangup">
<log>
DISCONNECT_HANGUP event. DNIS is
<value expr="session.telephone.dnis"/>
</log>
</catch>
|
Dealing with Web Server Problems
It is important to make your application resilient to potential errors.
In the sample below, we are using a second form to transition to a backup application server in the event of a problem contacting the primary. 'Primary' and 'secondary' are defined elsewhere as VoiceXML variables. Note that these will deal with any error.badfetch problem (which will include HTTP errors, or errors in fetching or processing page components).
<form id="primary">
<catch event="error.badfetch">
<log expr="'Primary Failed'"/>
<goto next="#secondary"/>
</catch>
<block>
<log expr="'Trying Primary'"/>
<submit fetchtimeout="2s" expr="primary"
namelist="session.telephone.ani session.telephone.dnis
session.telephone.uui session.telephone.iidigits" method="get"/>
</block>
</form>
<form id="secondary">
<catch event="error.badfetch">
<log expr="'Secondary Failed'"/>
<goto next="#lastresort"/>
</catch>
<block>
<log expr="'Trying Secondary'"/>
<submit fetchtimeout="2s" expr="primary"
namelist="session.telephone.ani session.telephone.dnis
session.telephone.uui session.telephone.iidigits"
method="get"/>
</block>
</form>
|
Global Grammars
Events can also be thrown as the result of a grammar match. These can be defined as 'link' grammars. Here is an example:
<link event ="help"
<grammar xml:lang = "en-US" version = "1.0" root = "Help">
<rule id = "Help" scope = "public">
<one-of>
<item> <tag> returnvalue="help" </tag> help</item>
<item> <tag> returnvalue="help'" </tag> save me</item>
<item> <tag> returnvalue="help" </tag> succour</item>
</one-of>
</rule>
</grammar>
</link>
|
This grammar could be placed in an application root document, and be made available to all pages in the application. The interesting thing about this is that the event will be thrown within the execution context when the grammar match occurs. This means that you can place a customized <help> handler at the appropriate places in the application, providing context sensitive help without having to replicate a grammar everywhere in the application.
Summary
Events are an integral part of VoiceXML, and provide a useful mechanism to handle exceptional conditions as well as application events. However, there are some fundamentals that you should understand to make the most effective use of the capabilities they provide. Once you do, you'll find them a useful addition to your toolbox for VoiceXML application development.
Reminder
If you're attending SpeechTEK (October 29-November 1, at the New York Marriott Marquis), take the time to attend the VoiceXML Fall Users Group Meeting sponsored by the VoiceXML Forum. The User Group Meeting is taking place on Thursday, October 31, from 12:15pm to 5:15pm. For details, have a look at the information page , or register on-line.
What's Next?
Next month, we'll spend some more time looking more closely at event generation and handling.
We'll also spend some time looking at the finer details of how the information returned from recognition is made available to your application. The Voice Browser Working Group has spent considerable effort ensuring that this mechanism is clearly and completely defined, and it is worthwhile to understand it.
back to the top
Copyright © 2001-2002 VoiceXML Forum. All rights reserved.
The VoiceXML Forum is a program of the
IEEE Industry Standards and Technology Organization (IEEE-ISTO).
|