3namespace Bitrix\Im\V2\Chat;
7use Bitrix\Im\V2\Analytics\ChatAnalytics;
8use Bitrix\Im\V2\Call\CallToken;
10use Bitrix\Im\V2\Chat\Copilot\CopilotPopupItem;
11use Bitrix\Im\V2\Chat\Param\Params;
12use Bitrix\Im\V2\Entity\File\ChatAvatar;
13use Bitrix\Im\V2\Entity\User\User;
14use Bitrix\Im\V2\Entity\User\UserCollection;
15use Bitrix\Im\V2\Entity\User\UserPopupItem;
16use Bitrix\Im\V2\Entity\User\UserType;
17use Bitrix\Im\V2\Integration\AI\AIHelper;
18use Bitrix\Im\V2\Integration\AI\EngineManager;
19use Bitrix\Im\V2\Integration\AI\RoleManager;
20use Bitrix\Im\V2\Integration\HumanResources\Structure;
21use Bitrix\Im\V2\Logger;
22use Bitrix\Im\V2\Message;
23use Bitrix\Im\V2\Message\Send\PushService;
24use Bitrix\Im\V2\Message\Send\SendingConfig;
25use Bitrix\Im\V2\Relation;
26use Bitrix\Im\V2\Relation\AddUsersConfig;
27use Bitrix\Im\V2\Rest\PopupData;
28use Bitrix\Im\V2\Rest\PopupDataAggregatable;
29use Bitrix\Im\V2\Result;
30use Bitrix\Im\V2\Service\Context;
31use Bitrix\ImBot\Bot\Network;
32use Bitrix\ImBot\Bot\Support24;
33use Bitrix\ImBot\Bot\SupportBox;
34use Bitrix\Main\Loader;
35use Bitrix\Main\Localization\Loc;
37use Bitrix\Im\V2\Message\Delete\DisappearService;
43 return self::IM_TYPE_CHAT;
64 return !$this->getEntityType();
71 if ($this->getRelationByUserId(
$userId) ===
null)
81 if (empty($structureNodes))
86 (
new Structure($this))->link($structureNodes);
91 if (empty($structureNodes))
96 (
new Structure($this))->unlink($structureNodes);
102 $skipAddMessage = (
$params[
'SKIP_ADD_MESSAGE'] ??
'N') ===
'Y';
103 $forceSendGreetingMessages = (
$params[
'SEND_GREETING_MESSAGES'] ??
'N') ===
'Y';
105 if ($paramsResult->isSuccess())
107 $params = $paramsResult->getResult();
111 return $result->addErrors($paramsResult->getErrors());
115 $chat->onBeforeAdd();
118 if (!$chat->getChatId())
123 $addedUsers = $usersToInvite = $chat->getUserIds() ?? [];
124 if ($chat->getAuthorId())
126 $addedUsers[$chat->getAuthorId()] = $chat->getAuthorId();
127 unset($usersToInvite[$chat->getAuthorId()]);
130 $chat->addUsersToRelation($addedUsers, $addUsersConfig);
131 $needToSendGreetingMessages = !$skipAddMessage && ($chat->needToSendGreetingMessages() || $forceSendGreetingMessages);
132 if ($needToSendGreetingMessages)
134 $chat->sendGreetingMessage($this->getContext()->getUserId());
135 $chat->sendBanner($this->getContext()->getUserId());
138 if (!$skipAddMessage)
140 $chat->sendMessageUsersAdd($usersToInvite, $addUsersConfig);
142 $chat->linkToStructureNodes(
$params[
'STRUCTURE_NODES'] ?? []);
143 $chat->sendEventUsersAdd($addedUsers);
145 if (!$skipAddMessage)
147 $chat->sendDescriptionMessage();
152 'CHAT_ID' => $chat->getChatId(),
157 $chat->onUserAddAfterChatAdd($usersToInvite);
164 $userIds = $this->getUserIds() ?? [];
165 $containsExtranet = UserCollection::hasUserByType($userIds, UserType::EXTRANET);
166 $this->setExtranet($containsExtranet)->setContext(
$context);
167 if (UserCollection::hasUserByType($userIds, UserType::COLLABER))
169 $this->getChatParams()->addParamByName(Params::CONTAINS_COLLABER,
true,
false);
170 $this->getChatParams()->addParamByName(Params::CONTAINS_COLLABER,
true,
false);
172 if (AIHelper::containsCopilotBot($this->usersIds))
177 $this->setUserCount(
count($userIds));
184 self::cleanCache($this->getChatId());
185 $this->isFilledNonCachedData =
false;
190 $this->disableUserDeleteMessage();
196 isset(
$params[
'MESSAGES_AUTO_DELETE_DELAY'])
197 && (
int)
$params[
'MESSAGES_AUTO_DELETE_DELAY'] !== 0
198 && !DisappearService::checkAvailability($this->getExtendedType(
false))->isSuccess()
201 unset(
$params[
'MESSAGES_AUTO_DELETE_DELAY']);
215 'Using AUTHOR_ID = 0 is deprecated and will be disallowed soon. Please provide a valid user ID.'
225 'The specified AUTHOR_ID does not match any existing user. Please provide a valid user ID.'
238 $params[
'AUTHOR_ID'] = (int)(
$params[
'AUTHOR_ID'] ?? $this->getContext()->getUserId());
240 if (!$validateAuthorIdResult->isSuccess())
242 (
new Logger(
'chat-creation-author-id-error'))->logErrors($validateAuthorIdResult->getErrorCollection());
245 $users =
$params[
'USERS'] ?? [];
246 $managers =
$params[
'MANAGERS'] ?? [];
247 $params[
'USERS'] = is_array($users) ? $users : [];
248 $params[
'MANAGERS'] = is_array($managers) ? $managers : [];
249 [$users, $structureNodes] = Structure::splitEntities(
$params[
'MEMBER_ENTITIES'] ?? []);
253 $params[
'STRUCTURE_NODES'] = $structureNodes;
257 && !is_numeric((
string)
$params[
'AVATAR'])
270 parent::addUsersToRelation($usersToAdd,
$config);
288 $usersMap[(int)
$userId] = $isManager;
303 $relations = $this->getRelations();
305 foreach ($usersMap as
$userId => $isManager)
307 $relation = $relations->getByUserId(
$userId, $this->getChatId());
308 if ($relation ===
null)
313 $relation->setManager($isManager);
315 if ($this->chatId !==
null)
321 $relations->save(
true);
335 'command' =>
'chatManagers',
337 'dialogId' => $this->getDialogId(),
338 'chatId' => $this->getId(),
339 'list' => $this->getManagerList()
353 if (!$this->getTitle())
365 $colorCodeKey =
'im_chat_color_' . $this->getColor();
366 $colorCodeCount = \CGlobalCounter::GetValue($colorCodeKey, \CGlobalCounter::ALL_SITES);
370 \CGlobalCounter::Set($colorCodeKey, 1, \CGlobalCounter::ALL_SITES,
'',
false);
373 $chatTitle = Loc::getMessage(
'IM_CHAT_NAME_FORMAT', [
375 '#NUMBER#' => ++$colorCodeCount,
377 \CGlobalCounter::Set($colorCodeKey, $colorCodeCount, \CGlobalCounter::ALL_SITES,
'',
false);
382 if ($this->getUserIds() &&
count($this->getUserIds()))
384 $userIds = $this->getUserIds();
386 $userIds = \CIMContactList::PrepareUserIds($userIds);
387 $users = \CIMContactList::GetUserData([
388 'ID' => array_values($userIds),
394 foreach ($users[
'users'] as
$user)
399 $chatTitle = Loc::getMessage(
'IM_CHAT_NAME_FORMAT_USERS', [
400 '#USERS_NAMES#' => implode(
', ', $usersNames),
404 return mb_substr($chatTitle, 0, 255);
410 $push = $pushFormat->formatMessageUpdate();
411 $push[
'params'][
'dialogId'] = $this->getDialogId();
412 if ($this->
getType() === self::IM_TYPE_COMMENT)
414 \CPullWatch::AddToStack(
'IM_PUBLIC_COMMENT_' .
$message->getChat()->getParentChatId(), $push);
418 Event::add($this->getUsersForPush(
true,
false), $push);
420 if ($this->needToSendPublicPull())
422 \CPullWatch::AddToStack(
'IM_PUBLIC_' .
$message->getChatId(), $push);
424 if ($this->
getType() === Chat::IM_TYPE_OPEN_CHANNEL &&
$message->getId() ===
$message->getChat()->getLastMessageId())
434 $authorId = $this->getAuthorId();
438 $replace = [
'#USER_NAME#' =>
"[USER={$authorId}][/USER]"];
444 'MESSAGE_TYPE' => $this->
getType(),
445 'TO_CHAT_ID' => $this->getChatId(),
446 'FROM_USER_ID' => $author->getId(),
447 'MESSAGE' => $messageText,
450 'SKIP_COUNTER_INCREMENTS' =>
'Y',
457 if ($authorId !== $this->getAuthorId())
465 return 'IM_CHAT_CREATE_' . $author->getGender();
470 $messageText = Loc::getMessage(
471 'IM_CHAT_APPOINT_OWNER_' . $author->getGender(),
479 'MESSAGE_TYPE' => $this->
getType(),
480 'TO_CHAT_ID' => $this->getChatId(),
481 'FROM_USER_ID' => $author->getId(),
482 'MESSAGE' => $messageText,
492 $authorId = $this->getAuthorId();
497 in_array($this->
getType(), [self::IM_TYPE_CHAT, self::IM_TYPE_OPEN, self::IM_TYPE_COPILOT],
true)
498 && empty($this->getEntityType())
502 'MESSAGE_TYPE' => $this->
getType(),
503 'TO_CHAT_ID' => $this->getChatId(),
504 'FROM_USER_ID' => $author->getId(),
505 'MESSAGE' => Loc::getMessage(
'IM_CHAT_CREATE_WELCOME_MSGVER_1'),
509 'COMPONENT_ID' =>
'ChatCreationMessage',
512 'SKIP_COUNTER_INCREMENTS' =>
'Y',
521 $authorId = $this->getAuthorId();
525 $userIds = array_unique($this->getUserIds());
526 if (
count($userIds) < 2)
531 $userIds = \CIMContactList::PrepareUserIds($userIds);
532 $users = \CIMContactList::GetUserData([
533 'ID' => array_values($userIds),
538 if (!isset($users[
'users']) ||
count($users[
'users']) < 2)
545 if ($authorId !== $this->getAuthorId())
550 foreach ($users[
'users'] as
$user)
552 if (
$user[
'name'] !== $author->getName())
558 $messageText = Loc::getMessage(
559 'IM_CHAT_JOIN_' . $author->getGender(),
562 '#USER_2_NAME#' => implode(
', ', array_unique($usersNames))
567 'MESSAGE_TYPE' => $this->
getType(),
568 'TO_CHAT_ID' => $this->getChatId(),
569 'FROM_USER_ID' => $author->getId(),
570 'MESSAGE' => $messageText,
581 $message->setAuthorId($this->getContext()->getUserId());
594 if (!Loader::includeModule(
'imbot'))
599 if ($this->getEntityType() !== Support24::CHAT_ENTITY_TYPE && $this->getEntityType() !== Network::CHAT_ENTITY_TYPE)
606 ->filter(fn (
Relation $relation) => !$relation->getUser()->isBot())
611 if ($this->getEntityType() === Support24::CHAT_ENTITY_TYPE)
613 if (Loader::includeModule(
'bitrix24') && Support24::isEnabled())
615 return Support24::getMultidialog($this->getId(), $this->getAuthorId(),
$userId) ?? [];
618 return SupportBox::getMultidialog($this->getId(), $this->getAuthorId(),
$userId) ?? [];
621 if ($this->getEntityType() === Network::CHAT_ENTITY_TYPE)
623 return Network::getMultidialog($this->getId(), $this->getAuthorId(),
$userId) ?? [];
631 if (!$this->getDescription())
638 $authorId = $this->getAuthorId();
642 'MESSAGE_TYPE' => $this->
getType(),
643 'TO_CHAT_ID' => $this->getChatId(),
644 'FROM_USER_ID' => $authorId,
651 return (
bool)$this->getChatParams()->get(Params::IS_COPILOT)?->getValue();
657 Loader::includeModule(
'imbot')
661 return (
new RoleManager())->getMainRole($this->getChatId());
669 $this->getChatParams()->addParamByName(
Chat\
Param\Params::IS_COPILOT,
true,
false);
674 if (isset($engineCode))
687 return $this->getChatParams()->get(
Chat\
Param\Params::COPILOT_ENGINE_CODE)?->getValue();
698 if (!$engineManager->validateEngineCode(
$code) || !$this->containsCopilot())
703 $engineCode = (string)$this->getChatParams()->get(
Chat\
Param\Params::COPILOT_ENGINE_CODE)?->getValue();
704 if ($engineCode !==
$code)
706 $this->getChatParams()->addParamByName(
Chat\
Param\Params::COPILOT_ENGINE_CODE,
$code,
false);
714 return EngineManager::getDefaultEngineCode();
719 $result = parent::mirrorDataEntityFields();
722 'get' =>
'getEngineCode',
723 'set' =>
'setEngineCode',
724 'default' =>
'getDefaultEngineCode',
734 $userId = $this->getContext()->getUserId();
736 return parent::getPopupData($excludedList)
738 ->add(CopilotPopupItem::getInstanceByChatIds([$this->getChatId()]))
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getType($chatData, bool $camelCase=true)
sendMessageAuthorChange(\Bitrix\Im\V2\Entity\User\User $author)
needToSendGreetingMessages()
onUserAddAfterChatAdd(array $addedUsers)
checkAccessInternal(int $userId)
prepareMessage(Message $message)
deleteManagers(array $userIds, bool $sendPush=true)
sendPushUpdateMessage(Message $message)
needToSendMessageUserDelete()
add(array $params, ?Context $context=null)
onAfterAdd(?Context $context=null)
getPopupData(array $excludedList=[])
setEngineCode(?string $code)
validateAuthorId(int $authorId)
sendBanner(?int $authorId=null)
getPushService(Message $message, SendingConfig $config)
onBeforeAdd(?Context $context=null)
unlinkStructureNodes(array $structureNodes)
changeManagers(array $userIds, bool $isManager, bool $sendPush=true)
prepareParams(array $params=[])
changeManagersByMap(array $usersMap, bool $sendPush=true)
filterParams(array $params)
sendDescriptionMessage(?int $authorId=null)
sendGreetingMessage(?int $authorId=null)
linkToStructureNodes(array $structureNodes)
sendInviteMessage(?int $authorId=null)
addUsersToRelation(array $usersToAdd, AddUsersConfig $config)
addManagers(array $userIds, bool $sendPush=true)
getCodeGreetingMessage(\Bitrix\Im\V2\Entity\User\User $author)
fillCopilotBeforeChatAdd(?Context $context)
static mirrorDataEntityFields()
static sendSharedPull(array $pull)
static saveAvatarByString(string $avatarBase64)
static getInstance(?int $id)
static sendMessageAfterChatAdd(Chat $chat)
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static GetStartChatMessage()
</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
htmlspecialcharsback($str)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']