1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CopilotEvent.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Analytics\Event;
4
5use Bitrix\AI\Engine;
6use Bitrix\Im\V2\Chat\CopilotChat;
7use Bitrix\Im\V2\Integration\AI\AIHelper;
8use Bitrix\Im\V2\Integration\AI\EngineManager;
9use Bitrix\Im\V2\Integration\AI\RoleManager;
10use Bitrix\Imbot\Bot\CopilotChatBot;
11use Bitrix\Main\Result;
12
13class CopilotEvent extends Event
14{
15 protected const ANALYTICS_STATUS = [
16 'SUCCESS' => 'success',
17 'ERROR_PROVIDER' => 'error_provider',
18 'ERROR_B24' => 'error_b24',
19 'ERROR_LIMIT_DAILY' => 'error_limit_daily',
20 'ERROR_LIMIT_MONTHLY' => 'error_limit_monthly',
21 'ERROR_AGREEMENT' => 'error_agreement',
22 'ERROR_TURNEDOFF' => 'error_turnedoff',
23 'ERROR_LIMIT_BAAS' => 'error_limit_baas',
24 ];
25
26 protected function getTool(): string
27 {
28 return 'ai';
29 }
30
31 protected function getCategory(string $eventName): string
32 {
33 return 'chat_operations';
34 }
35
36 protected function setDefaultParams(?Engine $engine = null, ?string $promptCode = null): self
37 {
38 $this
39 ->setSection('copilot_tab')
40 ->setCopilotP2()
41 ->setCopilotP3()
42 ->setCopilotP4()
43 ->setCopilotP5()
44 ;
45
46 return $this;
47 }
48
49 public function setCopilotStatus(Result $result): self
50 {
51 if ($result->isSuccess())
52 {
53 $this->status = self::ANALYTICS_STATUS['SUCCESS'];
54
55 return $this;
56 }
57
58 $error = $result->getErrors()[0];
59
60 if (!isset($error))
61 {
62 $this->status = self::ANALYTICS_STATUS['ERROR_B24'];
63
64 return $this;
65 }
66
67 $this->status = match ($error->getCode()) {
68 CopilotChatBot::AI_ENGINE_ERROR_PROVIDER => self::ANALYTICS_STATUS['ERROR_PROVIDER'],
69 CopilotChatBot::LIMIT_IS_EXCEEDED_DAILY => self::ANALYTICS_STATUS['ERROR_LIMIT_DAILY'],
70 CopilotChatBot::LIMIT_IS_EXCEEDED_MONTHLY => self::ANALYTICS_STATUS['ERROR_LIMIT_MONTHLY'],
71 CopilotChatBot::ERROR_AGREEMENT => self::ANALYTICS_STATUS['ERROR_AGREEMENT'],
72 CopilotChatBot::LIMIT_IS_EXCEEDED_BAAS => self::ANALYTICS_STATUS['ERROR_LIMIT_BAAS'],
73 default => self::ANALYTICS_STATUS['ERROR_B24'],
74 };
75
76 return $this;
77 }
78
79 public function setCopilotP1(?string $promptCode): self
80 {
81 $this->p1 = isset($promptCode) ? ('1st-type_' . self::convertUnderscore($promptCode)) : 'none';
82
83 return $this;
84 }
85
86 protected function setCopilotP2(): self
87 {
88 $engineName = null;
89
90 if ($this->chat instanceof CopilotChat)
91 {
92 $engineCode = $this->chat->getEngineCode() ?? EngineManager::getDefaultEngineCode();
93 $engineName = (new EngineManager())->getEngineNameByCode($engineCode);
94 }
95
96 $engineName ??= 'none';
97 $this->p2 = 'provider_' . $engineName;
98
99 return $this;
100 }
101
102 protected function setCopilotP3(): self
103 {
104 $this->p3 = $this->chat->getUserCount() > 2 ? 'chatType_multiuser' : 'chatType_private';
105
106 return $this;
107 }
108
109 protected function setCopilotP4(): self
110 {
111 $role = (new RoleManager())->getMainRole($this->chat->getChatId()) ?? '';
112 $this->p4 = 'role_' . self::convertUnderscore($role);
113
114 return $this;
115 }
116
117 protected function setCopilotP5(): self
118 {
119 $this->p5 = 'chatId_' . $this->chat->getChatId();
120
121 return $this;
122 }
123}
setCopilotP1(?string $promptCode)
Определения CopilotEvent.php:79
setDefaultParams(?Engine $engine=null, ?string $promptCode=null)
Определения CopilotEvent.php:36
getCategory(string $eventName)
Определения CopilotEvent.php:31
setCopilotStatus(Result $result)
Определения CopilotEvent.php:49
Определения result.php:20
$result
Определения get_property_values.php:14
Определения action.php:3
$engine
Определения options.php:121
$error
Определения subscription_card_product.php:20