Laying Down The Hammer Part 2 – TCL Auto Answer Script

So I got an interesting email yesterday, a person emailed me thanking me for my great Hammer blog but said they were trying to make a TCL script to answer the calls. I guess I never thought of it before, but many of you don’t have big juicy call centers to send the calls too.

A TCL script on the Cisco Router can totally be used to answer a call, play a simple G711ulaw wav file and then release the call when its finished. I wrote a very small and quick script for this gentlemen to use and he said it worked great. Since I have no posts on TCL here yet, I thought I would post one, since I use it quite a bit to do interesting development related projects.

Below is the code… At the top of the code in the comments is the router to config to use it. Make sure you use an incoming dial-peer with incoming called-number, TCL apps won’t trigger with the destination-pattern command. I see people make this mistake all the time.

This is a super simple script, but the biggest and craziest part of TCL is it uses what’s called a State Machine. Your best off looking it up on Wikipedia then getting a description from me. Basically functions are triggered based an application flow and what ‘state’ the application is in.

Lastly make sure to put a file name hold.wav in the root of your flash:. No Wav file, no media.

# Created by Chad Stachowicz
# cstachowicz@cloverhound.com
#
# Cloverhound, Inc.
#
#
#
# router#conf t
# router(config)#application
# router(config-app)# service simple_ivr flash:simple_ivr.tcl
# router(config)#dial-peer voice 100 pots
# router(config-dial-peer)#incoming called-number 1000
# router(config-dial-peer)#service simple_ivr
#

proc act_Setup { } {
    global incoming

    leg setupack leg_incoming
    leg proceeding leg_incoming
    leg connect leg_incoming
    set incoming [infotag get leg_incoming]
    set dnis [infotag get leg_dnis]
    set ani [infotag get leg_ani]
    media play leg_incoming flash:hold.wav
}
proc cleanup { } {

        call close
}
proc disconnect { } {

        set disc_leg [infotag get evt_legs]
        leg disconnect $disc_leg
}

requiredversion 2.0

set FSM(CALL_INIT,ev_setup_indication)          "act_Setup,disconnect"
set FSM(any_state,ev_disconnect_done)           "cleanup,same_state"
set FSM(any_state,ev_disconnected)              "disconnect,same_state"

fsm define FSM CALL_INIT