> For the complete documentation index, see [llms.txt](https://docs.mikopbx.com/mikopbx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mikopbx.com/mikopbx/faq/outbound-routing/number-templates/normalization.md).

# Нормализация набираемого номера телефона

Шаблон для исходящих на примере маршрута для провайдера Mango

## Отсечение "999"

1. Перейдите в раздел "Маршрутизация" -> "Исходящая маршрутизация":

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FuNqaNv8r5ROVbM15IurH%2FOutcomingRoutes.png?alt=media&amp;token=6c14b0e2-230f-4c4f-869e-c1659bbb4f5d" alt=""><figcaption><p>Раздел "Исходящие маршруты"</p></figcaption></figure>

2. Опишем исходящий маршрут с префиксом «999»:

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2F4PyfXmSYRwhwko2Luznh%2FoutboundForMango.jpg?alt=media&amp;token=ed61a2ab-f1ba-4e79-8c71-1b57ad7ebe03" alt=""><figcaption><p>Правило маршрута для Mango</p></figcaption></figure>

3. Перейдите в раздел "**Система**" -> "**Кастомизация системных файлов**":

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FIn35rPMX4a6Ty9sFCh0t%2FsystemFileCustomization.png?alt=media&amp;token=20e27e89-3807-475c-8dac-3a08229edab0" alt=""><figcaption><p>Раздел "Кастомизация системных файлов"</p></figcaption></figure>

4. Откройте для редактирования файл "**extensions.conf**". Установите режим "**Добавлять в конец файла**" и вставьте следующий контекст:

```php
[all_peers](+)
exten => _999XXXXXXXXXXX,1,Set(OUT_CALL_PREFIX=999)
    same => n,Goto(all_peers,${EXTEN:3},1)
```

{% hint style="success" %}
Этот код отрежет префикс для **14**ти значного номера, превратит его в 11ти значный.
{% endhint %}

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FwL0MbfWCQVo6Suvop9wW%2FaddToTheEndOfFilecontextforMango.jpg?alt=media&amp;token=33f3c049-3401-4841-82a3-a747376541d8" alt=""><figcaption><p>Добавление контекста в конец файла extensions.conf</p></figcaption></figure>

5. Добавьте еще один контекст:

{% code fullWidth="true" %}

```php
[outgoing-custom]
exten => _[0-9*#+a-zA-Z]!,1,NoOp()
    same => n,ExecIf($["${NEW_DST_EXTEN}x" != "x"]?return)  
    same => n,Set(NEW_DST_EXTEN=${OUT_CALL_PREFIX}${EXTEN})
    same => n,GosubIf($["${OUT_CALL_PREFIX}x" != "x"]?outgoing,${OUT_CALL_PREFIX}${EXTEN},1)
    same => n,return
exten => _[hit],1,Hangup()
```

{% endcode %}

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2F8pTvZzU0Sm0k5gmqClOa%2FaddToTheEndOfFilecontextforMango2.jpg?alt=media&amp;token=6ba9f1b9-6a17-49b8-a62f-1c5f24545974" alt=""><figcaption><p>Добавление контекста в конец файла extensions.conf</p></figcaption></figure>

При исходящем звонке будет добавлен отсеченный ранее префикс **999**. В истории вызовов отобразится номер без набранного префикса, в **11ти значном формате**:

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fgit-blob-79cd6854b0786a8ee861ca620155a6c5e587621a%2Fimage%20(117).png?alt=media" alt=""><figcaption><p>Раздел "История вызовов"</p></figcaption></figure>

Для звонков из CTI приложений нужно дополнить контекст:

{% code fullWidth="true" %}

```php
[internal-originate](+)
exten => _XXX!,1,Set(pt1c_cid=${FILTER(\*\#\+1234567890,${pt1c_cid})})

	same => n,ExecIf($[ ${LEN(${CALLERID(num)})} == 14 ]?Set(__OUT_CALL_PREFIX=7${pt1c_cid:0:3}))
	same => n,ExecIf($[ ${LEN(${CALLERID(num)})} == 14 ]?Set(pt1c_cid=7${pt1c_cid:3}))

	same => n,Set(MASTER_CHANNEL(ORIGINATE_DST_EXTEN)=${pt1c_cid})
	same => n,Set(number=${FILTER(\*\#\+1234567890,${EXTEN})})
	same => n,ExecIf($["${EXTEN}" != "${number}"]?Goto(${CONTEXT},${number},$[${PRIORITY} + 1]))
	same => n,Set(__IS_ORGNT=${EMPTY})
	same => n,Gosub(interception_start,${EXTEN},1)
	same => n,ExecIf($["${pt1c_cid}x" != "x"]?Set(CALLERID(num)=${pt1c_cid}))
	same => n,ExecIf($["${origCidName}x" != "x"]?Set(CALLERID(name)=${origCidName}))
	same => n,GosubIf($["${DIALPLAN_EXISTS(${CONTEXT}-custom,${EXTEN},1)}" == "1"]?${CONTEXT}-custom,${EXTEN},1)
	same => n,ExecIf($["${SRC_QUEUE}x" != "x"]?Goto(internal-originate-queue,${EXTEN},1))
	same => n,ExecIf($["${CUT(CHANNEL,\;,2)}" == "2"]?Set(__PT1C_SIP_HEADER=${SIPADDHEADER})) 
	same => n,ExecIf($["${PJSIP_ENDPOINT(${EXTEN},auth)}x" == "x"]?Goto(internal-num-undefined,${EXTEN},1))
	same => n,Gosub(set-dial-contacts,${EXTEN},1)
	same => n,ExecIf($["${FIELDQTY(DST_CONTACT,&)}" != "1" && "${ALLOW_MULTY_ANSWER}" != "1"]?Set(__PT1C_SIP_HEADER=${EMPTY_VAR}))
	same => n,ExecIf($["${DST_CONTACT}x" != "x"]?Dial(${DST_CONTACT},${ringlength},TtekKHhb(originate-create-channel,${EXTEN},1)U(originate-answer-channel),s,1)))
exten => _[hit],1,Gosub(interception_bridge_result,${EXTEN},1)
	same => n,Hangup
```

{% endcode %}


---

# 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://docs.mikopbx.com/mikopbx/faq/outbound-routing/number-templates/normalization.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.
