VoiceXML Developer Series: A Tour Through VoiceXML, Part XII
This PerlScript ASP file (view source) is responsible for taking the form field values passed from the take_order.vxml dialog and saving them to the PizzaOrder table in the Access database. If an error occured while saving the record, we transfer the caller to an operator on line 37. Lines 7 and 8 open a connection to the Access database. Lines 11 through 14 retrieve the form field values from the ASP Request object. Remember, we process VoiceXML forms on the backend the same way we do HTML forms. Lines 15 through 25 convert the phone number from words to numbers and strip out any extraneous text.
Now that we have a connection to the database and have retrieved our form data, it's time to build the SQL string that will save the data to the PizzaOrder table. Line 28 builds the INSERT SQL statement that is sent to Access with the ADO Execute method on line 29. Note that the syntax for the SQL statement may differ if you decide to use a database other than Access.
save_address.asp is now upload_audio.pl
Now let's step back to the validate_phone_number.asp script. If you recall, if we did not find a customer's address for a given phone number, or if the customer rejects the address on file, they are taken to the record_address form to record their address. This information is saved in a variable named AddressAudio and submitted to save_address.asp.
One of the strange annoyances of ASP is its innability to handle multipart form submittions, which are used to upload files from an HTML form. You would have thought Microsoft would have added this feature after 3 versions of ASP. They did finally add better support in ASP.NET, but this application is being developed in ASP 3 using PerlScript. I had hoped to find a reliable Perl script to handle binary files in ASP, but gave up after trying a few examples that only seemed to half work. Instead, I decided to fall back to a plain old, but very reliable, Perl CGI script to handle the uploaded text. To do this, I changed the next attribute in the validate_phone_number.asp (updated source) script to point to upload_audio.pl (view source) instead of save_address.asp. This script saves the address audio recording to a file named by the phone number that it's associated with. Once the audio file has been saved, the script transitions to take_order.vxml . The updated validate_phone_number.asp file also creates a new record in the Customers table on lines 39 and 40 if one does not already exist.
So now we have a complete application that utilizes many difference aspects of the VoiceXML language. I hope you've learned a lot about VoiceXML in this series, and I hope you keep coming back for more as we delve ever deeper into developing VoiceXML applications. If you have followed this series all the way through, please take some time and send me feedback to let me know that this series was of benefit to you or where you think it can be improved. I'm also working on getting the demo operational so that you can test it over the telephone if it happens that you are not able to test it on your own.
About Jonathan Eisenzopf
Jonathan is a member of the Ferrum Group, LLC based in Reston, Virginia that specializes in Voice Web consulting and training. He has also written articles for other online and print publications including WebReference.com and WDVL.com. Feel free to send an email to firstname.lastname@example.org regarding questions or comments about the VoiceXML Developer series, or for more information about training and consulting services.
Page 2 of 2