Recognizing Callers Example
You can interact with this demo directly by calling the Voxeo
assigned number, (650) 860-8895.
Lines 8 through 16 contain the first form that is executed
by the VoiceXML interpreter. On line 10, the <if> element
checks for a session.telephone.ani number. If the value is
null, it means that an ANI number was not sent. If this is the case,
then line 13 sends the the caller to the enter_pin form on
line 29. If the ANI session variable is not null, then the caller is
forwarded to the check_number form on line 18.
The check_number form on lines 18 through 27 matches the
ANI number with an existing customer record. In this case, since we
are not working with a dynamic script, we are looking for a specific
set of numbers (one number in this example). If the ANI number
matches the number on line 20, then the caller is forwarded to the jonathan
form, which starts on line 43; otherwise, the caller is forwarded to
the enter_pin form.
The enter_pin form is used if a call does not have an ANI
number, or if the ANI number does not match an existing record. This
second scenario will be common if registered users call from more
than one phone number on a regular basis. For example, the user may
have registered their home phone number, but they decide to call on
their cell phone. In that case, we have the wrong number but a
valid, registered caller; so we want to give them an opportunity to
log in with their PIN code. When the caller enters the valid PIN
number, 1234, they will be directed to the jonathan form.
The jonathan form plays a simple greeting and then exits.
There's a special treat on lines 45-56 however, and something that
we haven't seen up till now. The <script> element
encapsulates ECMA (or Javascript) code, which allows programmers to
create more interactive VoiceXML programs. This particular block of
ECMA code creates a new instance of the Date class and
evaluates the value of the getHour() ECMA Date method to set
the timeOfDay variable, which tells the caller whether it is
morning, afternoon or evening as part of the greeting.
1 <?xml version="1.0" encoding="Cp1252"?>
2
3 <!DOCTYPE vxml PUBLIC '-//Nuance/DTD VoiceXML 1.0//EN'
4 'http://voicexml.nuance.com/dtd/nuancevoicexml-1-2.dtd'>
5
6 <vxml version="1.0">
7 <meta content="V-Builder 1.2.30" name="Generator" />
8 <form id="main" scope="dialog">
9 <block>
10 <if cond="session.telephone.ani != ''">
11 <goto next="#check_number" />
12 <else />
13 <goto next="#enter_pin" />
14 </if>
15 </block>
16 </form>
17
18 <form id="check_number" scope="dialog">
19 <block>
20 <if cond="session.telephone.ani == '7034767080'">
21 <goto next="#jonathan" />
22 <else />
23 <goto next="#enter_pin" />
24 </if>
25
26 </block>
27 </form>
28
29 <form id="enter_pin" scope="dialog">
30 <field name="pin_number" type="digits?length=4">
31 <prompt>Please enter your four digit PIN number</prompt>
32 </field>
33
34 <filled>
35 <if cond="pin_number == '1234'">
36 <goto next="#jonathan" />
37 <else />
38 <reprompt />
39 </if>
40 </filled>
41 </form>
42
43 <form id="jonathan" scope="dialog">
44 <block>
45 <script><![CDATA[
46 var date = new Date;
47 var timeOfDay = '';
48 var hours = date.getHours();
49 if (hours < 12) {
50 timeOfDay = "morning";
51 } else if (date.getHours < 17) {
52 timeOfDay = "afternoon";
53 } else {
54 timeOfDay = "evening";
55 }
56 ]]></script>
57 Good <value expr="timeOfDay"/>, thanks for calling.
58 </block>
59 </form>
60
61
62 </vxml>
Conclusion
Now, if this were a dynamic application, I would have passed the
ANI number to a backend script to look up the customer record rather
than putting the check directly in the VoiceXML document. That might
be something that we cover in another tutorial. The example
above, however, should give you a good idea of what an ANI number is, how to
access it using VoiceXML, and gives you an idea of how to use this
information to recognize a caller automatically without asking them
for an identification number.
About Jonathan Eisenzopf
Jonathan is a member of the Ferrum Group, LLC which 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 eisen@ferrumgroup.com
regarding questions or comments about the VoiceXML Strategy series,
or for more information about training and consulting
services.