Parsing Caller Name field

Version 1
    This document was generated from CDN thread

    Created by: Chris Bomba on 03-03-2010 08:14:51 PM
    I have a gateway that is connected to a PBX.  The PBX doesn't send any information in the Calling Number field but instead sends the "name number" combination in the Calling Name field.  I would like to run that call through a script, grab the data in the Calling Number field, parse that information so I can grab the extension, then populate the calling number field with the extension I extract and forward it along its merry way.  
     
    Anyone have an easy fixes?

    Subject: RE: Parsing Caller Name field
    Replied by: Yawming Chen on 03-03-2010 11:33:48 PM
    Joe @ 1234 calling 4321
    when call arrives at gateway the calling number filed shows something like Joe1234 and you like to extract that so when 4321 receives the call it's showing 1234 calling 4321, is this the right ?
     
    Thanks,
     
    Yawming

    Subject: RE: Parsing Caller Name field
    Replied by: Chris Bomba on 13-09-2011 10:45:21 AM
    I am back to this problem again.  I have an issue with a 35 year old PBX.  I have an E1 connection via DTMF and the PBX can only send me the calling information in one field.  The string would look something like:

    ani * dnis


    I need to parse that information and connect the call to the "dnis" while sending the ani along as the caller ID.  I found this someone wrote but not sure what else I need to add to it as well as how to parse the string "ani*dnis" to populate those two variables?

    proc act_GotDest { } {
    global dnis
    global LegId
    global ani

    set LegId [infotag get evt_legs]
    puts "LEGID: "
    puts $LegId

    set dnis [infotag get evt_handoff dnis]
    set ani [infotag get leg_ani]

    puts "DNIS: "
    puts $dnis


    set callInfo(originationNum) [infotag get evt_handoff ani]
    leg setup $dnis callInfo leg_incoming

    }

    requiredversion 2.0

    #
    # State Machine
    #----------------------------------
    set fsm(any_state,ev_disconnected) "act_Cleanup,same_state"
    set fsm(CALL_INIT,ev_handoff) "act_GotDest,CALLACTIVE"
    set fsm(CALLDISCONNECT,ev_disconnected) "act_Cleanup,same_state"

    fsm define fsm CALL_INIT

    Subject: RE: Parsing Caller Name field
    Replied by: Chris Bomba on 13-09-2011 10:51:18 AM
    I wonder if I should try altering the ani_filter.tcl script instead?

    Subject: RE: Parsing Caller Name field
    Replied by: Chris Bomba on 13-09-2011 11:50:05 AM
     1proc init { } {
     2    global param
     3}
     4
     5proc act_Setup { } {
     6   
     7    leg setupack leg_incoming
     8
     9    set dnis [infotag get leg_dnis]
    10    set ani [infotag get leg_ani]
    11    set ani_deny NULL
    12    set ani_pi [infotag get leg_ani_pi]
    13    puts "dnis $dnis ani $ani ani_pi $ani_pi"
    14    if { $ani_pi != "presentation_allowed" } {
    15      set ani NULL
    16    }
    17
    18    if { $dnis = (\d+)[*](\d+) } {
    19    set ani = \1 && set dnis = \2
    20}
    21
    22    puts "Final dnis $dnis"
    23    leg proceeding leg_incoming
    24    leg setup $dnis callInfo leg_incoming
    25}
    26
    27proc act_CallSetupDone { } {
    28    global beep
    29 
    30    set status [infotag get evt_status]
    31 
    32    puts "Entering act_CallSetupDone"
    33    if { $status != "ls_000"} {
    34        puts "Call [infotag get con_all] got event $status while placing an outgoing call"
    35        call close
    36    }
    37}
    38
    39proc act_Cleanup { } {
    40    puts "Entering act_Cleanup"
    41    call close
    42}
    43
    44proc act_Abort { } {
    45    puts "Unexpected event - entering act_Abort"
    46    call close
    47}
    48
    49init
    50 
    51#----------------------------------
    52#   State Machine
    53#----------------------------------
    54  set TopFSM(any_state,ev_disconnected) "act_Abort,same_state"
    55  set TopFSM(CALL_INIT,ev_setup_indication) "act_Setup,PLACECALL"
    56  set TopFSM(PLACECALL,ev_setup_done)  "act_CallSetupDone,CALLACTIVE"
    57  set TopFSM(CALLACTIVE,ev_disconnected)   "act_Cleanup,CALLDISCONNECTED"
    58  set TopFSM(CALLDISCONNECTED,ev_disconnect_done) "act_Cleanup,same_state"
    59
    60  fsm define TopFSM  CALL_INIT




    With the following section my attempt at separating the values.

    1    if { $dnis = (\d+)[*](\d+) } {
    2    set ani = \1 && set dnis = \2
    3}


    Subject: RE: Parsing Caller Name field
    Replied by: Chris Bomba on 13-09-2011 01:02:59 PM
    So then my script would look like this?

     1proc init { } {
     2    global param
     3}
     4
     5proc act_Setup { } {
     6   
     7    leg setupack leg_incoming
     8
     9    set dnis [infotag get leg_dnis]
    10    set ani [infotag get leg_ani]
    11    set ani_deny NULL
    12    set ani_pi [infotag get leg_ani_pi]
    13    puts "dnis $dnis ani $ani ani_pi $ani_pi"
    14    if { $ani_pi != "presentation_allowed" } {
    15      set ani NULL
    16    }
    17
    18
    19    if { $dnis = (\d+)[*](\d+) } {
    20      set s_list [split $dnis *]
    21    set ani = "lindex $s_list 0"
    22    set dnis = "lindex $s_list 1"
    23
    24    puts "Final dnis $dnis"
    25    leg proceeding leg_incoming
    26    leg setup $dnis callInfo leg_incoming}
    27    else {   
    28    puts "Final dnis $dnis"
    29    leg proceeding leg_incoming
    30    leg setup $dnis callInfo leg_incoming
    31}
    32
    33
    34
    35}
    36
    37proc act_CallSetupDone { } {
    38    global beep
    39 
    40    set status [infotag get evt_status]
    41 
    42    puts "Entering act_CallSetupDone"
    43    if { $status != "ls_000"} {
    44        puts "Call [infotag get con_all] got event $status while placing an outgoing call"
    45        call close
    46    }
    47}
    48
    49proc act_Cleanup { } {
    50    puts "Entering act_Cleanup"
    51    call close
    52}
    53
    54proc act_Abort { } {
    55    puts "Unexpected event - entering act_Abort"
    56    call close
    57}
    58
    59init
    60 
    61#----------------------------------
    62#   State Machine
    63#----------------------------------
    64  set TopFSM(any_state,ev_disconnected) "act_Abort,same_state"
    65  set TopFSM(CALL_INIT,ev_setup_indication) "act_Setup,PLACECALL"
    66  set TopFSM(PLACECALL,ev_setup_done)  "act_CallSetupDone,CALLACTIVE"
    67  set TopFSM(CALLACTIVE,ev_disconnected)   "act_Cleanup,CALLDISCONNECTED"
    68  set TopFSM(CALLDISCONNECTED,ev_disconnect_done) "act_Cleanup,same_state"
    69
    70  fsm define TopFSM  CALL_INIT


    Subject: RE: Parsing Caller Name field
    Replied by: Chris Bomba on 13-09-2011 03:19:15 PM
    That might have done it.  I have someone testing soon.  I will post results.

    Subject: RE: Parsing Caller Name field
    Replied by: Yaw-Ming Chen on 13-09-2011 12:41:56 PM
    for parsing a string with a separator you can just use normal Tcl command "split"
    For example the ani*dnis string is 123*456

    we have
    set mysctring 123*456

    set s_list [split $mystring *]

    after this we have a list 123 456

    to get the 1st element  use "lindex $s_list 0" you will get 123

    2nd element "lindex $s_list 1" you will get 456

    Subject: RE: Parsing Caller Name field
    Replied by: Yaw-Ming Chen on 13-09-2011 01:14:55 PM
    no

    like this:


    20      set s_list [split $dnis *]
    21    set ani  [lindex $s_list 0]
    22    set dnis [lindex $s_list 1]

    be careful that your "dnis" have been overwritten

    I did not look the test of script