Data Exchange
To exchange data between the VoiceXML platform and an application server, you can use the <submit>, <subdialog>, or <data> tag. The platform can interact with an application server in the same way as a web browser does using these tags. The interaction is a series of HTTP GETs or HTTP POSTs where the application server processes these requests and returns valid VoiceXML.
The way this process works is that first, the caller starts a VoiceXML dialog with the VoiceXML platform and the platform makes a HTTP request to go fetch a VoiceXML document from an application server. The application server then parses the script you have written (.php, .jsp, .asp, etc.) and dynamically generates a VoiceXML document to be sent back to the platform. The platform parses the document and interacts with the caller. How the platform interacts with the application server using the <submit>, <subdialog>, and <data> tags is explained below.
Using the Submit Tag
The <submit> tag performs a GET or POST that will trigger a page transition. This means that document level variables will be lost once the new page is fetched and parsed. To preserve some of the current execution context, the <submit> tag can send document level variables as POST or GET variables to your application server script. This application server script gets parsed by your application server, which can then process variables sent to it before generating a VoiceXML document to be parsed by the VoiceXML platform to interact with the caller.
Here is an example that demonstrates the use of the <submit> tag:
From this example, the document-level variable “msg” gets passed by Plum DEV through the <submit> tag to the .php script, Save.php, on the application server. If the voice recording is a valid file, the VoiceXML document that gets generated by the application server will inform the user by saying, “Audio saved as 1181336379 [random value for $timestamp] dot wave.”
Using the Subdialog Tag
The <subdialog> tag is similar to a function call executed by a GET or POST. It allows you to execute a new VoiceXML document in a new context, but once the <subdialog> is complete, control will be returned to the parent document at the same location that the subdialog was called. The way this process works is that the <subdialog> tag sends document level variables to your application server script. Once the application server script gets parsed by the application server and generates a VoiceXML document, this VoiceXML document becomes a “subdialog” of your original VoiceXML document. Below is a diagram that shows how multiple subdialogs can be used before returning context back to the original VoiceXML document.
Here is an example that demonstrates the use of the <subdialog> tag:
From this example, parent.vxml can use the variables that are passed to it from subdialog.php. “stuff1”, “stuff2”, “stuff3” get sent back to parent.vxml with the string values of “green”, “blue”, and “yellow” attached to them respectively. Thus, Plum DEV would play the following:
The grass is green. The sky is blue. The sun is yellow.
Using the Data Tag
The <data> tag is also like a function call executed by a GET or POST. It differs from the <subdialog> tag in that it does not execute a remote VoiceXML document, but instead expects the remote application to return an XML or JSON result. The <data> tag sends document level variables to your application server script, which generates an XML or JSON file to be returned to Plum DEV. The file is then mapped directly into an ECMAScript DOM object for XML responses or just a generic ECMAScript object for JSON responses for Plum DEV to reference as a variable.
Here is an example that demonstrates the use of the <data> tag:
From this example, parent.vxml can use the variables that are passed to it from data.php. (A small note on XML: You can create and name a tag anything you want, as long as the tag is closed off properly within the XML document.) Note that data.xml is similar to subdialog.php in that both files can return the strings “green”, “blue”, and “yellow” back to the VoiceXML document. Thus, the VoiceXML document would play the following:
The grass is green. The sky is blue. The sun is yellow.
Here is that same example using a JSON document:
Submit vs. Subdialog vs. Data
Which tag to use often comes down to personal preference, coding style and the particular problem you are trying to solve. Sometimes, you might only need to collect a few inputs from your VoiceXML document and transition completely to a new page using the <submit> tag. This method helps minimize code complexity, keeps your code functionally separated, and moves the majority of the logic to the application server (perfect if you are less comfortable with VoiceXML).
Other times it is easier to code the various segments as function calls using the <subdialog> tag. This method makes code more reusable and further segments functionality. However, it can increase complexity within the VoiceXML code because you will need to create and process the return values of the <subdialog>.
Finally, sometimes you'd rather keep all call logic within the VoiceXML document and use the <data> tag. This method allows you to generate completely static VoiceXML scripts and only have the application server generate basic XML or JSON documents. This approach will create the most complex VoiceXML scripts and the simplest application server code.
Last updated