Apologies, we use 2.4 so all of my links point to that version. But I believe 
everything I have said is also true for 3.0. 

Ben Newlin 

On 3/29/20, 9:26 PM, "Users on behalf of Ben Newlin" 
<[email protected] on behalf of [email protected]> wrote:

    $ci, $fu, $tu, etc are all variables that reference parts of the SIP 
message in the current context. The E_DLG_STATE_CHANGED is an event route 
triggered by a change in dialog state; it does not run in the context of any 
SIP message. So none of those variables will be available in the event route.
    
    Additionally, I'm not sure why but the E_DLG_STATE_CHANGED event does not 
automatically load the context of the dialog that changed either. So $dlg_val 
variables are also not available. But for this there is a solution. The event 
provides several parameters [1]. These can be obtained by using 
fetch_event_params [2]. You can then use that information to call either 
get_dialog_vals [3] or get_dialog_info [4] to load the dialog variables you 
want. Ours looks like this:
    
    
fetch_event_params("hash_entry=$var(dlg_state_chg_hash_entry);hash_id=$var(dlg_state_chg_hash_id);callid=$var(dlg_state_chg_ci);old_state=$var(dlg_state_chg_old_state);new_state=$var(dlg_state_chg_new_state)");
    
get_dialog_vals("$avp(dlg_state_names)","$avp(dlg_state_vals)","$var(dlg_state_chg_ci)")
 ;
    
    So any values you will need to access, whether from a message or otherwise, 
will need to be saved in dlg_vals, as you are doing with $fu, and retrieved in 
this manner.
    
    This is the process we are using and the only one we've found to work. It 
is a lot of steps so I would be interested if anyone has found a better way.
    
    Note: One issue with this approach is that by default get_dialog_vals 
ignores dialogs in an ended state [5], so if you need any dlg_vals to process 
an ended event you have to store the values off yourself into some other 
storage from which you can retrieve them, because get_dialog_vals will not 
return any data once the BYE has been received. And if you are storing them 
into your own separate storage anyway, you might as well use that for your 
lookups for the other events too, rather than jump through all the hoops above.
    
    [1] - 
https://opensips.org/docs/modules/2.4.x/dialog.html#event_E_DLG_STATE_CHANGED
    [2] - 
https://opensips.org/docs/modules/2.4.x/event_route.html#func_fetch_event_params
    [3] - 
https://opensips.org/docs/modules/2.4.x/dialog.html#func_get_dialog_vals
    [4] - 
https://opensips.org/docs/modules/2.4.x/dialog.html#func_get_dialog_info
    [5] - https://github.com/OpenSIPS/opensips/issues/1637
    
    Ben Newlin 
    
    On 3/28/20, 9:09 AM, "Users on behalf of Aleksandar Sosic" 
<[email protected] on behalf of [email protected]> wrote:
    
        Hi Guys,
        
        I'm new to OpenSIPS, been using kamailio for some time but I'm not
        that of a SIP expert.
        
        Let me explain you my issue here...I'm trying to make HTTP REST calls
        to a service on an INVITE to check if the call can be made, then on
        the begin event of a call and when the call is closed.
        
        I've successfully done the first API call with this block of code in
        the main `route`:
        ```
        if (is_method("INVITE") && !has_totag()) {
            $dlg_val(account_tag) = $fU;
            route(rating_authorization);
        }
        ```
        
        Now I'm using the `E_DLG_STATE_CHANGED` like this:
        ```
        event_route[E_DLG_STATE_CHANGED] {
            if($param(new_state) == 4 ) {
                route(rating_begin_transaction);
            }
            ...
        }
        ```
        Which I'm not sure is correct. In Kamailio I just do this:
        ```
        event_route[dialog:start] {
            route(RATING_BEGIN_TRANSACTION);
        }
        ```
        
        So the problem here is that in the route `rating_begin_transaction` I
        don't see these variables here:
        ```
        xlog("L_NOTICE", "rating_begin_transaction :: $ci,
        $dlg_val(account_tag), $fu, $tu \n");
        ```
        
        They seem to be `<null>` but I need to pass them in the REST call:
        ```
        Mar 27 22:12:50 [376] rating_begin_transaction :: <null>, <null>, 
<null>, <null>
        ```
        
        What am I doing wrong here?
        
        Thanks,
        ---
        Aleksandar Sosic
        
        _______________________________________________
        Users mailing list
        [email protected]
        http://lists.opensips.org/cgi-bin/mailman/listinfo/users
        
        
    
    _______________________________________________
    Users mailing list
    [email protected]
    http://lists.opensips.org/cgi-bin/mailman/listinfo/users
    

_______________________________________________
Users mailing list
[email protected]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

Reply via email to