> 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/customers-assessment-of-the-quality-of-service.md).

# Оценка клиентом качества обслуживания

Совершенствование качества сервиса организации - крайне важная составляющая успешной работы компании. Механизм оценки работы оператора будет полезен любому бизнесу.

В текущей статье предлагаем пример реализации механизма оценки качества клиентом для АТС MikoPBX.

### Доработка Dialplan <a href="#dorabotka_dialplan" id="dorabotka_dialplan"></a>

{% hint style="warning" %}
На АТС предварительно следует закачать файлы записей вопросов / приветствия. Формат записей WAV (Microsoft) signed 16-bit PCM.\
Файлы можно для удобства разместить в каталоге: **/storage/usbdisk1/quality/sounds**.\
В dialplan путь к файлу следует указывать **без** расширения.
{% endhint %}

Для начала дополним логику обработки входящих звонков:

1\. Перейдите в раздел **Маршрутизация** → **Провайдеры телефонии**. Откройте для редактирования учетную запись провайдера для редактирования. Скопируйте в адресной строке **ID провайдера**, через которого абоненты звонят Вам в компанию. Обращаем Ваше внимание, что в нашем примере используется **единственный** провайдер Zadarma. Если у Вас настроено подключение **нескольких** провайдеров, то ниже описанные действия необходимо выполнить **для каждого провайдера**.

В нашем примере ID провайдера принимает вид: **SIP-1687947415**

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fv8XI7uMuWMhebclrfD42%2F1.png?alt=media&amp;token=ca449376-2264-417c-ade9-25abab096067" alt=""><figcaption></figcaption></figure>

2. Перейдите в раздел **Система** → **Кастомизация системных файлов**.

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fgit-blob-adbd213bbaa83f7bdcc9924ac01d209c89fcebd3%2F2%20(41).png?alt=media" alt=""><figcaption></figcaption></figure>

3. Откройте для редактирования конфигурационный файл **extensions.conf**.

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fgit-blob-afe8aa94b342e3d40f22c5b2d9f096a94d0efd6f%2F3%20(31).png?alt=media" alt=""><figcaption></figcaption></figure>

4. Установите режим «**Добавлять в конец файла**».

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fh9W7FOk2CfApIeZCpZ90%2F4.png?alt=media&amp;token=208c530f-6880-4a70-8d9a-b4baa0215956" alt=""><figcaption></figcaption></figure>

5. В черное окно добавьте следующий фрагмент кода:

```
[SIP-PROVIDER-SIP-1687947415-after-dial-custom]
exten => _.!,1,Goto(quality-start,s,1)
	same => n,return

[SIP-PROVIDER-SIP-1687947415-outgoing-custom]
exten => _.!,1,Set(DOPTIONS=${DOPTIONS}F(quality-start,s,1))
	same => n,return

[quality-start]
exten => _.!,1,NoOp(--- Quality assessment ---)
	same => n,ExecIf($[${M_DIALSTATUS}!=ANSWER]?return)
	;Описываем путь к файлу завершения разговора. Благодарим за оценку качества. 
	same => n,Set(filename_bye=/storage/usbdisk1/quality/sounds/bye)
	; Описываем пути к файлам опроса. 
	same => n,Set(filename_1=/storage/usbdisk1/quality/sounds/miko_hello)
	same => n,Set(filename_2=/storage/usbdisk1/quality/sounds/q_1)
	same => n,Set(filename_3=/storage/usbdisk1/quality/sounds/q_2)
	same => n,Set(f_num=0);
	same => n,Goto(ivr-quality,s,1)

[ivr-quality]
exten => s,1,NoOP( start ivr quality )
	same => n,Set(f_num=$[${f_num} + 1])
 	same => n,Set(filename=${filename_${f_num}})
	same => n,GotoIf($["x${filename}" == "x"]?ivr-quality,bye,1);
	same => n,Background(${filename})
	same => n,WaitExten(5)

exten => _[1-5],1,NoOP( quality is ${EXTEN})
	; AGI скрипт, который сохранит результат оценки разговора клиентом.
	same => n,AGI(/storage/usbdisk1/quality/quality_agi.php)
	same => n,Goto(ivr-quality,s,1)

exten => _[06-9],Goto(ivr-quality,s,1)

exten => bye,1,ExecIf($["x${filename_bye}" != "x"]?Playback(${filename_bye}));
	same => n,Hangup()
```

В выше приведенном фрагменте кода Вам необходимо составить правильное наименование контекста.\
Формат создаваемого контекста:

```
[ID-ПРОВАЙДЕРА-outgoing-custom]
[ID-ПРОВАЙДЕРА-after-dial-custom]
```

* **ID-ПРОВАЙДЕРА** - значение, которое вы сохранили на первом шаге данной инструкции. В нашем примере это **SIP-PROVIDER-**&#x31;687947415.

### Скрипт обработки результата оценки <a href="#skript_obrabotki_rezultata_ocenki" id="skript_obrabotki_rezultata_ocenki"></a>

{% hint style="info" %}
Файл следует сохранить на АТС по пути **/storage/usbdisk1/quality/quality\_agi.php**\
Создать файл можно используя файловый менеджер [WinSCP](/mikopbx/faq/troubleshooting/connecting-to-a-pbx-using-winscp.md)\
Файлу следует установить права доступа на выполнение. Подключитесь по [SSH](/mikopbx/faq/troubleshooting/connecting-to-a-pbx-using-ssh/putty.md) и выполните команду

```
chmod +x /storage/usbdisk1/quality/quality_agi.php
```

{% endhint %}

Пример реализации quality\_agi.php:

```php
#!/usr/bin/php
<?php
require_once 'phpagi.php';
require_once 'globals.php';

$agi 		= new AGI();
$linkedid   = $agi->get_variable('CDR(linkedid)', true);

$arr = [
    'quality'   => $agi->request['agi_extension'],
    'f_num'     => $agi->get_variable('f_num', true),
    'filename'  => $agi->get_variable('filename', true),
    // 'Оцененный оператор:' => $operator,
    'linkedid'  => $linkedid,
    'date'      => date('Y-m-d H:i:s'),
    'callerid'  => $agi->request['agi_callerid']
];

$file_log = '/storage/usbdisk1/quality/'.$linkedid.'.log';
Util::mw_mkdir(dirname($file_log));
file_put_contents($file_log, json_encode($arr)."\n", FILE_APPEND);
```

{% hint style="info" %}
Результат оценки будет сохранятся в файлы вида **/storage/usbdisk1/quality/\<ID>.log**
{% endhint %}

Пример файла:

{% code fullWidth="false" %}

```json
{"quality":"1","f_num":"1","filename":"\/offload\/asterisk\/sounds\/other\/miko_hello","linkedid":"mikopbx-1574331248.66","date":"2019-11-21 13:14:13","callerid":"79265775289"}
{"quality":"2","f_num":"2","filename":"beep","linkedid":"mikopbx-1574331248.66","date":"2019-11-21 13:14:15","callerid":"79265775289"}
{"quality":"3","f_num":"3","filename":"\/offload\/asterisk\/sounds\/other\/out_work_times","linkedid":"mikopbx-1574331248.66","date":"2019-11-21 13:14:16","callerid":"79265775289"}
```

{% 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/cases/customers-assessment-of-the-quality-of-service.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.
