1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
Chat.php
См. документацию.
1
<?php
2
declare(strict_types=1);
3
4
namespace
Bitrix\Landing\Copilot\Connector\Chat;
5
6
use Bitrix\Main\Loader;
7
use Bitrix\Main\Security;
8
use Bitrix\Landing;
9
use Bitrix\Landing\Copilot\Model\SiteToChatTable;
10
11
class
Chat
12
{
13
private
int
$userId;
14
15
public
function
__construct
()
16
{
17
$this->userId =
Landing\Manager::getUserId
();
18
}
19
24
public
function
setUserId
(
int
$userId): self
25
{
26
if
($userId > 0)
27
{
28
$this->userId = $userId;
29
}
30
31
return
$this;
32
}
33
34
public
static
function
getCreateSiteChatBot
(): ?
ICopilotChatBot
35
{
36
return
self::getChatBot(CreateSiteChatBot::class);
37
}
38
39
public
static
function
getChangeBlockChatBot
(): ?
ICopilotChatBot
40
{
41
return
self::getChatBot(ChangeBlockChatBot::class);
42
}
43
49
private
static
function
getChatBot(
string
$botClass): ?
ICopilotChatBot
50
{
51
if
(!Loader::includeModule(
'ai'
))
52
{
53
return
null
;
54
}
55
56
static
$chatBots = [];
57
if
(!isset($chatBots[$botClass]))
58
{
62
$chatBot =
new
$botClass();
63
$chatBot?->register();
64
$chatBots[$botClass] = $chatBot;
65
}
66
67
return
$chatBots[$botClass];
68
}
69
74
public
static
function
createChatEntityId
(): string
75
{
76
return
'site_copilot_'
.
Security\Random::getString
(6);
77
}
78
79
public
function
setChatForSite
(
int
$siteId
,
int
$chatId): bool
80
{
81
$exists = SiteToChatTable::query()
82
->where(
'SITE_ID'
,
$siteId
)
83
->where(
'CHAT_ID'
, $chatId)
84
->where(
'USER_ID'
, $this->userId)
85
->fetch()
86
;
87
if
($exists)
88
{
89
return
false
;
90
}
91
92
$add = SiteToChatTable::add([
93
'SITE_ID'
=>
$siteId
,
94
'CHAT_ID'
=> $chatId,
95
'USER_ID'
=> $this->userId,
96
]);
97
98
return
$add->isSuccess();
99
}
100
101
public
function
getChatForSite
(
int
$siteId
): ?int
102
{
103
$exists = SiteToChatTable::query()
104
->setSelect([
'CHAT_ID'
])
105
->where(
'SITE_ID'
,
$siteId
)
106
->where(
'USER_ID'
, $this->userId)
107
->fetch()
108
;
109
if
($exists)
110
{
111
return
(
int
)$exists[
'CHAT_ID'
];
112
}
113
114
return
null
;
115
}
116
}
Bitrix\Landing\Copilot\Connector\Chat\Chat\__construct
__construct()
Определения
Chat.php:15
Bitrix\Landing\Copilot\Connector\Chat\Chat\getChangeBlockChatBot
static getChangeBlockChatBot()
Определения
Chat.php:39
Bitrix\Landing\Copilot\Connector\Chat\Chat\getChatForSite
getChatForSite(int $siteId)
Определения
Chat.php:101
Bitrix\Landing\Copilot\Connector\Chat\Chat\createChatEntityId
static createChatEntityId()
Определения
Chat.php:74
Bitrix\Landing\Copilot\Connector\Chat\Chat\getCreateSiteChatBot
static getCreateSiteChatBot()
Определения
Chat.php:34
Bitrix\Landing\Copilot\Connector\Chat\Chat\setChatForSite
setChatForSite(int $siteId, int $chatId)
Определения
Chat.php:79
Bitrix\Landing\Copilot\Connector\Chat\Chat\setUserId
setUserId(int $userId)
Определения
Chat.php:24
Bitrix\Landing\Manager\getUserId
static getUserId()
Определения
manager.php:107
Bitrix\Main\Security\Random\getString
static getString($length, $caseSensitive=false)
Определения
random.php:76
Bitrix\Landing\Copilot\Connector\Chat\ICopilotChatBot
Определения
ICopilotChatBot.php:7
$siteId
$siteId
Определения
ajax.php:8
Bitrix\Landing\Chat
Определения
binding.php:2
bitrix
modules
landing
lib
Copilot
Connector
Chat
Chat.php
Создано системой
1.14.0