From c9b75e87fc0e20de17fefc552c7580e2334c2df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20Ravent=C3=B3s?= <36898236+Iru89@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:20:35 +0200 Subject: [PATCH] plugin-hubtype-analytics: Add target bot_interaction_id on feedback knowledge base events (#2877) ## Description **@botonic/core** Add a new bot_interaction_id attribute in request.input. Add bot_interaction_id in HandoffBuilder.withBotEvent **@botonic/react** Be able to store in a Text message the value of botInteractionId. Use the value of botInteractionId when creating a feedback_knowledge_base event **@botonic/plugin-flow-builder** When create a Text message using a knowledge base, add the attribute of botInteractionId **@botonic/plugin-hubtype-analytics** Add in feedback_knowledge_base event the attribute feedback_target_bot_interaction_id Refactor and split Webviews events in 2 classes and also add optionals attributes ## Context This new attribute is needed in the knowledge base feedback events. ## Testing Fix tests of @botonic/core, @botonic/plugin-flow-builder, @botnic/plugin-flow-builder adding bot_interaction_id in Input tests Add feedback_target_bot_interaction_id in feedback_knowledge_base test --- packages/botonic-core/src/handoff.ts | 1 + .../botonic-core/src/models/legacy-types.ts | 3 +- .../tests/routing/router.match-route.test.ts | 38 +++++++++++++++++-- .../src/content-fields/flow-handoff.tsx | 1 + .../content-fields/flow-knowledge-base.tsx | 5 ++- .../tests/helpers/utils.ts | 9 +++-- .../ht-event-feedback-knowledgebase.ts | 2 + ...ent-webview.ts => ht-event-webview-end.ts} | 16 +++++--- .../src/event-models/ht-event-webview-step.ts | 22 +++++++++++ .../src/event-models/ht-event.ts | 14 +++++++ .../src/event-models/index.ts | 3 +- .../src/index.ts | 3 +- .../src/types.ts | 20 ++++++++-- .../src/utils.ts | 7 +++- .../tests/event-custom.test.ts | 1 + .../tests/event-fallback.test.ts | 3 ++ .../event-feedback-knowledgebase.test.ts | 2 + .../tests/event-flow.test.ts | 1 + .../tests/event-handoff.test.ts | 3 ++ .../tests/event-intent-smart.test.ts | 1 + .../tests/event-intent.test.ts | 1 + .../tests/event-keyword.test.ts | 1 + .../tests/event-knowledge-base.test.ts | 2 + .../tests/event-webview.test.ts | 6 +++ .../tests/helpers/index.ts | 7 +++- .../src/components/index-types.ts | 1 + .../src/components/message/index.jsx | 2 + .../components/message/message-feedback.tsx | 8 +++- .../src/components/message/message-footer.tsx | 8 +++- .../botonic-react/src/components/text.tsx | 1 + 30 files changed, 167 insertions(+), 25 deletions(-) rename packages/botonic-plugin-hubtype-analytics/src/event-models/{ht-event-webview.ts => ht-event-webview-end.ts} (50%) create mode 100644 packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview-step.ts diff --git a/packages/botonic-core/src/handoff.ts b/packages/botonic-core/src/handoff.ts index fff8804f3e..cf898043be 100644 --- a/packages/botonic-core/src/handoff.ts +++ b/packages/botonic-core/src/handoff.ts @@ -32,6 +32,7 @@ export type HandoffExtraData = { interface BotEventData { language: string country: string + bot_interaction_id?: string } function contextDefaults(context: any): BackendContext { diff --git a/packages/botonic-core/src/models/legacy-types.ts b/packages/botonic-core/src/models/legacy-types.ts index e108ce1e9c..4562af760c 100644 --- a/packages/botonic-core/src/models/legacy-types.ts +++ b/packages/botonic-core/src/models/legacy-types.ts @@ -147,7 +147,8 @@ export interface Input extends Partial { context?: { campaign?: Campaign } - message_id?: string + message_id: string + bot_interaction_id: string } export interface Campaign { diff --git a/packages/botonic-core/tests/routing/router.match-route.test.ts b/packages/botonic-core/tests/routing/router.match-route.test.ts index d0ecb7c16b..714c04b5c2 100644 --- a/packages/botonic-core/tests/routing/router.match-route.test.ts +++ b/packages/botonic-core/tests/routing/router.match-route.test.ts @@ -2,29 +2,61 @@ import { BotRequest, INPUT, Input } from '../../src' import { Router } from '../../src/routing' import { testRoute, testSession } from '../helpers/routing' -const textInput: Input = { type: INPUT.TEXT, text: 'hi' } +const textInput: Input = { + type: INPUT.TEXT, + text: 'hi', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', +} + const textInputComplex: Input = { type: INPUT.TEXT, text: 'Cömplêx input &% 🚀', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', +} + +const textPayloadInput: Input = { + type: INPUT.TEXT, + text: 'hi', + payload: 'foo', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', +} + +const postbackInput: Input = { + type: INPUT.POSTBACK, + payload: 'foo', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', } -const textPayloadInput: Input = { type: INPUT.TEXT, text: 'hi', payload: 'foo' } -const postbackInput: Input = { type: INPUT.POSTBACK, payload: 'foo' } const audioInput: Input = { type: INPUT.AUDIO, src: 'data:audio/mpeg;base64,iVBORw0KG', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', } + const documentInput: Input = { type: INPUT.DOCUMENT, src: 'data:application/pdf;base64,iVBORw0KG', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', } + const imageInput: Input = { type: INPUT.IMAGE, src: 'data:image/png;base64,iVBORw0KG', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', } + const videoInput: Input = { type: INPUT.VIDEO, src: 'data:video/mp4;base64,iVBORw0KG', + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', } const requestInput: BotRequest = { diff --git a/packages/botonic-plugin-flow-builder/src/content-fields/flow-handoff.tsx b/packages/botonic-plugin-flow-builder/src/content-fields/flow-handoff.tsx index 0bf077a759..68af844a0c 100644 --- a/packages/botonic-plugin-flow-builder/src/content-fields/flow-handoff.tsx +++ b/packages/botonic-plugin-flow-builder/src/content-fields/flow-handoff.tsx @@ -56,6 +56,7 @@ export class FlowHandoff extends ContentFieldsBase { handOffBuilder.withBotEvent({ language: request.session.user.extra_data.language, country: request.session.user.extra_data.country, + bot_interaction_id: request.input.bot_interaction_id, }) this.isTestIntegration = request.session.is_test_integration await handOffBuilder.handOff() diff --git a/packages/botonic-plugin-flow-builder/src/content-fields/flow-knowledge-base.tsx b/packages/botonic-plugin-flow-builder/src/content-fields/flow-knowledge-base.tsx index fc76bfb139..f5cf3d6f81 100644 --- a/packages/botonic-plugin-flow-builder/src/content-fields/flow-knowledge-base.tsx +++ b/packages/botonic-plugin-flow-builder/src/content-fields/flow-knowledge-base.tsx @@ -1,4 +1,4 @@ -import { Text } from '@botonic/react' +import { ActionRequest, Text } from '@botonic/react' import React from 'react' import { ContentFieldsBase } from './content-fields-base' @@ -20,12 +20,13 @@ export class FlowKnowledgeBase extends ContentFieldsBase { return newKnowledgeBase } - toBotonic(id: string): JSX.Element { + toBotonic(id: string, request: ActionRequest): JSX.Element { return ( {this.text} diff --git a/packages/botonic-plugin-flow-builder/tests/helpers/utils.ts b/packages/botonic-plugin-flow-builder/tests/helpers/utils.ts index ed0d133ad0..a74e50d154 100644 --- a/packages/botonic-plugin-flow-builder/tests/helpers/utils.ts +++ b/packages/botonic-plugin-flow-builder/tests/helpers/utils.ts @@ -7,7 +7,6 @@ import { ResolvedPlugins, } from '@botonic/core' import { ActionRequest } from '@botonic/react' -import { v4 as uuid } from 'uuid' import BotonicPluginFlowBuilder, { FlowBuilderAction, @@ -48,7 +47,7 @@ export function createFlowBuilderPlugin({ } interface RequestArgs { - input: Input + input: Omit plugins?: ResolvedPlugins provider?: ProviderType isFirstInteraction?: boolean @@ -74,7 +73,11 @@ export function createRequest({ _hubtype_api: 'https://api.hubtype.com', is_test_integration: false, }, - input: { ...input, message_id: uuid() }, + input: { + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', + ...input, + }, lastRoutePath: '', plugins, } diff --git a/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-feedback-knowledgebase.ts b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-feedback-knowledgebase.ts index 776cde2fea..3c57c523b7 100644 --- a/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-feedback-knowledgebase.ts +++ b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-feedback-knowledgebase.ts @@ -9,6 +9,7 @@ import { HtEvent } from './ht-event' export class HtEventFeedbackKnowledgebase extends HtEvent { action: EventAction.FeedbackKnowledgebase knowledgebase_inference_id: string + feedback_target_bot_interaction_id: string feedback_target_id: string feedback_group_id: string possible_options: string[] @@ -22,6 +23,7 @@ export class HtEventFeedbackKnowledgebase extends HtEvent { this.type = EventType.WebEvent this.action = event.action this.knowledgebase_inference_id = event.knowledgebaseInferenceId + this.feedback_target_bot_interaction_id = event.feedbackBotInteractionId this.feedback_target_id = event.feedbackTargetId this.feedback_group_id = event.feedbackGroupId this.possible_options = event.possibleOptions diff --git a/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview.ts b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview-end.ts similarity index 50% rename from packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview.ts rename to packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview-end.ts index 27e26b24fc..6a8cbf85af 100644 --- a/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview.ts +++ b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview-end.ts @@ -1,21 +1,25 @@ -import { EventAction, EventType, EventWebview, RequestData } from '../types' +import { EventAction, EventType, EventWebviewEnd, RequestData } from '../types' import { HtEvent } from './ht-event' -export class HtEventWebview extends HtEvent { - action: EventAction.WebviewStep | EventAction.WebviewEnd +export class HtEventWebviewEnd extends HtEvent { + action: EventAction.WebviewEnd + flow_thread_id?: string webview_thread_id: string webview_name: string - webview_step_name?: string + webview_end_step_name?: string + webview_end_step_n?: number webview_end_fail_type?: string webview_end_fail_message?: string - constructor(event: EventWebview, requestData: RequestData) { + constructor(event: EventWebviewEnd, requestData: RequestData) { super(event, requestData) this.type = EventType.WebEvent this.action = event.action + this.flow_thread_id = event.flowThreadId this.webview_thread_id = event.webviewThreadId this.webview_name = event.webviewName - this.webview_step_name = event.webviewStepName + this.webview_end_step_name = event.webviewStepName + this.webview_end_step_n = event.webviewStepNumber this.webview_end_fail_type = event.webviewEndFailType this.webview_end_fail_message = event.webviewEndFailMessage } diff --git a/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview-step.ts b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview-step.ts new file mode 100644 index 0000000000..9ca9b88b36 --- /dev/null +++ b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-webview-step.ts @@ -0,0 +1,22 @@ +import { EventAction, EventType, EventWebviewStep, RequestData } from '../types' +import { HtEvent } from './ht-event' + +export class HtEventWebviewStep extends HtEvent { + action: EventAction.WebviewStep + flow_thread_id?: string + webview_thread_id: string + webview_name: string + webview_step_name?: string + webview_step_n?: number + + constructor(event: EventWebviewStep, requestData: RequestData) { + super(event, requestData) + this.type = EventType.WebEvent + this.action = event.action + this.flow_thread_id = event.flowThreadId + this.webview_thread_id = event.webviewThreadId + this.webview_name = event.webviewName + this.webview_step_name = event.webviewStepName + this.webview_step_n = event.webviewStepNumber + } +} diff --git a/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event.ts b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event.ts index 546975ae99..c522cb7cf2 100644 --- a/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event.ts +++ b/packages/botonic-plugin-hubtype-analytics/src/event-models/ht-event.ts @@ -1,5 +1,14 @@ import { EventAction, EventType, HtEventProps, RequestData } from '../types' +const excludedEvents = [ + EventAction.FeedbackCase, + EventAction.FeedbackConversation, + EventAction.FeedbackKnowledgebase, + EventAction.FeedbackWebview, + EventAction.WebviewStep, + EventAction.WebviewEnd, +] + export class HtEvent { chat_id: string type: EventType @@ -9,6 +18,7 @@ export class HtEvent { bot_version?: string flow_version?: string action: EventAction + bot_interaction_id?: string constructor(event: HtEventProps, requestData: RequestData) { this.chat_id = requestData.userId @@ -16,5 +26,9 @@ export class HtEvent { this.chat_country = requestData.country this.format_version = 2 this.action = event.action + + if (!excludedEvents.includes(event.action)) { + this.bot_interaction_id = requestData.botInteractionId + } } } diff --git a/packages/botonic-plugin-hubtype-analytics/src/event-models/index.ts b/packages/botonic-plugin-hubtype-analytics/src/event-models/index.ts index db6546c7b2..cadc4d5e1f 100644 --- a/packages/botonic-plugin-hubtype-analytics/src/event-models/index.ts +++ b/packages/botonic-plugin-hubtype-analytics/src/event-models/index.ts @@ -10,4 +10,5 @@ export { HtEventIntent } from './ht-event-intent' export { HtEventIntentSmart } from './ht-event-intent-smart' export { HtEventKeyword } from './ht-event-keyword' export { HtEventKnowledgeBase } from './ht-event-knowledge-base' -export { HtEventWebview } from './ht-event-webview' +export { HtEventWebviewEnd } from './ht-event-webview-end' +export { HtEventWebviewStep } from './ht-event-webview-step' diff --git a/packages/botonic-plugin-hubtype-analytics/src/index.ts b/packages/botonic-plugin-hubtype-analytics/src/index.ts index 8242f3524b..9028a651dc 100644 --- a/packages/botonic-plugin-hubtype-analytics/src/index.ts +++ b/packages/botonic-plugin-hubtype-analytics/src/index.ts @@ -1,5 +1,5 @@ import { BotRequest, Plugin } from '@botonic/core' -import axios, { AxiosError } from 'axios' +import axios from 'axios' import { HtEvent } from './event-models' import { EventType, HtEventProps, RequestData } from './types' @@ -44,6 +44,7 @@ export default class BotonicPluginHubtypeAnalytics implements Plugin { language: this.getLanguage(request), country: this.getCountry(request), userId: request.session.user.id, + botInteractionId: request.input?.bot_interaction_id, } } diff --git a/packages/botonic-plugin-hubtype-analytics/src/types.ts b/packages/botonic-plugin-hubtype-analytics/src/types.ts index 507015c7f3..40800b2d60 100644 --- a/packages/botonic-plugin-hubtype-analytics/src/types.ts +++ b/packages/botonic-plugin-hubtype-analytics/src/types.ts @@ -45,6 +45,7 @@ export interface EventFeedback extends HtBaseEventProps { export interface EventFeedbackKnowledgebase extends HtBaseEventProps { action: EventAction.FeedbackKnowledgebase knowledgebaseInferenceId: string + feedbackBotInteractionId: string feedbackTargetId: string feedbackGroupId: string possibleOptions: string[] @@ -130,11 +131,22 @@ export interface EventFallback extends HtBaseEventProps { fallbackMessageId: string } -export interface EventWebview extends HtBaseEventProps { - action: EventAction.WebviewStep | EventAction.WebviewEnd +export interface EventWebviewStep extends HtBaseEventProps { + action: EventAction.WebviewStep + flowThreadId?: string + webviewThreadId: string + webviewName: string + webviewStepName: string + webviewStepNumber?: number +} + +export interface EventWebviewEnd extends HtBaseEventProps { + action: EventAction.WebviewEnd + flowThreadId?: string webviewThreadId: string webviewName: string webviewStepName?: string + webviewStepNumber?: number webviewEndFailType?: string webviewEndFailMessage?: string } @@ -156,11 +168,13 @@ export type HtEventProps = | EventIntentSmart | EventKnowledgeBase | EventFallback - | EventWebview + | EventWebviewStep + | EventWebviewEnd | EventCustom export interface RequestData { language: string country: string userId: string + botInteractionId: string } diff --git a/packages/botonic-plugin-hubtype-analytics/src/utils.ts b/packages/botonic-plugin-hubtype-analytics/src/utils.ts index 74be62543c..371fdd833c 100644 --- a/packages/botonic-plugin-hubtype-analytics/src/utils.ts +++ b/packages/botonic-plugin-hubtype-analytics/src/utils.ts @@ -11,7 +11,8 @@ import { HtEventIntentSmart, HtEventKeyword, HtEventKnowledgeBase, - HtEventWebview, + HtEventWebviewEnd, + HtEventWebviewStep, } from './event-models' import { EventAction, HtEventProps, RequestData } from './types' @@ -55,8 +56,10 @@ export function createHtEvent( return new HtEventFallback(htEventProps, requestData) case EventAction.WebviewStep: + return new HtEventWebviewStep(htEventProps, requestData) + case EventAction.WebviewEnd: - return new HtEventWebview(htEventProps, requestData) + return new HtEventWebviewEnd(htEventProps, requestData) case EventAction.Custom: return new HtEventCustom(htEventProps, requestData) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-custom.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-custom.test.ts index ee7ab311e9..e268b5a10c 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-custom.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-custom.test.ts @@ -26,6 +26,7 @@ describe('Create custom events', () => { value: '12345', }, custom_sensitive_fields: { bank_account: '1234567890' }, + bot_interaction_id: 'testInteractionId', type: EventType.WebEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-fallback.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-fallback.test.ts index 0b0ddaeff0..dda53b1f1a 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-fallback.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-fallback.test.ts @@ -20,6 +20,7 @@ describe('Create fallback events', () => { user_input: 'userInputTest', fallback_out: 1, fallback_message_id: 'fallbackMessageIdTest', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) @@ -41,6 +42,7 @@ describe('Create fallback events', () => { user_input: 'userInputTest', fallback_out: 2, fallback_message_id: 'fallbackMessageIdTest', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) @@ -62,6 +64,7 @@ describe('Create fallback events', () => { user_input: 'userInputTest', fallback_out: 1, fallback_message_id: 'fallbackMessageIdTest', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-feedback-knowledgebase.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-feedback-knowledgebase.test.ts index d9bcdc1314..bd8c8e7568 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-feedback-knowledgebase.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-feedback-knowledgebase.test.ts @@ -8,6 +8,7 @@ describe('Create feedback knowledgebase event', () => { action: EventAction.FeedbackKnowledgebase, feedbackTargetId: 'messageIdTest', feedbackGroupId: 'groupIdTest', + feedbackBotInteractionId: 'testInteractionId', knowledgebaseInferenceId: 'knowledgebaseInferenceIdTest', possibleOptions: ['thumbs_down', 'thumbs_up'], possibleValues: [0, 1], @@ -23,6 +24,7 @@ describe('Create feedback knowledgebase event', () => { action: EventAction.FeedbackKnowledgebase, feedback_target_id: 'messageIdTest', feedback_group_id: 'groupIdTest', + feedback_target_bot_interaction_id: 'testInteractionId', knowledgebase_inference_id: 'knowledgebaseInferenceIdTest', possible_options: ['thumbs_down', 'thumbs_up'], possible_values: [0, 1], diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-flow.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-flow.test.ts index 2ba843ec1b..5e0d6f30ce 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-flow.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-flow.test.ts @@ -26,6 +26,7 @@ describe('Create flow event', () => { flow_node_id: 'flowNodeIdTest', flow_node_content_id: 'flowNodeContentIdTest', flow_node_is_meaningful: false, + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-handoff.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-handoff.test.ts index 69804d6e7a..14ec478bd0 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-handoff.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-handoff.test.ts @@ -26,6 +26,7 @@ describe('Create handoff events', () => { handoff_is_queue_open: true, handoff_is_available_agent: true, handoff_is_threshold_reached: false, + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) @@ -51,6 +52,7 @@ describe('Create handoff events', () => { handoff_is_queue_open: false, handoff_is_available_agent: false, handoff_is_threshold_reached: false, + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) @@ -70,6 +72,7 @@ describe('Create handoff events', () => { action: EventAction.HandoffOption, handoff_queue_id: 'handoffQueueIdTest', handoff_queue_name: 'handoffQueueNameTest', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-intent-smart.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-intent-smart.test.ts index 8090d98b9c..19cc9326ac 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-intent-smart.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-intent-smart.test.ts @@ -22,6 +22,7 @@ describe('Create nlu intent smart events', () => { nlu_intent_smart_num_used: 2, nlu_intent_smart_message_id: 'messageId', user_input: 'Add a bag', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-intent.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-intent.test.ts index ba6b9910bd..72fa393044 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-intent.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-intent.test.ts @@ -24,6 +24,7 @@ describe('Create nlu intent classic events', () => { nlu_intent_threshold: 0.6, nlu_intent_message_id: 'nluIntentMessageId', user_input: 'Add a bag', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-keyword.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-keyword.test.ts index ea4e7ca15c..e985c57c03 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-keyword.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-keyword.test.ts @@ -24,6 +24,7 @@ describe('Create nlu keyword events', () => { nlu_keyword_is_regex: false, nlu_keyword_message_id: 'messageId', user_input: 'hello', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-knowledge-base.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-knowledge-base.test.ts index e488b6e8a6..ebca0564f8 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-knowledge-base.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-knowledge-base.test.ts @@ -29,6 +29,7 @@ describe('Create knowledge base events', () => { knowledgebase_chunks_ids: ['cunkId1', 'chunkId2', 'chunkId3'], knowledgebase_message_id: 'knowledgebaseMessageId', user_input: 'What is Flow Builder?', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) @@ -56,6 +57,7 @@ describe('Create knowledge base events', () => { knowledgebase_chunks_ids: ['cunkId1', 'chunkId2', 'chunkId3'], knowledgebase_message_id: 'knowledgebaseMessageId', user_input: 'What is Flow Builder?', + bot_interaction_id: 'testInteractionId', type: EventType.BotEvent, }) }) diff --git a/packages/botonic-plugin-hubtype-analytics/tests/event-webview.test.ts b/packages/botonic-plugin-hubtype-analytics/tests/event-webview.test.ts index 2bf6c66b6c..a8837745ff 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/event-webview.test.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/event-webview.test.ts @@ -9,6 +9,7 @@ describe('Create webview events', () => { webviewThreadId: '12345', webviewName: 'ADD_A_BAG', webviewStepName: 'step1', + webviewStepNumber: 1, }) expect(htEvent).toEqual({ @@ -20,6 +21,7 @@ describe('Create webview events', () => { webview_thread_id: '12345', webview_name: 'ADD_A_BAG', webview_step_name: 'step1', + webview_step_n: 1, type: EventType.WebEvent, }) }) @@ -29,6 +31,8 @@ describe('Create webview events', () => { action: EventAction.WebviewEnd, webviewThreadId: '12345', webviewName: 'ADD_A_BAG', + webviewStepName: 'summary_step', + webviewStepNumber: 3, webviewEndFailType: 'canceled_by_user', webviewEndFailMessage: 'Closed by user', }) @@ -41,6 +45,8 @@ describe('Create webview events', () => { action: EventAction.WebviewEnd, webview_thread_id: '12345', webview_name: 'ADD_A_BAG', + webview_end_step_name: 'summary_step', + webview_end_step_n: 3, webview_end_fail_type: 'canceled_by_user', webview_end_fail_message: 'Closed by user', type: EventType.WebEvent, diff --git a/packages/botonic-plugin-hubtype-analytics/tests/helpers/index.ts b/packages/botonic-plugin-hubtype-analytics/tests/helpers/index.ts index da55f8ee10..c6c776f04a 100644 --- a/packages/botonic-plugin-hubtype-analytics/tests/helpers/index.ts +++ b/packages/botonic-plugin-hubtype-analytics/tests/helpers/index.ts @@ -36,7 +36,12 @@ export function createRequest(args?: RequestArgs): BotRequest { _hubtype_api: 'https://api.hubtype.com', is_test_integration: false, }, - input: { data: 'Hola', type: INPUT.TEXT }, + input: { + data: 'Hola', + type: INPUT.TEXT, + bot_interaction_id: 'testInteractionId', + message_id: 'testMessageId', + }, lastRoutePath: '', } } diff --git a/packages/botonic-react/src/components/index-types.ts b/packages/botonic-react/src/components/index-types.ts index 44ddd963b9..393b036fee 100644 --- a/packages/botonic-react/src/components/index-types.ts +++ b/packages/botonic-react/src/components/index-types.ts @@ -31,6 +31,7 @@ export interface TextProps extends MessageProps { markdown?: boolean feedbackEnabled?: boolean inferenceId?: string + botInteractionId?: string } export interface Webview { diff --git a/packages/botonic-react/src/components/message/index.jsx b/packages/botonic-react/src/components/message/index.jsx index 7f662e7f0c..bcffa05013 100644 --- a/packages/botonic-react/src/components/message/index.jsx +++ b/packages/botonic-react/src/components/message/index.jsx @@ -39,6 +39,7 @@ export const Message = props => { isUnread = true, feedbackEnabled, inferenceId, + botInteractionId, ...otherProps } = props @@ -269,6 +270,7 @@ export const Message = props => { sentBy={sentBy} feedbackEnabled={feedbackEnabled} inferenceId={inferenceId} + botInteractionId={botInteractionId} /> ) : null} diff --git a/packages/botonic-react/src/components/message/message-feedback.tsx b/packages/botonic-react/src/components/message/message-feedback.tsx index 0c4713fb7d..af1672ce59 100644 --- a/packages/botonic-react/src/components/message/message-feedback.tsx +++ b/packages/botonic-react/src/components/message/message-feedback.tsx @@ -15,11 +15,16 @@ interface ButtonsState { } interface RatingProps { + botInteractionId?: string inferenceId?: string messageId: string } -export const MessageFeedback = ({ inferenceId, messageId }: RatingProps) => { +export const MessageFeedback = ({ + botInteractionId, + inferenceId, + messageId, +}: RatingProps) => { const { webchatState, updateMessage, trackEvent } = useContext(WebchatContext) const request = useContext(RequestContext) @@ -64,6 +69,7 @@ export const MessageFeedback = ({ inferenceId, messageId }: RatingProps) => { const args = { knowledgebaseInferenceId: inferenceId, + feedbackBotInteractionId: botInteractionId, feedbackTargetId: messageId, feedbackGroupId: uuid(), possibleOptions: [FeedbackOption.ThumbsUp, FeedbackOption.ThumbsDown], diff --git a/packages/botonic-react/src/components/message/message-footer.tsx b/packages/botonic-react/src/components/message/message-footer.tsx index 3ec50f170c..438ef2e955 100644 --- a/packages/botonic-react/src/components/message/message-footer.tsx +++ b/packages/botonic-react/src/components/message/message-footer.tsx @@ -12,6 +12,7 @@ interface MessageFooterProps { sentBy: SENDERS feedbackEnabled: boolean inferenceId?: string + botInteractionId?: string } export const MessageFooter = ({ @@ -20,6 +21,7 @@ export const MessageFooter = ({ sentBy, feedbackEnabled, inferenceId, + botInteractionId, }: MessageFooterProps) => { const { getThemeProperty } = useContext(WebchatContext) @@ -45,7 +47,11 @@ export const MessageFooter = ({ /> ) : null} {feedbackEnabled ? ( - + ) : null} ) diff --git a/packages/botonic-react/src/components/text.tsx b/packages/botonic-react/src/components/text.tsx index 8cb5947fd8..7243ceeccf 100644 --- a/packages/botonic-react/src/components/text.tsx +++ b/packages/botonic-react/src/components/text.tsx @@ -31,6 +31,7 @@ export const Text = (props: TextProps) => { markdown: props.markdown === undefined ? true : props.markdown, feedbackEnabled: props.feedbackEnabled, inferenceId: props.inferenceId, + botInteractionId: props.botInteractionId, } const textProps = mapObjectNonBooleanValues({