1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AiAssistantService.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
7use Bitrix\AiAssistant\Core\Service\Bot\BotManager;
13
15{
16 private const AI_ASSISTANT_CHAT_CREATION_FEATURE_FLAG = 'ai_assistant_chat_creation_available';
17
18 private ?BotManager $botManager = null;
19
20 public function __construct()
21 {
22 if (Loader::includeModule('aiassistant'))
23 {
24 $this->botManager = ServiceLocator::getInstance()->get(BotManager::class);
25 }
26 }
27
28 public function isAiAssistantAvailable(): bool
29 {
30 return $this->botManager?->isAvailable() ?? false;
31 }
32
33 public function isAiAssistantChatCreationAvailable(): bool
34 {
35 return
37 && Option::get('im', self::AI_ASSISTANT_CHAT_CREATION_FEATURE_FLAG, 'N') === 'Y'
38 ;
39 }
40
41 public function getBotId(): int
42 {
43 return $this->botManager?->getBotId() ?? 0;
44 }
45
46 public function getPersonalAiAssistantChatId(int $userId): int
47 {
48 // TODO: add cache!!!
49 $botId = $this->getBotId();
50 if ($botId === 0)
51 {
52 return 0;
53 }
54
55 return \CIMMessage::GetChatId($botId, $userId, false);
56 }
57
58 public function isAiAssistantChat(Chat $chat): bool
59 {
60 if ($this->getBotId() === 0)
61 {
62 return false;
63 }
64
65 if (!($chat instanceof Chat\PrivateChat))
66 {
67 return false;
68 }
69
70 return $chat->getRelationByUserId($this->getBotId()) !== null;
71 }
72}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения dialog.php:11
Определения loader.php:13