> 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/how-to-setup-routing-script-filters.md).

# How to Setup Routing Script Filters

Filter Scripts are routing scripts that can be added to any other script. It modifies the behavior of the main script. For example, it can do a remapping of the incoming called number to make it uniform, such as removing the international code. It can also make sure there is no loop (do not route the call back to the incoming Network).

While filters can edit call attributes, they do it once for all matching routes.

\*\*Note: If you need to manipulate call attributes per matching route (providing different values for different matching routes), you should instead use \*\* [route\_remap](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/route-remap-tutorial/README.md).

### Setting up Filter Scripts

To setup a Filter, the main script needs to be modified. The main script can be either simple\_routing.rb, or any other script.

First, make sure scripts are enabled for this system:

```
Gateway
use Script -> Example Scripts  (If none are available, go to the second step, then come back here to chose the script group)
```

Second, go to the routing script section of the Web portal

```
Gateway -> Routes -> Routing scripts -> Example Scripts -> simple_routing.rb [Edit]
```

Three things need to be added. At the start of the script:

```
require '[filter_ruby_filename]'
```

In the main class:

```
include [module_name]
```

and

```
before_filter :method => :[method_name]
```

or

```
after_filter :method => :[method_name]
```

For example, the priority\_and\_weight\_load\_balancer.rb script would require this to be added to the main script:

```
require 'priority_and_weight_load_balancer'

class MyMainRoutingClass < BaseRouting
  include PriorityAndWeightLoadBalancer

  after_filter :method => :filter_by_priority_and_weight,
```

To find the module\_name and method, you need to look in the routing script itself:

```
Gateway -> Routes -> Routing Scripts -> Filters Scripts -> priority_and_weight_load_balancer.rb [Edit]
```

Then look for the \<Module> tag and the \<def> tag for the main class

#### Filter Scripts examples:

* **Request-URI routing (called\_pre\_remap\_and\_ruri.rb):** Will route the call on SIP RURI instead of the to: field
* **Modify the Nature of Address (noa\_npi\_remap.rb):** We can use this to change the NOA to national or international
* \*\*Remove Loop (FilterRemoveLoop.rb): \*\*Will prevent calls from being routed back to the sender
* **Load sharing on NAP groups or on route groups (priority\_and\_weight\_load\_balancer.rb):** This is script is now installed by default on the systems. See [Adding Priority and Load Sharing to Routing Script](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/adding-load-sharing-to-a-routing-script/README.md)
* **Black and White listing (black\_white\_listing.rb):** With this script, any called or calling number prefix can be blacklisted or whitelisted. This script can be assigned globally, or per NAP. It reads a file which has the called and calling number list. See [Adding White or Black listing to Routing Script](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/adding-white-or-black-listing-to-a-routing-script/README.md)
* **Capture dtmf input (capture\_dtmf.rb):** With this script, if the called number is a specific value, it will play an announcement and waits to capture digits used for routing. See [Adding capture dtmf script to Routing Script](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/voice-media/adding-capture-dtmf-script/README.md)
* **Route on Called and make call with Routing Number (r\_n\_cdr.rb):** With this script, the called number will be used to route the call, but the call will be made with the routing number. See [Adding Routing Number script to Routing Script](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/concepts/adding-routing-number-script/README.md)
* **Fraud call detection with YouMail (youmail\_spam\_risk.rb):** This script will query and External HTTPS server and it will return a spam risk level based on calling number data. See [Adding YouMail script to Routing scripts](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/adding-youmail-script-to-routing-scripts/README.md)
* **Controlling and Reading** [**CAS**](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/protocols/cas/README.md) **timeslots (timeslot\_control.rb):** This script is used to demonstrate how to make routing decisions based on the inbound timeslot, and how to use routing decisions to select an outbound timeslot, in CAS environments. See [Adding timeslot control to Routing scripts](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/transmission/adding-timeslot-control-to-routing-scripts/README.md)

One example is the Label Routing. Check here: [Adding Label Routing to any Routing Script](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/concepts/adding-label-routing-to-a-routing-script/README.md)

These filters can be merged in the same routing script.

Many more scripts can be found on the Forums: [Forums Routing Scripts](https://forums.freesbc.com/f24-routing-scripts)

Please contact support for more details.

#### Adding benchmarking to any script

Routing scripts need to be well designed to allow for maximum performance of a system.

To help evaluating the performance of a script (or part of a script), you can use this benchmarking tool.

See [Adding Benchmarking to your Routing scripts](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/adding-benchmarking-to-any-script/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/how-to-setup-routing-script-filters.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.
