18 private const COUNTER_CHAT_CODE =
'copilot_chat_counter';
22 return self::IM_TYPE_COPILOT;
27 return self::MANAGE_RIGHTS_NONE;
32 return self::MANAGE_RIGHTS_NONE;
37 return self::MANAGE_RIGHTS_NONE;
69 if (!Loader::includeModule(
'imbot'))
79 $copilotBotId = static::getBotIdOrRegister();
87 $params[
'USERS'] = [$context->getUserId(), $copilotBotId];
89 return parent::add($params, $context);
105 'MESSAGE_TYPE' => $this->
getType(),
106 'TO_CHAT_ID' => $this->getChatId(),
107 'FROM_USER_ID' =>
Bot\CopilotChatBot::getBotId(),
109 'SKIP_USER_CHECK' =>
'Y',
111 'SKIP_COUNTER_INCREMENTS' =>
'Y',
113 Params::COMPONENT_ID =>
Bot\CopilotChatBot::MESSAGE_COMPONENT_START,
114 Params::NOTIFY =>
'N',
131 unset($params[
'TITLE']);
133 return parent::prepareParams($params);
143 $copilotChatCounter = \CUserOptions::GetOption(
'im', self::COUNTER_CHAT_CODE, 1, $this->getContext()->getUserId());
144 $title =
Loc::getMessage(
'IM_CHAT_COPILOT_CHAT_TITLE', [
'#NUMBER#' => $copilotChatCounter]);
145 \CUserOptions::SetOption(
'im', self::COUNTER_CHAT_CODE, $copilotChatCounter + 1);
163 if (empty($usersToAdd))
168 foreach ($usersToAdd as $userId)
170 $relation = $this->getRelations()->getByUserId($userId, $this->getId());
171 if ($relation ===
null)
175 if ($relation->getUser()->isBot())
177 Im\Bot::changeChatMembers($this->getId(), $userId);
178 Im\Bot::onJoinChat(
'chat'.$this->getId(), [
179 'CHAT_TYPE' => $this->
getType(),
180 'MESSAGE_TYPE' => $this->
getType(),
182 'USER_ID' => $this->getContext()->getUserId(),
183 'CHAT_ID' => $this->getId(),
184 'CHAT_AUTHOR_ID' => $this->getAuthorId(),
185 'CHAT_ENTITY_TYPE' => $this->getEntityType(),
186 'CHAT_ENTITY_ID' => $this->getEntityId(),
187 'ACCESS_HISTORY' => (
int)$relation->getStartCounter() === 0,
188 'SILENT_JOIN' =>
'Y',
194 private static function getBotIdOrRegister(): int
196 return Bot\CopilotChatBot::getBotId() ?: Bot\CopilotChatBot::register();
201 return Loader::includeModule(
'imbot')
203 && static::getBotIdOrRegister();
208 $chatData = parent::toRestFormat($option);
210 $providerName = Im\V2\Integration\AI\AIHelper::getProviderName();
211 $chatData[
'aiProvider'] = $providerName;
static getType($chatData)
const COPILOT_NOT_INSTALLED
const IMBOT_NOT_INSTALLED
setCanPost(string $canPost)
sendMessageUsersAdd(array $usersToAdd, bool $skipRecent=false)
toRestFormat(array $option=[])
setManageUsersDelete(string $manageUsersDelete)
static getTitleTemplate()
add(array $params, ?Context $context=null)
sendBanner(?int $authorId=null)
sendEventUsersAdd(array $usersToAdd)
setManageUI(string $manageUI)
setManageSettings(string $manageSettings)
getDefaultManageSettings()
prepareParams(array $params=[])
setManageUsersAdd(string $manageUsersAdd)
sendDescriptionMessage(?int $authorId=null)
sendGreetingMessage(?int $authorId=null)
getDefaultManageUsersAdd()
getDefaultManageUsersDelete()
static getMessage($code, $replace=null, $language=null)