5use Bitrix\Im\V2\Chat\Background\Background;
6use Bitrix\Im\V2\Chat\Background\BackgroundId;
7use Bitrix\Im\V2\Chat\PrivateChat;
8use Bitrix\Im\V2\Entity\User\Data\BotData;
9use Bitrix\Im\V2\Message;
11use Bitrix\Main\Localization\Loc;
13Loc::loadMessages(__FILE__);
53 $type = in_array(
$fields[
'TYPE'], [self::TYPE_BOT, self::TYPE_SUPERVISOR, self::TYPE_NETWORK, self::TYPE_OPENLINE])
57 $installType = in_array(
$fields[
'INSTALL_TYPE'], [self::INSTALL_TYPE_SYSTEM, self::INSTALL_TYPE_USER, self::INSTALL_TYPE_SILENT])
59 : self::INSTALL_TYPE_SILENT;
60 $botFields =
$fields[
'PROPERTIES'];
65 $methodBotDelete = isset(
$fields[
'METHOD_BOT_DELETE'])?
$fields[
'METHOD_BOT_DELETE']:
'';
66 $methodMessageAdd = isset(
$fields[
'METHOD_MESSAGE_ADD'])?
$fields[
'METHOD_MESSAGE_ADD']:
'';
67 $methodMessageUpdate = isset(
$fields[
'METHOD_MESSAGE_UPDATE'])?
$fields[
'METHOD_MESSAGE_UPDATE']:
'';
68 $methodMessageDelete = isset(
$fields[
'METHOD_MESSAGE_DELETE'])?
$fields[
'METHOD_MESSAGE_DELETE']:
'';
69 $methodWelcomeMessage = isset(
$fields[
'METHOD_WELCOME_MESSAGE'])?
$fields[
'METHOD_WELCOME_MESSAGE']:
'';
70 $methodContextGet = isset(
$fields[
'METHOD_CONTEXT_GET']) ?
$fields[
'METHOD_CONTEXT_GET'] :
'';
71 $textPrivateWelcomeMessage = isset(
$fields[
'TEXT_PRIVATE_WELCOME_MESSAGE'])?
$fields[
'TEXT_PRIVATE_WELCOME_MESSAGE']:
'';
72 $textChatWelcomeMessage = isset(
$fields[
'TEXT_CHAT_WELCOME_MESSAGE'])?
$fields[
'TEXT_CHAT_WELCOME_MESSAGE']:
'';
73 $openline = isset(
$fields[
'OPENLINE']) &&
$fields[
'OPENLINE'] ==
'Y'?
'Y':
'N';
74 $isHidden = isset(
$fields[
'HIDDEN']) &&
$fields[
'HIDDEN'] ===
'Y' ?
'Y' :
'N';
75 $backgroundId = Background::validateBackgroundId(
$fields[
'BACKGROUND_ID'] ??
null);
78 if (
$type == self::TYPE_OPENLINE)
81 $installType = self::INSTALL_TYPE_SILENT;
86 $verified = isset(
$fields[
'VERIFIED']) &&
$fields[
'VERIFIED'] ==
'Y'?
'Y':
'N';
97 if (empty($class) || empty($methodMessageAdd))
101 if (!(!empty($methodWelcomeMessage) || isset(
$fields[
'TEXT_PRIVATE_WELCOME_MESSAGE'])))
107 $bots = self::getListCache();
110 foreach ($bots as $bot)
114 return $bot[
'BOT_ID'];
122 if (isset($botFields[
'COLOR']))
124 $color = $botFields[
'COLOR'];
125 unset($botFields[
'COLOR']);
129 if ($installType == self::INSTALL_TYPE_USER)
138 if (is_object(
$USER))
145 $installType = self::INSTALL_TYPE_SYSTEM;
154 if (!(isset($botFields[
'NAME']) || isset($botFields[
'LAST_NAME'])))
159 $botFields[
'LOGIN'] = mb_substr(self::LOGIN_START. mb_substr($userCode, 0, 40).
'_'.
randString(5), 0, 50);
160 $botFields[
'PASSWORD'] = md5($botFields[
'LOGIN'].
'|'.rand(1000,9999).
'|'.time());
161 $botFields[
'CONFIRM_PASSWORD'] = $botFields[
'PASSWORD'];
162 $botFields[
'EXTERNAL_AUTH_ID'] = self::EXTERNAL_AUTH_ID;
164 unset($botFields[
'GROUP_ID']);
166 $botFields[
'ACTIVE'] =
'Y';
168 unset($botFields[
'UF_DEPARTMENT']);
170 $botFields[
'WORK_POSITION'] = isset($botFields[
'WORK_POSITION'])? trim($botFields[
'WORK_POSITION']):
'';
171 if (empty($botFields[
'WORK_POSITION']))
173 $botFields[
'WORK_POSITION'] = Loc::getMessage(
'BOT_DEFAULT_WORK_POSITION');
177 $botId =
$user->Add($botFields);
183 $result = \Bitrix\Im\Model\BotTable::add(Array(
189 'LANG' => $language? $language:
'',
190 'METHOD_BOT_DELETE' => $methodBotDelete,
191 'METHOD_MESSAGE_ADD' => $methodMessageAdd,
192 'METHOD_MESSAGE_UPDATE' => $methodMessageUpdate,
193 'METHOD_MESSAGE_DELETE' => $methodMessageDelete,
194 'METHOD_WELCOME_MESSAGE' => $methodWelcomeMessage,
195 'METHOD_CONTEXT_GET' => $methodContextGet,
196 'TEXT_PRIVATE_WELCOME_MESSAGE' => $textPrivateWelcomeMessage,
197 'TEXT_CHAT_WELCOME_MESSAGE' => $textChatWelcomeMessage,
199 'VERIFIED' => $verified,
200 'OPENLINE' => $openline,
201 'HIDDEN' => $isHidden,
202 'BACKGROUND_ID' => $backgroundId,
205 $cache = \Bitrix\Main\Data\Cache::createInstance();
206 $cache->cleanDir(self::CACHE_PATH);
210 if (\
Bitrix\
Main\Loader::includeModule(
'pull'))
214 \CIMStatus::SetColor($botId, $color);
217 self::sendPullNotify($botId,
'botAdd');
219 if ($installType != self::INSTALL_TYPE_SILENT)
226 $message = Loc::getMessage(
'BOT_MESSAGE_INSTALL_USER'.($userGender ==
'F'?
'_F':
''), Array(
'#USER_NAME#' =>
$userName));
230 $message = Loc::getMessage(
'BOT_MESSAGE_INSTALL_SYSTEM');
233 $attach = new \CIMMessageParamAttach(
null, $color);
234 $attach->AddBot(Array(
241 \CIMChat::AddGeneralMessage(Array(
244 'SKIP_USER_CHECK' =>
'Y',
253 $user->Delete($botId);
266 $botId = intval($bot[
'BOT_ID']);
267 $moduleId = isset($bot[
'MODULE_ID'])? $bot[
'MODULE_ID']:
'';
268 $appId = isset($bot[
'APP_ID'])? $bot[
'APP_ID']:
'';
270 if (intval($botId) <= 0)
275 $bots = self::getListCache();
276 if (!isset($bots[$botId]))
286 if ($appId <>
'' && $bots[$botId][
'APP_ID'] != $appId)
291 \Bitrix\Im\Model\BotTable::delete($botId);
293 $cache = \Bitrix\Main\Data\Cache::createInstance();
294 $cache->cleanDir(self::CACHE_PATH);
297 $user->Delete($botId);
299 if (\
Bitrix\
Main\Loader::includeModule($bots[$botId][
'MODULE_ID']) && $bots[$botId][
"METHOD_BOT_DELETE"] && class_exists($bots[$botId][
"CLASS"]) && method_exists($bots[$botId][
"CLASS"], $bots[$botId][
"METHOD_BOT_DELETE"]))
301 call_user_func_array(
array($bots[$botId][
"CLASS"], $bots[$botId][
"METHOD_BOT_DELETE"]), Array($botId));
309 $orm = \Bitrix\Im\Model\CommandTable::getList(Array(
310 'filter' => Array(
'=BOT_ID' => $botId)
312 while ($row = $orm->fetch())
317 $orm = \Bitrix\Im\Model\AppTable::getList(Array(
318 'filter' => Array(
'=BOT_ID' => $botId)
320 while ($row = $orm->fetch())
325 self::sendPullNotify($botId,
'botDelete');
339 $botId = intval($bot[
'BOT_ID']);
340 $moduleId = isset($bot[
'MODULE_ID'])? $bot[
'MODULE_ID']:
'';
341 $appId = isset($bot[
'APP_ID'])? $bot[
'APP_ID']:
'';
353 $bots = self::getListCache();
354 if (!isset($bots[$botId]))
364 if ($appId <>
'' && $bots[$botId][
'APP_ID'] != $appId)
369 if (isset($updateFields[
'PROPERTIES']))
371 $update = $updateFields[
'PROPERTIES'];
373 $update[
'EXTERNAL_AUTH_ID'] = self::EXTERNAL_AUTH_ID;
375 if (isset($update[
'NAME']) && trim($update[
'NAME']) ==
'')
377 unset($update[
'NAME']);
379 if (isset($update[
'WORK_POSITION']) && trim($update[
'WORK_POSITION']) ==
'')
381 $update[
'WORK_POSITION'] = Loc::getMessage(
'BOT_DEFAULT_WORK_POSITION');
385 $delBotAvatar =
false;
386 $previousBotAvatar =
false;
388 !empty($update[
'PERSONAL_PHOTO'])
389 && is_numeric($update[
'PERSONAL_PHOTO'])
390 && (
int)$update[
'PERSONAL_PHOTO'] > 0
394 $botAvatar = (int)$update[
'PERSONAL_PHOTO'];
397 !empty($update[
'DELETE_PERSONAL_PHOTO'])
398 && $update[
'DELETE_PERSONAL_PHOTO'] ==
'Y'
402 $delBotAvatar =
true;
410 $update[
'CONFIRM_PASSWORD'],
412 $update[
'UF_DEPARTMENT'],
413 $update[
'PERSONAL_PHOTO'],
414 $update[
'DELETE_PERSONAL_PHOTO']
418 $user->Update($botId, $update);
420 if ($botAvatar > 0 && $botAvatar !== $previousBotAvatar)
423 $connection->query(
"UPDATE b_user SET PERSONAL_PHOTO = ".(
int)$botAvatar.
" WHERE ID = ".(
int)$botId);
428 $connection->query(
"UPDATE b_user SET PERSONAL_PHOTO = null WHERE ID = ".(
int)$botId);
431 if ($previousBotAvatar > 0)
433 \CFile::Delete($previousBotAvatar);
438 if (isset($updateFields[
'CLASS']) && !empty($updateFields[
'CLASS']))
440 $update[
'CLASS'] = $updateFields[
'CLASS'];
442 if (isset($updateFields[
'TYPE']) && !empty($updateFields[
'TYPE']))
444 $update[
'TYPE'] = $updateFields[
'TYPE'];
446 if (isset($updateFields[
'CODE']) && !empty($updateFields[
'CODE']))
448 $update[
'CODE'] = $updateFields[
'CODE'];
450 if (isset($updateFields[
'APP_ID']) && !empty($updateFields[
'APP_ID']))
452 $update[
'APP_ID'] = $updateFields[
'APP_ID'];
454 if (isset($updateFields[
'LANG']))
456 $update[
'LANG'] = $updateFields[
'LANG']? $updateFields[
'LANG']:
'';
458 if (isset($updateFields[
'METHOD_BOT_DELETE']))
460 $update[
'METHOD_BOT_DELETE'] = $updateFields[
'METHOD_BOT_DELETE'];
462 if (isset($updateFields[
'METHOD_MESSAGE_ADD']))
464 $update[
'METHOD_MESSAGE_ADD'] = $updateFields[
'METHOD_MESSAGE_ADD'];
466 if (isset($updateFields[
'METHOD_MESSAGE_UPDATE']))
468 $update[
'METHOD_MESSAGE_UPDATE'] = $updateFields[
'METHOD_MESSAGE_UPDATE'];
470 if (isset($updateFields[
'METHOD_MESSAGE_DELETE']))
472 $update[
'METHOD_MESSAGE_DELETE'] = $updateFields[
'METHOD_MESSAGE_DELETE'];
474 if (isset($updateFields[
'METHOD_WELCOME_MESSAGE']))
476 $update[
'METHOD_WELCOME_MESSAGE'] = $updateFields[
'METHOD_WELCOME_MESSAGE'];
478 if (isset($updateFields[
'METHOD_CONTEXT_GET']))
480 $update[
'METHOD_CONTEXT_GET'] = $updateFields[
'METHOD_CONTEXT_GET'];
482 if (isset($updateFields[
'TEXT_PRIVATE_WELCOME_MESSAGE']))
484 $update[
'TEXT_PRIVATE_WELCOME_MESSAGE'] = $updateFields[
'TEXT_PRIVATE_WELCOME_MESSAGE'];
486 if (isset($updateFields[
'TEXT_CHAT_WELCOME_MESSAGE']))
488 $update[
'TEXT_CHAT_WELCOME_MESSAGE'] = $updateFields[
'TEXT_CHAT_WELCOME_MESSAGE'];
490 if (isset($updateFields[
'VERIFIED']))
492 $update[
'VERIFIED'] = $updateFields[
'VERIFIED'] ==
'Y'?
'Y':
'N';
494 if (isset($updateFields[
'HIDDEN']))
496 $update[
'HIDDEN'] = $updateFields[
'HIDDEN'] ===
'Y' ?
'Y' :
'N';
498 if (isset($updateFields[
'BACKGROUND_ID']))
500 $update[
'BACKGROUND_ID'] = Background::validateBackgroundId($updateFields[
'BACKGROUND_ID']);
504 \Bitrix\Im\Model\BotTable::update($botId, $update);
506 $cache = \Bitrix\Main\Data\Cache::createInstance();
507 $cache->cleanDir(self::CACHE_PATH);
510 self::sendPullNotify($botId,
'botUpdate');
525 if (!\
Bitrix\
Main\Loader::includeModule(
'pull'))
530 $botForJs = self::getListForJs();
531 if (!isset($botForJs[$botId]))
536 if ($messageType ===
'botAdd' || $messageType ===
'botUpdate')
539 $userData = \CIMContactList::GetUserData([
543 'SHOW_ONLINE' =>
'N',
547 return \CPullStack::AddShared([
549 'command' => $messageType,
551 'bot' => $botForJs[$botId],
552 'user' => $userData[
'users'][$botId],
553 'userInGroup' => $userData[
'userInGroup'],
558 elseif ($messageType ===
'botDelete')
560 return \CPullStack::AddShared([
562 'command' => $messageType,
581 if (!\
Bitrix\
Main\Loader::includeModule(
'pull'))
592 $botForJs = self::getListForJs();
593 if (!isset($botForJs[$botId]))
598 return \Bitrix\Pull\Event::add(
$userId, [
601 'command' =>
'applicationOpenChat',
637 foreach ($botExecModule as
$params)
648 \Bitrix\Im\Model\BotTable::update(
$params[
'BOT_ID'],
array(
654 else if (class_exists(
$params[
"CLASS"]) && method_exists(
$params[
"CLASS"],
"onMessageAdd"))
662 $eventParams = [$botExecModule,
$messageId, $messageFieldsForEvents];
669 && \
Bitrix\
Main\Loader::includeModule(
'imopenlines')
672 $chat = new \Bitrix\Imopenlines\Chat(
$messageFields[
'TO_CHAT_ID']);
673 $chat->endBotSession();
707 foreach ($botExecModule as
$params)
716 if (
$params[
"METHOD_MESSAGE_UPDATE"] && class_exists(
$params[
"CLASS"]) && method_exists(
$params[
"CLASS"],
$params[
"METHOD_MESSAGE_UPDATE"]))
720 else if (class_exists(
$params[
"CLASS"]) && method_exists(
$params[
"CLASS"],
"onMessageUpdate"))
729 $eventParams = [$botExecModule,
$messageId, $messageFieldsForEvents];
748 foreach ($botExecModule as
$params)
757 if (
$params[
"METHOD_MESSAGE_DELETE"] && class_exists(
$params[
"CLASS"]) && method_exists(
$params[
"CLASS"],
$params[
"METHOD_MESSAGE_DELETE"]))
761 else if (class_exists(
$params[
"CLASS"]) && method_exists(
$params[
"CLASS"],
"onMessageDelete"))
778 $bots = self::getListCache();
784 if (!isset($joinFields[
'BOT_ID']) || !$bots[$joinFields[
'BOT_ID']])
789 $bot = $bots[$joinFields[
'BOT_ID']];
791 if (!\
Bitrix\
Main\Loader::includeModule($bot[
'MODULE_ID']))
804 \Bitrix\Im\Model\BotTable::update($joinFields[
'BOT_ID'], $updateCounter);
806 if ($bot[
"METHOD_WELCOME_MESSAGE"] && class_exists($bot[
"CLASS"]) && method_exists($bot[
"CLASS"], $bot[
"METHOD_WELCOME_MESSAGE"]))
808 call_user_func_array(
array($bot[
"CLASS"], $bot[
"METHOD_WELCOME_MESSAGE"]), Array($dialogId, $joinFields));
811 $bot[
"TEXT_PRIVATE_WELCOME_MESSAGE"] <>
''
813 && $joinFields[
'FROM_USER_ID'] != $joinFields[
'BOT_ID']
816 if ($bot[
'TYPE'] == self::TYPE_HUMAN)
818 self::startWriting(Array(
'BOT_ID' => $joinFields[
'BOT_ID']), $dialogId);
822 self::addMessage(Array(
'BOT_ID' => $joinFields[
'BOT_ID']), Array(
823 'DIALOG_ID' => $dialogId,
824 'MESSAGE' => str_replace(Array(
'#USER_NAME#'), Array(
$userName), $bot[
"TEXT_PRIVATE_WELCOME_MESSAGE"]),
828 $bot[
"TEXT_CHAT_WELCOME_MESSAGE"] <>
''
829 && in_array($joinFields[
'CHAT_TYPE'], \CIMChat::getGroupTypesExtra())
830 && $joinFields[
'FROM_USER_ID'] != $joinFields[
'BOT_ID']
833 if ($bot[
'TYPE'] == self::TYPE_HUMAN)
835 self::startWriting(Array(
'BOT_ID' => $joinFields[
'BOT_ID']), $dialogId);
838 self::addMessage(Array(
'BOT_ID' => $joinFields[
'BOT_ID']), Array(
839 'DIALOG_ID' => $dialogId,
840 'MESSAGE' => str_replace(Array(
'#USER_NAME#'), Array(
$userName), $bot[
"TEXT_CHAT_WELCOME_MESSAGE"]),
854 $bots = self::getListCache();
860 if (!isset($leaveFields[
'BOT_ID']) || !$bots[$leaveFields[
'BOT_ID']])
865 $bot = $bots[$leaveFields[
'BOT_ID']];
867 if (!\
Bitrix\
Main\Loader::includeModule($bot[
'MODULE_ID']))
880 \Bitrix\Im\Model\BotTable::update($leaveFields[
'BOT_ID'], $updateCounter);
893 $botList = $chat->getBotInChat();
895 $dialogId = self::getDialogIdByChat($chat);
896 if ($dialogId ===
null)
901 foreach ($botList as $botId)
906 || !\
Bitrix\
Main\Loader::includeModule($botData[
'MODULE_ID'])
912 $botsForEvent[$botId] = $botData;
914 if ($botData[
"METHOD_CONTEXT_GET"] && class_exists($botData[
"CLASS"]) && method_exists($botData[
"CLASS"], $botData[
"METHOD_CONTEXT_GET"]))
916 call_user_func([$botData[
"CLASS"], $botData[
"METHOD_CONTEXT_GET"]], $dialogId,
$params);
918 else if (class_exists($botData[
"CLASS"]) && method_exists($botData[
"CLASS"],
"onContextGet"))
920 call_user_func([$botData[
"CLASS"],
"onContextGet"], $dialogId,
$params);
924 if (empty($botsForEvent))
944 $params[
'CHAT_USER_COUNT'] = 2;
948 $params[
'CHAT_USER_COUNT'] = $chat->getUserCount();
952 ->setMessage(
$params[
'MESSAGE'] ??
'')
953 ->getUserIdsFromMention()
956 $params[
'PLATFORM_CONTEXT'] = self::getPlatformContext();
963 $botId = $bot[
'BOT_ID'];
964 $moduleId = isset($bot[
'MODULE_ID'])? $bot[
'MODULE_ID']:
'';
965 $appId = isset($bot[
'APP_ID'])? $bot[
'APP_ID']:
'';
967 if (intval($botId) <= 0)
977 $bots = self::getListCache();
978 if (!isset($bots[$botId]))
988 if ($appId <>
'' && $bots[$botId][
'APP_ID'] != $appId)
993 \CIMMessenger::StartWriting($dialogId, $botId,
$userName);
1000 $botId = (int)$bot[
'BOT_ID'];
1002 if (!self::checkBotValid($botId))
1009 if ($chat->getRelationByUserId($botId) ===
null)
1014 $chat->getBackground()->set($backgroundId);
1021 return self::changeChatTextFieldInternal($bot, $dialogId,
true);
1026 return self::changeChatTextFieldInternal($bot, $dialogId,
false);
1029 private static function changeChatTextFieldInternal(
array $bot, $dialogId,
bool $textFieldEnabled): bool
1031 $botId = (int)$bot[
'BOT_ID'];
1033 if (!self::checkBotValid($botId))
1040 if ($chat->getRelationByUserId($botId) ===
null)
1045 $chat->getTextFieldEnabled()->set($textFieldEnabled);
1050 private static function checkBotValid(
int $botId): bool
1063 if (!isset($botData))
1103 $botId = $bot[
'BOT_ID'];
1104 $moduleId = isset($bot[
'MODULE_ID'])? $bot[
'MODULE_ID']:
'';
1105 $appId = isset($bot[
'APP_ID'])? $bot[
'APP_ID']:
'';
1107 if (intval($botId) <= 0)
1117 $bots = self::getListCache();
1118 if (!isset($bots[$botId]))
1128 if ($appId <>
'' && $bots[$botId][
'APP_ID'] != $appId)
1133 $isPrivateSystem =
false;
1138 $isPrivateSystem =
true;
1158 if (\CIMChat::GetGeneralChatId() == $chatId && !\CIMChat::CanSendMessageToGeneralChat($botId))
1165 "FROM_USER_ID" => $botId,
1166 "TO_CHAT_ID" => $chatId,
1178 $ar[
'SYSTEM'] =
'Y';
1183 $ar[
'URL_PREVIEW'] =
'N';
1187 $ar[
'SKIP_CONNECTOR'] =
'Y';
1188 $ar[
'SILENT_CONNECTOR'] =
'Y';
1190 $ar[
'SKIP_COMMAND'] =
'Y';
1191 $id = \CIMChat::AddMessage(
$ar);
1196 if ($isPrivateSystem)
1201 $messageFields[
'MESSAGE'] = Loc::getMessage(
"BOT_MESSAGE_FROM", Array(
"#BOT_NAME#" =>
"[USER=".$botId.
"][/USER][BR]")).$messageFields[
'MESSAGE'];
1206 $fromUserId = $botId;
1211 "FROM_USER_ID" => $fromUserId,
1224 $ar[
'SYSTEM'] =
'Y';
1228 $ar[
'URL_PREVIEW'] =
'N';
1232 $ar[
'SKIP_CONNECTOR'] =
'Y';
1233 $ar[
'SILENT_CONNECTOR'] =
'Y';
1235 $ar[
'SKIP_COMMAND'] =
'Y';
1269 $botId = $bot[
'BOT_ID'];
1270 $moduleId = isset($bot[
'MODULE_ID'])? $bot[
'MODULE_ID']:
'';
1271 $appId = isset($bot[
'APP_ID'])? $bot[
'APP_ID']:
'';
1273 if (intval($botId) <= 0)
1279 $bots = self::getListCache();
1280 if (!isset($bots[$botId]))
1286 if ($appId <>
'' && $bots[$botId][
'APP_ID'] != $appId)
1301 \CIMMessageParam::Set(
$messageId, Array(
'ATTACH' => Array()));
1303 else if (
$messageFields[
'ATTACH'] instanceof \CIMMessageParamAttach)
1316 \CIMMessageParam::Set(
$messageId, Array(
'KEYBOARD' =>
'N'));
1331 \CIMMessageParam::Set(
$messageId, Array(
'MENU' =>
'N'));
1354 \CIMMessageParam::SendPull(
$messageId, Array(
'KEYBOARD',
'ATTACH',
'MENU'));
1361 $botId = $bot[
'BOT_ID'];
1362 $moduleId = isset($bot[
'MODULE_ID'])? $bot[
'MODULE_ID']:
'';
1363 $appId = isset($bot[
'APP_ID'])? $bot[
'APP_ID']:
'';
1369 if (intval($botId) <= 0)
1375 $bots = self::getListCache();
1376 if (!isset($bots[$botId]))
1382 if ($appId <>
'' && $bots[$botId][
'APP_ID'] != $appId)
1385 return \CIMMessenger::Delete(
$messageId, $botId);
1390 $botId = $bot[
'BOT_ID'];
1391 $moduleId = isset($bot[
'MODULE_ID'])? $bot[
'MODULE_ID']:
'';
1392 $appId = isset($bot[
'APP_ID'])? $bot[
'APP_ID']:
'';
1398 if (intval($botId) <= 0)
1404 $bots = self::getListCache();
1405 if (!isset($bots[$botId]))
1411 if ($appId <>
'' && $bots[$botId][
'APP_ID'] != $appId)
1425 $dialogId =
'chat'.($messageFields[
'TO_CHAT_ID'] ??
$messageFields[
'CHAT_ID']);
1435 return (
string)$chat->getContext()->getUserId();
1438 return $chat->getDialogId();
1443 $botList = self::getListCache();
1444 return isset($botList[$botId])? $botList[$botId]:
false;
1449 $cache = \Bitrix\Main\Data\Cache::createInstance();
1450 $cache->cleanDir(self::CACHE_PATH);
1457 $cache = \Bitrix\Main\Data\Cache::createInstance();
1458 if($cache->initCache(self::CACHE_TTL,
'list_r5', self::CACHE_PATH))
1465 $orm = \Bitrix\Im\Model\BotTable::getList();
1466 while ($row = $orm->fetch())
1468 $row[
'LANG'] = $row[
'LANG']? $row[
'LANG']:
null;
1469 $result[$row[
'BOT_ID']] = $row;
1472 $cache->startDataCache();
1473 $cache->endDataCache(
$result);
1476 if (
$type == self::LIST_OPENLINE)
1478 foreach (
$result as $botId => $botData)
1480 if ($botData[
'OPENLINE'] !=
'Y' || $botData[
'CODE'] ==
'marta')
1493 $bots = self::getListCache();
1494 foreach ($bots as $bot)
1497 $code = $bot[
'CODE'];
1499 if ($bot[
'TYPE'] == self::TYPE_NETWORK)
1504 $bot[
'CLASS'] == \
Bitrix\ImBot\
Bot\Support24::class
1505 || $bot[
'CLASS'] == \
Bitrix\ImBot\
Bot\SaleSupport24::class
1508 $type =
'support24';
1509 $code =
'network_cloud';
1511 else if ($bot[
'CLASS'] == \
Bitrix\ImBot\
Bot\Partner24::class)
1513 $type =
'support24';
1514 $code =
'network_partner';
1516 else if ($bot[
'CLASS'] == \
Bitrix\ImBot\
Bot\SupportBox::class)
1518 $type =
'support24';
1519 $code =
'network_box';
1522 else if ($bot[
'TYPE'] == self::TYPE_OPENLINE)
1526 else if ($bot[
'TYPE'] == self::TYPE_SUPERVISOR)
1528 $type =
'supervisor';
1531 $result[$bot[
'BOT_ID']] = Array(
1532 'id' => $bot[
'BOT_ID'],
1535 'openline' => $bot[
'OPENLINE'] ==
'Y',
1536 'backgroundId' => $bot[
'BACKGROUND_ID'] ??
null,
1575 $cache = \Bitrix\Main\Data\Cache::createInstance();
1576 if($cache->initCache(self::CACHE_TTL,
'language_v2',
'/bx/im/'))
1578 $languageId = $cache->getVars();
1585 'select' =>
array(
'LID',
'LANGUAGE_ID'),
1586 'filter' =>
array(
'=DEF' =>
'Y',
'=ACTIVE' =>
'Y'),
1587 'cache' => [
'ttl' => 86400],
1590 $languageId = (string)
$site[
'LANGUAGE_ID'];
1592 if ($languageId ==
'')
1594 if (\
Bitrix\
Main\Loader::includeModule(
'bitrix24'))
1596 $languageId = \CBitrix24::getLicensePrefix();
1600 $languageId = LANGUAGE_ID;
1603 if ($languageId ==
'')
1608 $languageId = mb_strtolower($languageId);
1610 $cache->startDataCache();
1611 $cache->endDataCache($languageId);
1619 $orm = \Bitrix\Im\Model\BotTokenTable::getList(Array(
1623 'select' =>
array(
'ID'),
1626 if ($token = $orm->fetch())
1632 DELETE FROM b_im_bot_token
1633 WHERE DATE_EXPIRE < ".$sqlHelper->getCurrentDateTimeFunction().
"
1637 return __METHOD__.
'();';
1646 $bots = self::getListCache();
1665 $botExecModule = [];
1685 else if (preg_match_all(
"/\[USER=([0-9]+)( REPLACE)?](.*?)\[\/USER]/i",
$message,
$matches))
1698 if (isset($bots[$botId]) && $bots[$botId][
'TYPE'] == self::TYPE_SUPERVISOR)
1700 $botFound[$botId] = $botId;
1704 if (!empty($botFound))
1706 foreach ($botFound as $botId)
1708 if (!isset($bots[$botId]))
1712 if (
$messageFields[
'CHAT_ENTITY_TYPE'] ==
'LINES' && $bots[$botId][
'OPENLINE'] ==
'N')
1716 $botExecModule[$botId] = $bots[$botId];
1721 return $botExecModule;
1726 self::$platformContext = self::resolvePlatformContext(
$context);
1733 'Bitrix24.Mobile', self::PLATFORM_CONTEXT_MOBILE => self::PLATFORM_CONTEXT_MOBILE,
1734 default => self::PLATFORM_CONTEXT_WEB,
1740 if (self::$platformContext !==
null)
1742 return self::$platformContext;
1746 self::$platformContext = self::resolvePlatformContext(
$context);
1748 return self::$platformContext;
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static unRegister(array $app)
static setPlatformContext(string $context)
static string $platformContext
const INSTALL_TYPE_SILENT
static onContextGet(\Bitrix\Im\V2\Chat $chat, array $params)
static unRegister(array $bot)
static addMessage(array $bot, array $messageFields)
static sendPullOpenDialog(int $botId, int $userId=null)
static onLeaveChat($dialogId, $leaveFields)
static onMessageAdd($messageId, $messageFields)
static setChatBackgroundId(array $bot, $dialogId, string $backgroundId)
const INSTALL_TYPE_SYSTEM
static update(array $bot, array $updateFields)
static getDefaultLanguage()
const PLATFORM_CONTEXT_MOBILE
static onMessageUpdate($messageId, $messageFields)
static addAdditionalParams(array $params)
static onMessageDelete($messageId, $messageFields)
static deleteMessage(array $bot, $messageId)
static deleteExpiredTokenAgent()
static enableChatTextField(array $bot, $dialogId)
static disableChatTextField(array $bot, $dialogId)
static sendPullNotify($botId, $messageType)
static getDialogId($messageFields)
static likeMessage(array $bot, $messageId, $action='AUTO')
const PLATFORM_CONTEXT_WEB
static getListCache($type=self::LIST_ALL)
static startWriting(array $bot, $dialogId, $userName='')
static resolvePlatformContext(string $context)
static onJoinChat($dialogId, $joinFields)
static getPlatformContext()
static getDialogIdByChat(\Bitrix\Im\V2\Chat $chat)
static updateMessage(array $bot, array $messageFields)
static unRegister(array $command)
static getUserId($userId=null)
static getChatId($dialogId, $userId=null)
static getInstance($userId=null)
static getInstance(?int $id)
static getConnection($name="")
static getList(array $parameters=array())
static detect(?string $userAgent=null)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
ExecuteModuleEventEx($arEvent, $arParams=[])
randString($pass_len=10, $pass_chars=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']