• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::botMessageDelete
static function botMessageDelete($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);
	}

	$res = CIMMessenger::Delete($arParams['MESSAGE_ID'], $arParams['BOT_ID'], $arParams['COMPLETE'] == 'Y');
	if (!$res)
	{
		throw new BitrixRestRestException("Time has expired for modification or you don't have access", "CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
	}

	return true;
}