Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/landing/lib/controller/ |
Upload File : |
<?php namespace Bitrix\Landing\Controller; use Bitrix\Main\Engine; use Bitrix\Main\Engine\Controller; use Bitrix\Landing; use Bitrix\Landing\Copilot\Generation; use Bitrix\Landing\Copilot\Data; use Bitrix\Landing\Copilot\Connector; use Bitrix\Main\Error; class Copilot extends Controller { public function getDefaultPreFilters(): array { return [ new Engine\ActionFilter\Authentication(), new ActionFilter\Extranet(), ]; } /** * Save relations between chat, site and user * @param int $siteId * @param int $chatId * @return bool */ public function addChatToSiteAction(int $siteId, int $chatId): bool { return (new Landing\Copilot\Connector\Chat\Chat())->setChatForSite($siteId, $chatId); } /** * Try to find and execute AI generation * @param int $generationId * @return bool */ public static function executeGenerationAction(int $generationId): bool { if ($generationId <= 0) { return false; } $generation = new Generation(); if (!$generation->initById($generationId)) { return false; } return $generation->execute(); } public static function checkBlockGeneratableAction(int $blockId, ?int $chatId = null): bool { $result = Data\Block\Operator::isBlockAvailableForScenarioChangeBlock($blockId); if (!$chatId || $chatId <= 0) { return $result; } /** * @var $chatBot Landing\Copilot\Connector\Chat\ChangeBlockChatBot */ $chatBot = Landing\Copilot\Connector\Chat\Chat::getChangeBlockChatBot(); if ($chatBot) { $message = new Landing\Copilot\Connector\Chat\ChatBotMessageDto($chatId); $result ? $chatBot->sendSelectBlockSuccessMessage($message) : $chatBot->sendSelectBlockWrongMessage($message); } return $result; } public function sendBlockGenerationNeedSelectMessageAction(int $siteId) { $chatId = (new Landing\Copilot\Connector\Chat\Chat())->getChatForSite($siteId); if (!$chatId) { return; } $chatBot = Landing\Copilot\Connector\Chat\Chat::getChangeBlockChatBot(); if ($chatBot) { $message = new Landing\Copilot\Connector\Chat\ChatBotMessageDto($chatId); $chatBot->sendNeedSelectBlockMessage($message); } } public function sendBlockGenerationWrongSelectMessageAction(int $siteId) { $chatId = (new Landing\Copilot\Connector\Chat\Chat())->getChatForSite($siteId); if (!$chatId) { return; } $chatBot = Landing\Copilot\Connector\Chat\Chat::getChangeBlockChatBot(); if ($chatBot) { $message = new Landing\Copilot\Connector\Chat\ChatBotMessageDto($chatId); $chatBot->sendSelectBlockWrongMessage($message); } } public function executeBlockGenerationAction(int $siteId, int $blockId, string $wishes): ?int { if ($siteId <= 0 || $blockId <= 0) { $this->addError(new Error('Incorrect block or chat ID')); return null; } if (!Data\Block\Operator::isBlockAvailableForScenarioChangeBlock($blockId)) { $this->addError(new Error('Block is unavailable to generate')); return null; } $siteData = new Data\Site(); $siteData->initByBlockIds([$blockId]); $chat = new Connector\Chat\Chat(); $generation = (new Generation()) ->setScenario(new Generation\Scenario\ChangeBlock()) ->setSiteData($siteData) ->setWishes((new Data\Wishes())->setWishes([$wishes])) ->setChatId($chat->getChatForSite($siteId) ?? 0) ; if ($generation->execute()) { return $generation->getId(); } return null; } }