- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::botUnRegister
static function botUnRegister($arParams, $n, CRestServer $server)
{
if ($server->getAuthType() == BitrixRestSessionAuthAuth::AUTH_TYPE)
{
throw new BitrixRestRestException("Access for this method not allowed by session authorization.", "WRONG_AUTH_TYPE", CRestServer::STATUS_FORBIDDEN);
}
$arParams = array_change_key_case($arParams, CASE_UPPER);
$customClientId = false;
$clientId = $server->getClientId();
if (!$clientId)
{
if (!empty($arParams['CLIENT_ID']))
{
$customClientId = true;
$clientId = 'custom'.$arParams['CLIENT_ID'];
}
else
{
throw new BitrixRestAccessException("Client ID not specified");
}
}
$bots = BitrixImBot::getListCache();
if (!isset($bots[$arParams['BOT_ID']]))
{
throw new BitrixRestRestException("Bot not found", "BOT_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
if ($bots[$arParams['BOT_ID']]['APP_ID'] != $clientId)
{
throw new BitrixRestRestException("Bot was installed by another rest application", "APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
$result = BitrixImBot::unRegister(Array('BOT_ID' => $arParams['BOT_ID']));
if (!$result)
{
throw new BitrixRestRestException("Bot can't be deleted", "WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
}
if ($customClientId)
{
self::unbindEvent("", $arParams['CLIENT_ID'], 'im', 'onImBotMessageAdd', 'OnImBotMessageAdd', true);
self::unbindEvent("", $arParams['CLIENT_ID'], 'im', 'onImBotMessageUpdate', 'OnImBotMessageUpdate', true);
self::unbindEvent("", $arParams['CLIENT_ID'], 'im', 'onImBotMessageDelete', 'OnImBotMessageDelete', true);
self::unbindEvent("", $arParams['CLIENT_ID'], 'im', 'onImBotJoinChat', 'OnImBotJoinChat', true);
self::unbindEvent("", $arParams['CLIENT_ID'], 'im', 'onImBotDelete', 'OnImBotDelete', true);
}
return true;
}