[OpenSIPS-Users] DIferent call Status when base on user Preference

Gustavo Mistrinelli gmistrinelli at gmail.com
Wed Jan 14 02:52:11 CET 2009


Hi,

You can use one line to load all user preferences to avps

  avp_db_load("$ru/username","*")

Assuming that usr_preferences table have records like that:

username | attribute   | value
------------------------------
abcd     | callForward | 123456
dcba     | voicemail   | true

Then you can check user settings asking:

if (is_avp_set($avp(s:callForward)) {
   $rU =  $avp(s:callForward)
}
if (is_avp_set($avp(s:voicemail)) {
  if ($avp(s:voicemail)=="true" {
      # Redirect to voicemail server
      rewritehostport("XXX.XXX.XXX.XXX:5070");
  }
}

I hope you get the idea, if not please review documentation  usr_preferences
and avpops module:
 http://www.opensips.org/html/docs/db/db-schema-1.4.x.html#AEN581
 http://www.opensips.org/html/docs/modules/1.4.x/avpops.html

Cheers,

Gustavo

On Tue, Jan 13, 2009 at 11:19 PM, pjgonzalez <pgonzalez at dgtec.net.do> wrote:

>
> Hi every body, i want to be able route calls from my sip, depending on his
> status, For example when the user is online he can change his status to
> ringOndevice to ring on his sip-phone, voice-mail to route to asterisk
> voicemail, and callforward to forward the call to a given number, the two
> first escerany are ok bu, i need to know how can i make a call forward base
> on users prefenrece.
>
> i alredy load the user preference from the usr_preference table.
>
> here my script part:
>
> if(nat_uac_test("19"))
>           {
>            setbflag(6);
>            fix_nated_contact();
>            xlog("L_INFO", "Fixing NAT AGAIN- M=$rm RURI=$ru F=$fu USR=$tU
> T=$tu IP=$si ID=$ci\n");
>           };
>
>        if(!lookup("location")){
>                avp_db_query("SELECT count(*) FROM usr_preferences WHERE
> uuid='$tU'","$avp(s:hasPreference)");
>                xlog("L_INFO", "User Preference:
> atributo:'$avp(s:hasPreference)'\n");
>
> CHECH IF USR is on preference DB to forward to voice Mail server.
>               if($avp(s:hasPreference)){
>                        route(9);
>                        exit;
>                }
> #OUTBOUNT CALLS/
>                        if (uri=~"^sip:[0-9]*@") {
>                                route(3);
>                                route(6);
>                                exit;
>                        };
>         }
>          else
>         {
>                route(13);
>         }
>
> route[11]
> {
>  xlog("L_INFO","Here on route 11");
>  avp_pushto("$ru", "$avp(s:callForward)");
>
>  rewritehostport("XXX.XXX.XXX.XXX:5070");
>  append_branch();
>
> xlog("L_INFO", "The call was forwarded to: $avp(s:callForward) - M=$rm
> RURI=$ru F=$fu USR=$tU T=$tu IP=$si ID=$ci\n");
> #t_on_failure("1");
> #t_on_reply("1");
> #t_relay();
> #xlog("L_INFO", "The call was relay to: $avp(s:callForward) - M=$rm
> RURI=$ru
> F=$fu USR=$tU T=$tu IP=$si ID=$ci\n");
> #route(6);
> #t_on_branch("1");
>  route(12);
> }
>
> route[12]{
>         xlog("L_INFO","Here on route 12");
>        t_on_failure("3");
>        t_on_reply("1");
>        if (!t_relay()) {
>          sl_reply_error();
>          xlog("L_INFO", "The error:  - M=$rm RURI=$ru F=$fu USR=$tU T=$tu
> IP=$si ID=$ci\n");
>
>        };
>        exit;
> }
>
> My script is base on sipwise sample.
>
> thanks a lot.
>
> route[13]
> {
>
>                xlog("L_INFO", "User is Online - M=$rm RURI=$ru F=$fu
> USR=$tU T=$tu IP=$si ID=$ci\n");
>
>                 if(avp_db_load("$ru/username","$avp(s:callForward)"))
>                   {
>                        #xlog("L_INFO", "The call was forwarded to:
> $avp(s:callForward) - M=$rm RURI=$ru F=$fu USR=$tU T=$tu IP=$si ID=$ci\n");
>                        #avp_pushto("$tu", "$avp(s:callForward)");
>                        route(11);
>                        exit;
>                   }
>                 else if(avp_db_load("$ru/username","$avp(s:ringOnDevice)"))
>                   {
>                        xlog("L_INFO"," The call is ringing on: $ruri");
>                                route(3);
>                                route(8);
>                                exit;
>                   }
>                 else if(avp_db_load("$ru/username","$avp(s:voiceMail)"))
>                   {
>                     xlog("L_INFO", "Voice Mail HERE!! - M=$rm RURI=$ru
> F=$fu T=$tu IP=$si ID=$ci\n");
>                                route(9);
>                                exit;
>                   };
>
> exit;
> }
>
>
>
> --
> View this message in context:
> http://n2.nabble.com/DIferent-call-Status-when-base-on-user-Preference-tp2154604p2154604.html
> Sent from the OpenSIPS - Users mailing list archive at Nabble.com.
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>



-- 
Gustavo Mistrinelli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.opensips.org/pipermail/users/attachments/20090113/f147562b/attachment-0001.htm 


More information about the Users mailing list