File Coverage

blib/lib/VoiceXML/Client.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 36 36 100.0


line stmt bran cond sub pod time code
1             package VoiceXML::Client;
2              
3              
4              
5             =head1 NAME
6              
7             VoiceXML::Client - Perl extension for VoiceXML (VXML) clients, including useragent, parser and interpreter.
8              
9             =head1 SYNOPSIS
10              
11            
12             #!/usr/bin/perl
13            
14             use VoiceXML::Client;
15            
16             use strict;
17            
18             # basic info for VoiceXML source
19             my $sourceSite = 'voicexml.psychogenic.com';
20             my $startURL = '/vocp.cgi';
21            
22            
23             # using dummy device here, to get started
24             my $telephonyDevice = VoiceXML::Client::Device::Dummy->new();
25             $telephonyDevice->connect();
26            
27             # our workhorse: the user agent
28             my $vxmlUserAgent = VoiceXML::Client::UserAgent->new($sourceSite);
29            
30             # go for it:
31             $vxmlUserAgent->runApplication($startURL, $telephonyDevice);
32            
33             # that's it... runApplication will return when it has hung up the device.
34            
35              
36             =head1 DESCRIPTION
37              
38             The VoiceXML::Client library allows you to fetch, parse and interpret VoiceXML files.
39              
40             It was developed as a supporting component of the (upcoming version of the) VOCP voice messaging system (http://www.vocpsystem.com).
41              
42             It's role is to:
43              
44             - fetch vxml files
45             - parse their contents
46             - interpret them by executing the instructions therein
47              
48             It is not (yet) a complete implementation of the VoiceXML specs, but does support a lot of interesting features.
49             Have a look at the included exampleBBSBox.vxml file for an idea of what is possible.
50             A quick tour of this file will give you a taste of what's available.
51              
52              
53             =head2 Telephony Interface
54              
55              
56             As noted above, the user agent's runApplication() method is called with two parameters:
57             a URL and a handle to some telephony device.
58              
59             While executing the voicexml code, VoiceXML::Client will likely need to do things like
60             play audio files, collect user DTMF input and allow callers to leave messages. The vxml
61             page tells VoiceXML::Client what to do, and the telephony interface is used to actually
62             perform these actions.
63              
64             Exactly how the device collects user input etc is left as an excercise to the implementor.
65             The only thing that counts from VoiceXML::Client's perspective is that the handle support
66             the VoiceXML::Client::DeviceHandle interface.
67              
68             During testing, you may use VoiceXML::Client::Device::Dummy as the telephony handle. This
69             is a simplified implementation whose only effect is to print all calls to stdout and
70             request DTMF input from the command line, when required.
71              
72             As a programmer, the majority of your work will be in replacing the VoiceXML::Client::Device::Dummy device in the code above with
73             some implementation of the API that actually controls an interesting device. See the Telephony Interface section on
74              
75            
76             http://voicexml.psychogenic.com/api.php
77              
78              
79             for a complete discussion, or have a look at the VoiceXML::Client::Device::Dummy and VoiceXML::Client::DeviceHandle documentation.
80              
81              
82              
83              
84             =head2 VoiceXML
85              
86             A complete discussion of the supported VoiceXML can be found at
87            
88             http://voicexml.psychogenic.com/voicexml.php
89              
90             A summary is provided here.
91              
92              
93             VXML provides for TUI forms to be "displayed" to users (through recorded prompts), and can accept input that fills fields within the form.
94              
95             Each user input field is set based on user DTMF input, and other variables can be created and manipulated in the VXML:
96              
97              
98            
99            
100            
101              
102            
103            
104            
105              
106            
107            
108            
109            
110            
111            
112            
113            
114            
115            
116            
117              
118            
119            
120            
121            
122            
123            
124            
125            
126            
127            
128            
129            
130            
131            
132            
133            
134              
135             Here you can see a lot of the action. The invalidcount variable is created and set to 0. The first form encountered is entered, the prompt for the first field (movetosel) contains prompts which are played. The filled item awaits user input. Once this is received (or times out), a variable of the same name as the field is initialized with user input.
136              
137             Conditionals can check the value entered by the user, and jump to other forms within the page (or to other pages). Simple arthmetic can also be performed as demonstrated by the invalidcount counter.
138              
139             Voice recordings can be made by users through the use of a item:
140              
141            
142            
143             You may also use items to GET another page:
144            
145            
146            
147             and more complex actions may be performed by submitting data collected through a submit element:
148              
149            
150            
151              
152             would fetch the page output by the same script but would also pass along the values of each of the variables specified in the namelist.
153              
154             More information can be found at http://voicexml.psychogenic.com/
155              
156             =head2 Supported Elements
157              
158             Currently, the following VoiceXML elements are recognized and supported, at least partially:
159              
160             - assign
161             - audio
162             - block
163             - break
164             - clear
165             - disconnect
166             - else
167             - elseif
168             - field
169             - filled
170             - form
171             - goto
172             - grammar
173             - if
174             - noinput
175             - nomatch
176             - option
177             - prompt
178             - record
179             - reprompt
180             - return
181             - rule
182             - subdialog
183             - submit
184             - var
185              
186             A description and examples of each will be found in the VoiceXML section of the project site, at
187              
188             http://voicexml.psychogenic.com/voicexml.php
189            
190            
191              
192             =head2 Interpreter
193              
194             Variables may be set and manipulated while executing the contents of a voicexml page. The
195             Voice Extensible Markup Language specifications are, currently, far from respected in this
196             regard within VoiceXML::Client. Instead of using a full ECMAScript interpreter, a simple
197             Perl interpreter was created that is, to date, sufficient for most of our requirements.
198              
199             What is available includes, variable creation:
200              
201            
202            
203              
204              
205             and assignment:
206            
207            
208            
209              
210             Note that, unlike numeric values, strings need to be 'quoted'. Comparison operators may be used in the
211             cond attribute of if/elseif elements, and simple arithmetic may be performed in expr attributes:
212              
213              
214            
215            
216            
217            
218            
219            
220             221            
222            
223            
224            
225            
226              
227             Note here that <, >, <= and >= must be HTML encoded.
228              
229             Variables may also be used in places like
230              
231            
232            
233              
234             Since this is a variable name, it is not 'quoted'... that's why the file played is whatever is set in the
235             filetoplay variable, rather than a file called 'filetoplay'.
236              
237             This implementation is far from complete and has a number of limitations (e.g. though expr="invalidcount + 1"
238             currently works, changing the order or adding two variables would likely fail) but a number of examples can
239             be seen within the included exampleBBSBox.vxml file and on http://voicexml.psychogenic.com/
240              
241             If you stick to these conventions, you're vxml will work now and in the future, when a true
242             interpreter is developed for or incorporated within VoiceXML::Client.
243              
244              
245             =head1 SEE ALSO
246              
247             Detailed documentation is available on the project site at
248              
249            
250             http://voicexml.psychogenic.com/
251              
252              
253             VoiceXML::Client was created as a supporting component of the second version of the
254             VOCP voice messaging system (http://www.vocpsystem.com).
255              
256             It relies on the capabilities of the pure perl XML::Mini xml parser (http://minixml.psychogenic.com/)
257              
258              
259             =head1 AUTHOR
260              
261             Pat Deegan, http://www.psychogenic.com
262              
263             =head1 COPYRIGHT AND LICENSE
264              
265            
266             Copyright (C) 2007,2008 by Pat Deegan.
267             All rights reserved
268             http://voicexml.psychogenic.com
269              
270             This library is released under the terms of the GNU GPL version 3, making it available only for
271             free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details).
272             Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to
273             acquire a distinct license for their application. This approach encourages the use of free software
274             while allowing for proprietary solutions that support further development.
275              
276              
277             This file is part of VoiceXML::Client.
278              
279            
280            
281             VoiceXML::Client is free software: you can redistribute it and/or modify
282             it under the terms of the GNU General Public License as published by
283             the Free Software Foundation, either version 3 of the License, or
284             (at your option) any later version.
285              
286             VoiceXML::Client is distributed in the hope that it will be useful,
287             but WITHOUT ANY WARRANTY; without even the implied warranty of
288             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
289             GNU General Public License for more details.
290              
291             You should have received a copy of the GNU General Public License
292             along with VoiceXML::Client. If not, see .
293              
294              
295              
296             =cut
297              
298              
299 3     3   65555 use 5.008008;
  3         11  
  3         111  
300 3     3   15 use strict;
  3         5  
  3         98  
301 3     3   14 use warnings;
  3         15  
  3         95  
302              
303 3     3   15 use strict;
  3         5  
  3         108  
304              
305 3     3   1916 use VoiceXML::Client::DeviceHandle;
  3         7  
  3         82  
306 3     3   1692 use VoiceXML::Client::Device::Dummy;
  3         9  
  3         113  
307 3     3   1477 use VoiceXML::Client::UserAgent;
  3         11  
  3         126  
308              
309 3         298 use vars qw{
310             $Debug
311 3     3   21 };
  3         7  
312              
313             $Debug = 0;
314              
315             # get rid of annoying deep recursion warnings from XML::Mini...
316             $SIG{__WARN__} = sub {
317             my $msg = shift;
318             print STDERR $msg if ($msg !~ /Deep recursion/);
319             };
320              
321             require Exporter;
322 3     3   2740 use AutoLoader qw(AUTOLOAD);
  3         4273  
  3         21  
323              
324             our @ISA = qw(Exporter);
325              
326              
327             # will save memory.
328             our %EXPORT_TAGS = ( 'all' => [ qw(
329            
330             ) ] );
331              
332             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
333              
334             our @EXPORT = qw(
335            
336             );
337              
338             our $VERSION = '1.01';
339              
340              
341              
342              
343             1;
344             __END__