1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
copilot.php
См. документацию.
1<?php
2
3namespace Bitrix\Landing\Controller;
4
5use Bitrix\Main\Engine;
6use Bitrix\Main\Engine\Controller;
7use Bitrix\Landing;
8use Bitrix\Landing\Copilot\Generation;
9use Bitrix\Landing\Copilot\Data;
10use Bitrix\Landing\Copilot\Connector;
11use Bitrix\Main\Error;
12
13class Copilot extends Controller
14{
15 public function getDefaultPreFilters(): array
16 {
17 return [
20 ];
21 }
22
29 public function addChatToSiteAction(int $siteId, int $chatId): bool
30 {
31 return (new Landing\Copilot\Connector\Chat\Chat())->setChatForSite($siteId, $chatId);
32 }
33
39 public static function executeGenerationAction(int $generationId): bool
40 {
41 if ($generationId <= 0)
42 {
43 return false;
44 }
45
46 $generation = new Generation();
47 if (!$generation->initById($generationId))
48 {
49 return false;
50 }
51
52 return $generation->execute();
53 }
54
55 public static function checkBlockGeneratableAction(int $blockId, ?int $chatId = null): bool
56 {
58 if (!$chatId || $chatId <= 0)
59 {
60 return $result;
61 }
62
67 if ($chatBot)
68 {
71 ? $chatBot->sendSelectBlockSuccessMessage($message)
72 : $chatBot->sendSelectBlockWrongMessage($message);
73 }
74
75 return $result;
76 }
77
79 {
80 $chatId = (new Landing\Copilot\Connector\Chat\Chat())->getChatForSite($siteId);
81 if (!$chatId)
82 {
83 return;
84 }
85
87 if ($chatBot)
88 {
90 $chatBot->sendNeedSelectBlockMessage($message);
91 }
92 }
93
95 {
96 $chatId = (new Landing\Copilot\Connector\Chat\Chat())->getChatForSite($siteId);
97 if (!$chatId)
98 {
99 return;
100 }
101
103 if ($chatBot)
104 {
106 $chatBot->sendSelectBlockWrongMessage($message);
107 }
108 }
109
110 public function executeBlockGenerationAction(int $siteId, int $blockId, string $wishes): ?int
111 {
112 if ($siteId <= 0 || $blockId <= 0)
113 {
114 $this->addError(new Error('Incorrect block or chat ID'));
115
116 return null;
117 }
118
119 if (!Data\Block\Operator::isBlockAvailableForScenarioChangeBlock($blockId))
120 {
121 $this->addError(new Error('Block is unavailable to generate'));
122
123 return null;
124 }
125
126 $siteData = new Data\Site();
127 $siteData->initByBlockIds([$blockId]);
128 $chat = new Connector\Chat\Chat();
129 $generation = (new Generation())
130 ->setScenario(new Generation\Scenario\ChangeBlock())
131 ->setSiteData($siteData)
132 ->setWishes((new Data\Wishes())->setWishes([$wishes]))
133 ->setChatId($chat->getChatForSite($siteId) ?? 0)
134 ;
135
136 if ($generation->execute())
137 {
138 return $generation->getId();
139 }
140
141 return null;
142 }
143}
sendBlockGenerationWrongSelectMessageAction(int $siteId)
Определения copilot.php:94
static executeGenerationAction(int $generationId)
Определения copilot.php:39
executeBlockGenerationAction(int $siteId, int $blockId, string $wishes)
Определения copilot.php:110
addChatToSiteAction(int $siteId, int $chatId)
Определения copilot.php:29
sendBlockGenerationNeedSelectMessageAction(int $siteId)
Определения copilot.php:78
static getChangeBlockChatBot()
Определения Chat.php:39
static isBlockAvailableForScenarioChangeBlock(int $blockId)
Определения Operator.php:212
addError(Error $error)
Определения controller.php:1070
Определения error.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$siteId
Определения ajax.php:8
Определения binding.php:2
Определения ai.php:3
Определения agent.php:3
Определения aliases.php:105
$message
Определения payment.php:8