> 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/cases/notification-in-telegram.md).

# Уведомление в мессенджер о пропущенных

## Уведомление Телеграм на базе Dialplan <a href="#primer_na_baze_dialplan" id="primer_na_baze_dialplan"></a>

{% hint style="success" %}
[Полезная статья](https://gist.github.com/dideler/85de4d64f66c1966788c1b2304b9caf1) по работе с Telegram-ботом средствами **curl.**
{% endhint %}

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

<figure><img src="/files/Upq0VL0XG34cyY35yCmo" alt=""><figcaption><p>Раздел "<strong>Кастомизация системных файлов</strong>"</p></figcaption></figure>

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

```php
[add-trim-prefix-clid-custom]
exten => _[0-9*#+a-zA-Z][0-9*#+a-zA-Z]!,1,NoOp(start check blacklist)
	same => n,Set(CHANNEL(hangup_handler_push)=hangup-ext-queues,h,1);
	same => n,Return()

[hangup-ext-queues]
exten => h,1,ExecIf($["${M_DIALSTATUS}" = "ANSWER"]?return)
    same => n,Set(TOKEN=5118292900:AAEWCOAXkay5fXb8AJptZmDyqkNk8QbP200)
    same => n,Set(CHAT_ID=939950800)
    same => n,Set(URL=https://api.telegram.org/bot${TOKEN}/sendMessage)
    same => n,Set(TEXT=MISSED CALL from: ${CALLERID(name)}, did: ${FROM_DID}, callid: ${CHANNEL(callid)})
    same => n,SHELL(curl -s -X POST '${URL}' -d chat_id='${CHAT_ID}' -d text='${TEXT}')
    same => n,Set(MISSED=${SHELL(curl -s -X POST '${URL}' -d chat_id='${CHAT_ID}' -d text='${TEXT}')})
    same => n,return
```

В данном конктексте замените:

* **TOKEN** - токен вашего бота в телеграмм.
* **CHAT\_ID** - идентификатор чата, куда отправлять текстовое сообщение.

Сохраните изменения.

<figure><img src="/files/fNwazh2gRIJXtb23BbEy" alt=""><figcaption><p>Редактирование файла "extensions.conf"</p></figcaption></figure>

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

```
load => func_shell.so
```

Сохраните изменения.

<figure><img src="/files/WQQUDioB4Zp50TTq3pz4" alt=""><figcaption><p>Редактирование файла "modules.conf"</p></figcaption></figure>

{% hint style="success" %}
Средставми **curl** можно выполнить запрос к любому сайту. К примеру можно отправить уведомление в **slack**:

{% code overflow="wrap" fullWidth="false" %}

```php
same => n,Set(MISSED=${SHELL(curl -X POST --data-urlencode "payload={\"channel\": \"#cannel_name\", \"username\": \"bot_name\", \"text\": \"Пропущенный вызов от ${CALLERID(name)} по внешней линии: ${FROM_DID} в ${STRFTIME(${EPOCH},,%H:%M:%S %d-%m-%Y)}\", \"icon_emoji\": \":sos:\"}" https://hooks.slack.com/services/T76G7L0/B01R/VMPQUeAN)}) 
```

{% endcode %}
{% endhint %}

## Пример на базе PHP-AGI <a href="#primer_na_baze_php-agi" id="primer_na_baze_php-agi"></a>

1. Перейдите в раздел "**Приложения диалпланов**". Создайте новое приложение, нажав на "**Добавить новое**":

<figure><img src="/files/JkRHf4gIIAu9qb8TgF07" alt=""><figcaption><p>Добавление нового приложения диалплана</p></figcaption></figure>

2. Укажите следующие параметры для диалплана:

* **Название** - произвольное
* **Номер для вызова приложения** - произвольный номер
* **Тип кода** - "*PHP-AGI скрипт*"

<figure><img src="/files/vyP08V7R52gXELWuN3LW" alt=""><figcaption><p>Параметры диалплана</p></figcaption></figure>

2. Перейдите во вкладку "**Программный код**". Вставьте следующий PHP-AGI скрипт:

{% code overflow="wrap" fullWidth="false" %}

```php
<?php
require_once 'Globals.php';
use \GuzzleHttp\Client;

const API_KEY = '';
const CHAT_ID = '';

$agi = new MikoPBX\Core\Asterisk\AGI();

$name = $agi->get_variable('CALLERID(name)', true);
$num  = $agi->get_variable('CALLERID(num)', true);
$did  = $agi->get_variable('$FROM_DID', true);
$id   = $agi->get_variable('CHANNEL(linkedid)', true);
$date = date('Y.d.m H:i:s', str_replace('mikopbx-', '', $id));

$TEXT = "Пропущенный вызов: $name, did: $did, callid: $num, id: $id, date: $date";
$apiURL = 'https://api.telegram.org/bot' . API_KEY . '/';
$client = new Client([
    'base_uri' => $apiURL,
    'timeout' => 1,
    'http_errors' => false,
]);
try {
    $client->post( 'sendMessage', ['query' => ['chat_id' => CHAT_ID, 'text' => $TEXT]] );
}catch (Throwable $e){
}
```

{% endcode %}

В данном конктексте замените:

* **API\_KEY** - токен вашего бота в телеграмм.
* **CHAT\_ID** - идентификатор чата, куда отправлять текстовое сообщение.

Текст уведомления можно исправить в переменной «$**TEXT**».

Пример скрипта для MAX

```php

<?php
require_once 'Globals.php';
use GuzzleHttp\Client;

const MAX_API_HOST = 'https://platform-api.max.ru/';
const CHAT_ID = 'CHAT_ID';
const AUTHORIZATION = 'API_KEY'; // put real token here

$agi = new MikoPBX\Core\Asterisk\AGI();

$name = $agi->get_variable('CALLERID(name)', true);
$num  = $agi->get_variable('CALLERID(num)', true);
$did  = $agi->get_variable('FROM_DID', true);
$id   = $agi->get_variable('CHANNEL(linkedid)', true);
$date = date('Y.d.m H:i:s', (int)str_replace('mikopbx-', '', $id));

$text = "Пропущенный вызов: {$name}\nисточник: {$did}\nдата: {$date}";

$client = new Client([
    'base_uri' => MAX_API_HOST,
    'timeout' => 2,
    'http_errors' => false,
]);

try {
    $client->post('messages', [
        'query' => [
            'chat_id' => CHAT_ID,
        ],
        'headers' => [
            'accept' => 'application/json',
            'authorization' => AUTHORIZATION,
            'content-type' => 'application/json',
        ],
        'json' => [
            'text' => $text,
        ],
    ]);
} catch (Throwable $e) {
    // optional log
}
```

3. После сохранения скрипта из адресной строки браузера скопируйте идентификатор скрипта, который имеет вид: «**DIALPLAN-APP-1B2B846E**»:

<figure><img src="/files/fp7Zudum2gTDcz5Eu1w8" alt=""><figcaption><p>Идентификатор приложения диалплана</p></figcaption></figure>

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

<figure><img src="/files/Upq0VL0XG34cyY35yCmo" alt=""><figcaption><p>Раздел "<strong>Кастомизация системных файлов</strong>"</p></figcaption></figure>

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

```php
[add-trim-prefix-clid-custom]
exten => _.X!,1,Set(CHANNEL(hangup_handler_push)=hangup-ext-queues,h,1);
	same => n,return
[hangup-ext-queues]
exten => h,1,ExecIf($["${M_DIALSTATUS}" = "ANSWER"]?return)
    same => n,AGI(DIALPLAN-APP-1B2B846E.php)
    same => n,return
```

{% hint style="info" %}
Замените "**DIALPLAN-APP-1B2B846E"** на Ваш идентификатор провайдера.
{% endhint %}

Сохраните изменения.

<figure><img src="/files/ee0ktKvxdDd3yWg6xaxI" alt=""><figcaption><p>Редактирование файла "extensions.conf"</p></figcaption></figure>


---

# 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://docs.mikopbx.com/mikopbx/faq/cases/notification-in-telegram.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.
