Общие вопросы по API ВАТС MANGO OFFICE

Функции API Виртуальной АТС

  • Уведомление о входящем звонке
  • Совершение исходящего звонка
  • Получение истории звонков
  • Получение записей разговоров
  • Перемаршрутизация звонков
  • Перехват звонков
  • Получение списка и контактов сотрудников
  • Групповой звонок с автоматическим выбором свободного оператора
  • Выбор линии АТС для исходящего звонка
  • Уведомление о нажатиях DTMF клавиш

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

Использование функции описано в технической документации API MANGO OFFICE, примерах использования (см. ниже) и дополнительных примерах:

Запрос на звонок

Пример выполнения запроса:

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свой ключ
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свою подпись

$url = 'https://app.mango-office.ru/vpbx/commands/callback';

$data = array(
    "command_id" => "ID" . rand(10000000, 99999999),

    "from" => array(
        "extension" => "101", // внутренний номер, за счет которого производится звонок (например 101)

        "number" => "sip:example@example.mangosip.ru"
        // "number" => "74951234567"
    ),

    "to_number" => "74950001122"
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign'         => $sign,
    'json'         => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);

curl_close($ch);

echo $response; // вывести результат команды

?>

Запрос на звонок с подстановкой определенного номера DID из личного кабинета

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свой ключ
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свою подпись

$url = 'https://app.mango-office.ru/vpbx/commands/callback';

$data = array(
    "command_id" => "ID" . rand(10000000,99999999),

    "from" => array(
        "extension" => "101", // внутренний номер сотрудника, за счет которого производится звонок (например 101)

        "number" => "sip:example@example.mangosip.ru"
        // "number" => "74950001122"
    ),

    "to_number"  => "74950007788", // кому позвонить
    "line_number" => "74950000666" // АОН (номер линии)
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign' => $sign,
    'json' => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);

curl_close($ch);

echo $response;

?>

Запрос на групповой звонок

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свой ключ
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свою подпись

$url = 'https://app.mango-office.ru/vpbx/commands/callback_group';

$data = array(
    "command_id" => "ID" . rand(10000000,99999999),

    "from" => "222", // внутренний номер группы

    "to" => "79260001122", // номер клиента

    "line_number" => "74957777777" // номер линии (АОН)
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign' => $sign,
    'json' => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);

curl_close($ch);

echo $response;

?>

Запрос истории

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // указать свой ключ
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // указать свою подпись

$url = 'https://app.mango-office.ru/vpbx/stats/request';

$data = array(
    "date_from" => "1481630491",
    "date_to"   => "1481734491",

    "from" => array(
        "extension" => "",
        "number"    => ""
    ),

    "to" => array(
        "extension" => "",
        "number"    => ""
    ),

    "fields" => "records,start,finish,answer,from_extension,from_number,to_extension,to_number,disconnect_reason,line_number,location,entry_id"
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign'         => $sign,
    'json'         => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = json_decode(curl_exec($ch));

curl_close($ch);

// Получить ключ запроса в переменную $response.

// Запрос на получение массива данных статистики вызовов.

$url_result = 'https://app.mango-office.ru/vpbx/stats/result';

$data_result = $response;

$json_result = json_encode($data_result);

$sign_result = hash('sha256', $api_key . $json_result . $api_salt);

$post_data_result = array(
    'vpbx_api_key' => $api_key,
    'sign'         => $sign_result,
    'json'         => $json_result
);

$post_result = http_build_query($post_data_result);

$ch_result = curl_init($url_result);

curl_setopt($ch_result, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_result, CURLOPT_POST, 1);
curl_setopt($ch_result, CURLOPT_POSTFIELDS, $post_result);

$history_data = curl_exec($ch_result);

curl_close($ch_result);

echo $history_data; // вывести полученную историю

?>

Запрос на получение записи

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свой ключ
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // вставить свою подпись

$url = 'https://app.mango-office.ru/vpbx/queries/recording/post/';

$data = array(
    "recording_id" => "MTo4MzE0NjoyODU4NzI0NjQ1OjA=", // идентификатор записи
    "action" => "download" // download — скачать, play — воспроизвести
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign' => $sign,
    'json' => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

$response = curl_exec($ch);

curl_close($ch);

$link = substr($response, strripos($response, 'location') + 9);

echo $link; // вывести ссылку на MP3

?>

Запрос на получение всех сотрудников

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxx';

$url = 'https://app.mango-office.ru/vpbx/config/users/request';

$data = array(
    // Оставьте массив пустым, чтобы получить список всех сотрудников.
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign' => $sign,
    'json' => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);

curl_close($ch);

echo $response; // вывести список сотрудников

?>

Запрос на получение сотрудника

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxx';

$url = 'https://app.mango-office.ru/vpbx/config/users/request';

$data = array(
    "extension" => "27" // добавочный номер сотрудника
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign' => $sign,
    'json' => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);

curl_close($ch);

echo $response; // вывести информацию о сотруднике

?>

Запрос на отправку SMS

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Уникальный код вашей АТС
$api_salt = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Ключ для создания подписи

$url = 'https://app.mango-office.ru/vpbx/commands/sms';

$data = array(
    "command_id"    => "ID" . rand(10000000, 99999999), // идентификатор команды
    "from_extension" => "101",                          // внутренний номер сотрудника
    "text"          => "Example php SMS Send",          // текст SMS
    "to_number"     => "74950001122",                   // номер получателя
    "sms_sender"    => ""                               // имя отправителя; если не заполнено, используется имя из Личного кабинета
);

$json = json_encode($data);

$sign = hash('sha256', $api_key . $json . $api_salt);

$postdata = array(
    'vpbx_api_key' => $api_key,
    'sign'         => $sign,
    'json'         => $json
);

$post = http_build_query($postdata);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);

curl_close($ch);

echo $response; // вывести результат

?>

Сетевые настройки

Для корректной работы API необходимо настроить доступ к следующим IP-адресам.

IP-адреса для уведомлений

API отправляет уведомления на внешние системы со следующих IP-адресов:

  • 81.88.80.132
  • 81.88.80.133
  • 81.88.82.36

IP-адрес API

Для выполнения запросов используйте следующий IP-адрес:

  • 81.88.85.67

Настройка сетевого оборудования

На сетевом оборудовании необходимо открыть доступ к следующему IP-адресу:

  • 81.88.82.36

Примечание

Услуга записи разговоров тарифицируется в зависимости от версии Виртуальной АТС.

Подключить API вы можете в личном кабинете. Получить больше информации обо всех особенностях и возможностях API вы можете на странице Подключение по API

npm библиотека для API Виртуальной АТС. Смотреть подробнее.

Примечание: техническая поддержка MANGO OFFICE не предоставляет консультацию по использованию вышеупомянутой npm библиотеки.