ECMAScript and VoiceXML

March 29, 2011

A number of developers have posted questions about the use of ECMAScript in their VoiceXML scripts.  Below is a definition of ECMAScript and an example from Plum’s VoiceXML tutorial.

From Wikipedia:

ECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used for client-side scripting on the web, in the form of several well-known dialects such as JavaScript, JScript, and ActionScript.

From Plum’s VoiceXML tutorial:

Plum’s VoiceXML IVR Platform has a fully functioning JavaScript engine, similar to a standard web browser. This allows us to define functions and make use of all of the features that the JavaScript language has to offer.

Now, suppose we have a field that checks the length of a customer identification number.

<field name=”id” type=”digits”>
<prompt>
Please enter your customer identification number.
</prompt>
<filled>
<if cond=”id.length == 7″>
<assign name=”customerid” expr=”id”/>
You entered <value expr=”id”/>.
<!– transfer to premium support –>
<else/>
Invalid ID number. Please check the number
and try again.
<clear namelist=”id”/>
<reprompt/>
</if>
</filled>
</field>

In this example, “id” is an ECMAScript variable that is set when the caller enters a customer identification number. In the if conditional of the filled block, the contents of the “cond” attribute, “id.length == 7″, are evaluated as an ECMAScript expression. If the user entered a 7-digit number, the if conditional would be true and a new variable, “customerid”, would be assigned the value of “id”. Finally, the <value expr/> expression converts the contents of “id” into a string for playback and the application states what the user entered for their “id”. If the user did not enter 7 digits, the if conditional would be false and go to the else conditional. The application would say to the user, “Invalid ID number. Please check the number and try again.” The “id” variable would be cleared with the <clear> tag and the application would reprompt the user for their customer identification number.

Comments are closed.