Press 1, Press 2, route to variables

Version 1
    This document was generated from CDN thread

    Created by: Chris Bomba on 31-08-2011 12:24:06 PM
    I am using changing the ITS script to play the Welcome Prompt then Enter Destination prompt.  I am trying to make it so that if you press 1 it grabs the extension that is configured for the "brand1" variable and sending the call to that number.  When you press 2 it grabs the extension that is configured for the "brand2" variable and sends the caller to that number.  Not having much luck.  When I press 1 or 2 it give me the cd_006 status and gives me an error.
     
    Attached is the script and my router config:
     
     
     service flagship-optionb flash:its-CISCO-Flagship-OptionB.1.tcl
      param brand2-ext 72102
      paramspace english index 0
      paramspace english language en
      paramspace english location flash:
      param queue-len 2
      param brand1-ext 55011
      param max-extension-length 1
      param aa-pilot 8000
      param en 0

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Raghavendra Gutty Veeranagappa on 01-09-2011 02:08:53 AM
    Hi Chris,

    since there is no dialplan found with the collected digits(1 or 2) script recieved cd_006(The digit collection failed because the number collected was invalid).

    If your are expecting only one digit to dial you can use maxDigits param then script will recieve cd_005 to collect the digit.

    set param1(maxDigits) 1

    Thanks,
    Raghavendra

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Chris Bomba on 07-09-2011 10:13:06 AM
    Where does the "set param1(maxDigits) 1" go?  Does it replace the "set param1(dialPlan) true"?

     1proc act_Setup { } {
     2    global param1
     3    global selectCnt
     4    global dest
     5    global beep
     6    global callInfo
     7    global dnis
     8    global fcnt
     9    global aaPilot
    10    global brand1
    11    global brand2
    12    global busyPrompt
    13    global legConnected
    14
    15    puts "proc act_Setup"
    16    set busyPrompt _dest_unreachable.au
    17    set beep 0
    18    init_perCallVars
    19    infotag set med_language 1
    20
    21    if { ($dnis == "") || ($dnis == $aaPilot) } {
    22        leg setupack leg_incoming
    23        leg proceeding leg_incoming
    24        leg connect leg_incoming
    25        set legConnected true
    26
    27        puts "\nNo DNIS\n"
    28        set param1(dialPlan) true
    29        leg collectdigits leg_incoming param1
    30
    31        media play leg_incoming _welcome.au %s1000 _enter_dest.au
    32    } else {
    33        set fcnt 6
    34        leg setupack leg_incoming
    35        #handoff callappl leg_incoming default "DESTINATION=$dnis"
    36        set callInfo(alertTime) 30
    37        leg setup $dnis callInfo leg_incoming
    38        fsm setstate HANDOFF
    39    }
    40
    41
    42}


    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Chris Bomba on 07-09-2011 12:27:05 PM
    I got this working.  I had to use to elseif statements in the proc act_GotDest step.  Thanks for the help everyone.

     1proc act_GotDest { } {
     2    global dest
     3    global maxExtensionLen
     4    global destExtLen
     5    global callInfo
     6    global oprtr
     7    global oprtr1
     8    global busyPrompt
     9    puts "\n proc act_GotDest"
    10    set status [infotag get evt_status]
    11    set callInfo(alertTime) 30
    12
    13    if {  ($status == "cd_004") } {
    14        set dest [infotag get evt_dcdigits]
    15
    16        set destExtLen [string length $dest]
    17
    18      set extLength [expr $maxExtensionLen - $destExtLen]
    19        if { $dest == "1" } {
    20                set dest $oprtr
    21        } elseif { $dest == "2" } {
    22                set dest $oprtr1
    23        }
    24
    25        #handoff callappl leg_incoming default "DESTINATION=$dest"
    26        if {($maxExtensionLen > 0) && ($extLength >= 0)} {
    27            leg setup $dest callInfo leg_incoming
    28        } else {
    29            set busyPrompt _invalid_extn.au
    30            act_Select
    31        }
    32    } elseif { ($status == "cd_001") || ($status == "cd_002") } {
    33        set dest $oprtr
    34        #handoff callappl leg_incoming default "DESTINATION=$dest"
    35        leg setup $dest callInfo leg_incoming
    36    }   else {
    37        if { $status == "cd_006" } {
    38                set busyPrompt _dest_unreachable.au
    39        }
    40        puts "\nCall [infotag get con_all] got event $status collecting destination"
    41        set dest [infotag get evt_dcdigits]
    42        if { $dest == "1" } {
    43                set dest $oprtr
    44                #handoff callappl leg_incoming default "DESTINATION=$dest"
    45                leg setup $dest callInfo leg_incoming
    46        } elseif { $dest == "2" } {
    47                set dest $oprtr1
    48                #handoff callappl leg_incoming default "DESTINATION=$dest"
    49                leg setup $dest callInfo leg_incoming
    50        } else {
    51                act_Select
    52        }
    53    }
    54}

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 25-04-2012 06:08:38 AM
    Would you please post whole modified script ?

    I tried doing it your way but choosing "1" doesn't call brand1 (i.e. brand1-ext in parameters)
    - but instead tries to call "1" number (from debug voip dialpeer)

    thanks,
    Michal

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Anusha Kannappan on 25-04-2012 06:26:44 AM
    Hi Michal,

    Please cross check whether you have set the dest to the appropriate the brand extension before doing a leg setup with the dest value as shown below, if not it will just take the value you press for placing the call.

    set dest $oprtr

    Thanks,
    Anusha

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 25-04-2012 08:02:15 AM
    ok, but the whole idea was to pass these values through parameters
    that's how I understand this thread

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Raghavendra Gutty Veeranagappa on 25-04-2012 08:34:55 AM
    Hi michal,

    could you please post your script.

    Thanks,
    Raghavendra

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Raghavendra Gutty Veeranagappa on 26-04-2012 08:55:37 AM
    Hi michal,

    thanks for sharing the logs, there are "elseif" scripts errors in your script please correct it.

    Apr 26 07:43:18.447: //60//AFW_:/vtr_ev_dcdigits: DCDIGITS [1]
    Apr 26 07:43:18.447: //60//AFW_:/AFW_FSM_Drive: Tcl_Eval to drive FSM inside Tcl modulespace. code=1 code=ERROR
    Apr 26 07:43:18.447: TCL script failure
            Result:
                             invalid command name "elseif"
    Apr 26 07:43:18.447:    TCL script failure errorInfo:
                            invalid command name "elseif"
        while executing
    "elseif { $dest == "1" } {
                    #set dest $oprtr
                                    set dest $menu1
                    #handoff callappl leg_incoming default "DESTINATION=..."
        (procedure "act_GotDest" line 51)
        invoked from within
    "act_GotDest"


    Thanks,
    Raghavendra

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 26-04-2012 02:48:15 AM
    here you are

    of course I pass extension through "line1" value
      param line1 609


      1
      2proc init { } {
      3    global param1
      4    global selectCnt
      5    global callInfo
      6    global legConnected
      7    global maxExtensionLen
      8
      9    set param1(interruptPrompt) true
     10    set param1(abortKey) *
     11    set param1(terminationKey) #
     12
     13    set selectCnt 0
     14    set legConnected false
     15}
     16
     17proc init_ConfigVars { } {
     18    global destination
     19    global aaPilot
     20    global oprtr
     21    global menu1
     22    global maxExtensionLen
     23
     24# aa-pilot is the IVR number configured on the gateway to be used by the customer
     25# operator is the operator number for assisted calling
     26
     27    if [infotag get cfg_avpair_exists aa-pilot] {
     28        set aaPilot [string trim [infotag get cfg_avpair aa-pilot]]
     29    } else {
     30        set aaPilot "NONE"
     31    }
     32    if [infotag get cfg_avpair_exists operator] {
     33        set oprtr [string trim [infotag get cfg_avpair operator]]
     34    } else {
     35        set oprtr "NONE"
     36    }
     37    if [infotag get cfg_avpair_exists line1] {
     38        set menu1 [string trim [infotag get cfg_avpair line1]]
     39    } else {
     40        set menu1 "NONE"
     41    }   
     42    if [infotag get cfg_avpair_exists max-extension-length] {
     43      set maxExtensionLen [string trim [infotag get cfg_avpair max-extension-length]]
     44      if { $maxExtensionLen < 0 } {
     45          call close
     46         }
     47    } else {
     48        set maxExtensionLen 5
     49    }
     50}
     51
     52proc init_perCallVars { } {
     53    puts "\nproc init_perCallvars"
     54    global ani
     55    global digit_enabled
     56    global fcnt
     57    global retrycnt
     58    global dnis
     59
     60    set fcnt 0
     61    set retrycnt 6
     62    set ani ""
     63    set dnis ""
     64
     65    set digit_enabled "FALSE"
     66    set ani [infotag get leg_ani]
     67    puts "\nANI $ani"
     68    set dnis [infotag get leg_dnis]
     69    puts "\nDNIS $dnis"
     70}
     71
     72proc act_Setup { } {
     73    global param1
     74    global selectCnt
     75    global dest
     76    global beep
     77    global callInfo
     78    global dnis
     79    global fcnt
     80    global aaPilot
     81    global oprtr
     82    global menu1
     83    global busyPrompt
     84    global legConnected
     85
     86    puts "proc act_Setup"
     87    set busyPrompt _dest_unreachable.au
     88    set beep 0
     89    init_perCallVars
     90    infotag set med_language 1
     91
     92    if { ($dnis == "") || ($dnis == $aaPilot) } {
     93        leg setupack leg_incoming
     94        leg proceeding leg_incoming
     95        leg connect leg_incoming
     96        set legConnected true
     97
     98        puts "\nNo DNIS\n"
     99        set param1(dialPlan) true
    100        leg collectdigits leg_incoming param1
    101
    102        media play leg_incoming _welcome.au %s1000 _enter_dest.au
    103    } else {
    104        set fcnt 6
    105        leg setupack leg_incoming
    106        #handoff callappl leg_incoming default "DESTINATION=$dnis"
    107        set callInfo(alertTime) 30
    108        leg setup $dnis callInfo leg_incoming
    109        fsm setstate HANDOFF
    110    }
    111
    112
    113}
    114
    115proc act_GotDest { } {
    116    global dest
    117    global maxExtensionLen
    118    global destExtLen
    119    global callInfo
    120    global oprtr
    121    global menu1
    122    global busyPrompt
    123    puts "\n proc act_GotDest"
    124    set status [infotag get evt_status]
    125    set callInfo(alertTime) 30
    126
    127    if {  ($status == "cd_004") } {
    128        set dest [infotag get evt_dcdigits]
    129
    130        set destExtLen [string length $dest]
    131
    132      set extLength [expr $maxExtensionLen - $destExtLen]
    133        if { $dest == "0" } {
    134                set dest $oprtr
    135        }
    136        elseif { $dest == "1" } {
    137                #set dest $oprtr
    138                set dest $menu1
    139        }       
    140
    141        #handoff callappl leg_incoming default "DESTINATION=$dest"
    142        if {($maxExtensionLen > 0) && ($extLength >= 0)} {
    143            leg setup $dest callInfo leg_incoming
    144        } else {
    145            set busyPrompt _invalid_extn.au
    146            act_Select
    147        }
    148    } elseif { ($status == "cd_001") || ($status == "cd_002") } {
    149        set dest $oprtr
    150        #set dest $menu1
    151        #handoff callappl leg_incoming default "DESTINATION=$dest"
    152        leg setup $dest callInfo leg_incoming
    153    }   else {
    154        if { $status == "cd_006" } {
    155                set busyPrompt _dest_unreachable.au
    156        }
    157        puts "\nCall [infotag get con_all] got event $status collecting destination"
    158        set dest [infotag get evt_dcdigits]
    159        if { $dest == "0" } {
    160                set dest $oprtr
    161                #set dest $menu1
    162                #handoff callappl leg_incoming default "DESTINATION=$dest"
    163                leg setup $dest callInfo leg_incoming
    164        }
    165        elseif { $dest == "1" } {
    166                #set dest $oprtr
    167                set dest $menu1
    168                #handoff callappl leg_incoming default "DESTINATION=$dest"
    169                leg setup $dest callInfo leg_incoming
    170        }         
    171        else {
    172                act_Select
    173        }
    174    }
    175}
    176
    177proc act_CallSetupDone { } {
    178    global busyPrompt
    179    global legConnected
    180
    181    set status [infotag get evt_status]
    182    if { $status == "ls_000" } {
    183        puts "\n Connection success"
    184        handoff appl leg_all default
    185        act_Cleanup
    186    } else {
    187        if { $legConnected == "false" } {
    188            leg proceeding leg_incoming 
    189            leg connect leg_incoming 
    190            set legConnected true
    191        }
    192        puts "\n Call failed.  Play prompt and collect digit"
    193        if { ($status == "ls_007") } {
    194            set busyPrompt _dest_busy.au
    195        }
    196        act_Select
    197   }
    198}
    199
    200proc act_Select { } {
    201    global destination
    202    global promptFlag2
    203    global destBusy
    204    global param1
    205    global fcnt
    206    global retrycnt
    207    global busyPrompt
    208   
    209    puts "\n proc act_Select"
    210
    211    set promptFlag2 0
    212    set param1(interruptPrompt) true
    213    set param1(abortKey) *
    214    set param1(terminationKey) #
    215    set param1(dialPlan) true
    216    set param1(dialPlanTerm) true
    217
    218    leg collectdigits leg_incoming param1
    219    if { $fcnt < $retrycnt } {
    220        media play leg_incoming $busyPrompt %s500 _reenter_dest.au
    221        incr fcnt
    222        fsm setstate GETDEST
    223    } else {
    224        act_DestBusy
    225    }
    226}
    227
    228proc act_DestBusy { } {
    229    puts "\n proc act_DestBusy"
    230    media play leg_incoming _disconnect.au
    231    fsm setstate CALLDISCONNECT
    232}
    233
    234proc act_Cleanup { } {
    235    call close
    236}
    237
    238requiredversion 2.0
    239init
    240
    241init_ConfigVars
    242#----------------------------------
    243#   State Machine
    244#----------------------------------
    245  set fsm(any_state,ev_disconnected)   "act_Cleanup  same_state"
    246
    247  set fsm(any_state,ev_disconnect_done)   "act_Cleanup  same_state"
    248 
    249  set fsm(CALL_INIT,ev_setup_indication) "act_Setup  GETDEST"
    250
    251  set fsm(GETDEST,ev_collectdigits_done) "act_GotDest HANDOFF"
    252
    253  #set fsm(HANDOFF,ev_returned)   "act_CallSetupDone  CONTINUE"
    254
    255  set fsm(HANDOFF,ev_setup_done)   "act_CallSetupDone  CONTINUE"
    256
    257  set fsm(CALLDISCONNECT,ev_media_done) "act_Cleanup  same_state"
    258 
    259  fsm define fsm CALL_INIT
    260# Script Approval Signature: C/775c


    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Raghavendra Gutty Veeranagappa on 26-04-2012 03:26:00 AM
    Hi michal,

    script looks fine could you please send us the logs by enabling below debugs.

    debug voip app

    Thanks,
    Raghavendra

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 26-04-2012 03:47:10 AM
    here you are :
    script file name is miguel
    service name miguelaa

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 26-04-2012 08:43:02 AM
    here you are :
    script file name is miguel
    service name miguelaa

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 26-04-2012 09:17:07 AM
    ok, I corrected
    }
    elseif { } {


    to
    } elseif { } {


    didn't know it meant..

    right now calling is ok, but ... after 15 seconds (same time like waiting for an operator)
    is it possible to process digits immediately ?

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 26-04-2012 09:33:49 AM
    what is more strange...
    I modified script to accept 5 menu options (5 lines - line1... line5)
    passed 3 values line1, line2, line3
    while choosing 3 button - call is immediately passed to "line3" number
    buttons 1 and 2 - wait 15seconds

    I thought it was the case of last defined number, and added 4th, but result is weird :
    buttons : 1,2,4 - 15 second timeout
    button 3 - immediate redirect

    how come ?
    (modified script in attachment)

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Raghavendra Gutty Veeranagappa on 26-04-2012 10:09:18 AM
    Hi michal,

    as i said in previous post you can use maxdigits pattern

    set param1(maxDigits) 1

    Thanks,
    Raghavendra

    Subject: RE: Press 1, Press 2, route to variables
    Replied by: Michal Myszor on 27-04-2012 03:00:43 AM
    working like a charm
    thank you