> 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/telecom-concepts/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](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/telecom-concepts/routing-class-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.
