1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
AiAssistantService.php
См. документацию.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Bitrix\Im\V2\Integration\AiAssistant
;
6
7
use Bitrix\AiAssistant\Core\Service\Bot\BotManager;
8
use
Bitrix\Im\Dialog
;
9
use
Bitrix\Im\V2\Chat
;
10
use
Bitrix\Main\Config\Option
;
11
use
Bitrix\Main\DI\ServiceLocator
;
12
use
Bitrix\Main\Loader
;
13
14
class
AiAssistantService
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
36
$this->
isAiAssistantAvailable
()
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
}
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Im\Dialog
Определения
dialog.php:11
Bitrix\Im\V2\Chat\PrivateChat
Определения
PrivateChat.php:33
Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService
Определения
AiAssistantService.php:15
Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService\__construct
__construct()
Определения
AiAssistantService.php:20
Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService\isAiAssistantAvailable
isAiAssistantAvailable()
Определения
AiAssistantService.php:28
Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService\getBotId
getBotId()
Определения
AiAssistantService.php:41
Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService\getPersonalAiAssistantChatId
getPersonalAiAssistantChatId(int $userId)
Определения
AiAssistantService.php:46
Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService\isAiAssistantChatCreationAvailable
isAiAssistantChatCreationAvailable()
Определения
AiAssistantService.php:33
Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService\isAiAssistantChat
isAiAssistantChat(Chat $chat)
Определения
AiAssistantService.php:58
Bitrix\Main\Config\Option
Определения
option.php:15
Bitrix\Main\DI\ServiceLocator
Определения
servicelocator.php:19
Bitrix\Main\Loader
Определения
loader.php:13
Bitrix\Im\V2\Chat
Bitrix\Im\V2\Integration\AiAssistant
Определения
AiAssistantService.php:5
bitrix
modules
im
lib
V2
Integration
AiAssistant
AiAssistantService.php
Создано системой
1.14.0