- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::botMessageLike
static function botMessageLike($arParams, $n, CRestServer $server)
{
$arParams = array_change_key_case($arParams, CASE_UPPER);
$clientId = $server->getClientId();
if (!$clientId)
{
if (!empty($arParams['CLIENT_ID']))
{
$clientId = 'custom'.$arParams['CLIENT_ID'];
}
else
{
throw new BitrixRestAccessException("Client ID not specified");
}
}
$bots = BitrixImBot::getListCache();
if (isset($arParams['BOT_ID']))
{
if (!isset($bots[$arParams['BOT_ID']]))
{
throw new BitrixRestRestException("Bot not found", "BOT_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
if ($clientId && $bots[$arParams['BOT_ID']]['APP_ID'] != $clientId)
{
throw new BitrixRestRestException("Bot was installed by another rest application", "APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
}
else
{
$botFound = false;
foreach ($bots as $bot)
{
if ($bot['APP_ID'] == $clientId)
{
$botFound = true;
$arParams['BOT_ID'] = $bot['BOT_ID'];
break;
}
}
if (!$botFound)
{
throw new BitrixRestRestException("Bot not found", "BOT_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
}
$arParams['MESSAGE_ID'] = intval($arParams['MESSAGE_ID']);
if ($arParams['MESSAGE_ID'] <= 0)
{
throw new BitrixRestRestException("Message ID can't be empty", "MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
$arParams['ACTION'] = mb_strtolower($arParams['ACTION']);
if (!in_array($arParams['ACTION'], Array('auto', 'plus', 'minus')))
{
$arParams['ACTION'] = 'auto';
}
$result = CIMMessenger::Like($arParams['MESSAGE_ID'], $arParams['ACTION'], $arParams['BOT_ID']);
if ($result === false)
{
throw new BitrixRestRestException("Action completed without changes", "WITHOUT_CHANGES", CRestServer::STATUS_WRONG_REQUEST);
}
return true;
}