1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
CopilotChatBot.php
См. документацию.
1
<?php
2
declare(strict_types=1);
3
4
namespace
Bitrix\Landing\Copilot\Connector\Chat;
5
6
use Bitrix\AI\Chatbot\Chatbot;
7
use Bitrix\AI\Chatbot\Message\Message;
8
use Bitrix\AI\Chatbot\Message\SystemMessage;
9
use Bitrix\Landing\Copilot\Generation\Type\GenerationErrors;
10
use Bitrix\Landing\Manager;
11
use Bitrix\Pull;
12
13
abstract
class
CopilotChatBot
extends
Chatbot implements
ICopilotChatBot
14
{
18
public
function
sendErrorMessage
(
ChatBotMessageDto
$message
): void
19
{
20
$errorCode =
$message
->errorCode;
21
if
(!$errorCode)
22
{
23
return
;
24
}
25
26
$chatId =
$message
->chatId;
27
if
($chatId <= 0)
28
{
29
return
;
30
}
31
32
if
($errorCode === GenerationErrors::requestQuotaExceeded)
33
{
34
$answer = $this->
getQuotaExceededMessage
($message);
35
}
36
elseif
($errorCode === GenerationErrors::restrictedRequest)
37
{
38
$answer = $this->
getRestrictedRequestMessage
($message);
39
}
40
elseif
(
41
$errorCode === GenerationErrors::notExistResponse
42
|| $errorCode === GenerationErrors::notFullyResponse
43
|| $errorCode === GenerationErrors::notCorrectResponse
44
|| $errorCode === GenerationErrors::errorInRequest
45
)
46
{
47
$answer = $this->
getVendorErrorMessage
($message);
48
}
49
elseif
(
50
$errorCode === GenerationErrors::dataValidation
51
|| $errorCode === GenerationErrors::notSendRequest
52
)
53
{
54
$answer = $this->
getB24ErrorMessage
($message);
55
}
56
57
if
(!isset($answer))
58
{
59
$answer =
new
SystemMessage(
'Unknown error'
);
60
}
61
62
$this->sendAnswer(
$message
->chatId, $answer);
63
$this->stopWriting(
$message
->chatId,
false
);
64
}
65
70
abstract
protected
function
getQuotaExceededMessage
(
ChatBotMessageDto
$message
): ?
Message
;
71
75
abstract
protected
function
getRestrictedRequestMessage
(
ChatBotMessageDto
$message
):
Message
;
76
80
abstract
protected
function
getVendorErrorMessage
(
ChatBotMessageDto
$message
):
Message
;
81
85
abstract
protected
function
getB24ErrorMessage
(
ChatBotMessageDto
$message
):
Message
;
86
90
public
function
onRequestQuotaOk
(
ChatBotMessageDto
$message
): void
91
{
92
$chatId =
$message
->chatId;
93
if
($chatId <= 0)
94
{
95
return
;
96
}
97
98
$this->sendAnswer($chatId, $this->
getStartGenerationMessage
());
99
$this->stopWriting($chatId,
false
);
100
}
101
105
abstract
protected
function
getStartGenerationMessage
():
Message
;
106
110
abstract
protected
function
getFinishGenerationMessage
():
Message
;
111
112
protected
function
sendFrontendEvent
(
ChatBotCommands
$command,
array
$params
= []): void
113
{
114
$userId
=
Manager::getUserId
();
115
if
(
$userId
<= 0)
116
{
117
return
;
118
}
119
120
$commandName =
'LandingCopilotChatbot:on'
. ucfirst($command->value);
121
Pull\Event::add
(
$userId
, [
122
'module_id'
=>
'landing'
,
123
'command'
=> $commandName,
124
'params'
=>
$params
,
125
]);
126
Pull\Event::send
();
127
}
128
}
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Landing\Copilot\Connector\Chat\ChatBotMessageDto
Определения
ChatBotMessageDto.php:9
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot
Определения
CopilotChatBot.php:14
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\sendErrorMessage
sendErrorMessage(ChatBotMessageDto $message)
Определения
CopilotChatBot.php:18
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\getB24ErrorMessage
getB24ErrorMessage(ChatBotMessageDto $message)
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\onRequestQuotaOk
onRequestQuotaOk(ChatBotMessageDto $message)
Определения
CopilotChatBot.php:90
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\getQuotaExceededMessage
getQuotaExceededMessage(ChatBotMessageDto $message)
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\sendFrontendEvent
sendFrontendEvent(ChatBotCommands $command, array $params=[])
Определения
CopilotChatBot.php:112
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\getStartGenerationMessage
getStartGenerationMessage()
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\getFinishGenerationMessage
getFinishGenerationMessage()
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\getVendorErrorMessage
getVendorErrorMessage(ChatBotMessageDto $message)
Bitrix\Landing\Copilot\Connector\Chat\CopilotChatBot\getRestrictedRequestMessage
getRestrictedRequestMessage(ChatBotMessageDto $message)
Bitrix\Landing\Manager\getUserId
static getUserId()
Определения
manager.php:107
Bitrix\Pull\DTO\Message
Определения
message.php:8
Bitrix\Pull\Event\send
static send()
Определения
event.php:387
Bitrix\Pull\Event\add
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения
event.php:22
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Landing\Copilot\Connector\Chat\ICopilotChatBot
Определения
ICopilotChatBot.php:7
Bitrix\Landing\Copilot\Connector\Chat\ChatBotCommands
ChatBotCommands
Определения
ChatBotCommands.php:7
$message
$message
Определения
payment.php:8
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
bitrix
modules
landing
lib
Copilot
Connector
Chat
CopilotChatBot.php
Создано системой
1.14.0