1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CopilotChatBot.php
См. документацию.
1<?php
2declare(strict_types=1);
3
4namespace Bitrix\Landing\Copilot\Connector\Chat;
5
6use Bitrix\AI\Chatbot\Chatbot;
7use Bitrix\AI\Chatbot\Message\Message;
8use Bitrix\AI\Chatbot\Message\SystemMessage;
9use Bitrix\Landing\Copilot\Generation\Type\GenerationErrors;
10use Bitrix\Landing\Manager;
11use Bitrix\Pull;
12
13abstract class CopilotChatBot extends Chatbot implements ICopilotChatBot
14{
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
71
76
81
86
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 {
115 if ($userId <= 0)
116 {
117 return;
118 }
119
120 $commandName = 'LandingCopilotChatbot:on' . ucfirst($command->value);
122 'module_id' => 'landing',
123 'command' => $commandName,
124 'params' => $params,
125 ]);
127 }
128}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
sendErrorMessage(ChatBotMessageDto $message)
Определения CopilotChatBot.php:18
onRequestQuotaOk(ChatBotMessageDto $message)
Определения CopilotChatBot.php:90
getQuotaExceededMessage(ChatBotMessageDto $message)
sendFrontendEvent(ChatBotCommands $command, array $params=[])
Определения CopilotChatBot.php:112
getRestrictedRequestMessage(ChatBotMessageDto $message)
static getUserId()
Определения manager.php:107
static send()
Определения event.php:387
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения event.php:22
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799