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

	if (!BitrixImCommon::isDialogId($arParams['DIALOG_ID']))
	{
		throw new BitrixRestRestException("Dialog ID can't be empty", "DIALOG_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
	}

	BitrixImBot::startWriting(Array('BOT_ID' => $arParams['BOT_ID']), $arParams['DIALOG_ID']);

	return true;
}