1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AiAssistantChat.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Im\V2\Chat\Ai;
6
7use Bitrix\Im\V2\Message;
8use Bitrix\Im\V2\Message\Send\SendingConfig;
9use Bitrix\Im\V2\Message\Send\SendingService;
10use Bitrix\Main\Localization\Loc;
11
13{
14 protected bool $isConvertedRecently = false;
15
16 protected function getDefaultType(): string
17 {
18 return self::IM_TYPE_AI_ASSISTANT;
19 }
20
21 public function markAsConverted(): self
22 {
23 $this->isConvertedRecently = true;
24
25 return $this;
26 }
27
28 protected function onAfterMessageSend(Message $message, SendingService $sendingService): void
29 {
30 $this->handleJustConversion();
31
32 parent::onAfterMessageSend($message, $sendingService);
33 }
34
35 protected function handleJustConversion(): void
36 {
37 if (!$this->isConvertedRecently)
38 {
39 return;
40 }
41
42 $this->isConvertedRecently = false;
44 }
45
46 protected function sendAssistantGreetingMessage(): void
47 {
48 $assistantBotId = $this->aiAssistantService->getBotId();
49 $messageText = Loc::getMessage('IM_CHAT_CONVERSION_TO_AI_ASSISTANT_MESSAGE');
50
51 if ($messageText)
52 {
53 $message =
54 (new Message())
55 ->setMessage($messageText)
56 ->setAuthorId(0)
57 ->setContextUser($assistantBotId)
58 ->disableNotify()
59 ;
60
61 $sendingConfig = new SendingConfig(['PUSH' => 'N']);
62
63 $this->sendMessage($message, $sendingConfig);
64 }
65 }
66}
onAfterMessageSend(Message $message, SendingService $sendingService)
Определения AiAssistantChat.php:28
Определения Uuid.php:3
$message
Определения payment.php:8