change number on out-bound

Version 1
    This document was generated from CDN thread

    Created by: Jonathan Smith on 15-02-2011 10:26:02 AM
    Hi folks,
     
    I'm trying to change the destination number of a call, in order to add or remove a leading 1 as required.  My script seems to just get in a loop and I'm not sure why.  Debugging is difficult because the router becomes unresponsive and my connection drops before I can see much of what's happening.  This keeps up until the router starts auto-killing my misbehaving script.
     
    From what I can tell, it looks like my script gets called over and over again, even though there's only been 1 call placed.  I'm not sure exactly how it works when my script is invoked on out-bound but my thought is that I end up recursively calling my script when I call leg setup.  I don't know how I would complete the call without calling leg setup though.  There seem to be no examples of scripts written on the out-bound side and I'm running out of ideas.  Any help would be awsome.
     
    Here is a basic testing script that is supposed to just call out the number it gets in:
     

     1
     2proc init { } {
     3    puts "JRS: in init, does nothing"
     4}
     5 
     6proc do_setup { } {
     7 
     8    puts "JRS: starting setup"
     9 
    10    global dnis
    11    set dnis [infotag get evt_handoff dnis]
    12    puts "got number $dnis"
    13    puts "calling setup"
    14    leg setup $dnis callInfo leg_incoming
    15 
    16    puts "JRS: ending setup"
    17 
    18}
    19 
    20 
    21proc do_cleanup { } {
    22 
    23    puts "JRS: starting cleanup"
    24 
    25    call close
    26 
    27    puts "JRS: ending cleanup"
    28 
    29}
    30 
    31 
    32proc print_event { } {
    33 
    34    puts "JRS: starting print_event"
    35 
    36    set ev [infotag get evt_event]
    37    set st [infotag get evt_status]
    38    puts "recieved event $ev with status $st"
    39 
    40    puts "JRS: ending print_event"
    41 
    42}
    43 
    44proc do_connect { } {
    45 
    46    puts "JRS: starting do_connect"
    47 
    48    set st [infotag get evt_status]
    49    puts "setup status was $st"
    50    if { $st == "ls_000" } {
    51        puts "call setup completed"
    52        fsm setstate IN_CALL
    53    } else {
    54        puts "setup failed, closing call"
    55        call close
    56    }
    57    puts "JRS: ending do_connect"
    58 
    59}
    60 
    61 
    62init
    63 
    64#------------
    65# States
    66#
    67# CALL_SETUP - waiting to setup a call
    68# IN_SETUP - called leg setup waiting for response
    69# IN_CALL - currently there is an inprocess call
    70#------------
    71 
    72set my_fsm(any_state,ev_disconnected) "do_cleanup same_state"
    73set my_fsm(CALL_SETUP,ev_handoff) "do_setup IN_SETUP"
    74set my_fsm(IN_SETUP,ev_setup_done) "do_connect same_state"
    75set my_fsm(IN_CALL,ev_any_event) "print_event same_state"
    76 
    77fsm define my_fsm CALL_SETUP
    78 


     
     
    and here is some debug output, as much as I can get
     

     1
     2.Feb 15 15:13:54.687: //-1//SERV:/AFW_Service_CCInterface: Received Event 26 for service Default modulehandle NULL
     3.Feb 15 15:13:54.687: //-1//SERV:/AFW_Service_GetExecEnv: Script Name = Default
     4.Feb 15 15:13:54.687: //-1//SERV:/AFW_Service_GetExecEnv: Using Cached ExecEnv
     5.Feb 15 15:13:54.687: //-1//AFW_:/AFW_M_TclModule_NewDup:
     6.Feb 15 15:13:54.687: //-1//AFW_:HN24135ED0:/AFW_M_TclModule_Free:  MOD[TclModule_4B71C830_2_605128748] ( )
     7.Feb 15 15:13:54.687: //-1//AFW_:EE4B729404000:/AFW_ExecEnv_RestoreDataBackup: Restore DataArea from Script
     8.Feb 15 15:13:54.687: //-1//AFW_:EE4B729404000:/AFW_ExecEnv_RestoreDataBackup: Restore TokenTable from Script
     9.Feb 15 15:13:54.687: //146512/09A7E2F1BAA9/AFW_:/incrementIncomingDialPeerCallStats: Incrementing call-stat to [0] for dial-peer [40002]
    10.Feb 15 15:13:54.691: //146512//AFW_:/AFW_M_TclModule_Action:
    11.Feb 15 15:13:54.691: //146512//AFW_:/AFW_TclModule_DefaultEvHandling:
    12.Feb 15 15:13:54.695: //-1//SERV:/AFW_Service_CCInterface: Received Event 16 for service kevinapp modulehandle NULL
    13.Feb 15 15:13:54.695: //-1//SERV:/AFW_Service_GetExecEnv: Script Name = kevinapp
    14.Feb 15 15:13:54.699: //-1//AFW_:/AFW_TclModule_New:
    15.Feb 15 15:13:54.699: //-1//AFW_:EE4BCE4C50000:/Tcl_Link: Linking script kevinapp
    16.Feb 15 15:13:54.703: //-1//ACPK:EE4BCE4C50000:/AppCommon_SetSecurity: security = undefined
    17.Feb 15 15:13:54.703: //-1//ACPK:EE4BCE4C50000:/AppCommon_SetEventLog: event-log = unconfigured
    18.Feb 15 15:13:54.707: //-1//TCL :EE4BCE4C50000:/tcl_PutsObjCmd: JRS: in init, does nothing
    19.Feb 15 15:13:54.707:
    20.Feb 15 15:13:54.707: //-1//TCL :EE4BCE4C50000:/tcl_FSMObjCmd:  fsm define my_fsm CALL_SETUP
    21.Feb 15 15:13:54.707: //-1//TCL :EE4BCE4C50000:/tcl_FSMDefineObjCmd: State Machine: Array my_fsm: Start State: CALL_SETUP
    22.Feb 15 15:13:54.707: //-1//TCL :EE4BCE4C50000:/tcl_FSMDefineObjCmd: FSM Data structure
    23.Feb 15 15:13:54.707: (CALL_SETUP(1), ev_handoff(22)--(do_setup)-->(IN_SETUP(2))
    24.Feb 15 15:13:54.707: (IN_CALL(3), ev_any_event(0)--(print_event)-->(any_state(0))
    25.Feb 15 15:13:54.707: (any_state(0), ev_disconnected(18)--(do_cleanup)-->(any_state(0))
    26.Feb 15 15:13:54.707: (IN_SETUP(2), ev_setup_done(204)--(do_connect)-->(any_state(0))
    27.Feb 15 15:13:54.707: FSM start state CALL_SETUP(1)
    28.Feb 15 15:13:54.707: //-1//AFW_:EE4BCE4C50000:/Tcl_Link: Script kevinapp succesfully linked.
    29.Feb 15 15:13:54.707: //-1//AFW_:EE4BCE4C50000:/AFW_ExecEnv_SetScript: Num of packTable entries: 21
    30.Feb 15 15:13:54.711: //-1//SERV:/AFW_Service_Process_Space:
    31.Feb 15 15:13:54.711: Process Started
    32.Feb 15 15:13:54.715: //146512//AFW_:/AFW_M_TclModule_Action:
    33.Feb 15 15:13:54.715: //146512//AFW_:/AFW_TclModule_DefaultEvHandling:
    34.Feb 15 15:13:54.715: //146512//TCL :/tcl_PutsObjCmd: JRS: starting setup
    35.Feb 15 15:13:54.715:
    36.Feb 15 15:13:54.715: //146512//TCL :/tcl_InfotagObjCmd:  infotag get evt_handoff dnis
    37.Feb 15 15:13:54.715: //146512//TCL :/tcl_InfotagGetObjCmd: infotag get evt_handoff dnis
    38.Feb 15 15:13:54.715: //146512//AFW_:/vtr_ev_handoff: argc 3 argindex 2
    39.Feb 15 15:13:54.715: //146512//AFW_:/vtr_ev_handoff: event=CC_EV_CALL_HANDOFF, string=14165551234
    40.Feb 15 15:13:54.715: //146512//TCL :/tcl_PutsObjCmd: got number 14165551234
    41.Feb 15 15:13:54.715:
    42.Feb 15 15:13:54.715: //146512//TCL :/tcl_PutsObjCmd: calling setup
    43.Feb 15 15:13:54.719:
    44.Feb 15 15:13:54.719: //146512//TCL :/tcl_LegObjCmd:  leg setup 14165551234 callInfo leg_incoming
    45.Feb 15 15:13:54.719: //146512//AFW_:/vtd_lg_incoming: argc 4
    46.Feb 15 15:13:54.719: //146512//AFW_:/vtd_lg_incoming: Legs [146512 ]
    47.Feb 15 15:13:54.719: //146512//Tcl :/tcl_parseCallID_vartagObj: VARTAG Translation Leg Count=1
    48.Feb 15 15:13:54.723: //-1//SERV:/AFW_Service_CCInterface: Received Event 16 for service kevinapp modulehandle NULL
    49.Feb 15 15:13:54.723: //-1//SERV:/AFW_Service_GetExecEnv: Script Name = kevinapp
    50.Feb 15 15:13:54.723: //-1//AFW_:/AFW_TclModule_New:
    51.Feb 15 15:13:54.723: //-1//AFW_:EE4BCE4D38000:/Tcl_Link: Linking script kevinapp
    52.Feb 15 15:13:54.727: //-1//ACPK:EE4BCE4D38000:/AppCommon_SetSecurity: security = undefined
    53.Feb 15 15:13:54.727: //-1//ACPK:EE4BCE4D38000:/AppCommon_SetEventLog: event-log = unconfigured
    54.Feb 15 15:13:54.731: //-1//TCL :EE4BCE4D38000:/tcl_PutsObjCmd: JRS: in init, does nothing
    55.Feb 15 15:13:54.731:
    56.Feb 15 15:13:54.731: //-1//TCL :EE4BCE4D38000:/tcl_FSMObjCmd:  fsm define my_fsm CALL_SETUP
    57.Feb 15 15:13:54.731: //-1//TCL :EE4BCE4D38000:/tcl_FSMDefineObjCmd: State Machine: Array my_fsm: Start State: CALL_SETUP
    58.Feb 15 15:13:54.731: //-1//TCL :EE4BCE4D38000:/tcl_FSMDefineObjCmd: FSM Data structure
    59.Feb 15 15:13:54.731: (CALL_SETUP(1), ev_handoff(22)--(do_setup)-->(IN_SETUP(2))
    60.Feb 15 15:13:54.731: (IN_CALL(3), ev_any_event(0)--(print_event)-->(any_state(0))
    61.Feb 15 15:13:54.735: (any_state(0), ev_disconnected(18)--(do_cleanup)-->(any_state(0))
    62.Feb 15 15:13:54.735: (IN_SETUP(2), ev_setup_done(204)--(do_connect)-->(any_state(0))
    63.Feb 15 15:13:54.735: FSM start state CALL_SETUP(1)
    64.Feb 15 15:13:54.735: //-1//AFW_:EE4BCE4D38000:/Tcl_Link: Script kevinapp succesfully linked.
    65.Feb 15 15:13:54.735: //-1//AFW_:EE4BCE4D38000:/AFW_ExecEnv_SetScript: Num of packTable entries: 21
    66.Feb 15 15:13:54.735: //146512//TCL :/tcl_PutsObjCmd: JRS: ending setup
    67.Feb 15 15:13:54.735:
    68.Feb 15 15:13:54.735: //146512//AFW_:/AFW_M_TclModule_Action:
    69.Feb 15 15:13:54.735: //146512//AFW_:/AFW_TclModule_DefaultEvHandling:
    70.Feb 15 15:13:54.735: //146512//TCL :/tcl_PutsObjCmd: JRS: starting setup
    71.Feb 15 15:13:54.735:
    72.Feb 15 15:13:54.735: //146512//TCL :/tcl_InfotagObjCmd:  infotag get evt_handoff dnis
    73.Feb 15 15:13:54.739: //146512//TCL :/tcl_InfotagGetObjCmd: infotag get evt_handoff dnis
    74.Feb 15 15:13:54.739: //146512//AFW_:/vtr_ev_handoff: argc 3 argindex 2
    75.Feb 15 15:13:54.739: //146512//AFW_:/vtr_ev_handoff: event=CC_EV_CALL_HANDOFF, string=14165551234
    76.Feb 15 15:13:54.739: //146512//TCL :/tcl_PutsObjCmd: got number 14165551234
    77.Feb 15 15:13:54.739:
    78.Feb 15 15:13:54.739: //146512//TCL :/tcl_PutsObjCmd: calling setup
    79.Feb 15 15:13:54.739:
    80.Feb 15 15:13:54.739: //146512//TCL :/tcl_LegObjCmd:  leg setup 14165551234 callInfo leg_incoming
    81.Feb 15 15:13:54.739: //146512//AFW_:/vtd_lg_incoming: argc 4
    82.Feb 15 15:13:54.739: //146512//AFW_:/vtd_lg_incoming: Legs [146512 ]
    83.Feb 15 15:13:54.739: //146512//Tcl :/tcl_parseCallID_vartagObj: VARTAG Translation Leg Count=1
    84.Feb 15 15:13:54.743: //-1//SERV:/AFW_Service_CCInterface: Received Event 16 for service kevinapp modulehandle NULL
    85.Feb 15 15:13:54.743: //-1//SERV:/AFW_Service_GetExecEnv: Script Name = kevinapp
    86.Feb 15 15:13:54.743: //-1//AFW_:/AFW_TclModule_New:

    Subject: RE: change number on out-bound
    Replied by: Raghavendra Gutty Veeranagappa on 16-02-2011 07:37:45 AM
    Hi Jonathan,

    I think the issue with dial-peer, the dial-peer you have used for associating TCL script and the dial-peer for matching this dest(14165551234) are same.

    Thanks,
    Raghavendra

    Subject: RE: change number on out-bound
    Replied by: Jonathan Smith on 17-02-2011 11:31:53 AM
    Raghavendra,

    Yes the script is dialing out the same dial-peer as it is on.  I thought that was the problem but I was hoping I was missing something.  I have moved the script to the inbound side now.  This will cause complications for me in the future, but it is working now and I'll worry about this again then.

    Thanks for your help.

    Subject: RE: change number on out-bound
    Replied by: Chris Bomba on 17-06-2013 12:10:11 PM
    Jonathan Smith:
    Raghavendra,

    Yes the script is dialing out the same dial-peer as it is on.  I thought that was the problem but I was hoping I was missing something.  I have moved the script to the inbound side now.  This will cause complications for me in the future, but it is working now and I'll worry about this again then.

    Thanks for your help.

    I was hoping to do the same thing you are doing but I want to put my matching pairs in a flat file because there are 1100 entries.  How would I call the file from the tcl script?

    Subject: RE: change number on out-bound
    Replied by: Jonathan Smith on 17-06-2013 01:41:14 PM
    Chris Bomba:
    Jonathan Smith:
    Raghavendra,

    Yes the script is dialing out the same dial-peer as it is on.  I thought that was the problem but I was hoping I was missing something.  I have moved the script to the inbound side now.  This will cause complications for me in the future, but it is working now and I'll worry about this again then.

    Thanks for your help.

    I was hoping to do the same thing you are doing but I want to put my matching pairs in a flat file because there are 1100 entries.  How would I call the file from the tcl script?

    Hi Chris,

    I never read the pairs from a file so I can't help with that.  I did have ~1600 entries in my TCL script though so your 1100 shouldn't be any worse.

    Here was what I did in my script:

     1
     2# fixnum num
     3# num - the phone number you want to fix
     4# takes num, decides if it's local or long distance and adds/removes a leading 1 as required
     5# returns the new phone number with or without the 1
     6proc fixnum {num} {
     7
     8# a list of all local prefixes
     9# if a match isn't found in this list it is assumed the number is long distance
    10# these must all be 6 characters long or you will need to change the code
    11set local [list \
    12 289200 \
    13 289202 \
    14# removed lots of numbers
    15 289206 \
    16 905998 \
    17 905999 \
    18              ];
    19
    20
    21# if the number is < 10 digits don't change it
    22if { [ string length $num ] < 10 } {
    23    return $num;
    24}
    25
    26# get the first digit
    27set fd [ string index $num 0 ];
    28
    29#if the first digit is 0 don't change it (meant for international 011 calls)
    30if { $fd == 0 } {
    31    return $num;
    32}
    33
    34# if first digit is 1 we drop the 1 regardless, we want to work the first 6 digits, starting with the area code
    35if { $fd == 1 } {
    36    set num [ string range $num 1 [ string length $num ] ];
    37}
    38
    39# get first 6 digits, and see if they're in the list of local numbers
    40set snum [ string range $num 0 5 ];
    41set islocal [ lsearch $local $snum ];
    42
    43# if they're not local add the 1 at the start
    44if { $islocal == -1 } {
    45    set num "1$num";
    46}
    47
    48# return the number with the 1 added/removed as required
    49return $num;
    50
    51}


    Subject: RE: change number on out-bound
    Replied by: Jonathan Smith on 17-06-2013 01:48:35 PM
    Chris Bomba:
    Jonathan Smith:
    Raghavendra,

    Yes the script is dialing out the same dial-peer as it is on.  I thought that was the problem but I was hoping I was missing something.  I have moved the script to the inbound side now.  This will cause complications for me in the future, but it is working now and I'll worry about this again then.

    Thanks for your help.

    I was hoping to do the same thing you are doing but I want to put my matching pairs in a flat file because there are 1100 entries.  How would I call the file from the tcl script?

    Hi Chris,

    I never read the pairs from a file so I can't help with that.  I did have ~1600 entries in my TCL script though so your 1100 shouldn't be any worse.

    Here was what I did in my script.  It worked for us, but this was the first thing I ever wrote in TLC so there's probably a better way to do it.

     1
     2# fixnum num
     3# num - the phone number you want to fix
     4# takes num, decides if it's local or long distance and adds/removes a leading 1 as required
     5# returns the new phone number with or without the 1
     6proc fixnum {num} {
     7
     8# a list of all local prefixes
     9# if a match isn't found in this list it is assumed the number is long distance
    10# these must all be 6 characters long or you will need to change the code
    11set local [list \
    12 289200 \
    13 289202 \
    14 289206 \
    15# removed lots of numbers
    16 905998 \
    17 905999 \
    18              ];
    19
    20
    21# if the number is < 10 digits don't change it
    22if { [ string length $num ] < 10 } {
    23    return $num;
    24}
    25
    26# get the first digit
    27set fd [ string index $num 0 ];
    28
    29#if the first digit is 0 don't change it (meant for international 011 calls)
    30if { $fd == 0 } {
    31    return $num;
    32}
    33
    34# if first digit is 1 we drop the 1 regardless, we want to work the first 6 digits, starting with the area code
    35if { $fd == 1 } {
    36    set num [ string range $num 1 [ string length $num ] ];
    37}
    38
    39# get first 6 digits, and see if they're in the list of local numbers
    40set snum [ string range $num 0 5 ];
    41set islocal [ lsearch $local $snum ];
    42
    43# if they're not local add the 1 at the start
    44if { $islocal == -1 } {
    45    set num "1$num";
    46}
    47
    48# return the number with the 1 added/removed as required
    49return $num;
    50
    51}


    Subject: RE: change number on out-bound
    Replied by: Jonathan Smith on 17-06-2013 01:50:58 PM
    Chris Bomba:
    Jonathan Smith:
    Raghavendra,

    Yes the script is dialing out the same dial-peer as it is on.  I thought that was the problem but I was hoping I was missing something.  I have moved the script to the inbound side now.  This will cause complications for me in the future, but it is working now and I'll worry about this again then.

    Thanks for your help.

    I was hoping to do the same thing you are doing but I want to put my matching pairs in a flat file because there are 1100 entries.  How would I call the file from the tcl script?

    Hi Chris,

    I never read the pairs from a file so I can't help with that.  I did have ~1600 entries in my TCL script though so your 1100 shouldn't be any worse.

    Here was what I did in my script.  It worked for us, but this was the first thing I ever wrote in TLC so there's probably a better way to do it.

     1
     2# fixnum num
     3# num - the phone number you want to fix
     4# takes num, decides if it's local or long distance and adds/removes a leading 1 as required
     5# returns the new phone number with or without the 1
     6proc fixnum {num} {
     7
     8# a list of all local prefixes
     9# if a match isn't found in this list it is assumed the number is long distance
    10# these must all be 6 characters long or you will need to change the code
    11set local [list \
    12 289200 \
    13 289202 \
    14 289206 \
    15# removed lots of numbers
    16 905998 \
    17 905999 \
    18              ];
    19
    20
    21# if the number is < 10 digits don't change it
    22if { [ string length $num ] < 10 } {
    23    return $num;
    24}
    25
    26# get the first digit
    27set fd [ string index $num 0 ];
    28
    29#if the first digit is 0 don't change it (meant for international 011 calls)
    30if { $fd == 0 } {
    31    return $num;
    32}
    33
    34# if first digit is 1 we drop the 1 regardless, we want to work the first 6 digits, starting with the area code
    35if { $fd == 1 } {
    36    set num [ string range $num 1 [ string length $num ] ];
    37}
    38
    39# get first 6 digits, and see if they're in the list of local numbers
    40set snum [ string range $num 0 5 ];
    41set islocal [ lsearch $local $snum ];
    42
    43# if they're not local add the 1 at the start
    44if { $islocal == -1 } {
    45    set num "1$num";
    46}
    47
    48# return the number with the 1 added/removed as required
    49return $num;
    50
    51}


    Subject: RE: change number on out-bound
    Replied by: Chris Bomba on 17-06-2013 02:49:50 PM
    I am trying to accomplish the exact same thing.  What else do I need to finish the script?  I am sending the 9 to the gateway so I made some adjustments, do they look right?
     1# if the number is < 10 digits don't change it
     2if { [ string length $num ] < 10 } {
     3    return $num;
     4}
     5
     6# get the first two digits
     7set ftd [ string range $num 0 1 ];
     8
     9#if the first two digits are 90 don't change it (meant for international 011 calls)
    10if { $ftd == 90 } {
    11    return $num;
    12}
    13
    14# if first two digits are 91 we drop the 1 regardless, we want to work the first 6 digits, starting with the area code
    15if { $ftd == 91 } {
    16    set num [ string range $num 2 [ string length $num ] ];
    17}
    18
    19# get first 6 digits, and see if they're in the list of local numbers
    20set snum [ string range $num 0 5 ];
    21set islocal [ lsearch $local $snum ];
    22
    23# if they're not local add the 91 at the start
    24if { $islocal == -1 } {
    25    set num "91$num";
    26}
    27
    28# return the number with the 1 added/removed as required
    29return $num;


    Subject: RE: change number on out-bound
    Replied by: Chris Bomba on 19-06-2013 08:56:25 AM
    Does this logic go under proc do_setup?

    Subject: RE: change number on out-bound
    Replied by: Lisandro Quinteros on 19-06-2013 09:40:06 AM
    Chris, I haven't read your complete script, but you could put that logic after you got the dialed number on a variable and before leg setup..


      set dnis [infotag get evt_handoff dnis]
    # I think you  could put that logic between this lines

      leg setup $dnis callInfo leg_incoming

    Take care about variables becouse  

    Jonathan Smith 

    is using $num and you are using $dnis