OpenSIPS, how to avoid duplicate invite when registering through push notifications?

335 Views Asked by At

This is my script. I found that for a register, E_UL_CONTACT_INSERT will be triggered one or more times. I don’t want to invite the same client multiple times.

route[route_to_user] {

        t_newtran();

        t_on_branch("per_branch_ops");
        t_on_reply("handle_nat");

        t_wait_for_new_branches();

        $avp(filter) = "aor="+$rU+"@"+$rd;
        notify_on_event("E_UL_CONTACT_INSERT", $avp(filter), "fork_call", 60);

        lookup("location");

        exit;
}

route[fork_call] {
    
        t_inject_branches("event");
}

These are what i tried:

  1. According to the document

As an exception, in the notification route, the EBR module will make available the transaction ID from the subscriber context.

In fork_call, I want to use transaction ID and $avp(uri) as the cache key to detect duplicate E_UL_CONTACT_INSERT. But I can't find how to get transaction ID in fork_call.

  1. Let E_UL_CONTACT_INSERT be triggered only once, but I have no idea here.

Is there a better solution? thanks.

1

There are 1 best solutions below

1
Fulo Lin On

I modified the setting of working_mode_preset to solve this problem.

original:

modparam("usrloc", "working_mode_preset", "sql-only")

route[route_to_user] {

        t_newtran();

        t_on_branch("per_branch_ops");
        t_on_reply("handle_nat");

        t_wait_for_new_branches();

        $avp(filter) = "aor="+$rU+"@"+$rd;
        notify_on_event("E_UL_CONTACT_INSERT", $avp(filter), "fork_call", 60);

        lookup("location");

        exit;
}

route[fork_call] {
    
        t_inject_branches("event");
}

modified:

modparam("usrloc", "working_mode_preset", "single-instance-sql-write-through")

route[route_to_user] {

        t_newtran();

        t_on_branch("per_branch_ops");
        t_on_reply("handle_nat");

        t_wait_for_new_branches();

        $avp(filter) = "aor="+$rU+"@"+$rd;
        notify_on_event("E_UL_CONTACT_INSERT", $avp(filter), "fork_call", 60);

        if (lookup("location")) {
                route(relay);
        }

        exit;
}

route[fork_call] {
    
        t_inject_branches("event");
}

When working_mode_preset is sql-only, lookup will trigger E_UL_CONTACT_INSERT, but it will trigger one or more times.

When working_mode_preset is single-instance-sql-write-through, lookup will not trigger E_UL_CONTACT_INSERT, so I have to execute route(relay).

I am not sure if this is a bug, but this solved my problem and I am still looking for the correct answer.