Using ANI to Recognize Callers

by Jonathan Eisenzopf

In the last tutorial, we learned how to use the Dialed Number Identification Service (or DNIS) to direct callers to sub-menus in VoiceXML applications. In this follow-up tutorial, we will learn how to use Automatic Number Identification (ANI) to recognize callers.

In our last tutorial, we learned how to use the Dialed Number Identification Service (or DNIS) to direct callers to sub-menus in VoiceXML applications. In this follow-up tutorial, we will learn how to use Automatic Number Identification (ANI) to recognize callers. 

ANI Overview

Like DNIS, ANI is sent by a telephone company along with a request for connection, which rings your phone. ANI is more commonly known as "Caller ID". Many people have Caller ID boxes connected to their telephone line to identify who a caller is. ANI information is usually received by the time you hear the second ring. ANI information includes the phone number of the caller, and sometimes even their name.

Accessing the ANI number in VoiceXML

The session.telephone.ani session variable in VoiceXML holds the ANI number.

The VoiceXML example below builds on the example in the previous tutorial, the difference being that it will say the number that you are calling from:

1  <?xml version="1.0" encoding="Cp1252"?>
3  <!DOCTYPE vxml PUBLIC '-//Nuance/DTD VoiceXML 1.0//EN' 
5  <vxml version="1.0">
6    <meta name="Generator" content="V-Builder 1.2.30" />
7    <form id="form1">
8      <block name="block1">You have dialed
9    <value expr="session.telephone.dnis" class="digits" />. 
10   Your phone number is
11   <value expr="session.telephone.ani" class="digits" />
12        Goodbye.      
13        <exit />
14        <disconnect />
15      </block>
16    </form>
17  </vxml>

Lines 10 and 11 will play the value of the ANI number IF it was sent to and handled by the VoiceXML gateway. Remember that not all phone companies support ANI and some callers may opt to block this information, so you must be ready to handle this exception. You cannot count on the ANI number being available or accurate 100% of the time.

Recognizing Callers

One way of identifying callers without making them enter some kind of registration number is to lookup their customer record by the ANI number. This technique should not be used when the information that will be given to callers is confidential or sensitive because other people may use the same phone that someone else registered.

In our next example, we will use the ANI number to route a call to a specific form. If an ANI number was not sent or if the number doesn't match a caller's profile, then we will ask them for their PIN number.

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"?>
3  <!DOCTYPE vxml PUBLIC '-//Nuance/DTD VoiceXML 1.0//EN' 
4  'http://voicexml.nuance.com/dtd/nuancevoicexml-1-2.dtd'>
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>
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>
26      </block>
27    </form>
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>
34      <filled>
35        <if cond="pin_number == '1234'">
36          <goto next="#jonathan" />
37          <else />
38          <reprompt />
39        </if>
40      </filled>
41    </form>
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>
62  </vxml>


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.

This article was originally published on Thursday Oct 10th 2002
Mobile Site | Full Site