- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::dialogMessagesGet
static function dialogMessagesGet($arParams, $offset, CRestServer $server)
{
$arParams = array_change_key_case($arParams, CASE_UPPER);
if (isset($arParams['CHAT_ID']) && intval($arParams['CHAT_ID']) > 0)
{
$arParams['DIALOG_ID'] = 'chat'.$arParams['CHAT_ID'];
}
if (!BitrixImCommon::isDialogId($arParams['DIALOG_ID']))
{
throw new BitrixRestRestException("Dialog ID can't be empty", "DIALOG_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
}
if (!BitrixImDialog::hasAccess($arParams['DIALOG_ID']))
{
throw new BitrixRestRestException("You do not have access to the specified dialog", "ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
}
$chatId = BitrixImDialog::getChatId($arParams['DIALOG_ID']);
if (isset($arParams['FIRST_ID']))
{
if (!preg_match('/^d{1,}$/i', $arParams['FIRST_ID']))
{
throw new BitrixRestRestException("First ID can't be string", "FIRST_ID_STRING", CRestServer::STATUS_WRONG_REQUEST);
}
$options['FIRST_ID'] = intval($arParams['FIRST_ID']);
}
else if (isset($arParams['LAST_ID']))
{
if (!preg_match('/^d{1,}$/i', $arParams['LAST_ID']))
{
throw new BitrixRestRestException("Last ID can't be string", "LAST_ID_STRING", CRestServer::STATUS_WRONG_REQUEST);
}
$options['LAST_ID'] = intval($arParams['LAST_ID']) > 0? intval($arParams['LAST_ID']): 0;
}
$options['LIMIT'] = isset($arParams['LIMIT'])? (intval($arParams['LIMIT']) > 50? 50: intval($arParams['LIMIT'])): 20;
$options['CONVERT_TEXT'] = isset($arParams['CONVERT_TEXT']) && $arParams['CONVERT_TEXT'] == 'Y';
$options['JSON'] = 'Y';
return BitrixImChat::getMessages($chatId, null, $options);
}