Table Of Contents
Sample Scripts
SIP Headers
Passing SIP Headers
Retrieving SIP Headers
Services
Service Register and Start
Session Interaction
Hybrid Scripting
A
Sample Scripts
Note
The scripts that appear in this section are only examples. They are not necessarily intended to be fully functional. For the latest versions of all sample scripts, go to the Developer Support web site at http://www.cisco.com/go/developersupport
SIP Headers
Passing SIP Headers
The following script prompts for an account number, then makes a call to URL "sip:elmo@sip.tgw.com," where the account number is passed in the SIP header under the header named "AccountInfo." Other static headers, such as Subject, To, From, and Priority, are also passed from the script, either as part of the URL or separately.
#------------------------------------------------------------------
# Copyright (c) 2004 by cisco Systems, Inc.
#------------------------------------------------------------------
set param(interruptPrompt) true
set param(terminationKey) #
leg setupack leg_incoming
leg proceeding leg_incoming
media play leg_incoming http://townsend.cisco.com/vxml/audio/enterAccount.au
set callinfo(alertTime) 30
leg collectdigits leg_incoming param pattern
proc act_GotAccount { } {
set status [infotag get evt_status]
if { $status == "cd_005" } {
set account [infotag get evt_dcdigits]
# These are additional headers for the setup request message
set headers(AccountInfo) "[set account]"
# this Subject header overwrites the one overloaded in the destination URL
set headers(Subject) "HelloSipTCL"
set headers(To) "sip:oscar@abc.com"
set headers(From) "sip:nobody"
set callinfo(protoHeaders) headers
# this destination URL has an overloaded header named "Subject"
set dest "sip:elmo@sip.tgw.com?Subject=Hello&Priority=Urgent"
leg setup $dest callinfo leg_incoming
puts "\nCall [infotag get con_all] got event $status collecting destination"
proc act_CallSetupDone { } {
set status [infotag get evt_status]
if { $status == "ls_000"} {
timer start leg_timer 30 leg_incoming
set status [infotag get evt_status]
puts "\n STATUS is $status"
# puts "\nCAME BACK FROM TRANSFER AND CLOSING CALL"
#----------------------------------
#----------------------------------
set fsm(any_state,ev_disconnected) "act_Cleanup same_state"
set fsm(CALL_INIT,ev_setup_indication) "act_Setup MEDIAPLAY"
set fsm(MEDIAPLAY,ev_media_done) "act_MediaDone GETDEST"
set fsm(GETDEST,ev_collectdigits_done) "act_GotAccount PLACECALL"
set fsm(PLACECALL,ev_setup_done) "act_CallSetupDone CALLACTIVE"
set fsm(CALLACTIVE,ev_leg_timer) "act_Cleanup same_state"
set fsm(CALLACTIVE,ev_disconnected) "act_Cleanup CALLDISCONNECT"
set fsm(CALLDISCONNECT,ev_disconnected) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_media_done) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_disconnect_done) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_leg_timer) "act_Cleanup same_state"
Retrieving SIP Headers
The following script plays the prompt "The number is," along with the account number received from the originating gateway. Other headers received are displayed in debug messages.
#------------------------------------------------------------------
# Copyright (c) 2004 by cisco Systems, Inc.
#------------------------------------------------------------------
set param(interruptPrompt) true
set param(terminationKey) #
leg setupack leg_incoming
leg proceeding leg_incoming
infotag set med_language 1
set ani [infotag get leg_ani]
set dnis [infotag get leg_dnis]
puts "\n get_headers.tcl: ani is $ani"
puts "\n get_headers.tcl: dnis is $dnis"
set Subject [infotag get evt_proto_headers Subject]
puts "\n get_headers.tcl: Subject = $Subject"
set Priority [infotag get evt_proto_headers Priority]
puts "\n get_headers.tcl: Priority = $Priority"
set From [infotag get evt_proto_headers From]
puts "\n get_headers.tcl: From = $From"
set To [infotag get evt_proto_headers To]
puts "\n get_headers.tcl: To = $To"
set Via [infotag get evt_proto_headers Via]
puts "\n get_headers.tcl: Via = $Via"
set tsp [infotag get evt_proto_headers tsp]
puts "\n get_headers.tcl: tsp = $tsp"
set phone_context [infotag get evt_proto_headers phone-context]
puts "\n get_headers.tcl: phone-context = $phone_context"
set AccountInfo [infotag get leg_proto_headers AccountInfo]
puts "\n get_headers.tcl - act_Setup: AccountInfo = $AccountInfo"
media play leg_incoming tftp://townsend.cisco.com/audio/num_is.au %n$AccountInfo
proc act_CallSetupDone { } {
set status [infotag get evt_status]
if { $status == "ls_000"} {
timer start leg_timer 30 leg_incoming
set status [infotag get evt_status]
puts "\n STATUS is $status"
# puts "\nCAME BACK FROM TRANSFER AND CLOSING CALL"
#----------------------------------
#----------------------------------
set fsm(any_state,ev_disconnected) "act_Cleanup same_state"
set fsm(CALL_INIT,ev_setup_indication) "act_Setup MEDIAPLAY"
set fsm(PLACECALL,ev_setup_done) "act_CallSetupDone CALLACTIVE"
set fsm(CALLACTIVE,ev_leg_timer) "act_Cleanup same_state"
set fsm(CALLACTIVE,ev_disconnected) "act_Cleanup CALLDISCONNECT"
set fsm(CALLDISCONNECT,ev_disconnected) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_media_done) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_disconnect_done) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_leg_timer) "act_Cleanup same_state"
Services
The following script demonstrates how to use the service register command and the start service configuration. The script registers as a service to provide data to other scripts and wakes up on a timer to get the latest data.
Service Register and Start
#--------------------------------------------------------------
# This script will not accept incoming calls.
#--------------------------------------------------------------
set myname "sample_service.tcl"
# Someone is telling us to terminate. The service will unregister
puts "$myname received a terminate event, closing up."
# Got an initial event when the script starts running. Register as
# as service, get the initial data, and wait on a timer.
puts "$myname is starting up."
puts "Starting timer for 30 seconds"
timer start call_timer0 30
set r [service register data_service]
puts " Register of data_service returned $r"
# Simulate getting some data. We could subscribe, or be collecting info
# from calls. Just keep a counter.
set data(run_time) [expr $data(run_time)+30]
# The initial call setup has come in. Output some display to the console.
# If we are the second session, send a message to the first.
puts "$myname got a setup. Refusing the call."
# We received a message from another session.
set src [infotag get evt_msg_source]
infotag get evt_msg msg_array
puts "$myname got a message. Respond with the data."
set r [sendmsg $src -p data]
puts "Send of data to $src returned $r"
# The timer has gone off. Get the data, and reset the timer.
puts "Timer went off. Get data, and reset the timer.\n"
timer start call_timer0 30
# Ignore this event. Output the event name to the console.
set ev [infotag get evt_event]
puts "$myname is ignoring event $ev"
#----------------------------------
#----------------------------------
set fsm(any_state,ev_session_indication) "act_Session same_state"
set fsm(any_state,ev_session_terminate) "act_Terminate same_state"
set fsm(CALL_INIT,ev_setup_indication) "act_Setup same_state"
set fsm(any_state,ev_msg_indication) "act_Rx_Msg same_state"
set fsm(any_state,ev_call_timer0) "act_Timer same_state"
set fsm(any_state,ev_any_event) "act_Ignore same_state"
fsm define fsm start_state
Session Interaction
The following script demonstrates session interaction. The script runs a VoiceXML script to get the list of handles.
# handles - list of handles of other sessions (not our own)
# If they crash, we will not know, so may be out of date.
# my_handle - handle of this session
# my_leg - leg id of the initial leg we will keep
# recorded_names - array of ptrs to RAM based recordings, indexed by handles.
# The init routine runs once when the script is loaded.
# Setup the global media_parm array for use every time we turn on
# Code here runs when the script is loaded.
# Setup parameter array for collecting digits
set media_parm(interruptPrompt) true
set media_parm(enableReporting) true
set media_parm(maxDigits) 1
# When the call comes in, just check in with the si demo
# server by firing up the vxml doc that will submit our handle.
# I expect it to return a ptr to a recorded name of this caller,
# and a list of active participants in the demo.
set my_handle [infotag get mod_handle]
set my_leg [infotag get leg_incoming]
si_demo_main.tcl got a setup for leg $my_leg
leg setupack leg_incoming
set parray(handle) [infotag get mod_handle]
leg vxmldialog leg_incoming -u http://px1-sun/dramstha/si_demo.vxml -p parray
# Playout the list of participants so far.
puts " Playout the list of callers."
foreach handle [array names recorded_names] {
lappend playlist $recorded_names($handle)
if { [llength $playlist] <= 0 } {
media play leg_incoming http://px1-sun/dramstha/no_others.au
media play leg_incoming http://px1-sun/dramstha/participants_are.au $playlist
# Handoff the call to another leg.
# We could setup a menu to select which one, but here we simply
# find the first that is not us.
proc act_do_handoff { } {
if { [llength $handles] <= 0 } {
puts "Weird handofff, now no handles"
media play leg_incoming http://px1-sun/dramstha/no_others.au
foreach handle $handles {
set ret [handoff callappl leg_incoming $handle -s "Here is a leg"]
if { $ret != "unavailable" } break;
if { $ret == "unavailable" } {
puts "Bailing out on the handoff"
media play leg_incoming http://px1-sun/dramstha/no_others.au
$my_handle handed off leg to $handle status=$ret"
# We got a digit while conferenced. Don't care who sent it, disconnect.
proc act_Control_Conf { } {
puts "Destroying the connection"
connection destroy con_all
# Main routine to handle a digit when running the demo.
# Implement the 4 options, playout help for anything else.
set digit [infotag get evt_digit]
puts "Digit entered=$digit"
leg collectdigits leg_incoming media_parm
if { [infotag get evt_state_current] != "RUNNING" } {
Ignoring digit when not running yet"
if { [llength $handles] <= 0 } {
media play leg_incoming http://px1-sun/dramstha/no_others.au
media play leg_incoming http://px1-sun/dramstha/sending_msg.au
foreach handle $handles {
set r [sendmsg $handle -p oparms]
if { [llength $handles] <= 0 } {
media play leg_incoming http://px1-sun/dramstha/no_others.au
puts "Playing handing_off.au"
media play leg_incoming http://px1-sun/dramstha/handing_off.au
media play leg_incoming http://px1-sun/dramstha/si_feature_description.au
http://px1-sun/dramstha/si_demo_description.au
media play leg_incoming http://px1-sun/dramstha/si_help.au
# Got a return from the initial submit to the si demo server.
# Save the recorded name of this caller, and the list of handles of other
# Checkin with the other callers if there are any.
# Now we are up and running, although we may not have everyones
# name until we get responses from the checkin.
proc act_submit_done { } {
puts "Tcl script si_demo_main got a return from VXML"
set my_name http://px1-sun/dramstha/si_unknown_caller.au
set r_event [infotag get evt_vxmlevent]
Tcl got on return from initial submit:
if { [string match error $r_event] == 1 } {
set rlist [infotag get evt_vxmlevent_params parray]
set msg " Returned data from si server includes:"
append msg "\n $i=$parray($i)\n"
regsub $my_handle $handles "" $handles
set index [lsearch $handles $my_handle]
if { $i == "recorded_name" } {
Returned data from si server includes: $msg"
set recorded_names([infotag get mod_handle]) $my_name
puts "****RUNNING handles=$handles"
leg collectdigits leg_incoming media_parm
media play leg_incoming http://px1-sun/dramstha/si_help.au
# Checkin with other active calls. Send each a checking message.
set oparms(recorded_name) $my_name
foreach handle $handles {
if { $handle == [infotag get mod_handle] } continue
set r [sendmsg $handle -p oparms]
Just sent a checkin msg to $handle.
# All done, disconnect the calls we are handling.
set ev [infotag get evt_event]
puts "Script for callids <[infotag get leg_all]> got event $ev"
# Send a submit to remove the incoming leg from the database. Tell the other
# sessions (calls) we are gone.
Tcl Firing up VXML to submit to remove handle [infotag get mod_handle]"
set parray(handle) [infotag get mod_handle]
leg vxmldialog leg_incoming -u http://px1-sun/dramstha/si_demo_disconnect.vxml -p
parray
set oparms(id) "uncheckin"
foreach handle $handles {
set r [sendmsg $handle -p oparms]
puts "Uncheckin message Send to $handle returned $r"
# Got a message from another instance. Handle it:
# If they are checking in, save the info and respond.
# If they are responding to a checkin, save the info.
# If their caller is sending a msg, tell our caller
set src [infotag get evt_msg_source]
set parm_list [infotag get evt_msg parm_array]
append msg "\n parm($i)=$parm_array($i)"
Leg [infotag get leg_incoming] got a message with [llength $parm_list] args
if { [info exists parm_array(id)] } {
if { [info exists parm_array(recorded_name)] } {
set recorded_name $parm_array(recorded_name)
set recorded_name "http://px1-sun/dramstha/si_unknown_caller.au"
if { $id == "checkin" } {
set recorded_names($src) $recorded_name
puts "\n $src checked in. Now handles=
set oparms(id) "checkin_rsp"
set oparms(recorded_name) $my_name
set r [sendmsg $src -p oparms]
puts "Message Send to $src returned $r"
if { $id == "checkin_rsp" } {
puts "\nSomeone responded to our check in"
if { [lsearch $handles $src] == -1 } {
Error, We don't have src of the checkin response
set recorded_names($src) $recorded_name
if { $id == "uncheckin" } {
set index [lsearch handles $src]
Error, We don't know who is unchecking in
lreplace $handles $index $index
After uncheckin, handles=$handles"
Telling our incoming leg we got a message"
media play leg_incoming http://px1-sun/dramstha/received_msg_from.au
$recorded_names($src)
# Refuse a handoff of another leg by simply returning it.
proc act_fail_handoff { } {
Got a handoff in state [infotag get evt_state_current]. Returning it."
set legs [infotag get leg_all]
set leg2 [lindex $legs 1]
handoff return $leg2 refused
# We got a handoff of another leg. Conference him
puts "Got a handoff. string=[infotag get evt_handoff_string]"
set legs [infotag get leg_all]
set leg1 [lindex $legs 0]
set leg2 [lindex $legs 1]
if { [infotag get evt_state_current] != "RUNNING" } {
Returning handoff leg in state [infotag get evt_state_current]"
handoff return $leg2 success
puts "Connecting legs $leg1 and $leg2 together"
connection create $leg1 $leg2
# The conference create completed. Simply turn on collect digits so
# both callers can disconnect.
proc act_create_done { } {
puts "Connection Created."
leg collectdigits $leg1 media_parm
leg collectdigits $leg2 media_parm
# The conference has been destroyed. Return the other leg to it's
proc act_destroy_done { } {
# Figure out which one to keep.
if { $leg1 == $my_leg } {
Returning leg $retleg, keeping $my_leg"
handoff return $retleg "success"
media play $my_leg http://px1-sun/dramstha/si_help.au
# We got the call leg returned to us after handoff.
# Just go back to running.
Leg was returned. Going back to running"
media play leg_incoming http://px1-sun/dramstha/si_help.au
leg collectdigits leg_incoming media_parm
set ev [infotag get evt_event]
Script for callids <[infotag get leg_all]>
in state [infotag get evt_state_current]
#----------------------------------
#----------------------------------
# SUBMIT - We got a setup message, and submitted our handle to the
# RUNNING - Waiting for a command from the caller. Could be playing a
# HANDED_OFF - We handed off the incoming leg to another session. We
# PRE_HANDOFF - playing a prompt to caller telling them we will handoff
# CONFERENCED - Either setting up (waiting for conf create done) or
# UNCONFING - Disconnecting the conference prior to returning a leg
# DBREMOVE - Got a disconnect, removing ourselves from the server Data Base before
# CALLDISCONNECT - All done. Have disconnected the caller.
# CALL_INIT - Initial state before a call comes in
set fsm(any_state,ev_any_event) "act_Ignore same_state"
set fsm(any_state,ev_disconnected) "act_db_remove DBREMOVE"
set fsm(any_state,ev_msg_indication) "act_rx_msg same_state"
set fsm(any_state,ev_handoff) "act_fail_handoff same_state"
set fsm(any_state,ev_create_done) "act_create_done same_state"
set fsm(any_state,ev_destroy_done) "act_destroy_done RUNNING"
set fsm(any_state,ev_digit_end) "act_Ignore same_state"
set fsm(any_state,ev_media_done) "act_Ignore same_state"
set fsm(RUNNING,ev_handoff) "act_handoff CONFERENCED"
set fsm(CONFERENCED,ev_digit_end) "act_Control_Conf UNCONFING"
set fsm(RUNNING,ev_digit_end) "act_Control same_state"
set fsm(SUBMIT,ev_vxmldialog_done) "act_submit_done RUNNING"
set fsm(DBREMOVE,ev_vxmldialog_done) "act_Cleanup CALLDISCONNECT"
set fsm(CALL_INIT,ev_setup_indication) "act_Setup SUBMIT"
set fsm(CALLDISCONNECT,ev_disconnect_done) "act_Ignore same_state"
set fsm(PRE_HANDOFF,ev_media_done) "act_do_handoff HANDED_OFF"
set fsm(HANDED_OFF,ev_returned) "act_return RUNNING"
Hybrid Scripting
The following script adds the message waiting indication(MWI) feature to an existing Tcl-VoiceXML (VXML) hybrid application that places an outbound call. The MWI feature is implemented using the SIP SUBSCRIBE/NOTIFY mechanism.
The script demonstrates how to separate the VXML portion to handle the IVR and the Tcl portion to handle call control. The VXML dialogs will play prompts and collect inputs as well as interfaces with the HTTP web server. The main Tcl script handles the call control portion which provides the equivalent function of the standard VXML Transfer. When the user calls into the gateway, a VXML dialog is invoked. The VXML dialog queries the backend server with the ANI of the caller. The VXML document returned presents the user with choices of who he can call. This can be the personal phone book or a company directory. In addition, the VXML Transfer element attributes are passed from the VXML document to the Tcl procedure to place call. The returned information also includes a URL which contains the location of VXML dialog to run after the called party hangs up. This VXML dialog emulates a voicemail message which is played to the user if he chooses to listen to them.
The user also hear a prompt indicating new voicemails in his mailbox after the call has been connected. He can choose to listen to the voicemail or ignore it. If he selects to listen to his voicemail, the music on hold treatment will be applied to the called party This feature is enabled when the Tcl application subscribes to a MWI event package running on a SIP server. For this sample, the MWI event package is another Tcl application running on another gateway. The server application will notify the client application when a new message is delivered to the mailbox.
#----------------------------------------------------------------------------------------
# The init procedure defines the initial parameters of digit collection. Users are
# expected to enter a single DTMF key within 5 secs and are allowed to enter a digit
# before a prompt is played out. This is used when a prompt is played to the user
# indicating a new voicemail and the user may enter any DTMF key to listen to the
set param(interruptPrompt) true
set param(initialDigitTimeout) 5
#-----------------------------------------------------------------------------------------
# In this procedure, CLI configurations are read
# Users can configure the location of the Tcl script on the router and this is stored in
# Users can configure the number of notifications that are sent before the subscription
# closes. The default is 4.
proc init_ConfigVars {} {
if {[infotag get cfg_avpair_exists base-url]} {
set baseURI [string trim [infotag get cfg_avpair base-url]]
set baseURI tftp://TFTP-SERVER/scripts/
if {[infotag get cfg_avpair_exists notification-num]} {
set notNum [string trim [infotag get cfg_avpair notification-num]]
puts "\n\n\n**** Base Url is $baseURI\n\n"
puts "\n\n\n**** Number of notifications in CLI is $notNum\n\n"
#-----------------------------------------------------------------------------------------
# Procedure init_perCallVars
# In this procedure, the global variables are initialized
# The IP address for the SIP server is configured on the router as follows :
# ip host x.x.x.x sip-server
proc init_perCallVars { } {
set subUrl sip:mwi@sip-server
#----------------------------------------------------------------------------------------
# The act_Start procedure is executed when it receives an ev_setup indication event.
# A setup acknowledgement, call proceeding and connect message is sent to the incoming
# call leg. The parameters in the subscribe request are defined and a subscribe request
# to the MWI event package is sent.
infotag set med_language 1
leg setupack leg_incoming
leg proceeding leg_incoming
set ani [infotag get leg_ani]
set subInfo(notificationReceiver) mwiClient
# expiration time is 1 hour
set subInfo(expirationTime) 3600
set subinfo(subscriptionContext) context
set headers(Account) $ani
set headers(Subject) "Message Waiting Indication Subscription"
set subInfo(protoHeaders) headers
set subInfo(protoContents) "This is a subscription request from mwiclient"
set subInfo(protoContentTypes) "text/plain"
set subId [subscription open $subUrl subInfo]
#----------------------------------------------------------------------------------------
# Procedure act_VxmlDialog1
# This procedure is called from act_Notify. It is called once in the application after the
# script receives a ev_notify_ind event.
# In this procedure, the ANI of the user is submitted to sipWebQuery.php script on the
# backend web server. The result is a dynamically generated VXML document which contains
# information required for call setup. The user is prompted to enter the destination
# number of the person he wishes to call. The destination number together with the
# attributes to the VXML transfer element and the URL for the subsequent VXML dialog are
# passed back to the Tcl script. The IP address of the Web server is configured on the
# router as follows: ip host x.x.x.x HTTP-SERVER
proc act_VxmlDialog1 { } {
puts "\n\n\n******** Procedure VxmlDialog1 ********\n\n"
<catch event="error.badfetch.com">
<log>Web Server down ! Submit action in VxmlDialog1 failed. </log>
<var name="WEB_SERVER" expr="'http://HTTP-SERVER/vxml/'"/>
<var name="ANI" expr="session.telephone.ani"/>
<submit expr="WEB_SERVER+'sipWebQuery.php'" method="get" namelist="ANI"/>
leg vxmldialog leg_incoming -u $baseURI -v $vxmlDialog1
#----------------------------------------------------------------------------------------
# Procedure act_SubscribeDone
# This procedure is executed when an ev_unsubscribe_done event is received. The status of
# the event is checked. If the subscription failed, the subscription is closed.
proc act_SubscribeDone { } {
puts "\n\n\n******** Procedure SubscribeDone ********\n\n"
set subId [infotag get evt_subscription_id]
puts "\n\n\n**** Subscription ID is $subId"
set status [infotag get evt_status]
puts "\n\n\n**** Subscription status, $status swith ID: $subId is successful\n\n"
puts "\n\n\n**** Subscription status, $status with ID: $subId is pending\n\n"
puts "\n\n\n**** Subscription statu, $status swith ID: $subId failed\n\n"
subscription close $subId
#----------------------------------------------------------------------------------------
# This procedure is received when an ev_notify_ind event is received. Both standard and
# non standard SIP headers sent by the server are read. The non standard headers are
# MessageStatus and MessageSummary. MessageStatus indicates that there are new
# voicemail and MessageSummary indicates the number of new voicemails.
# An acknowledgement is sent back to the server in response to the notification event.
# This procedure is called every time an ev_notify_ind event is received (except for the
# last one). The subscription is terminated depending of the value configured
# for the number of times a notification is sent.
puts "\n\n\n******** Procedure Notify ********\n\n"
set status [infotag get evt_status]
puts "\n\n\n**** Status of subscription is $status\n\n"
set subId [infotag get evt_subscription_id]
puts "\n\n\n**** Subscription ID is subId=$subId"
set event_header [infotag get evt_proto_headers Event]
puts "\n\n\n**** Event header is $event_header\n\n"
set hello [infotag get evt_proto_headers "Hello"]
puts "\n\n\n**** Hello Header from Notification is $hello\n\n"
set message_status [infotag get evt_proto_headers "MessageStatus"]
regexp {Messages-waiting:([a-z]+)} $message_status dummy mWaiting
puts "\n\n\n**** Message Waiting is $mWaiting\n\n"
set message_summary [infotag get evt_proto_headers "MessageSummary"]
regexp {Voicemail:([0-9]+)} $message_summary dummy mNew
puts "\n\n\n**** New message is $mNew\n\n"
set content_type [infotag get evt_proto_content_type]
puts "\n\n\n**** Notification content_type=$content_type\n\n"
set content [infotag get evt_proto_content]
puts "\n\n\n**** Notification content=$content\n\n"
set exp_time [infotag get evt_proto_headers Expires]
puts "\n\n\n**** Subscription Expires: $exp_time\n\n"
set notifyRecr [infotag get subscription_info $subId notificationReceiver]
puts "\n\n\n**** Notification Receiver is $notifyRecr\n\n"
puts "\n\n\n**** Subscription is terminated"
set headers(Title) "This is the last acknowledgement from the client"
set ackInfo(protoContents) "Ending subscription"
set headers(Title) "This is an acknowledgement from the client"
set ackInfo(protoContents) "This is CONTENT from client"
set headers(Account) $ani
set ackInfo(protoHeaders) headers
set ackInfo(respCode) ack
set ackInfo(protoContentTypes) "text/plain"
subscription notify_ack $subId -i ackInfo
puts "\n\n\n**** Start VXML Dialog \n\n"
if {$counter < $notNum} {
if {$mWaiting == "yes"} {
puts "\n\n\n**** Number of notifications received is $counter"
puts "\n After $counter notifications, close the subscription now.\n\n"
subscription close $subId
#---------------------------------------------------------------------------------------
# Procedure act_MessageIndication
# This procedure is first invoked when the script receives an ev_leg_timer event. The
# timer event comes up if there is a new voicemail after the call has been connected.
# To play a prompt to the user that a new voicemail is in the mailbox, the connection
# between the incoming and outgoing call legs is destroyed.
proc act_MessageIndication {} {
puts "\n\n\n******** Procedure MessageIndication ********\n\n"
connection destroy con_all
leg collectdigits leg_incoming param
media play leg_incoming _new_voicemail.au %n$mNew %s1000 _check_new_voicemail.au
fsm setstate CHECKVOICEMAIL
#----------------------------------------------------------------------------------------
# Procedure act_PlayMessageInd
# This procedure plays the prompt "You have X new voicemails" to the user when the script
# receives an ev_destroy_done event is received. The act_PlayMusic is invoked to provide
# music on hold treatment to the called party
proc act_PlayMessageInd {} {
puts "\n\n******* Procedure PlayMessageInd ********\n\n"
puts "\n\n\n**** Number of new vmail are $mNew\n\n"
leg collectdigits leg_incoming param
media play leg_incoming _new_voicemail.au %n$mNew %s1000 _check_new_voicemail.au
#media play leg_incoming _you_have.au %n$mNew %s1000 _seconds.au
fsm setstate CHECKVOICEMAIL
#----------------------------------------------------------------------------------------
# Procedure act_PlayMusic
# This procedure plays a music prompt to the called party while the user is checking
# his voicemail messages.
puts "\n\n******* Procedure PlayMusic ********\n\n"
media play leg_outgoing _song.au
#----------------------------------------------------------------------------------------
# Procedure act_FinalNotify
# This procedure is invoked when the script receives the final ev_notify_ind event.
# The SIP server application sends this event when the client script closes the
proc act_FinalNotify { } {
puts "\n\n******* Procedure FinalNotify ********\n\n"
set status [infotag get evt_status]
puts "\n\nstatus=$status\n\n"
set sub_id [infotag get evt_subscription_id]
# you can access any standard headers
set From [infotag get evt_proto_headers From]
puts "\n\n**** From header is: $From\n\n"
set headers(Title) "Hello, this is the final acknowledgement from the client"
set ackInfo(protoHeaders) headers
set ackInfo(protoContents) "This is CONTENT from client"
set ackInfo(protoContentTypes) "text/plain"
set ackInfo(respCode) ack
subscription notify_ack $sub_id -i ackInfo
#----------------------------------------------------------------------------------------
# Procedure act_UnsubscribeDone
# This procedure is invoked when the script receives an ev_unsubscribe_done event. This
# event is sent when the subscription is closed.
proc act_UnsubscribeDone { } {
puts "\n\n\n******** Procedure UnsubscribeDone ********\n\n"
set status [infotag get evt_status]
puts "\n\n\n**** Status of unsubscribe_done is $status\n\n"
#----------------------------------------------------------------------------------------
# Procedure act_SubscribeClose
# This procedure is invoked when the script receives an ev_unsubscribe_indication or an
# ev_subscribe_cleanup event. An ev_unsubscribe_indcation event is received if the server
# sends unsubscribe request, subscription expires or other errors. An
# ev_subscribe_cleanup event is received when the CLI, "clear sub all" is executed
# The subscription is closed.
proc act_SubscribeClose { } {
puts "\n\n\n******** Procedure SubscribeClose ********\n\n"
puts "\n\n**** Unsubscribe Indication received or Subscribe Clean up event
set sub_id [infotag get evt_subscription_id]
subscription close $sub_id
#----------------------------------------------------------------------------------------
# Procedure act_GetTransferAttr
# This procedure handles the transfer attributes sent by VxmlDialog1.
# It parses the evParam array to get the attributes.
proc act_GetTransferAttr {} {
puts "\n\n\n******** Procedure GetTransferAttr ********\n\n"
set tclProc GetTransferAttr
set ev [infotag get evt_vxmlevent]
if {$ev != "vxml.dialog.transferEvent"} {
puts "\n\n\t\t **** Expected event vxml.dialog.transferEvent, got $ev"
# get all the parameters sent from VXML dialog
set eventParam [infotag get evt_vxmlevent_params evParam]
for {set i 0} {$i < [llength $eventParam]} {incr i} {
set [set value [lindex $eventParam $i]] $evParam($value)
puts "\n\n\t\t **** $value = $evParam($value)"
#----------------------------------------------------------------------------------------
# This procedure is called when the application receives the vxml_dialog_done event.
# It checks for the destination number, set the callInfo array with the relevant
# transfer attributes and places a call to that number.
puts "\n\n\n******** Procedure Transfer ********\n\n"
# check the sub-event name
set exp_ev vxml.session.complete
set ev [infotag get evt_vxmlevent]
puts "\n\n\t\t **** Expected event $exp_ev, got $ev"
# check the dialog status
set status [infotag get evt_status]
#get the transfer attribute, destination
infotag get evt_vxmlevent_params transfer_param
if !{[info exists transfer_param(destination)]} {
puts "\n\n\t\t **** destination number does not exist"
act_LogStatus $status $tclProc
set destination $transfer_param(destination)
set callinfo(alerTime) $maxtime
set callinfo(newguid) $longpound
leg setup $destination callInfo leg_incoming
puts "\n\n\t\t **** VXML Dialog status, expected vd_000, got
act_LogStatus $status $tclProc
#----------------------------------------------------------------------------------------
# Procedure act_TransferDone
# If leg setup is successful, the 2 parties are conferenced. If not, the status of leg
# setup is sent to the web server. If there are new voicemail messages, a timer is
# started for 2 seconds and act_MessageIndication procedure is called.
proc act_TransferDone { } {
puts "\n\n\n******** Procedure TransferDone ********\n\n"
set status [infotag get evt_status]
puts "\n\n\t\t **** Status of leg setup is $status \n"
set incoming [infotag get leg_incoming]
set outgoing [infotag get leg_outgoing]
set creditTimeLeft [infotag get leg_settlement_time leg_all]
if { ($creditTimeLeft == "unlimited") || ($creditTimeLeft=="uninitialized")}
{puts "\n\n\t\t **** UnLimited Call Time\n"
puts "\n\n\t\t **** Are there new voicemail messages ? $mWaiting \n\n"
if { $mWaiting == "yes" } {timer start leg_timer 2 leg_incoming}}
# start the timer for ...
if { $creditTimeLeft < 10 } {
set delay $creditTimeLeft
set delay [expr $creditTimeLeft - 10]
timer start leg_timer $delay leg_incoming
"ls_007" {puts "\n\n\t\t **** Call status is $status, Destination is Busy \n"
set transferStatus NOANSWER
act_LogStatus $transferStatus $tclProc
"ls_008" {puts "\n\n\t\t **** Call status is $status, Incoming Disconnected
set transferStatus NEAR_END_DISCONNECT
act_LogStatus $transferStatus $tclProc
"ls_009" {puts "\n\n\t\t **** Call status is $status, Outcoming Disconnect
set transferStatus FAR_END_DISCONNECT
act_LogStatus $transferStatus $tclProc
puts "\n\n\t\t **** Call status is $status\n"
set transferStatus UNKNOWN
act_LogStatus $transferStatus $tclProc
#----------------------------------------------------------------------------------------
# Procedure act_VxmlDialog2
# This procedure is called when the caller chooses to listen to his new voicemail
# messages, the script receives an ev_collectdigits_done event.
# After the called party hangs up, the application invokes the second VXML dialog which
# is a fake voicemail service for the user.
proc act_VxmlDialog2 { } {
puts "\n\n\n******** Procedure VxmlDialog2 ********\n\n"
puts "\n\n\t\t **** URL of voicemail is $uri \n\n"
leg disconnect leg_outgoing
set event [infotag get evt_event]
set status [infotag get evt_status]
puts "\n\n\n**** Caller wants to check new voicemail \n\n"
leg vxmldialog leg_incoming -u $uri
# play media to say cannot access voicemails
media play leg_incoming _technicalProblem.au
puts "\n\n\n**** Caller didn't enter digit to check new
voicemail\n\n"
connection create $incoming $outgoing
puts "\n\n\n**** The digit collection was terminated because
of an unsupported or unknown feature or event\n\n"
#----------------------------------------------------------------------------------------
# Procedure act_VxmlDialog2Done
# This procedure is invoked when the ev_vxmldialog_done event is received.
# The conference between the incoming and outgoing call legs is bridged again after the
user is done listening to the new voicemail messages.
proc act_VxmlDialog2Done { } {
puts "\n\n\n******** Procedure VxmlDialog2Done ********\n\n"
set tclProc VxmlDialog2Done
set exp_ev vxml.session.complete
set ev [infotag get evt_vxmlevent]
puts "\n\n\t\t **** Expected event $exp_ev, got $ev"
act_LogStatus $ev $tclProc
if {[infotag get evt_legs] == $incoming} {
connection create $incoming $outgoing
#----------------------------------------------------------------------------------------
# Procedure act_LogStatus
# The status code for leg setup, vxml dialog are sent to the backend web server in this
proc act_LogStatus {statusCode tclProcedure} {
puts "\n\n\n******** Procedure LogStatus ********\n\n"
puts "\n\n\t\t***** Status Code is $statusCode in procedure $tclProcedure"
<var name="WEB_SERVER" expr="'http://HTTP-SERVER/vxml/'"/>
<var name="ANI" expr="session.telephone.ani"/>
<var name="STATUSCODE" expr="com.cisco.params.code"/>
<var name="PROCEDURE" expr="com.cisco.params.procedure"/>
<catch event="error.badfetch.com">
<log>Web Server down ! Submit action in VxmlDialog3 failed. </log>
<log> Tcl Status Code : <value expr="STATUSCODE"/> found in Tcl
Procedure : <value expr="PROCEDURE"/></log>
<submit expr="WEB_SERVER+'status.php'" method="get" namelist="ANI
set tclStatusParam(code) $statusCode
set tclStatusParam(procedure) $tclProcedure
leg vxmldialog leg_incoming -u $baseURI -v $vxmlDialog3 -p tclStatusParam
#----------------------------------------------------------------------------------------
# This procedure is invoked when the timer expires. If the call duration is unlimited,
# this will not be invoked.
puts "\n\n\n******** Procedure Timer ********\n\n"
set incoming [infotag get leg_incoming]
set outgoing [infotag get leg_outgoing]
#insert a beep ...to the caller
connection destroy con_all
connection destroy con_all
media play leg_incoming _outOfTime.au
media play leg_incoming _beep.au
#----------------------------------------------------------------------------------------
# Procedure act_PlayMessageIndDone
# When the script receives an ev_media_done event is received, this procedure will be
# executed. If the event happened on the outgoing leg, the music prompt is repeated to
# the called party. If the event is received on the incoming leg, the prompt playout
# is terminated on the outgoing side and the 2 legs are conferenced.
proc act_PlayMessageIndDone { } {
puts "\n\n\n******** Procedure PlayMessageIndDone ********\n\n"
set incoming [infotag get leg_incoming]
set outgoing [infotag get leg_outgoing]
if {[infotag get evt_legs] == $outgoing} {
media play leg_outgoing _song.au
if {[infotag get evt_legs] == $incoming} {
connection create $incoming $outgoing
connection create $incoming $outgoing
proc act_ConnectedAgain { } {
puts "\n\n\t\t***** Call Connected Again\n\n "
#----------------------------------------------------------------------------------------
# Procedure act_HandleOutgoing
# When the called party hangs up, the connection is destroyed
proc act_HandleOutgoing { } {
global outgoingDisconnect
puts "\n\n\t\t********* Procedure HandleOutgoing *********\n\n "
if {[infotag get evt_legs] == [infotag get leg_outgoing]} {
connection destroy con_all
fsm setstate CALLDISCONNECT
#----------------------------------------------------------------------------------------
# Procedure act_LongPound
# If the user enters the Pound key, the connection to the called party will be destroyed.
# The user hear the voicemail emulation in VxmlDialo2
puts "\n\n\n******** Procedure LongPound ********\n\n"
puts "\n\n\t\t***** Calling Party entered long pound"
if {[infotag get evt_digit] != "#"} {
set duration [infotag get evt_digit_duration]
if {$duration < $DURATION} {
connection destroy con_all
#---------------------------------------------------------------------------------------
# This procedure is invoked when the application receives an ev_disconnected event.
puts "\n\n\n******** Procedure Cleanup ********\n\n"
#----------------------------------------------------------------------------------------
# Procedure act_SessionClose
# This procedure will be invoked if a script receives an ev_session_terminate event.
# Note that this will not be invoked in this application since this application requires
an incoming call leg
proc act_SessionClose { } {
puts "\n\n\n******** Procedure SessionClose ********\n\n"
#----------------------------------
#----------------------------------
set fsm(any_state,ev_disconnected) "act_Cleanup same_state"
set fsm(any_state,ev_subscribe_done) "act_SubscribeDone SUBSCRIBED"
set fsm(any_state,ev_notify_ind) "act_Notify NOTIFIED"
set fsm(any_state,ev_unsubscribe_done) "act_UnsubscribeDone same_state"
set fsm(any_state,ev_unsubscribe_indication) "act_SubscribeClose same_state"
set fsm(any_state,ev_subscribe_cleanup) "act_SubscribeClose same_state"
set fsm(any_state,ev_session_terminate) "act_SessionClose same_state"
set fsm(CALL_INIT,ev_setup_indication) "act_Start SUBSCRIBE"
set fsm(NOTIFIED,ev_media_done) "act_Ignore same_state"
set fsm(CHECKVOICEMAIL,ev_collectdigits_done) "act_VxmlDialog2 same_state"
set fsm(MUSICONHOLD,ev_media_done) "act_PlayMessageIndDone same_state"
set fsm(CLOSESUB,ev_notify_ind) "act_FinalNotify same_state"
set fsm(WEBQUERY,ev_vxmldialog_event) "act_GetTransferAttr same_state"
set fsm(WEBQUERY,ev_vxmldialog_done) "act_Transfer TRANSFER"
set fsm(TRANSFER,ev_setup_done) "act_TransferDone CALLACTIVE"
set fsm(CALLACTIVE,ev_leg_timer) "act_MessageIndication CHECKVOICEMAIL"
set fsm(CALLACTIVE,ev_disconnected) "act_HandleOutgoing CONNDESTROY"
set fsm(CALLACTIVE,ev_digit_end) "act_LongPound CONNDESTROY"
set fsm(CHECKVOICEMAIL,ev_vxmldialog_done) "act_VxmlDialog2Done same_state"
set fsm(CHECKVOICEMAIL,ev_create_done) "act_ConnectedAgain CALLACTIVE"
set fsm(LOGSTATUS,ev_vxmldialog_done) "act_Cleanup same_state"
set fsm(CHECKVOICEMAIL,ev_destroy_done) "act_PlayMessageInd same_state"
set fsm(PLAYBEEP,ev_media_done) "act_Beeped same_state"
set fsm(INSERTBEEP,ev_destroy_done) "act_Destroy same_state"
set fsm(INSERTBEEP,ev_media_done) "act_Beeped same_state"
set fsm(INSERTBEEP,ev_create_done) "act_ConnectedAgain CALLACTIVE"
set fsm(LASTWARN,ev_destroy_done) "act_LastWarn CALLDISCONNECT"
set fsm(CALLDISCONNECT,ev_disconnect_done) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_media_done) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_disconnect_done) "act_Cleanup same_state"
set fsm(CALLDISCONNECT,ev_leg_timer) "act_Cleanup same_state"