How do I receive a REFER event in my TCL script?

Version 1
    This document was generated from CDN thread

    Created by: Keith Haugen on 10-04-2013 05:30:47 PM
    The TCL IVR 2.0 manual indicates under the SIP Call Transfer, Transferee support, that "
    A Tcl IVR script can receive a SIP REFER", but I do not seem to get any events in my TCL script until I get the NOTIFY.  What do I need to do to receive an event when my call gets a REFER?

    Subject: RE: How do I receive a REFER event in my TCL script?
    Replied by: Yaw-Ming Chen on 10-04-2013 05:44:08 PM
    Did you have  "infotag set evt_report "ev_transfer_request"" ?
     
    Do it whne you get "ev_setup_indication"
     infotag set evt_report "ev_transfer_request"

       leg setupack leg_incoming
       leg proceeding leg_incoming
       leg connect leg_incoming

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 11-04-2013 10:49:25 AM
    What I am really trying to do is catch a transfer request to a bad number – is there an event specific for that I can trigger off of, or do I need to look at the ev_transfer_request information and determine myself the number is bad (i.e., not matched by any dial peer)

    From: Cisco Developer Community Forums [mailto:cdicuser@developer.cisco.com]
    Sent: Wednesday, April 10, 2013 5:44 PM
    To: cdicuser@developer.cisco.com
    Subject: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API: RE: How do I receive a REFER event in my TCL script?

    Yaw-Ming Chen has created a new message in the forum "TCL-API": -------------------------------------------------------------- Did you have  "infotag set evt_report "ev_transfer_request"" ?

    Do it whne you get "ev_setup_indication"
    infotag set evt_report "ev_transfer_request"

       leg setupack leg_incoming
       leg proceeding leg_incoming
       leg connect leg_incoming
    --
    To respond to this post, please click the following link: http://developer.cisco.com/web/vgapi/forums/-/message_boards/view_message/14131335 or simply reply to this email.

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Yaw-Ming Chen on 11-04-2013 11:18:52 AM
    For transfer we are waiting for ev_transfer_reques then do "infotag get evt_transfer_info ......" to get transfer information
    Thanks !

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 11-04-2013 11:41:39 AM
    So to make sure I understand, there is no way for the TCL script to avoid doing all the transfer setup and only trigger off the events for transfer failure (such as trying to transfer to an invalid number?)

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Yaw-Ming Chen on 11-04-2013 12:42:28 PM
    I am not quote following you. But once you catch the transfer trigger you can transfer to whatever number you like.  

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 18-04-2013 03:50:20 PM
    Yaw-Ming Chen:
    I am not quote following you. But once you catch the transfer trigger you can transfer to whatever number you like.  
        OK, I will ask a different question now.  I am handling the refers via the attached script outbound_call.tcl.txt, but when I try to transfer to a busy number and then transfer to a valid number, the script fails.  I attached the script log debug_transfer.txt from one of the failures with the script debugging turned on.  I first call 918473872681, then try to transfer to 918475769434 (there is only one outbound PSTN line, so this fails), and then try to transfer to 234 (a valid and registered SIP extension), and the script fails on the leg setup indicating that the call is already bridged.  Any idea what I am doing wrong in the script?  Thanks!

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Yaw-Ming Chen on 18-04-2013 04:37:34 PM
    You got that error because there is a connection that you haven't detroyed. any reason you use " leg transferdone $refer_leg_incoming ts_007" ? Anyway, script should look very simple, when you get REFER trigger (in your atc_Refer) once you got all informaton (refer to number...etc) you do "connection destroy con_all" (at this movement I would change state don't using CALLACTIVE,but REFRING,TRANSFERING...etc) after getting ev_destroy_done then you do the leg setup to your transfer to number then wait for en_setup_done. Then you check the status, if it's not ls_000 then you make sure there is no connection then do the leg setup again to NEW destionation. Also I didn't see you change to new distination after transfer to distination is not reachable.        

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 22-04-2013 03:49:54 PM
    Yaw-Ming Chen:
    You got that error because there is a connection that you haven't detroyed. any reason you use " leg transferdone $refer_leg_incoming ts_007" ? Anyway, script should look very simple, when you get REFER trigger (in your atc_Refer) once you got all informaton (refer to number...etc) you do "connection destroy con_all" (at this movement I would change state don't using CALLACTIVE,but REFRING,TRANSFERING...etc) after getting ev_destroy_done then you do the leg setup to your transfer to number then wait for en_setup_done. Then you check the status, if it's not ls_000 then you make sure there is no connection then do the leg setup again to NEW destionation. Also I didn't see you change to new distination after transfer to distination is not reachable.        
      That did not seem to make any difference, if I understood what you   were saying correctly.  I still got the same error in the same place after updating the script (see attached).  I use the transferdone ts_007 t0 send a NOTIFY with status 503 back to the phone doing the transfer so that it knows the transfer was unsuccessful.

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 22-04-2013 04:06:06 PM
    Maybe to make it a little more clear, the flow I am trying to make work is: Setup call (SIP phone to PSTN 918473872681) Transfer call request (REFER) to PSTN 918475769434 -- this includes the SIP phone putting the call on hold Since there is only one phone line, I send a NOTIFY 503 back to the SIP phone since the transfer can not be completed. SIP phone takes call off hold SIP phone retries transfer to a second SIP phone (including putting the call on hold again)-- this is where the script fails with the "Call is already bridged" error in act_Resetup, even though I do a connection destroy con_all in the act_Refer (with the ev_destroy_done being handled by act_Resetup).

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Yaw-Ming Chen on 22-04-2013 04:13:46 PM
    I would use "connection destroy con_all" to make sure all connection been destroyed.
    Also in act_Resetup check it again.
    Regarding trasfer status, IOS won't take care of it so you need to use transferdone ? I saw there are some SIPP error in log, do you know what is the cause ?
     
     
     
     
     
     
    proc act_Resetup { } {
    puts "act_Resetup"
       global referring_leg
       global transfer_dest
    if {$con_status != ""} {
              puts  "Still have connection, Destroy Connection All"
              connection destroy con_all             
          } 
    #   connection create $refer_leg_incoming $refer_leg_outgoing
    puts "Referring leg is $referring_leg"
       leg setup $transfer_dest callInfo $referring_leg
    }

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Yaw-Ming Chen on 22-04-2013 04:40:09 PM
    I notice that you have received trasfer request twice, do you know why is that ?

    Thanks

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Yaw-Ming Chen on 22-04-2013 05:00:42 PM
    Keith Haugen:
    Maybe to make it a little more clear, the flow I am trying to make work is: Setup call (SIP phone to PSTN 918473872681) Transfer call request (REFER) to PSTN 918475769434 -- this includes the SIP phone putting the call on hold Since there is only one phone line,when you use connection destroy you can separate legs and you can play prompt/MOH to SIP phone (SIP phoen on hold)
    I send a NOTIFY 503 back to the SIP phone since the transfer can not be completed(Don't know why you need to do that)

    . SIP phone takes call off hold SIP phone retries transfer (again, we son't need to do anything unless we want to promt caller SIP phone that transfer is in progress. now after leg setup to 918475769434 we should receive stup status other than ls_000 (maybe ls_003 <setup failed because of a lack of resource> or other ls_xxx) as soons as we receive that we then check if there is any connection after makinf sure this is none then leg setup again to new SIP phone
    to a second SIP phone (including putting the call on hold again)-- this is where the script fails with the "Call is already bridged" error in act_Resetup, even though I do a connection destroy con_all in the act_Refer (with the ev_destroy_done being handled by act_Resetup).

    I would use blind transfer not consult for originating SIP phone. Also need to investigate why there are 2 transfer request ?

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 23-04-2013 10:09:13 AM
    This is the overall flow and why there are two transfer requests.  The reason I am trying to do this via my script rather than IOS handle it is because IOS is hanging on the bad transfer request and never sending any NOTIFY message.  This leaves my SIP phone in a bad state that it can not recover from.  There are 2 transfer requests because when the first transfer request fails and I get the indication of the failure, I try a second transfer request manually at the SIP phone.  That is the scenario I am testing that is failing.

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 23-04-2013 10:12:17 AM
    I added the check to destroy all in act_Resetup, but I still got the same call is already bridged error.

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Yaw-Ming Chen on 23-04-2013 11:52:02 AM
    If you really need to do consult transfer you can refer to the following script. It's not SIP but the way to handle trasfer is the same
    You will need CCO login
    http://software.cisco.com/download/release.html?mdfid=277641082&reltype=all&relind=AVAILABLE&release=2.0.0.10&softwareid=283451126&sortparam=
    If you can use blind transfer this is how we can do it. you like to use Tcl to do transfer so let Tcl handle the call incluing handling transfer status.
    1. A calls B
    2. B answers the call. Now in talking state
    3. A initiates transfer B to C (REFER)
    4. A disconnected and B is calling C
    5. B either connected to C or
    6. Transfer failed, (receiving other than ls_000)
    7. Make sure there is no connection (if there is do 'connection destroy)
    8. Make a call to new destination again and repeat from 6
    We should not see 2 transfer request.
    It's should work.
     
     
     

    Subject: RE: New Message from Yaw-Ming Chen in Voice Gateway API (VGAPI) - TCL-API:
    Replied by: Keith Haugen on 01-05-2013 02:34:31 PM
    It  turned out I needed to reconnect the incoming and outgoing legs myself (in the script via connection create) after the failed transfer attempt.  That solved my issue.