- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/rest.php
- Класс: BitrixImOpenLinesRest
- Вызов: Rest::botSessionTransfer
static function botSessionTransfer($arParams, $n, CRestServer $server)
{
if ($server->getAuthType() == SessionAuthAuth::AUTH_TYPE)
{
throw new RestException('Access for this method not allowed by session authorization.', 'WRONG_AUTH_TYPE', CRestServer::STATUS_FORBIDDEN);
}
$arParams['CHAT_ID'] = (int)$arParams['CHAT_ID'];
$arParams['LEAVE'] = isset($arParams['LEAVE']) && $arParams['LEAVE'] == 'Y'? 'Y': 'N';
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);
}
$bots = ImBot::getListCache();
$botFound = false;
$botId = 0;
foreach ($bots as $bot)
{
if ($bot['APP_ID'] == $server->getAppId())
{
$botFound = true;
$botId = $bot['BOT_ID'];
break;
}
}
if (!$botFound)
{
throw new RestException('Bot not found', 'BOT_ID_ERROR', CRestServer::STATUS_WRONG_REQUEST);
}
$chat = new Chat($arParams['CHAT_ID']);
$result = $chat->transfer(Array(
'FROM' => $botId,
'TO' => $transferId,
'MODE' => Chat::TRANSFER_MODE_BOT,
'LEAVE' => $arParams['LEAVE']
));
if (!$result)
{
throw new RestException('You can not redirect to this operator', 'OPERATOR_WRONG', CRestServer::STATUS_WRONG_REQUEST);
}
return true;
}