> 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/tmedia-documentation/other-pages/call-routing-scripts/modifying-transit-network-selection-filters.md).

# Modifying Transit Network Selection Filters

> **Applies to:** Tmedia 3.0, 3.2, 3.3

### Before filter

This filter is **specific to SPIROU**. In SPIROU, the Network Identification used for Transit Network Selection can be added at the beginning of the called number, when Nature Of Address (NOA) is set to **"international number with transit network selection"** or **"national number with transit network selection"**. This example works for Network Identification of 4 digits, modify it to match the number of digits in your specific network.

```
  # Specific to Spirou, remaps called nature of address, removes selection prefix
  # and uses it as the network_identification field
  # This example will work for selection prefixes of 4 digits, modify .slice!(0..3) according to
  # the length of the selection prefixes in your network
  def transit_network_selection_before_filter params
    #Reset value to false
    @route_rejected = false

    call = params[:call]
    called_noa = call[:called_noa]

    case called_noa
      when 'international_number_with_transit_network_selection'
        call[:called_noa] = 'international_number'
        call[:network_identification] = call[:called].slice!(0..3)
      when 'national_number_with_transit_network_selection'
        call[:called_noa] = 'national_number'
        call[:network_identification] = call[:called].slice!(0..3)
    end

  params

  end
```

### Route match

This filter allows to match routes according to the network\_identification column when Transit Network Selection (TNS) is present. Calls will be routed normally if the TNS IE is not present.

See [Add Network Identification column to Routes](/tmedia-documentation/configuration/web-portal-3-3/call-route/routing-script/add-noa-columns-in-routes.md).

```
  # Will only accept calls if no network identification is requested, or if
  # the network identification of the route matches with the requested one
  def transit_network_selection_route_match( route, call, nap_list )
    requested_network_id = call[:network_identification]

    if requested_network_id.nil?
      return true
    end

    route_network_id = route[:network_identification]

    if requested_network_id != route_network_id
      #Keep track if a route was rejected because of transit network selection, to return the good release cause
      @route_rejected = true
      return false
    end

    return true
  end
```

### After filter

This filter removes the Transit Network Selection information from the route, after the information has been used to route the call. It also makes sure the correct release reason is sent when there is no route because no route matched the requested network identification. Do not use this filter if it is required to transmit the Transit Network Selection IE from the incoming leg to the outgoing leg.

```
  #Test to send the good release reason if there is no route
  #Removes network identification, we do not want to transmit it in the outgoing call
  def transit_network_selection_after_filter params
    routes = params[ :routes ]
    #If no routes where found because routes were rejected for transit network selection,
    #raise an exception with the correct error code
    raise RoutingException, :invalid_transit_network if (routes.empty? && @route_rejected == true)

    call = params[:call]
    call[:network_identification] = nil

    params

  end
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://prosbcdocs.telcobridges.com/tmedia-documentation/other-pages/call-routing-scripts/modifying-transit-network-selection-filters.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
