# Audio file name customization

{% hint style="info" %}
The customization is configured in `process_record_file_path.php`, it is located in the directory:
{% endhint %}

|          itgrix\_bx (Bitrix24)          |           itgrix\_kmo (Kommo)           |
| :-------------------------------------: | :-------------------------------------: |
| **/opt/itgrix\_bx/customizer/actions/** | **/opt/itgrix\_kmo/customizer/actions** |

## Parameters

**Input:**

```javascript
{
  "call_id": “<Call ID>”,
  "from": “<Caller number>”,
  "to": “<The number to which the call came>”,
  "path": “<Path to record>”
}
```

**Return:**

```javascript
{
  "data": {
    "path": “<Customized path to record>”
  },
  "state": "success"
}
```

{% hint style="info" %}
The first step is to understand how the file name is generated. Sometimes it is necessary to substitute a folder with a specific date or other parameters into the file path.
{% endhint %}

## File before recording .wav

In case all records are stored in one directory and their names look like .wav, the following solution of file selection customization without DBMS access is possible:

```php
$callId = $params['call_id'];
$from = $params['from'];
$to = $params['to'];
$path = $params['path'];

extract(pathinfo($path));

$path = $dirname . '/' . $callID . '.wav';

return array(
    'state' => 'success',
    'data' => array(
        'path' => $path,
    ),
);
```

## Complex file name for which data should be compiled from DBMS

Let's consider an example of customization for a format record: `/var/spool/asterisk/monitor/<дата-время>-<from>-<to>-<Call ID>.<extension>`

Example:\
`/var/spool/asterisk/monitor/20180330140245-321654987-154-1522395542.2897.mp3`

In this case we can see that the file name consists of digits - date/time of call, incoming number, internal number and uniqueid of call, which are specified with hyphens. Let's get the missing data from the database.

```php
$callId = $params['call_id'];
$from   = $params['from'];
$to     = $params['to'];
$path   = $params['path'];

// If more parameters are needed to generate a file name,
// then they can be obtained in the database by making an additional query.
// Code example:
$dbResult = Utils::mysqliQuery(
    "SELECT * FROM `cdr` WHERE `uniqueid` = '".$callId."' ORDER BY `calldate` DESC LIMIT 1",
    true);

if ($dbResult === false) {
    return array(
        'state' => 'error',
        'data'  => 'Error during request in CDR',
    );
}
if (empty($dbResult)) {
    return array(
        'state' => 'error',
        'data'  => "There are no records found in the CDR for the call '$callId'",
    );
}

//Next, we compile the file name from the received data
$row = $dbResult[0];
$path = sprintf('/var/spool/asterisk/monitor/%s-%s-%s-%s.%s',
    date('YmdHis', strtotime($row['calldate'])),
    $row['src'],
    $row['dst'],
    $callId,
    pathinfo($row['recordingfile'], PATHINFO_EXTENSION)
);

return array(
    'state' => 'success',
    'data'  => array(
        'path' => $path,
    ),
);
```


---

# Agent Instructions: 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:

```
GET https://docs.itgrix.com/custom_common/audio-file-name-customization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
