Answers
to Your Questions About VoiceXML
In
this monthly column, an industry expert will answer
common questions about VoiceXML and related technologies.
Readers are encouraged to submit questions about VoiceXML,
including development, voice-user interface design,
and speech technology in general, or how VoiceXML is
being used commercially in the marketplace. If you have
a question about VoiceXML, e-mail it to speak.and.listen@voicexmlreview.org
and be sure to read future issues of VoiceXML Review
for the answer.
This
month we examine more questions from our readers.
Q: Hi, I would like to ask is it possible for me to
get the caller ID (i.e. the phone number which the user
called from)? Please help.
A: The caller ID information can be accessed
through the VoiceXML session variable session.telephone.ani
-IF- it is provided by the telephony interface. Also,
if you are using analog telephone lines, you would need
to ensure that your service provider is providing the
caller ID (also known as the ANI - automatic number
identification) on the line. An example of VoiceXML
code that retrieves the caller Id info would look something
like the following:
<?xml version="1.0"?>
<vxml version="1.0">
<var name="phoneNumber" />
<script>
phoneNumber = session.telephone.ani;
</script>
<form id="sayNumber">
<block>
Your phone number is <value expr="phoneNumber"/>
</block>
</form>
</vxml>
|
Q:
How can I determine the duration of a phone call in
VoiceXML?
A:
There is no predefined VoiceXML variable that will return
the duration of a phone call. However, you can calculate
this on your own with some simple ECMAScript and event
handling. Let's look at an example:
<?xml version="1.0"?>
<vxml version="1.0">
<var name="startDate" />
<var name="startTime" />
<script>
startDate = new Date();
startTime = startDate.getTime();
</script>
<catch event="telephone.disconnect.hangup">
<script>
var endDate = new Date();
var endTime = endDate.getTime();
var callDuration = endTime - startTime;
</script>
<submit next = "http://someURL/logTime.jsp"
namelist = "callDuration"
method = "get" />
</catch>
<form id="sayGoodbye">
<block name="block1">You can hangup now.
<throw event="telephone.disconnect.hangup" />
</block>
</form>
</vxml>
|
In
this example, the initial <script> executes upon
loading the document into the VoiceXML interpreter.
An ECMAScript Date object is instantiated as
startDate and the starting time is determined
through the getTime() method of this object (for
those unfamiliar with ECMAScript or JavaScript, I recommend
paging through one of the many excellent books currently
available on the topic). Finally, when the caller hangs
up a telephone.disconnect.hangup event is thrown.
This event is caught with application scope by the <catch
event = "telephone.disconnect.hangup">
tag and all handling is performed by the enclosed code.
This includes a <script> that gets the time at
which the event was thrown by instantiating a new Date
object endDate, and calculating the call duration
(the difference between the starting and finishing times).
It should be noted that all return values of the getTime()
method are in msec. Hence, the value of the callDuration
variable will also be in msec. After determining the
call duration, the application sends the value to a
server page called "logTime.jsp" for processing
via the <submit> tag.
Note
that if an application spans two or more VoiceXML documents,
it would be necessary to declare and initialize the
startTime variable in the application root document.
back
to the top
Copyright
© 2001 VoiceXML Forum. All rights reserved.
The VoiceXML Forum is a program of the
IEEE
Industry Standards and Technology Organization (IEEE-ISTO).
|