Telcobridges - Session Border Controllers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Adding user=phone to URI and headers

2 posters

Go down

Adding user=phone to URI and headers Empty Adding user=phone to URI and headers

Post by Admin Tue Jan 22, 2019 7:36 am

In some cases far ends wants to see user=phone on URI and headers. You can simply add this to your URI and headers with following;


  1. Create a new script named add_user_phone
    Adding user=phone to URI and headers Add_us10

  2. Copy following  script part and Save
    Code:
    #
    # Script version 1.0
    #
    # Version history:
    #  1.0  Initial version of this script
    #
    # This filter is used to add "user=phone" to call URI's

    #

    module AddUserPhone
      def init_add_user_phone(params)
      end

      def add_sip_header_param( call, field, param_level, value )
        call[ field ] = {} unless call[ field ].is_a? Hash
        call[ field ] ||= {} # Create a hash if not already present
        call[ field ][ param_level ] ||= "" # Create a string if not already present
        call[ field ][ param_level ] += ";" if call[ field ][ param_level  ] != "" # Append ; if already some parameters
        call[ field ][ param_level ] += value # Append the value
      end

      def add_user_phone(params)
        call = params[ :call ]

        # Add to SIP URI
        call[:request_uri_forward_enabled] = true
        if call[:request_uri] && !call[:request_uri].include?( "user=phone" )
         call[:request_uri] += ";user=phone"
        end

        add_sip_header_param( call, :calling_parameters,          :uri_param, "user=phone" ) # Add to From header
        add_sip_header_param( call, :called_parameters,           :uri_param, "user=phone" ) # Add to To header
        add_sip_header_param( call, :contact_parameters,          :uri_param, "user=phone" ) # Add to Contact header
        add_sip_header_param( call, :private_address_parameters,  :uri_param, "user=phone" ) # Add to P-Asserted-Identity
      add_sip_header_param( call, :redirecting_number_parameters, :uri_param, "user=phone") # Add to SIP Diversion
        # header
        # Remote-party-id -> Can't modify for now
        

        params
      end  
    end

  3. Select simple_routing_sbc script and add following script parts and Save
    Code:

    .
    .
    require 'add_user_phone'
    .
    .
    include AddUserPhone
    .
    .
    after_filter :method => :add_user_phone
    .
    .
    [*]Activate the configuration


Admin
Admin

Number of Messages : 516
Point : 1211
Registration Date : 2017-11-27

http://freesbc.yetkinforum.com

Back to top Go down

Adding user=phone to URI and headers Empty Re: Adding user=phone to URI and headers

Post by zictec Tue Jan 26, 2021 2:51 pm

Hi, I tried to follow the instructions, but is doesn't work.
I'm using weight and load balance filter script also, do I need to merge both ?

zictec

Number of Messages : 5
Point : 9
Registration Date : 2018-06-18

Back to top Go down

Adding user=phone to URI and headers Empty Re: Adding user=phone to URI and headers

Post by Guest Wed Jan 27, 2021 7:35 am

You could use an after filter script to add user=phone easily to the field required. This script is called “sip_header_params.rb” from routing script section of web portal.

Below is a detailed instruction to use this script (it is available in the script itself),

# How to use this script
#    1. Import this script with other filter script in the Web Portal (if not already done)
#    2. Locate your "main" script (the routing scripts entry point, like "simple_routing.rb")
#       and include current filter as an after_remap_filter
#       2.1. Add the following line at begining of the main routing script to load current filter script:
#            require 'sip_header_params' unless defined?(SipHeaderParams)
#       2.2. Include the current filter to your routing script's main class (first line afer 'class MyScriptName')
#            include SipHeaderParams
#       2.3. Attach current filter as an 'after_remap_filter', passing as argument an array that defines headers to add.
#            Example:
#              after_remap_filter :method => :sip_header_params, :headers_to_add => [{ :type=>:user_param, :contents=>"user=phone", :sip_headers=>[:called] }]
#            Each element of this array is a hash that contains the following keys:
#              - :type         Define the type of SIP header parameter to add.
#                                :user_param, :uri_param, or :header_param
#                                (see documentation above in this file for more information)
#              - :contents     Contents to add for this parameter. No need to add ; separator, this will be automatically handled.
#                                Example: "user=phone"
#              - :sip_headers  An array of headers to add the parameter to. Possible values:
#                                :calling                 (SIP "From" header)
#                                :called                  (SIP "To" header)
#                                :private_address         (SIP "P-Asserted-Identity" or "Remote-Party-ID header" header)
#                                :contact                 (SIP "Contact" header)
#                                :redirecting_number      (SIP first "Diversion" header)
#                                :original_called_number  (SIP second "Diversion" header)
#                              This can also be any "generic" SIP header (unparsed by routing script):
#                                "X-CustomHeader"
#                                In this case, the script will attempt to find this header (raw) and add header parameters to it.
#                                This may not work in all cases...
#                              Other headers with specific handling:
#                                :request_uri             (SIP request-URI header)
#                                                         Normally automatically build using information from "To" header.
#                                                             So use this ONLY if you need request_uri to be different from "To".
#                                                           Not recomended, this may generate inappropriate Request URI header.
#            Longer example:
#             after_remap_filter :method => :sip_header_params, :headers_to_add => [
#               {
#                 :documentation  => "Add user=phone to user parameters of most SIP headers",
#                 :type           => :uri_param,
#                 :contents       => "user=phone",
#                 :sip_headers    => [
#                   :calling,
#                   :called,
#                   :private_address,
#                   :contact,
#                   :redirecting_number,
#                   :original_called_number,
#                   "X-CustomHeader"
#                 ]
#               },
#               {
#                 :documentation  => "Add foo=123 to uri parameters of 'From' header",
#                 :type         => :uri_param,
#                 :contents     => "foo=bar",
#                 :sip_headers  => [ :calling ]
#               }
#             ]
#    3. Optionnally, you can create a new route column named "add_sip_header_params", type boolean.
#       This route column (attribute) will determine, per route, if the defined SIP headers must be added or not.
#       (custom route column can be created in the "Routes" section of the web portal under "Create New Route Column")
#

It is self explanatory. The above script also can cater if you want to do this just per route, using point 3, create a new route column.  You could do this at static route, “create new route column,
Adding user=phone to URI and headers 110



For adding after filter, please also see below,

How to Setup Filters - TBwiki (telcobridges.com)

You could also copy existing configuration to another new configuration with new name, and work on the new name configuration, so you would not affect the current active configuration.

For any change, please do save and activate configuration.  If there is any question, we could advise you further.

Kindly note routing script development normally would require a purchase of 9-5 professional service package.

Guest
Guest


Back to top Go down

Adding user=phone to URI and headers Empty Re: Adding user=phone to URI and headers

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum