#!/usr/bin/perl ########################################################################################## ## 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. # ## # ## This sample accesses the Log Access Service to get a VoiceXML call log. # ## # ## Example usage: # ## getLog.pl -c production-s 2003-bvcamed001-ch001-0123a4b -x log2html.xsl > log.html # ## # ## This script uses a store for security keys. See its documentation in # ## http://cafe.bevocal.com/resources/voicexml_samples/keyRing.pl # ########################################################################################## #use SOAP::Lite +trace => 'debug', xmlschema => 2001; use SOAP::Lite xmlschema => 2001; use strict; require "../keyRing.pl"; # NOTE: This script requires 'xsltproc' to be on your PATH, in order # to use the XML -> HTML feature. # Define global variables my $soapVXMLlogURL = 'LogAccessService_v1/services/LogAccessService_v1'; my $soapURL = ''; my $accessSystem = ''; my $orgId = ''; my $appId = ''; my $soapServer = ''; my $myAccessKey = ''; my $customer = "production"; # default to using Production my $sessionID = ''; my $outFile = ''; my $xsltStylesheet = 'log2html.xsl'; # default to this stylesheet my $transformTimestamps = '0'; #-----------------------------------------------------------# # main -- Get a log with a specific SessionID # #-----------------------------------------------------------# processArgs(@ARGV); getVXMLlog($customer, $sessionID, $outFile); exit(0); #-------------------------------------------------------------# # Supporting functions below this point # #-------------------------------------------------------------# sub usage { print "ERROR: $_[0]\n\n"; print "USAGE: getLog.pl -s [-c ] [-x ] [-o ]\n"; print "\n"; print " The VXML log specified by is written to .\n"; print " If is not specified, the log is sent to stdout.\n"; print "\n"; print " The -x switch transforms the log using the specified XSLT stylesheet.\n"; print " Note: This switch also causes epoch-based timestamps to be transformed\n"; print " to a human-readable format before the XSLT stylesheet is applied.\n"; print " The default is now to do the HTML transformation.\n"; print "\n"; print " If a customer is not specified, 'production' is assumed.\n"; print "\n"; exit(1); } #-----------------------------------------------------------------------# sub processArgs { while ($#_ >= 0) { if ($_[0] eq '-x') { shift(@_); $xsltStylesheet = $_[0]; $transformTimestamps = '1'; } elsif ($_[0] eq '-t') { $transformTimestamps = '1'; } elsif ($_[0] eq '-c') { shift(@_); $customer = $_[0]; } elsif ($_[0] eq '-s') { shift(@_); $sessionID = $_[0]; } elsif ($_[0] eq '-o') { shift(@_); $outFile = $_[0]; } else { usage("Incorrect parameter given: '" . $_[0] . "'"); } shift(@_); } # get the AccessKey, based on the customer specified on the command line ($accessSystem, $orgId, $appId, $soapServer, $myAccessKey) = getProviderData($customer); if ($accessSystem eq "NoProviderFound") { usage("No valid SOAP Provider given"); } } #---------------------------------------------------------------# # getVXMLlog(sessionId) # # # # input: String sessionId, e.g. 2003-bvcamed007-ch021-195e5g # # # # errors: if there is a SOAP fault, or a transport error, # # the perl process will die with an error message. # #---------------------------------------------------------------# sub getVXMLlog { my ($customer, $sessionId, $outFile)= @_; $soapURL = "http://$soapServer/$soapVXMLlogURL"; # Setup a pointer to the Log Service my $vxmlLogRequest = SOAP::Lite ->proxy($soapURL) ->uri('http://www.bevocal.com/soap/services/') ->on_fault( sub { my($vxmlLogRequest, $res) = @_; die ref $res ? $res->faultstring : $vxmlLogRequest->transport->status, "\n"; }); # To call this service, we need an Access Key, # passed in via the SOAP header, as per the W3C. my $head = SOAP::Header->name(platformServicesSessionID => $myAccessKey); # If there's a problem, print out fault or transport info and die. my $res1 = $vxmlLogRequest->getCallLog ( $head, SOAP::Data->type('string')->name(sessionID => $sessionId) ); writeLog($outFile, $sessionId, $res1->result()); return $res1->result(); } #---------------------------------------------------------------# # writeLog(outFile, sessionID, data) # # # # input: String outFile, e.g. foo.html # # String sessionId, e.g. 2003-bvcamed007-ch021-195e5g # # String logData # # # # errors: if there is a SOAP fault, or a transport error, # # or any error in opening a file, # # the perl process will die with an error message. # #---------------------------------------------------------------# sub writeLog { my ($outFile, $sessionId, $logData) = @_; # ---------------------------- # optional timestamp transform here # if (transformTimestamps) { # Convert timestamps (millis since the epoch) to human-readable strings $logData =~ s/timestamp="(\d+)"/sprintf("timestamp=\"%s\"", scalar localtime(substr($1,0,length($1)-3)) )/ge; } # ---------------------------- # ---------------------------- # optional XSLT transform here # if ($xsltStylesheet ne "") { # write the xml file to a temp file # truncate and open for writing open(Out1, ">temp123.xml") || die ("Could not open temporary file temp123.xml\n"); print Out1 $logData; close(Out1); # transform temp123.xml -> temp123.html using $xslStylesheet # sorry, xsltproc only works on files on disk... my $return = `xsltproc --param p1 1 --param p2 1 --param p3 1 --param p4 1 --param p5 1 --param p6 1 --param p7 1 --param p8 1 --param p9 1 --param p10 1 --param p11 1 --param p12 1 $xsltStylesheet temp123.xml > temp123.html`; if ($outFile ne "") # send HTML to a file { # delete $outFile, if it exists $return = `rm -f $outFile`; # rename temp123.html -> $outFile $return = `mv temp123.html $outFile`; } else # send HTML to standard out { # print out temp123.html on stdout open(TEMP, ") { print; } close(TEMP); # delete temp123.html $return = `rm -f temp123.html`; } # delete temp123.xml and exit $return = `rm -f temp123.xml`; exit(0); } # ---------------------------- # No XSLT transformation, just send it out if ($outFile ne "") # send XML to a file { # truncate and open for writing open(Out1, ">" . $outFile) || die ("Could not open output file $outFile\n"); print Out1 $logData; close(Out1); } else # send XML to stdout { print $logData; } }