• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::dialogContextGet
static function dialogContextGet($arParams, $n, CRestServer $server)
{
	$arParams = array_change_key_case($arParams, CASE_UPPER);
	if (!isset($arParams['MESSAGE_ID']) || (int)$arParams['MESSAGE_ID'] <= 0)
	{
		throw new BitrixRestRestException('Message ID can`t be empty', 'MESSAGE_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
	}

	$messageId = (int)$arParams['MESSAGE_ID'];

	$message = new BitrixImV2Message($messageId);

	if ($message->getMessageId() === null)
	{
		throw new BitrixRestRestException('Message not found', BitrixImV2MessageMessageError::MESSAGE_NOT_FOUND, CRestServer::STATUS_WRONG_REQUEST);
	}

	if (!$message->getChat()->hasAccess())
	{
		throw new BitrixRestRestException('You do not have access to this chat', BitrixImV2RestRestError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	if (!isset($arParams['RANGE']))
	{
		throw new BitrixRestRestException('Range can`t be empty', 'RANGE_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
	}

	$range = (int)$arParams['RANGE'];
	$range = ($range <= 50 && $range >= 0) ? $range : 50;

	$result = (new BitrixImV2MessageMessageService($message))->getMessageContext($range);
	if (!$result->isSuccess())
	{
		$error = $result->getErrors()[0];
		if (isset($error))
		{
			throw new BitrixRestRestException($error->getMessage(), $error->getCode(), CRestServer::STATUS_WRONG_REQUEST);
		}
	}

	/** @var BitrixImV2MessageCollection $messages */
	$messages = $result->getResult();

	return (new BitrixImV2RestRestAdapter($messages))->toRestFormat();
}