> For the complete documentation index, see [llms.txt](https://tmediadocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tmediadocs.telcobridges.com/telecom-references/developer-reference/routing-scripts/routing-class-tutorial.md).

# Routing Class Tutorial

### Routing Class Tutorial

This is a basic tutorial about script routing. This page will explain the different methods required in a script routing.

Here is a list of routes of a sip/isdn gateway:

```
Calling  Called  NAP  Remapped NAP
2220000 1110000 sip   isdn
4440000 3330000 isdn   sip
```

These routes are pretty restrictive, since the calling and called number are set to a single number. We could simply remove the number in the calling and called number to allow any number to go from sip to isdn. But for the sake of this example we won't.

Let's create a class that will only match the call by nap and remap it (sip to isdn / isdn to sip).

```
require 'base_routing'

class IsdnSipGw < BaseRouting
route_match :call_field_name => :nap
route_remap :call_field_name => :nap, :route_field_name => :remapped_nap
end

@@routing = IsdnSipGw.new

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

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

Let's analyze the script in more detail:

```
class IsdnSipGw < BaseRouting
route_match :call_field_name => :nap
route_remap :call_field_name => :nap, :route_field_name => :remapped_nap
end
```

This is the definition of the routing class which is called IsdnSipGw and has BaseRouting as base class. It will match call to the route according to its incoming nap. It will also remap the nap field value with the value of the remapped\_nap field located in the route.

```
@@routing = IsdnSipGw.new
```

Creates a routing object of IsdnSipGw type. This line is executed when the script is loaded into the gateway application.

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

Send the routes list to the routing objects. If you want to pre-order your routes because the priority will not change through time or because of the incoming call parameter, now it is a good time. The init\_routes is called only once when the script is loaded in the gateway (think applying the configuration).

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

This method order the routes, then match the call to a route, then remap the fields if there was a match.

***

Back to [Routing Script Tutorial](/telecom-references/developer-reference/routing-scripts.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 by asking a question.

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

```
GET https://tmediadocs.telcobridges.com/telecom-references/developer-reference/routing-scripts/routing-class-tutorial.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.
