1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CopilotAnalytics.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Im\V2\Analytics;
6
7use Bitrix\Im\V2\Analytics\Event\ChatEvent;
8use Bitrix\Im\V2\Analytics\Event\CopilotEvent;
9use Bitrix\Im\V2\Analytics\Event\Event;
10use Bitrix\Im\V2\Chat;
11use Bitrix\Main\Result;
12
14{
15 protected const GENERATE = 'generate';
16 protected const RECEIVED_RESULT = 'received_result';
17 protected const ADD_USER = 'add_user';
18 protected const DELETE_USER = 'delete_user';
19 protected const CHANGE_ROLE = 'change_role';
20 protected const CHANGE_MODEL = 'change_model';
21
22 public function addGenerate(Result $result, ?string $promptCode = null): void
23 {
24 $this->async(function () use ($promptCode, $result) {
25 $this
26 ->createCopilotEvent(self::GENERATE, $promptCode)
27 ?->send()
28 ;
29 $this
30 ->createCopilotEvent(self::RECEIVED_RESULT, $promptCode)
31 ?->setCopilotStatus($result)
32 ?->send()
33 ;
34 });
35 }
36
37 public function addChangeRole(string $oldRole): void
38 {
39 $this->async(function () use ($oldRole) {
40
41 (new ChatEvent(self::CHANGE_ROLE, $this->chat, $this->userId))
42 ->setP1(null)
43 ->setP3('oldRole_' . Event::convertUnderscore($oldRole))
44 ->send()
45 ;
46 });
47 }
48
49 public function addChangeEngine(string $oldEngineName): void
50 {
51 $this->async(function () use ($oldEngineName) {
52 (new ChatEvent(self::CHANGE_MODEL, $this->chat, $this->userId))
53 ->setP1(null)
54 ->setP3('oldProvider_' . Event::convertUnderscore($oldEngineName))
55 ->send()
56 ;
57 });
58 }
59
60 public function addAddUser(): void
61 {
62 $this
63 ->createCopilotEvent(self::ADD_USER)
64 ?->send()
65 ;
66 }
67
68 public function addDeleteUser(): void
69 {
70 $this
71 ->createCopilotEvent(self::DELETE_USER)
72 ?->send()
73 ;
74 }
75
76 protected function createCopilotEvent(
77 string $eventName,
78 ?string $promptCode = null,
79 ): ?CopilotEvent
80 {
81 if (!$this->isCopilot())
82 {
83 return null;
84 }
85
86 return (new CopilotEvent($eventName, $this->chat, $this->userId))
87 ->setCopilotP1($promptCode)
88 ;
89 }
90
91 protected function isCopilot(): bool
92 {
93 return $this->chat instanceof Chat\CopilotChat;
94 }
95}
createCopilotEvent(string $eventName, ?string $promptCode=null,)
Определения CopilotAnalytics.php:76
addChangeRole(string $oldRole)
Определения CopilotAnalytics.php:37
addChangeEngine(string $oldEngineName)
Определения CopilotAnalytics.php:49
addGenerate(Result $result, ?string $promptCode=null)
Определения CopilotAnalytics.php:22
setCopilotP1(?string $promptCode)
Определения CopilotEvent.php:79
Определения result.php:20
$result
Определения get_property_values.php:14