Play message, then connect to final DNIS (if modified)

Version 1
    This document was generated from CDN thread

    Created by: RYAN WEST on 22-03-2011 10:14:45 AM
    I tried researching this one as much as possible, but I'm hitting a wall.  I have modified the ani_filter script to play a message when a number is being blocked (redirected).  However, the script completes the redirect too early.  It seems to work in my test system, but the early redirect on another system is causing an ISDN failure and early termination.  
     

    # ani_filter.tcl
    # Script Version 1.0(1)
    #------------------------------------------------------------------
    # October 2002, Niels Brunsgaard
    #
    # Copyright (c) 1998-2002 by cisco Systems, Inc.
    # All rights reserved.
    #------------------------------------------------------------------
    #
    # This tcl script filters calls based on ANI. If there is a match # against a pe-configured list of numbers it changes the DNIS # to a configurable value #
    #
     
    proc init { } {
       global param
    }
     
    proc act_Setup { } {
     
       leg setupack leg_incoming
     
       set dnis [infotag get leg_dnis]
       set new_dnis [infotag get cfg_avpair new_dest]
       set ani [infotag get leg_ani]
       set ani_deny NULL
       set ani_pi [infotag get leg_ani_pi]
       puts "dnis $dnis new_dnis $new_dnis ani $ani ani_pi $ani_pi"
       if { $ani_pi != "presentation_allowed" } {
         set ani NULL
       }
     if [infotag get cfg_avpair_exists welcome-prompt] {
           set welcomePrompt [string trim [infotag get cfg_avpair welcome-prompt]]
        } else {
           set welcomePrompt flash:en_bacd_disconnect.au
        }
     
       set x 1
       while {1} {
         if {[infotag get cfg_avpair_exists clid$x]} {
           set ani_deny [infotag get cfg_avpair clid$x]
           puts "clid$x = $ani_deny"
           if { $ani == $ani_deny} {
             set dnis $new_dnis
             puts "match clid $ani_deny x=$x"
             media play leg_incoming $welcomePrompt
    #
    # I would like a pause here before completing the rest of the script
    #
    #
             timer start named_timer 20 PROMPT_TIMER
             break
           }
         } else {
           puts "No more clid at $x"
           break
         }
         incr x
         if { $x > 1000 } { puts "Too many clids" }
       }
       puts "Final dnis $dnis"
       leg proceeding leg_incoming
       leg setup $dnis callInfo leg_incoming
    }
     
    proc act_CallSetupDone { } {
       global beep
     
       set status [infotag get evt_status]
     
       puts "Entering act_CallSetupDone"
       if { $status != "ls_000"} {
           puts "Call [infotag get con_all] got event $status while placing an outgoing call"
           call close
       }
    }
     
    proc act_Cleanup { } {
       puts "Entering act_Cleanup"
       call close
    }
     
    proc act_Abort { } {
       puts "Unexpected event - entering act_Abort"
       call close
    }
     
    init
     
    #----------------------------------
    #   State Machine
    #----------------------------------
     set TopFSM(any_state,ev_disconnected) "act_Abort,same_state"
     set TopFSM(CALL_INIT,ev_setup_indication) "act_Setup,PLACECALL"
     set TopFSM(PLACECALL,ev_setup_done)  "act_CallSetupDone,CALLACTIVE"
     set TopFSM(CALLACTIVE,ev_disconnected)   "act_Cleanup,CALLDISCONNECTED"
     set TopFSM(CALLDISCONNECTED,ev_disconnect_done) "act_Cleanup,same_state"
     
     fsm define TopFSM  CALL_INIT




    Thanks!


    -ryan

    Subject: RE: Play message, then connect to final DNIS (if modified)
    Replied by: Yaw-Ming Chen on 22-03-2011 10:51:12 AM
    You may need to separate you act_setup procedure.
    You start a timer so you need to wait until timer expire (ev_named_timer event)
    Add one more line in state machine to handle ev_named_timer event


      set myTimer [infotag get evt_timer_name]

    if {$myTimer == "PROMPT_TIMER"} {
          --------
        }

    Subject: RE: Play message, then connect to final DNIS (if modified)
    Replied by: RYAN WEST on 22-03-2011 11:36:35 AM
    Yaw-Ming,

    Thanks for your reply.  I'm still having difficulty implementing that logic.

    I tried adding the following below the timer:

             media play leg_incoming $welcomePrompt
             timer start named_timer 20 PROMPT_TIMER

             set myTimer [infotag get evt_timer_name]
             if {$myTimer == "PROMPT_TIMER"}{
             break

    As I only want it to play if the ANI is matched.  However that is causing TCL script failure:


    Mar 22 11:21:40.386: TCL script failure
            Result:
                             extra characters after close-brace
    Mar 22 11:21:40.386:    TCL script failure errorInfo:
                            extra characters after close-brace
        while compiling
    "if {$myTimer == "PROMPT_TIMER""
        ("if" then script line 7)
        while compiling
    "if { $ani == $ani_deny} {
             set dnis $new_dnis
             puts "match clid $ani_deny x=$x"
             media play leg_incoming $welcomePrompt
             timer start..."
        ("if" then script line 4)
        while compiling
    "if {[infotag get cfg_avpair_exists clid$x]} {
           set ani_deny [infotag get cfg_avpair clid$x]
           puts "clid$x = $ani_deny"
           if { $ani ==..."
        ("while" body line 2)
        while compiling
    "while {1} {
         if {[infotag get cfg_avpair_exists clid$x]} {
           set ani_deny [infotag get cfg_avpair clid$x]
           puts "clid$x = $ani_deny"
      ..."
        (compiling body of proc "act_Setup", line 21)
        invoked from within
    "act_Setup"


    Could you provide a more complete example of where you think it should be implemented or how the act_Setup procedure should be broken up.

    Also, I set the following in the state machine:


    set TopFSM(PLACECALL,ev_named_timer) "act_Setup,same_state"


    Thanks,

    -ryan

    Subject: RE: Play message, then connect to final DNIS (if modified)
    Replied by: Yaw-Ming Chen on 22-03-2011 12:36:06 PM
    Like I said before you may want to separate you act_Setup event into two procedure. First handle everything to the point of start timer. Then when receive ev_named_timer event call up another procedure to continue what you like to do.

    Please refer Tcl API programming guide. You can also look at BACD script to see how it handles timer.