- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/rest.php
- Класс: BitrixImOpenLinesRest
- Вызов: Rest::operatorTransfer
static function operatorTransfer($arParams, $n, CRestServer $server)
{
$arParams['CHAT_ID'] = (int)$arParams['CHAT_ID'];
if ($arParams['CHAT_ID'] <= 0)
{
throw new RestException('Chat ID can't be empty', 'CHAT_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
$transferId = null;
if (isset($arParams['TRANSFER_ID']))
{
if (mb_substr($arParams['TRANSFER_ID'], 0, 5) == 'queue')
{
$arParams['QUEUE_ID'] = mb_substr($arParams['TRANSFER_ID'], 5);
}
else
{
$arParams['USER_ID'] = $arParams['TRANSFER_ID'];
}
}
if (isset($arParams['USER_ID']))
{
$arParams['USER_ID'] = (int)$arParams['USER_ID'];
if ($arParams['USER_ID'] <= 0)
{
throw new RestException('User ID can't be empty', 'USER_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
$transferId = $arParams['USER_ID'];
}
else if (isset($arParams['QUEUE_ID']))
{
$arParams['QUEUE_ID'] = (int)$arParams['QUEUE_ID'];
if ($arParams['QUEUE_ID'] <= 0)
{
throw new RestException('QUEUE ID can't be empty', 'QUEUE_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
$transferId = 'queue'.$arParams['QUEUE_ID'];
}
else
{
throw new RestException('Queue ID or User ID can't be empty', 'TRANSFER_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
$control = new Operator($arParams['CHAT_ID']);
$result = $control->transfer([
'TRANSFER_ID' => $transferId,
]);
if (!$result)
{
throw new RestException('You can not redirect to this operator', 'OPERATOR_WRONG', CRestServer::STATUS_WRONG_REQUEST);
}
return true;
}