October 24, 2018
Hot Topics:

Tellme More

  • December 1, 2002
  • By Jonathan Eisenzopf
  • Send Email »
  • More Articles »

Dynamic VoiceXML

Continuing with our PIN number scenario, it's time to develop the CGI script that provides a response to the user's input. First, let's look at our completed VoiceXML form.

Example 4.

<?xml version="1.0"?>
<vxml version="1.0" >
<form id="login">
<field name="pin">
<prompt>Please enter your 4 digit pin code.</prompt>
<submit next="http://www.webreference.com/cgi-bin/perl/20/pin.pl"/> </filled>
<noinput count="1">No PIN entered.
<noinput count="2">You must enter your PIN number to proceed.
<noinput count="3">Please press or say exactly four numbers.
<nomatch count="1">Invalid pin code.
<nomatch count="2">Please press or say exactly four numbers.
<nomatch count="3">Too many attempts.
Please call back another time.

As you've probably already guessed, the CGI script will be written in Perl. As it turns out, if you know how to use the CGI.pm Perl module, you'll know how to handle VoiceXML form input.

#!/usr/bin/perl -w

use strict;
use CGI;

my %users = (
'1234' => 'Eisenzopf',
'2468' => 'King'

my $q = new CGI;
my $pin = $q->param('pin');
print "Content-Type: text/xml\n\n";
print <<VXML;
<?xml version="1.0"?>

print "Good Morning Mr. $users{$pin}. How may I help you?"
|| "$pin is an invalid pin code.";

print <<VXML;

Basically, we create a new instance of the CGI.pm module. We access the value of the pin field with the following line of code:

my $pin = $q->param('pin');

It's important to make sure you return the proper HTTP header. The default header will not work properly. Instead, you must use the following statement as the first output back to Tellme:

print "Content-Type: text/xml\n\n";

The rest of the script is straightforward Perl. We lookup the user's last name based on their PIN code. If we find a name, we welcome them, otherwise, we return an error. It's a very rudimentary script, but it's our first taste of developing a dynamic VoiceXML application.

Page 6 of 7

Comment and Contribute


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



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


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