Sending call from one script to another by pressing digit

Version 1
    This document was generated from CDN thread

    Created by: Chris Bomba on 19-10-2011 12:22:54 PM
    I know there is a better way to do this in one script but I have the following scrip that I use to ask the user to press 1 or 2 and then transfer to the variables that are associated with either "param operator" or "param operator1" within the router.  I need to add a level on top of that and ask the user to first press 1 for French and 2 for English.  I am going to have a the French prompts just play, not worring about the default error prompts being in French. 
     
    I tried to setup the following but I get the below error:
     
    Setup: (Users call into POTS lines and get the first service.  It asks them to press 1 for French and 2 for English).  I thought I could just send the users to a VoIP dial-peer pointing to the Loopback interface to get them into the other scripts.  The other scripts look exactly the same as the first except the "_welcome.au" prompt was renamed to "_french.au" and "_english.au" respectively.
     
     service Flagship-OptionA flash:its-CISCO-Flagship-OptionA.tcl

      paramspace english language en

      paramspace english index 0

      param operator1 8002

      param queue-len 2

      paramspace english location flash:

      param aa-pilot 8000

      param en 0

      param operator 8001
     
    service Flagship-OptionA-French flash:its-CISCO-Flagship-OptionA-French.tcl
      paramspace english language en
      paramspace english index 0
      param aa-pilot 8001
      param en 0
      paramspace english location flash:
      param operator 72105
      param operator1 72102
      param queue-len 2
    service Flagship-OptionA-English flash:its-CISCO-Flagship-OptionA-English.tcl
      paramspace english language en
      paramspace english index 0
      param aa-pilot 8002
      param en 0
      paramspace english location flash:
      param operator 72105
      param operator1 72102
      param queue-len 2
    !
    dial-peer voice 20 pots
     service flagship-optiona
     port 0/0/0
    !
    dial-peer voice 21 pots
     service flagship-optiona
     port 0/0/1
    !
    dial-peer voice 22 pots
     service flagship-optiona
     port 0/0/2
    !
    dial-peer voice 30 voip
     service flagship-optiona-french
     destination-pattern 8001
     session target ipv4:192.168.100.5
     dtmf-relay h245-alphanumeric
     codec g711ulaw
     no vad
    !
    dial-peer voice 31 voip
     service flagship-optiona-english
     destination-pattern 8002
     session target ipv4:192.168.100.5
     dtmf-relay h245-alphanumeric
     codec g711ulaw
     no vad

     
    Error:
     
    Router#
    000801: Oct 19 12:07:01.155 EDT: //32//TCL :/tcl_PutsObjCmd: proc act_Setup
    000802: Oct 19 12:07:01.155 EDT:
    000803: Oct 19 12:07:01.155 EDT: //32//TCL :/tcl_PutsObjCmd:
    proc init_perCallvars
    000804: Oct 19 12:07:01.159 EDT:
    000805: Oct 19 12:07:01.159 EDT: //32//TCL :/tcl_PutsObjCmd:
    ANI 13576
    000806: Oct 19 12:07:01.159 EDT:
    000807: Oct 19 12:07:01.159 EDT: //32//TCL :/tcl_PutsObjCmd:
    DNIS 8000
    000808: Oct 19 12:07:01.159 EDT:
    000809: Oct 19 12:07:01.159 EDT: //-1//PACK:/Media_LangCode_GetByIndex: Unable to retrieve language element with index 1
    000810: Oct 19 12:07:01.159 EDT: //32//TCL :/tcl_PutsObjCmd:
    No DNIS

    000811: Oct 19 12:07:01.159 EDT:
    000812: Oct 19 12:07:04.463 EDT: //32//AFW_:/AFW_FSM_Drive: FSM no match for (GETDEST[3],ev_media_done[175])
    000813: Oct 19 12:07:07.607 EDT: //32//TCL :/tcl_PutsObjCmd:
     proc act_GotDest
    000814: Oct 19 12:07:07.607 EDT:
    000815: Oct 19 12:07:07.607 EDT: //32//TCL :/tcl_PutsObjCmd:
    Call  got event cd_005 collecting destination
    000816: Oct 19 12:07:07.607 EDT:
    000817: Oct 19 12:07:07.607 EDT: //-1//AFW_:/AFW_Util_CopyLegServiceCodeToCallInfoContainer: Service Code not available on Leg
    000818: Oct 19 12:07:07.607 EDT: //-1//AFW_:/AFW_Util_CopyLegRouteCodeToCallInfoContainer: Route Code not available on Leg
    000819: Oct 19 12:07:07.607 EDT: //-1//AFW_:/AFW_Util_GetTgCicValue: CIC Not  found for tag(56)
    000820: Oct 19 12:07:07.607 EDT: //-1//AFW_:/C_PackageSession_GetSigPeer:
    000821: Oct 19 12:07:07.607 EDT: //32/3690BBAF8035/AFW_:/C_PackageSession_GetSigPeer: No Interworking module on Leg, no signal peer
    000822: Oct 19 12:07:07.607 EDT: //-1//AFW_:/AFW_Util_CopyMLPPDataToCallInfoContainer: Voice MLPP not configured
    000823: Oct 19 12:07:07.607 EDT: //-1//AFW_:/AFW_Util_CopyMLPPDataToCallInfoContainer: Voice MLPP not configured
    000824: Oct 19 12:07:07.607 EDT: //-1//AFW_:/AFW_Util_CopyMLPPDataToCallInfoContainer: Voice MLPP not configured
    000825: Oct 19 12:07:17.611 EDT: //32//TCL :/tcl_PutsObjCmd:
     Call failed.  Play prompt and collect digit
    000826: Oct 19 12:07:17.611 EDT:
    000827: Oct 19 12:07:17.611 EDT: //32//TCL :/tcl_PutsObjCmd:
     proc act_Select
    000828: Oct 19 12:07:17.611 EDT:
     
     
     
     
    Script looks like this:
     
    proc init { } {
        global param1
        global selectCnt
        global callInfo
        global legConnected
        global maxExtensionLen

        set param1(interruptPrompt) true
        set param1(abortKey) *
        set param1(terminationKey) #
            set param1(maxDigits) 1

        set selectCnt 0
        set legConnected false
    }

    proc init_ConfigVars { } {
        global destination
        global aaPilot
        global oprtr
        global oprtr1
        global maxExtensionLen

    # aa-pilot is the IVR number configured on the gateway to be used by the customer
    # operator is the operator number for assisted calling

        if [infotag get cfg_avpair_exists aa-pilot] {
            set aaPilot [string trim [infotag get cfg_avpair aa-pilot]]
        } else {
            set aaPilot "NONE"
        }
            if [infotag get cfg_avpair_exists operator] {
            set oprtr [string trim [infotag get cfg_avpair operator]]
        } else {
            set oprtr "NONE"
        }

            if [infotag get cfg_avpair_exists operator1] {
            set oprtr1 [string trim [infotag get cfg_avpair operator1]]
        } else {
            set oprtr1 "NONE"
        }
        if [infotag get cfg_avpair_exists max-extension-length] {
              set maxExtensionLen [string trim [infotag get cfg_avpair max-extension-length]]
              if { $maxExtensionLen < 0 } {
                      call close
                 }
        } else {
            set maxExtensionLen 1
        }
    }

    proc init_perCallVars { } {
        puts "\nproc init_perCallvars"
        global ani
        global digit_enabled
        global fcnt
        global retrycnt
        global dnis

        set fcnt 0
        set retrycnt 6
        set ani ""
        set dnis ""

        set digit_enabled "FALSE"
        set ani [infotag get leg_ani]
        puts "\nANI $ani"
        set dnis [infotag get leg_dnis]
        puts "\nDNIS $dnis"
    }

    proc act_Setup { } {
        global param1
        global selectCnt
        global dest
        global beep

        global callInfo
        global dnis
        global fcnt
        global aaPilot
        global oprtr
        global oprtr1
        global busyPrompt
        global legConnected

        puts "proc act_Setup"
        set busyPrompt _dest_unreachable.au
        set beep 0
        init_perCallVars
        infotag set med_language 1

        if { ($dnis == "") || ($dnis == $aaPilot) } {
            leg setupack leg_incoming
            leg proceeding leg_incoming
            leg connect leg_incoming
            set legConnected true

            puts "\nNo DNIS\n"
            set param1(dialPlan) true
            leg collectdigits leg_incoming param1

            media play leg_incoming _welcome.au
        } else {
            set fcnt 6
            leg setupack leg_incoming
            #handoff callappl leg_incoming default "DESTINATION=$dnis"
            set callInfo(alertTime) 30
            leg setup $dnis callInfo leg_incoming
            fsm setstate HANDOFF
        }


    }

    proc act_GotDest { } {
        global dest

        global maxExtensionLen
        global destExtLen
        global callInfo
        global oprtr
        global oprtr1
        global busyPrompt
        puts "\n proc act_GotDest"
        set status [infotag get evt_status]
        set callInfo(alertTime) 30

        if {  ($status == "cd_004") } {
            set dest [infotag get evt_dcdigits]

            set destExtLen [string length $dest]

              set extLength [expr $maxExtensionLen - $destExtLen]
            if { $dest == "1" } {
                    set dest $oprtr
            } elseif { $dest == "2" } {
                    set dest $oprtr1
            }

            #handoff callappl leg_incoming default "DESTINATION=$dest"
            if {($maxExtensionLen > 0) && ($extLength >= 0)} {
                leg setup $dest callInfo leg_incoming
            } else {
                set busyPrompt _invalid_extn.au
                act_Select
            }
        } elseif { ($status == "cd_001") || ($status == "cd_002") } {
            set dest $oprtr
            #handoff callappl leg_incoming default "DESTINATION=$dest"
            leg setup $dest callInfo leg_incoming
        }   else {
            if { $status == "cd_006" } {
                    set busyPrompt _dest_unreachable.au
            }
            puts "\nCall [infotag get con_all] got event $status collecting destination"
            set dest [infotag get evt_dcdigits]
            if { $dest == "1" } {

                    set dest $oprtr
                    #handoff callappl leg_incoming default "DESTINATION=$dest"
                    leg setup $dest callInfo leg_incoming
            } elseif { $dest == "2" } {
                    set dest $oprtr1
                    #handoff callappl leg_incoming default "DESTINATION=$dest"
                    leg setup $dest callInfo leg_incoming
            } else {
                    act_Select
            }
        }
    }

    proc act_CallSetupDone { } {
        global busyPrompt
        global legConnected

        set status [infotag get evt_status]
        if { $status == "ls_000" } {
            puts "\n Connection success"
            handoff appl leg_all default
            act_Cleanup
        } else {
            if { $legConnected == "false" } {
                leg proceeding leg_incoming
                leg connect leg_incoming
                set legConnected true
            }
            puts "\n Call failed.  Play prompt and collect digit"
            if { ($status == "ls_007") } {
                set busyPrompt _dest_busy.au
            }
            act_Select
       }
    }

    proc act_Select { } {
        global destination
        global promptFlag2
        global destBusy

        global param1
        global fcnt
        global retrycnt
        global busyPrompt

        puts "\n proc act_Select"

        set promptFlag2 0
        set param1(interruptPrompt) true
        set param1(abortKey) *
        set param1(terminationKey) #
        set param1(dialPlan) true
        set param1(dialPlanTerm) true
            set param1(maxDigits) 1

        leg collectdigits leg_incoming param1
        if { $fcnt < $retrycnt } {
            media play leg_incoming $busyPrompt %s500 _reenter_dest.au
            incr fcnt
            fsm setstate GETDEST
        } else {
            act_DestBusy
        }
    }

    proc act_DestBusy { } {
        puts "\n proc act_DestBusy"
        media play leg_incoming _disconnect.au
        fsm setstate CALLDISCONNECT
    }

    proc act_Cleanup { } {
        call close
    }

    requiredversion 2.0
    init

    init_ConfigVars
    #----------------------------------

    #   State Machine
    #----------------------------------
      set fsm(any_state,ev_disconnected)   "act_Cleanup  same_state"

      set fsm(any_state,ev_disconnect_done)   "act_Cleanup  same_state"

      set fsm(CALL_INIT,ev_setup_indication) "act_Setup  GETDEST"

      set fsm(GETDEST,ev_collectdigits_done) "act_GotDest HANDOFF"

      #set fsm(HANDOFF,ev_returned)   "act_CallSetupDone  CONTINUE"

      set fsm(HANDOFF,ev_setup_done)   "act_CallSetupDone  CONTINUE"

      set fsm(CALLDISCONNECT,ev_media_done) "act_Cleanup  same_state"

      fsm define fsm CALL_INIT
    # Script Approval Signature: C/775c

     
     
    Thanks,
    Chris
     

    Subject: RE: Sending call from one script to another by pressing digit
    Replied by: Yaw-Ming Chen on 19-10-2011 01:19:54 PM
    I didn't look deep into your script but I am wondering why in the service for French you use "paramspace english language en"

    Do you use "en_french.au" ?

    Since it complained about the following , try to change index to 1 see if it helps.

    Also to trigger another script you can use "handoff" command if you just handoff to another script and it is not related to any called number.

    "000809: Oct 19 12:07:01.159 EDT: //-1//PACK:/Media_LangCode_GetByIndex: Unable to retrieve language element with index 1"

    For two languages selection I usually do it in this way:
    Let call press "x" for "second" choice of language otherwise timeout or press "Y" to use default and use one script maybe easier to manage.



    service Flagship-OptionA-French flash:its-CISCO-Flagship-OptionA-French.tcl
      paramspace english language en
      paramspace english index 0
      param aa-pilot 8001
      param en 0
      paramspace english location flash:
      param operator 72105
      param operator1 72102
      param queue-len 2

    Subject: RE: Sending call from one script to another by pressing digit
    Replied by: Chris Bomba on 19-10-2011 01:55:27 PM
    I am using en_french.au.  I changed the index to 1 and that took care of that error.  How would I use the handoff command from the first service to the other two depending on pressing 1 or 2?

    Subject: RE: Sending call from one script to another by pressing digit
    Replied by: Yaw-Ming Chen on 19-10-2011 02:32:02 PM
    Please refer programming guide for detail.
    Assuming that we like to handoff from service A to service B

    Basically in service A script when ready to handoff we do

    handoff appl leg_incoming $name_of_service_B  -s "message to pass to service B"

    Then script for service B looks like the following :

    1. The event trigger is "ev_handoff"
    2. set r_string [infotag get evt_handoff_string] --> get the message passing from service A (may or may not need it)
    3. for ANI and DNIS need to use
        [infotag get evt_handoff dnis]
        [infotag get evt_handoff ani]
    to get them





    proc act_Handoff_receive { } {

    puts "Handoff_called: second aaplication initated"
    set r_legs [infotag get evt_legs ]
    puts " Handoff_called: This is are the legs from calling apps: $r_legs"
    set r_string [infotag get evt_handoff_string]
    puts  " Handoff_called: This is the string received while handoff  $r_string"
    set r_con [infotag get evt_connections]
    puts "DNIS of handed off leg: [infotag get evt_handoff dnis] "
    puts "ANI of handed off leg: [infotag get evt_handoff ani] "
    puts "Handoff_called: This is there in connections $r_con"
    handoff return $r_legs "Application Handoff returned"

    }

    #----------------------------------
    #   State Machine
    #----------------------------------

      set fsm(CALL_INIT,ev_handoff) "act_Handoff_receive      PLACECALL"
      fsm define fsm CALL_INIT

    Subject: RE: Sending call from one script to another by pressing digit
    Replied by: Chris Bomba on 19-10-2011 03:23:02 PM
    What kind of message would I want to pass?  I just need to get the call into the next application.  I tried the following but I got an error:


    First application:

     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                handoff appl leg_incoming FlagshipOptionAFrench
    46        } elseif { $dest == "2" } {
    47                set dest $oprtr1
    48                #handoff callappl leg_incoming default "DESTINATION=$dest"
    49                handoff appl leg_incoming FlagshipOptionAEnglish
    50        } else {
    51                act_Select
    52        }
    53    }
    54}


    Second application (clip):

     1proc act_Handoff_receive { } {
     2
     3puts "Handoff_called: second aaplication initated"
     4set r_legs [infotag get evt_legs ]
     5puts " Handoff_called: These are the legs from calling apps: $r_legs"
     6set r_string [infotag get evt_handoff_string]
     7puts " Handoff_called: This is the string received while handoff $r_string"
     8set r_con [infotag get evt_connections]
     9puts "DNIS of handed off leg: [infotag get evt_handoff dnis] "
    10puts "ANI of handed off leg: [infotag get evt_handoff ani] "
    11puts "Handoff_called: This is there in connections $r_con"
    12handoff return $r_legs "Application Handoff returned"
    13
    14}
    15
    16proc act_DestBusy { } {
    17    puts "\n proc act_DestBusy"
    18    media play leg_incoming _disconnect.au
    19    fsm setstate CALLDISCONNECT
    20}
    21
    22proc act_Cleanup { } {
    23    call close
    24}
    25
    26requiredversion 2.0
    27init
    28
    29init_ConfigVars
    30#----------------------------------
    31#   State Machine
    32#----------------------------------
    33  set fsm(CALL_INIT,ev_handoff) "act_Handoff_receive PLACECALL"
    34   
    35  set fsm(any_state,ev_disconnected)   "act_Cleanup  same_state"
    36
    37  set fsm(any_state,ev_disconnect_done)   "act_Cleanup  same_state"
    38 
    39  set fsm(CALL_INIT,ev_setup_indication) "act_Setup  GETDEST"
    40
    41  set fsm(GETDEST,ev_collectdigits_done) "act_GotDest HANDOFF"
    42
    43  #set fsm(HANDOFF,ev_returned)   "act_CallSetupDone  CONTINUE"
    44
    45  set fsm(HANDOFF,ev_setup_done)   "act_CallSetupDone  CONTINUE"
    46
    47  set fsm(CALLDISCONNECT,ev_media_done) "act_Cleanup  same_state"
    48 
    49  fsm define fsm CALL_INIT
    50# Script Approval Signature: C/775c


    Subject: RE: Sending call from one script to another by pressing digit
    Replied by: Yaw-Ming Chen on 19-10-2011 04:10:22 PM
    -s <argstring>¿Information to pass to another application instance.

    2. set r_string [infotag get evt_handoff_string] --> get the message passing from service A (may or may not need it)