app-tutor-ai-consumer 1.37.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +1 -1
  3. package/src/config/datahub/actions.ts +3 -2
  4. package/src/config/datahub/constants.ts +1 -0
  5. package/src/config/datahub/entities.ts +2 -1
  6. package/src/config/datahub/schemas/constants.ts +2 -1
  7. package/src/config/datahub/schemas/tutor/__tests__/{try-send-tutor-message.spec.ts → try-send-message.spec.ts} +11 -6
  8. package/src/config/datahub/schemas/tutor/__tests__/{view-tutor-answer-message.spec.ts → view-answer-message.spec.ts} +9 -4
  9. package/src/config/datahub/schemas/tutor/__tests__/view-chat.spec.ts +38 -0
  10. package/src/config/datahub/schemas/tutor/index.ts +2 -2
  11. package/src/config/datahub/schemas/tutor/{try-send-tutor-message.ts → try-send-message.ts} +22 -12
  12. package/src/config/datahub/schemas/tutor/{view-tutor-answer-message.ts → view-answer-message.ts} +20 -7
  13. package/src/config/datahub/schemas/tutor/view-chat.ts +56 -0
  14. package/src/config/datahub/types.ts +5 -0
  15. package/src/modules/messages/hooks/use-send-text-message/use-send-text-message.spec.tsx +1 -1
  16. package/src/modules/messages/hooks/use-send-text-message/use-send-text-message.tsx +11 -17
  17. package/src/modules/messages/hooks/use-subscribe-message-received-event/use-subscribe-message-received-event.tsx +9 -5
  18. package/src/modules/widget/components/chat-page/chat-page.tsx +3 -2
  19. package/src/modules/widget/hooks/index.ts +1 -0
  20. package/src/modules/widget/hooks/use-send-view-chat-event/index.ts +1 -0
  21. package/src/modules/widget/hooks/use-send-view-chat-event/use-send-view-chat-event.tsx +28 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [1.38.0](https://github.com/Hotmart-Org/app-tutor-ai-consumer/compare/v1.37.0...v1.38.0) (2025-11-10)
2
+
3
+ ### Features
4
+
5
+ - add chat interaction datahub events ([e3df5bb](https://github.com/Hotmart-Org/app-tutor-ai-consumer/commit/e3df5bb4223579128edb0511b718f74fb4d1bf79))
6
+
1
7
  # [1.37.0](https://github.com/Hotmart-Org/app-tutor-ai-consumer/compare/v1.36.0...v1.37.0) (2025-11-10)
2
8
 
3
9
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-tutor-ai-consumer",
3
- "version": "1.37.0",
3
+ "version": "1.38.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "dev": "rspack serve --env=development --config config/rspack/rspack.config.js",
@@ -13,7 +13,7 @@ export const ActionNames = {
13
13
  CLICK_HOTMART_TUTOR: `${DataHubActions.CLICK}_hotmart_tutor`,
14
14
  CLICK_TUTOR_MINIMIZE: `${DataHubActions.CLICK}_tutor_minimize`,
15
15
  TRY_PRODUCT_TUTOR: `${DataHubActions.TRY}_product_tutor`,
16
- TRY_SEND_TUTOR_MESSAGE: `${DataHubActions.TRY}_send_tutor_message`,
16
+ TRY_SEND_MESSAGE: `${DataHubActions.TRY}_send_message`,
17
17
  CLICK_TUTOR_BACK: `${DataHubActions.CLICK}_tutor_back`,
18
18
  CLICK_TUTOR_HISTORY: `${DataHubActions.CLICK}_tutor_history`,
19
19
  CLICK_TUTOR_INFO: `${DataHubActions.CLICK}_tutor_info`,
@@ -22,5 +22,6 @@ export const ActionNames = {
22
22
  CLICK_TUTOR_TEST_KNOWLEDGE: `${DataHubActions.CLICK}_tutor_test_knowledge`,
23
23
  CLOSE_TUTOR_ONBOARDING: `${DataHubActions.CLOSE}_tutor_onboarding`,
24
24
  VIEW_PRODUCT_TUTOR: `${DataHubActions.VIEW}_product_tutor`,
25
- VIEW_TUTOR_ANSWER_MESSAGE: `${DataHubActions.VIEW}_tutor_answer_message`
25
+ VIEW_ANSWER_MESSAGE: `${DataHubActions.VIEW}_answer_message`,
26
+ VIEW_CHAT: `${DataHubActions.VIEW}_chat`
26
27
  }
@@ -28,6 +28,7 @@ export const ComponentNames = {
28
28
  BUTTON_CLOSE_TUTOR_CHAT: 'BUTTON_CLOSE_TUTOR_CHAT',
29
29
  BUTTON_VIEW_AGENT: 'BUTTON_VIEW_AGENT',
30
30
  BUTTON_SEND_MESSAGE: 'BUTTON_SEND_MESSAGE',
31
+ CHAT: 'CHAT',
31
32
  VIEW_ANSWER: 'VIEW_ANSWER',
32
33
  PRODUCT_CONSUME_CLICK_TUTOR_BACK: 'product_consume_click_tutor_back',
33
34
  PRODUCT_CONSUME_CLICK_TUTOR_HISTORY: 'product_consume_click_tutor_history',
@@ -1,5 +1,6 @@
1
1
  export const DataHubEntities = {
2
2
  ADMIN: 'admin',
3
3
  HOME: 'home',
4
- PRODUCT_CONSUME: 'product_consume'
4
+ PRODUCT_CONSUME: 'product_consume',
5
+ CONVERSATIONAL_AGENT: 'conversational_agent'
5
6
  } as const
@@ -11,5 +11,6 @@ export const UserRole = {
11
11
 
12
12
  export const ProductCategories = {
13
13
  OnlineServices: 'category.online_services.name',
14
- Ebook: 'category.ebook.name'
14
+ Ebook: 'category.ebook.name',
15
+ ConversationalAgent: 'category.conversational_agent.name'
15
16
  } as const
@@ -2,21 +2,24 @@ import { chance } from '@/src/config/tests'
2
2
  import { HttpCodes } from '@/src/lib/utils'
3
3
  import { ComponentNames, ComponentSource } from '../../../constants'
4
4
  import { DataHubEntities } from '../../../entities'
5
- import TrySendTutorMessage from '../try-send-tutor-message'
5
+ import { AgentType } from '../../../types'
6
+ import TrySendMessage from '../try-send-message'
6
7
 
7
- describe('TrySendTutorMessage', () => {
8
+ describe('TrySendMessage', () => {
8
9
  it('should send the event with the correct structure', () => {
9
10
  const event = {
10
11
  questionType: 'TEXT',
11
- questionId: chance.guid()
12
+ messageId: chance.guid(),
13
+ conversationId: chance.guid(),
14
+ agent: AgentType.HOTMART_TUTOR
12
15
  }
13
16
 
14
- expect(new TrySendTutorMessage(event).getDataHubEventData()).toMatchObject({
17
+ expect(new TrySendMessage(event).getDataHubEventData()).toMatchObject({
15
18
  appVersion: '',
16
19
  clubVersion: 'MEMBERSHIP',
17
20
  componentName: ComponentNames.BUTTON_SEND_MESSAGE,
18
21
  componentSource: ComponentSource.HOTMART_TUTOR,
19
- entity: DataHubEntities.PRODUCT_CONSUME,
22
+ entity: DataHubEntities.CONVERSATIONAL_AGENT,
20
23
  failureDescription: 'NOT_FAILURE_RESULT_EVENT',
21
24
  isLogged: true,
22
25
  membershipId: 'UNDEFINED',
@@ -24,7 +27,9 @@ describe('TrySendTutorMessage', () => {
24
27
  osVersion: '537.36',
25
28
  platform: 'WEB',
26
29
  platformDetail: 'WebKit',
27
- questionId: event.questionId,
30
+ messageId: event.messageId,
31
+ conversationId: event.conversationId,
32
+ agent: AgentType.HOTMART_TUTOR,
28
33
  questionType: event.questionType,
29
34
  result: 'SUCCESSFUL',
30
35
  sessionId: 'UNDEFINED',
@@ -1,15 +1,18 @@
1
1
  import { chance } from '@/src/config/tests'
2
2
  import { ComponentNames, ComponentSource } from '../../../constants'
3
3
  import { DataHubEntities } from '../../../entities'
4
+ import { AgentType } from '../../../types'
4
5
  import { UserRole } from '../../constants'
5
- import ViewTutorAnswerMessage from '../view-tutor-answer-message'
6
+ import ViewTutorAnswerMessage from '../view-answer-message'
6
7
 
7
- describe('ViewTutorAnswerMessage', () => {
8
+ describe('ViewAnswerMessage', () => {
8
9
  it('should send the event with the correct structure', () => {
9
10
  const event = {
10
11
  messageType: 'TEXT',
11
12
  messageId: chance.guid(),
12
- correlationId: chance.guid()
13
+ correlationId: chance.guid(),
14
+ conversationId: chance.guid(),
15
+ agent: AgentType.HOTMART_TUTOR
13
16
  }
14
17
 
15
18
  expect(new ViewTutorAnswerMessage(event).getDataHubEventData()).toMatchObject({
@@ -19,7 +22,9 @@ describe('ViewTutorAnswerMessage', () => {
19
22
  componentName: ComponentNames.VIEW_ANSWER,
20
23
  componentSource: ComponentSource.HOTMART_TUTOR,
21
24
  correlationId: event.correlationId,
22
- entity: DataHubEntities.PRODUCT_CONSUME,
25
+ conversationId: event.conversationId,
26
+ agent: AgentType.HOTMART_TUTOR,
27
+ entity: DataHubEntities.CONVERSATIONAL_AGENT,
23
28
  isLogged: true,
24
29
  membershipId: 'UNDEFINED',
25
30
  membershipSlug: 'UNDEFINED',
@@ -0,0 +1,38 @@
1
+ import { chance } from '@/src/config/tests'
2
+ import { ComponentNames, ComponentSource } from '../../../constants'
3
+ import { DataHubEntities } from '../../../entities'
4
+ import { AgentType } from '../../../types'
5
+ import { UserRole } from '../../constants'
6
+ import ViewChatSchema from '../view-chat'
7
+
8
+ describe('ViewChatSchema', () => {
9
+ it('should send the event with the correct structure', () => {
10
+ const event = {
11
+ conversationId: chance.guid(),
12
+ agent: AgentType.HOTMART_TUTOR
13
+ }
14
+
15
+ expect(new ViewChatSchema(event).getDataHubEventData()).toMatchObject({
16
+ appVersion: '',
17
+ arrivedFrom: 'HOME_CLASS_CONSUMER',
18
+ clubVersion: 'MEMBERSHIP',
19
+ componentName: ComponentNames.CHAT,
20
+ componentSource: ComponentSource.HOTMART_TUTOR,
21
+ conversationId: event.conversationId,
22
+ agent: AgentType.HOTMART_TUTOR,
23
+ entity: DataHubEntities.CONVERSATIONAL_AGENT,
24
+ isLogged: true,
25
+ membershipId: 'UNDEFINED',
26
+ membershipSlug: 'UNDEFINED',
27
+ osVersion: '537.36',
28
+ platform: 'WEB',
29
+ platformDetail: 'WebKit',
30
+ productType: 'category.online_services.name',
31
+ sessionId: 'UNDEFINED',
32
+ ucode: 'UNDEFINED',
33
+ url: 'http://localhost:3000/',
34
+ userId: 0,
35
+ userRole: UserRole.CONSUMER
36
+ })
37
+ })
38
+ })
@@ -8,6 +8,6 @@ export { default as ClickTutorOnboardingStartSchema } from './click-tutor-onboar
8
8
  export { default as ClickTutorTestKnowledgeSchema } from './click-tutor-test-knowledge'
9
9
  export { default as CloseTutorOnboardingSchema } from './close-tutor-onboarding'
10
10
  export * from './constants'
11
- export { default as TrySendTutorMessageSchema } from './try-send-tutor-message'
11
+ export { default as TrySendMessageSchema } from './try-send-message'
12
12
  export * from './types'
13
- export { default as ViewTutorAnswerMessageSchema } from './view-tutor-answer-message'
13
+ export { default as ViewAnswerMessageSchema } from './view-answer-message'
@@ -2,26 +2,32 @@ import { HttpCodes } from '@/src/lib/utils'
2
2
  import { ActionNames } from '../../actions'
3
3
  import { ComponentNames, ComponentSource } from '../../constants'
4
4
  import { DataHubEntities } from '../../entities'
5
- import type { DataHubEntityTypes } from '../../types'
5
+ import type { AgentType, DataHubEntityTypes } from '../../types'
6
6
  import type { ActionNamesType } from '../../types'
7
7
  import type { BaseTrySchemaConstructorArgs } from '../base-try-schema'
8
8
  import BaseTrySchema from '../base-try-schema'
9
9
 
10
- export type TrySendTutorMessageConstructorArgs = Partial<BaseTrySchemaConstructorArgs> & {
10
+ export type TrySendMessageConstructorArgs = Partial<BaseTrySchemaConstructorArgs> & {
11
11
  questionType?: string
12
- questionId?: string
12
+ messageId?: string
13
+ conversationId?: string
14
+ agent: AgentType
13
15
  }
14
16
 
15
- class TrySendTutorMessageSchema extends BaseTrySchema {
17
+ class TrySendMessageSchema extends BaseTrySchema {
16
18
  action: ActionNamesType
17
19
  entity: DataHubEntityTypes
18
20
  questionType: string
19
- questionId: string
21
+ messageId?: string
22
+ conversationId?: string
23
+ agent?: AgentType
20
24
 
21
- constructor(args?: TrySendTutorMessageConstructorArgs) {
25
+ constructor(args?: TrySendMessageConstructorArgs) {
22
26
  const {
23
27
  questionType = 'TEXT',
24
- questionId = '',
28
+ messageId,
29
+ conversationId,
30
+ agent,
25
31
  componentSource = ComponentSource.HOTMART_TUTOR,
26
32
  componentName = ComponentNames.BUTTON_SEND_MESSAGE,
27
33
  failureDescription = 'NOT_FAILURE_RESULT_EVENT',
@@ -37,19 +43,23 @@ class TrySendTutorMessageSchema extends BaseTrySchema {
37
43
  statusCode
38
44
  })
39
45
 
40
- this.action = ActionNames.TRY_SEND_TUTOR_MESSAGE
41
- this.entity = DataHubEntities.PRODUCT_CONSUME
46
+ this.action = ActionNames.TRY_SEND_MESSAGE
47
+ this.entity = DataHubEntities.CONVERSATIONAL_AGENT
42
48
  this.questionType = questionType
43
- this.questionId = questionId
49
+ this.messageId = messageId
50
+ this.conversationId = conversationId
51
+ this.agent = agent
44
52
  }
45
53
 
46
54
  getDataHubEventData(): Record<string, unknown> {
47
55
  return {
48
56
  ...this.prepare(),
49
57
  questionType: this.questionType,
50
- questionId: this.questionId
58
+ messageId: this.messageId,
59
+ conversationId: this.conversationId,
60
+ agent: this.agent
51
61
  }
52
62
  }
53
63
  }
54
64
 
55
- export default TrySendTutorMessageSchema
65
+ export default TrySendMessageSchema
@@ -1,27 +1,35 @@
1
1
  import { ActionNames } from '../../actions'
2
2
  import { ComponentNames, ComponentSource } from '../../constants'
3
- import type { ActionNamesType } from '../../types'
3
+ import { DataHubEntities } from '../../entities'
4
+ import type { ActionNamesType, AgentType, DataHubEntityTypes } from '../../types'
4
5
  import type { BaseViewSchemaConstructorArgs } from '../base-view-schema'
5
6
  import BaseViewSchema from '../base-view-schema'
6
7
 
7
- export type ViewTutorAnswerMessageConstructorArgs = Partial<BaseViewSchemaConstructorArgs> & {
8
+ export type ViewAnswerMessageConstructorArgs = Partial<BaseViewSchemaConstructorArgs> & {
8
9
  messageType?: string
9
10
  messageId?: string
10
11
  correlationId?: string
12
+ conversationId?: string
13
+ agent?: AgentType
11
14
  }
12
15
 
13
- class ViewTutorAnswerMessageSchema extends BaseViewSchema {
16
+ class ViewAnswerMessageSchema extends BaseViewSchema {
14
17
  private messageType?: string
15
18
  private messageId?: string
16
19
  private correlationId?: string
20
+ private conversationId?: string
21
+ private agent?: AgentType
17
22
 
18
23
  action: ActionNamesType
24
+ entity: DataHubEntityTypes
19
25
 
20
- constructor(args?: ViewTutorAnswerMessageConstructorArgs) {
26
+ constructor(args?: ViewAnswerMessageConstructorArgs) {
21
27
  const {
22
28
  messageType = 'TEXT',
23
29
  messageId,
24
30
  correlationId,
31
+ conversationId,
32
+ agent,
25
33
  arrivedFrom,
26
34
  entity,
27
35
  isLogged,
@@ -39,10 +47,13 @@ class ViewTutorAnswerMessageSchema extends BaseViewSchema {
39
47
  componentSource
40
48
  })
41
49
 
42
- this.action = ActionNames.VIEW_TUTOR_ANSWER_MESSAGE
50
+ this.action = ActionNames.VIEW_ANSWER_MESSAGE
51
+ this.entity = DataHubEntities.CONVERSATIONAL_AGENT
43
52
  this.messageType = messageType
44
53
  this.messageId = messageId
45
54
  this.correlationId = correlationId
55
+ this.conversationId = conversationId
56
+ this.agent = agent
46
57
  }
47
58
 
48
59
  getDataHubEventData(): Record<string, unknown> {
@@ -50,9 +61,11 @@ class ViewTutorAnswerMessageSchema extends BaseViewSchema {
50
61
  ...super.prepare(),
51
62
  messageType: this.messageType,
52
63
  messageId: this.messageId,
53
- correlationId: this.correlationId
64
+ correlationId: this.correlationId,
65
+ conversationId: this.conversationId,
66
+ agent: this.agent
54
67
  }
55
68
  }
56
69
  }
57
70
 
58
- export default ViewTutorAnswerMessageSchema
71
+ export default ViewAnswerMessageSchema
@@ -0,0 +1,56 @@
1
+ import { ActionNames } from '../../actions'
2
+ import { ComponentNames, ComponentSource } from '../../constants'
3
+ import { DataHubEntities } from '../../entities'
4
+ import type { ActionNamesType, AgentType, DataHubEntityTypes } from '../../types'
5
+ import type { BaseViewSchemaConstructorArgs } from '../base-view-schema'
6
+ import BaseViewSchema from '../base-view-schema'
7
+
8
+ export type ViewChatConstructorArgs = Partial<BaseViewSchemaConstructorArgs> & {
9
+ conversationId?: string
10
+ agent?: AgentType
11
+ }
12
+
13
+ class ViewChatSchema extends BaseViewSchema {
14
+ private conversationId?: string
15
+ private agent?: AgentType
16
+
17
+ action: ActionNamesType
18
+ entity: DataHubEntityTypes
19
+
20
+ constructor(args?: ViewChatConstructorArgs) {
21
+ const {
22
+ conversationId,
23
+ agent,
24
+ arrivedFrom,
25
+ entity,
26
+ isLogged,
27
+ productType,
28
+ componentName = ComponentNames.CHAT,
29
+ componentSource = ComponentSource.HOTMART_TUTOR
30
+ } = args ?? {}
31
+
32
+ super({
33
+ arrivedFrom,
34
+ entity,
35
+ isLogged,
36
+ productType,
37
+ componentName,
38
+ componentSource
39
+ })
40
+
41
+ this.action = ActionNames.VIEW_CHAT
42
+ this.entity = DataHubEntities.CONVERSATIONAL_AGENT
43
+ this.conversationId = conversationId
44
+ this.agent = agent
45
+ }
46
+
47
+ getDataHubEventData(): Record<string, unknown> {
48
+ return {
49
+ ...super.prepare(),
50
+ conversationId: this.conversationId,
51
+ agent: this.agent
52
+ }
53
+ }
54
+ }
55
+
56
+ export default ViewChatSchema
@@ -18,6 +18,11 @@ export type ComponentSourceType = (typeof ComponentSource)[keyof typeof Componen
18
18
  export type ScreenNamesType = (typeof ScreenNames)[keyof typeof ScreenNames]
19
19
  export type ResultType = (typeof Result)[keyof typeof Result]
20
20
 
21
+ export enum AgentType {
22
+ HOTMART_TUTOR = 'HOTMART_TUTOR',
23
+ PRODUCT_AGENT = 'PRODUCT_AGENT'
24
+ }
25
+
21
26
  export type SchemaType = {
22
27
  action: ActionNamesType
23
28
  entity: DataHubEntityTypes
@@ -76,7 +76,7 @@ describe('useSendTextMessage', () => {
76
76
 
77
77
  expect(DataHubService.sendEvent).toHaveBeenCalledWith({
78
78
  schema: expect.objectContaining({
79
- questionId: mockResponse.id,
79
+ messageId: mockResponse.id,
80
80
  questionType: 'TEXT'
81
81
  })
82
82
  })
@@ -3,8 +3,8 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
3
3
  import { UAParser } from 'ua-parser-js'
4
4
  import { v4 } from 'uuid'
5
5
 
6
- import { ComponentSource, DataHubService } from '@/src/config/datahub'
7
- import { TrySendTutorMessageSchema } from '@/src/config/datahub/schemas/tutor'
6
+ import { AgentType, ComponentSource, DataHubService } from '@/src/config/datahub'
7
+ import { TrySendMessageSchema } from '@/src/config/datahub/schemas/tutor'
8
8
  import { APP_VERSION, HttpCodes, PLATFORM } from '@/src/lib/utils'
9
9
  import { DirectMessagesService as MessagesService } from '@/src/modules/messages'
10
10
  import { useGetProfile } from '@/src/modules/profile'
@@ -115,25 +115,19 @@ function useSendTextMessage() {
115
115
  },
116
116
  onSuccess(data) {
117
117
  setMessagesCache({ queryKey: messagesQueryConfig.queryKey, queryClient, data })()
118
-
119
- DataHubService.sendEvent({
120
- schema: new TrySendTutorMessageSchema({
121
- questionId: data.id,
122
- componentSource: isAgentMode
123
- ? ComponentSource.PRODUCT_AGENT
124
- : ComponentSource.HOTMART_TUTOR
125
- })
126
- })
127
118
  },
128
- onError(error) {
119
+ onSettled(data, error) {
129
120
  DataHubService.sendEvent({
130
- schema: new TrySendTutorMessageSchema({
131
- statusCode: HttpCodes.BAD_REQUEST,
132
- result: 'FAILURE',
133
- failureDescription: error.message,
121
+ schema: new TrySendMessageSchema({
122
+ messageId: data?.id,
123
+ statusCode: error ? HttpCodes.BAD_REQUEST : HttpCodes.OK,
124
+ result: error ? 'FAILURE' : 'SUCCESSFUL',
125
+ failureDescription: error?.message,
134
126
  componentSource: isAgentMode
135
127
  ? ComponentSource.PRODUCT_AGENT
136
- : ComponentSource.HOTMART_TUTOR
128
+ : ComponentSource.HOTMART_TUTOR,
129
+ agent: isAgentMode ? AgentType.PRODUCT_AGENT : AgentType.HOTMART_TUTOR,
130
+ conversationId: settings?.conversationId
137
131
  })
138
132
  })
139
133
  }
@@ -4,7 +4,8 @@ import { useQueryClient } from '@tanstack/react-query'
4
4
  import { produce } from 'immer'
5
5
 
6
6
  import { ComponentSource, DataHubService } from '@/src/config/datahub'
7
- import { ViewTutorAnswerMessageSchema } from '@/src/config/datahub/schemas/tutor'
7
+ import { ViewAnswerMessageSchema } from '@/src/config/datahub/schemas/tutor'
8
+ import { AgentType } from '@/src/config/datahub/types'
8
9
  import { useUpdateCursor } from '@/src/modules/cursor/hooks'
9
10
  import { useGetProfile } from '@/src/modules/profile'
10
11
  import { SparkieService } from '@/src/modules/sparkie'
@@ -67,12 +68,14 @@ const useSubscribeMessageReceivedEvent = () => {
67
68
 
68
69
  if (!isMine) {
69
70
  DataHubService.sendEvent({
70
- schema: new ViewTutorAnswerMessageSchema({
71
- correlationId: data.metadata.correlationId,
72
- messageId: data.id,
71
+ schema: new ViewAnswerMessageSchema({
72
+ correlationId: data?.metadata?.correlationId,
73
+ messageId: data?.id,
73
74
  componentSource: isAgentMode
74
75
  ? ComponentSource.PRODUCT_AGENT
75
- : ComponentSource.HOTMART_TUTOR
76
+ : ComponentSource.HOTMART_TUTOR,
77
+ agent: isAgentMode ? AgentType.PRODUCT_AGENT : AgentType.HOTMART_TUTOR,
78
+ conversationId: settings?.conversationId
76
79
  })
77
80
  })
78
81
 
@@ -91,6 +94,7 @@ const useSubscribeMessageReceivedEvent = () => {
91
94
  profileId,
92
95
  queryClient,
93
96
  setWidgetLoading,
97
+ settings?.conversationId,
94
98
  useUpdateCursorMutation
95
99
  ]
96
100
  )
@@ -9,6 +9,7 @@ import { getAllMessagesQuery, useSendTextMessage } from '@/src/modules/messages/
9
9
  import { useMessagesMaxCount } from '@/src/modules/messages/store'
10
10
  import { useGetProfile } from '@/src/modules/profile'
11
11
  import { TutorWidgetEvents } from '../../events'
12
+ import { useSendViewChatEvent } from '../../hooks'
12
13
  import { useSendViewTutorEvent } from '../../hooks/use-send-view-tutor-event'
13
14
  import {
14
15
  useWidgetLoadingAtom,
@@ -45,11 +46,11 @@ function ChatPage() {
45
46
  }),
46
47
  [conversationId, limit, profileId]
47
48
  )
49
+ useSendViewTutorEvent()
50
+ useSendViewChatEvent()
48
51
 
49
52
  const messagesQuery = useInfiniteQuery(messagesQueryConfig)
50
53
 
51
- useSendViewTutorEvent()
52
-
53
54
  const handleSendMessage = () => {
54
55
  const text = chatInputRef.current?.value ?? ''
55
56
 
@@ -1,3 +1,4 @@
1
1
  export * from './use-listen-to-theme-change-event'
2
2
  export * from './use-listen-to-visibility-events'
3
+ export * from './use-send-view-chat-event'
3
4
  export * from './use-send-view-tutor-event'
@@ -0,0 +1 @@
1
+ export { default as useSendViewChatEvent } from './use-send-view-chat-event'
@@ -0,0 +1,28 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ import { AgentType, ComponentSource, DataHubEntities, DataHubService } from '@/src/config/datahub'
4
+ import ViewChatSchema from '@/src/config/datahub/schemas/tutor/view-chat'
5
+ import { useIsAgentParentAtomValue, useWidgetSettingsAtomValue } from '../../store'
6
+
7
+ function useSendViewChatEvent() {
8
+ const isAgentMode = useIsAgentParentAtomValue()
9
+ const settings = useWidgetSettingsAtomValue()
10
+
11
+ const sent = useRef(false)
12
+
13
+ useEffect(() => {
14
+ if (sent.current) return
15
+
16
+ const schema = new ViewChatSchema({
17
+ componentSource: isAgentMode ? ComponentSource.PRODUCT_AGENT : ComponentSource.HOTMART_TUTOR,
18
+ agent: isAgentMode ? AgentType.PRODUCT_AGENT : AgentType.HOTMART_TUTOR,
19
+ conversationId: settings?.conversationId,
20
+ entity: DataHubEntities.CONVERSATIONAL_AGENT
21
+ })
22
+
23
+ DataHubService.sendEvent({ schema })
24
+ sent.current = true
25
+ }, [isAgentMode, settings?.conversationId])
26
+ }
27
+
28
+ export default useSendViewChatEvent