- Модуль: imbot
- Путь к файлу: ~/bitrix/modules/imbot/lib/bot/network.php
- Класс: BitrixImBotBotNetwork
- Вызов: Network::operatorMessageReceived
static function operatorMessageReceived($params)
{
if (!MainLoader::includeModule('im'))
{
return false;
}
$messageData = ImModelMessageTable::getList([
'select' => ['CHAT_ID'],
'filter' => ['=ID' => $params['MESSAGE_ID']]
])->fetch();
if (!$messageData)
{
return false;
}
$chatId = -1;
if (BitrixImCommon::isChatId($params['DIALOG_ID']))
{
$chatCheckRes = BitrixImModelBotChatTable::getList([
'select' => ['CHAT_ID'],
'filter' => [
'=BOT_ID' => (int)$params['BOT_ID'],
'=CHAT_ID' => (int)BitrixImDialog::getChatId($params['DIALOG_ID']),
]
]);
if ($chatCheck = $chatCheckRes->fetch())
{
$chatId = (int)$chatCheck['CHAT_ID'];
}
}
else
{
$chatId = (int)CIMMessage::getChatId($params['BOT_ID'], $params['DIALOG_ID']);
}
if ($chatId <= 0)
{
return false;
}
if ($messageData['CHAT_ID'] != $chatId)
{
return false;
}
$messageParamData = ImModelMessageParamTable::getList([
'select' => ['PARAM_VALUE'],
'filter' => [
'=MESSAGE_ID' => $params['MESSAGE_ID'],
'=PARAM_NAME' => self::MESSAGE_PARAM_SENDING
]
])->fetch();
if (!$messageParamData || $messageParamData['PARAM_VALUE'] != 'Y')
{
return false;
}
$messageParams = [
self::MESSAGE_PARAM_SENDING => 'N',
self::MESSAGE_PARAM_SENDING_TIME => 0,
];
if ($params['CONNECTOR_MID'])
{
$messageParams[self::MESSAGE_PARAM_CONNECTOR_MID] = $params['CONNECTOR_MID'];
}
if ((int)$params['SESSION_ID'] > 0)
{
$messageParams[self::MESSAGE_PARAM_SESSION_ID] = $params['SESSION_ID'];
}
CIMMessageParam::set($params['MESSAGE_ID'], $messageParams);
CIMMessageParam::sendPull($params['MESSAGE_ID'], array_keys($messageParams));
if ((int)$params['SESSION_ID'] > 0)
{
self::instanceDialogSession((int)$params['BOT_ID'], $params['DIALOG_ID'])
->setSessionId((int)$params['SESSION_ID']);
}
return true;
}