#!/usr/local/perl5/bin/perl5 # Edit the line above, to point at your local installation of Perl5, # then put this file into your cgi-bin directory, so it can be # accessed by the VXML interpreter. # *********************************************************************** # * BeVocal Sample Code * # * (C) Copyright BeVocal, Inc. 2003, All rights reserved. * # * * # * This Sample Code is provided for your reference purposes, and * # * carries no warranty whatsoever. Use of this code is restricted to * # * use in connection with the BeVocal Cafe developer's program. * # * BeVocal disclaims and excludes any and all warranties of * # * merchantability, title and fitness for a particular purpose. * # * BeVocal does not warrant that the software will satisfy your * # * requirements, or that the software is without defect or error. * # * You are using the software at your own risk. * # *********************************************************************** use CGI; use Cwd; use File::Basename; use Time::localtime; # --------------------------------------------------------------------- # These are here for debugging, in case you need more information # about exactly how the parameters were passed in. if (defined($ENV{'REQUEST_METHOD'})) { $method = $ENV{'REQUEST_METHOD'}; } if (defined($ENV{'CONTENT_TYPE'})) { $content_type = $ENV{'CONTENT_TYPE'}; } if (defined($ENV{'CONTENT_LENGTH'})) { $content_length = $ENV{'CONTENT_LENGTH'}; } # Go ahead and print the HTTP headers here, # because we need them no matter what happens print "Content-type: application/voicexml+xml\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; #print "Method is $method\n"; #exit; # Ask the CGI module to read the request my $cgi = new CGI; # Find the "greeting" parameter, which has the recorded data in it my $greeting = $cgi->param('greeting'); # Figure out what directory this script lives in. # That's where we want to save the recorded file. # I'm not totally sure why the fileparse_set_fstype is necessary, but it is fileparse_set_fstype("MSDOS"); my ($scriptName, $scriptDir, $scriptSuffix) = fileparse($0, (".pl")); print "\$0 = $0\n"; print "scriptDir = $scriptDir\n"; print "scriptName = $scriptName\n"; print "scriptSuffix = $scriptSuffix\n"; if ($method eq "POST") { my $filename = "greeting.wav"; print "Content-Type = $content_type\n"; if ($content_type =~ /^multipart\/form-data;/) { # For a multipart/form-data POST request, "greeting" has two meanings: # In a scalar context, it is the file name sent by the VXML Interpreter # In a filehandle context, it's a read-only filehandle for reading the data open(LOCAL, ">$scriptDir/$filename") or error($!); while (<$greeting>) { print LOCAL $_; } close LOCAL or error($!); } else { # application/x-www-form-urlencoded # The binary recorded data is in the "greeting" variable. open(LOCAL, ">$scriptDir/$filename") or error($!); print LOCAL $greeting; close LOCAL or error($!); } } else { error ("Not a POST request."); } # ------------------------------------------------------------------------- # Now, let's get the local time, and return a nicely formed VXML file. $hour = localtime->hour(); $min = localtime->min(); $oh = ''; if ($min < 10) # minutes should always be 2 digits { $oh = "oh"; } if ($hour > 12) # AM vs PM { $hour -= 12; $ampm = "P M"; } else { $ampm = "A M"; } if ($hour == 0) # correct for 12 midnight - 1 am { $hour = "12"; } $theTime = "The time is $hour $oh $min $ampm."; print " \n"; print " [yes no]\n"; print " Greeting saved.\n"; # This next line will say the time, that we calculated above. print " $theTime Do you want to quit?\n"; print " Please say yes or no.\n"; print " \n"; print " \n"; print " OK. Goodbye.\n"; print " \n"; print " \n"; # Edit this next line, to point at the original record.vxml file. print " \n"; print " \n"; print " \n"; print " \n"; print_footer(); sub print_footer { print "
\n"; print "
\n"; } sub error($) { my ($error) = @_; print " Error. $error\n"; print_footer(); exit 0; }