> For the complete documentation index, see [llms.txt](https://prosbcdocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/route-match-tutorial.md).

# route match Tutorial

### route\_match tutorial

'route\_match' is a method implemented in the base\_routing and is use to match a route to a call through parameters and/or status. This tutorial will explain how to use the parameter for the 'route\_match' method.

#### route\_match examples

***

Things to know about these examples:

* A new field called 'priority' needs to be add to the routes.
* A new field called 'asr\_threshold' needs to be add to the routes.
* A new field called 'usage\_threshold' needs to be add to the routes.

**route\_match setup**

Time to take a look how to match route to a call. List of routes use for the example: Calling Called NAP Remapped NAP Priority 5550000 1110000 isdn sip 4 5550000 2220000 sip isdn 3 5550000 3330000 sip\_p2 isdn\_1 2

List of naps: Name Asr threshold Usage threshold isdn 40 90 sip 52 92

Input used in the test script window: @call\_params = {:calling => '5550000', :called => '5550002', :nap => 'isdn'} @nap\_list = \[ {:name => 'sip', }, {:name => 'isdn' }, {:name => 'sip\_p3' } ]

#### :call\_field\_name and :route\_field\_name parameter

***

**:call\_field\_name and :route\_field\_name script example**

Let's start with the :call\_field\_name and :route\_field\_name combo. The first example shows how to use the :call\_field\_name to match the calling number of the incoming call with the calling number of the route.

It will also try to find a route which has the same remapped nap parameter as the nap parameter of the incoming call, therefore ignoring the nap parameter of the route. require 'base\_routing'

```
class MatchTutorial < BaseRouting
route_match :call_field_name => :calling
route_match :call_field_name => :calling, :route_field_name => :calling
route_match :call_field_name => :nap, :route_field_name => :remapped_nap

end

@@routing = MatchTutorial.new

def init_routes( routes )
@@routing.init routes
end

def route( call, nap_list )
@@routing.route call, nap_list
end
```

**:call\_field\_name and :route\_field\_name script output**

If you look at the first 2 lines of the MatchTutorial class definition: route\_match :call\_field\_name => :calling route\_match :call\_field\_name => :calling, :route\_field\_name => :calling

Both lines do the exact same thing. The both try to match the calling number of the incoming call with the calling number of the routing call.

By default the if the :route\_field\_name is not explicitly declared, route\_match will try to match the parameter from the :call\_field\_name to the same parameter in the route (in this case :calling). It is also important to notice that the :route\_field\_name parameter cannot be use without a :call\_field\_name parameter first.

It is also important to notice that the called number, the nap and the priority in the routes were ignored by our match rules.

The script will find a match. Here is the output: Call Params: Reason: ok Called: 5550002 Calling: 5550000 Nap: isdn Matched route: Remapped calling: Called: 2220000 Calling: 5550000 Remapped called: Priority: 3 Remapped nap: isdn Nap: sip Output: OUT: Nap attribute must be remapped OUT:

#### :method and :proc parameter

***

Let's try the :method and :proc. The next example is a isdn-sip gateway.

It uses the one of the method contain in base\_routing (:match\_nap\_availability), it will compare the :asr\_statistics\_struct\_last\_24h\_asr\_percent nap status with the :asr\_threshold in the naps, and will also compare the :usage\_percent nap status with the :usage\_threshold.

The threshold and the status in this example were set so that a sip to isdn call will be dropped, but a isdn to sip call will be accepted.

**:method and :proc input**

It is possible to set the nap status values in the test windows. Here is the input in the test window: @call\_params = {:calling => '5550000', :called => '5550002', :nap => 'isdn'} @nap\_list = \[ {:name => 'sip', :availability\_percent => '100', :asr\_statistics\_struct\_last\_24h\_asr\_percent => '60', :usage\_percent => '85' }, {:name => 'isdn', :availability\_percent => '100', :asr\_statistics\_struct\_last\_24h\_asr\_percent => '40', :usage\_percent => '100' }, {:name => 'sip\_p3', :availability\_percent => '0', :asr\_statistics\_struct\_last\_24h\_asr\_percent => '10', :usage\_percent => '90' } ]

**:method and :proc script example**

```
require 'base_routing'
```

1\.

1. This class requires that your add columns in the nap called asr\_threshold and usage\_threshold
2. class MatchProcMethodTutorial < BaseRouting route\_match :call\_field\_name => :nap route\_match :method => :match\_nap\_availability route\_match :method => :match\_nap\_available\_call route\_match :proc => Proc.new { |route, call, nap\_list| result = true
3. get the outgoing nap nap=nap\_list\[route\[:remapped\_nap].intern] puts "usage remapped nap #{nap\[:name]}" if nap.nil? puts "Cannot found route with outgoing nap '#{route\[:remapped\_nap]}'" result = false end
4. get the last 24hrs asr asr\_24hrs\_status = nap\[:asr\_statistics\_struct\_last\_24h\_asr\_percent].to\_i asr\_24hrs\_threshold = nap\[:asr\_threshold].to\_i puts "asr status #{asr\_24hrs\_status}, treshold#{asr\_24hrs\_threshold}" if asr\_24hrs\_status < asr\_24hrs\_threshold puts "Insufficient ASR in the last 24hrs for nap '#{route\[:remapped\_nap]}'" result = false end

   result }

   def match\_nap\_available\_call(route, call, nap\_list)
5. get the outgoing nap nap=nap\_list\[route\[:remapped\_nap].intern] puts "usage remapped nap #{nap\[:name]}" if nap.nil? puts "Cannot found route with outgoing nap '#{route\[:remapped\_nap]}'" return false end
6. verify how many calls are available in the nap nap\_usage\_status = nap\[:usage\_percent].to\_i nap\_usage\_threshold = nap\[:usage\_threshold].to\_i puts "usage status #{nap\_usage\_status}, treshold#{nap\_usage\_threshold}" if nap\_usage\_status > nap\_usage\_threshold puts "Nap usage of '#{route\[:remapped\_nap]}' is higher then threshold '#{nap\_usage\_status}' " return false end

   true

   end

   end

   @@routing = MatchProcMethodTutorial.new

   def init\_routes( routes ) @@routing.init routes end

   def route( call, nap\_list ) @@routing.route call, nap\_list end

**:method and :proc output**

The gateway application queries every second the status and keep it available for routing script (due to the synchronous nature of the status query, it is preferable to have another thread polling the status than querying the status for each call).

The script uses 2 status available (:asr\_statistics\_struct\_last\_24h\_asr\_percent and :asr\_threshold in the naps) in the naps, for a complete list of the status available go [here](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/routing-script-tutorial-development-guide/README.md#nap-status) in the NAP\_STATS\_FIELDS define.

If you check the NAP\_STATS\_FIELDS define, you will see that :asr\_statistics\_struct\_last\_24h\_asr\_percent is the combination of 2 field names asr\_statistics\_struct and last\_24h\_asr\_percent.

You might have noticed that the block in the proc function did not use the return keyword, it is a rule from ruby where you cannot use the return keyword in a block.

Here is the output: Call Params: Reason: ok Called: 5550002 Calling: 5550000 Nap: isdn Matched route: Remapped calling: Called: 1110000 Calling: 5550000 Remapped called: Priority: 4 Remapped nap: sip Nap: isdn

```
Output: OUT: usage remapped nap sip
OUT:
OUT: usage status 85, treshold92
OUT:
OUT: usage remapped nap sip
OUT:
OUT: asr status 60, treshold52
OUT:
OUT: Nap attribute must be remapped
OUT:
```

***

Back to [Routing Script Tutorial](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/routing-script-tutorial/README.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/route-match-tutorial.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
