-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feedback knoweldege base with thumbsUp/thumbsDown (#2859)
## Description Add feedback_knowledgebase event Be able to add ThumbsUp and ThumbsDown buttons to give feedback on webchat messages. When the flow builder creates a message using the knowledge base Uses the Text component with new withfeedback and inferenceid attributes The withfeedback and inferenceid attributes cannot be declared using camelCase because when they pass through the backen they come back with everything in lowercase, it doesn't work with snake_case either. I'm not sure but I think it's because of the html parser, the <message> attributes have to be single words or use kebab-case. ## Context Review this PR commit by commit: [plugin-hubtype-analytics](dc8f373): add feedback_knowledgebase event [botonic-react](3fa97b0): Refactor the FooterMessage and add the FeedbackMessage which contains the ThumbsUp ThumbsDown buttons and uses the trackEvent function when clicked. [botonic-react](bb98f33): Add the possibility to inject the onTrackEvent function from the bot to the webchat to create events from the frontend. Just like we already have the onInit, onOpen, onClose, onMessage functions. [plugin-flow-builder](8d90eb7): When the flow builder plugin uses the knowledge base to generate a message it creates a @botonic/react Text with the new withfeedback and inferenceid attributes needed for tracking. The other commits are a refactor that renumbers the with_feedback attrbute to feebackEnabled using camelCase ## Approach taken / Explain the design Design ![Captura de pantalla 2024-06-21 a las 14 02 23](https://github.com/hubtype/botonic/assets/36898236/992cac28-fcdc-4109-bd9e-fc27d67e7204) ## To document / Usage example How to pass the tracking function from bot to webchat /webchat/index.ts ```typescript export const webchat: WebchatArgs = { onInit: app => { window.botonicOnInit(app) }, ... onTrackEvent: async (request, eventName, args) => { const pluginHubtypeAnalytics = new BotonicPluginHubtypeAnalytics() const htEventProps = { action: eventName as EventAction, ...args, } as HtEventProps await pluginHubtypeAnalytics.trackEvent(request, htEventProps) }, theme: { ... ``` ## Testing Adds a test for the new feedback_knowledgebase event
- Loading branch information
Showing
24 changed files
with
391 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ages/botonic-plugin-hubtype-analytics/src/event-models/ht-event-feedback-knowledgebase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
EventAction, | ||
EventFeedbackKnowledgebase, | ||
EventType, | ||
RequestData, | ||
} from '../types' | ||
import { HtEvent } from './ht-event' | ||
|
||
export class HtEventFeedbackKnowledgebase extends HtEvent { | ||
action: EventAction.FeedbackKnowledgebase | ||
knowledgebase_inference_id: string | ||
feedback_target_id: string | ||
feedback_group_id: string | ||
possible_options: string[] | ||
possible_values?: number[] | ||
option: string | ||
value?: number | ||
comment?: string | ||
|
||
constructor(event: EventFeedbackKnowledgebase, requestData: RequestData) { | ||
super(event, requestData) | ||
this.type = EventType.WebEvent | ||
this.action = event.action | ||
this.knowledgebase_inference_id = event.knowledgebaseInferenceId | ||
this.feedback_target_id = event.feedbackTargetId | ||
this.feedback_group_id = event.feedbackGroupId | ||
this.possible_options = event.possibleOptions | ||
this.possible_values = event.possibleValues | ||
this.option = event.option | ||
this.value = event.value | ||
this.comment = event.comment | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/botonic-plugin-hubtype-analytics/tests/event-feedback-knowledgebase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createHtEvent, EventAction, EventType } from '../src' | ||
import { getRequestData } from './helpers' | ||
|
||
describe('Create feedback knowledgebase event', () => { | ||
test('A message generated for a knowledge base recive feedback', () => { | ||
const requestData = getRequestData() | ||
const htEvent = createHtEvent(requestData, { | ||
action: EventAction.FeedbackKnowledgebase, | ||
feedbackTargetId: 'messageIdTest', | ||
feedbackGroupId: 'groupIdTest', | ||
knowledgebaseInferenceId: 'knowledgebaseInferenceIdTest', | ||
possibleOptions: ['thumbs_down', 'thumbs_up'], | ||
possibleValues: [0, 1], | ||
option: 'thumbs_down', | ||
value: 0, | ||
}) | ||
|
||
expect(htEvent).toEqual({ | ||
chat_id: 'chatIdTest', | ||
chat_language: 'es', | ||
chat_country: 'ES', | ||
format_version: 2, | ||
action: EventAction.FeedbackKnowledgebase, | ||
feedback_target_id: 'messageIdTest', | ||
feedback_group_id: 'groupIdTest', | ||
knowledgebase_inference_id: 'knowledgebaseInferenceIdTest', | ||
possible_options: ['thumbs_down', 'thumbs_up'], | ||
possible_values: [0, 1], | ||
option: 'thumbs_down', | ||
value: 0, | ||
type: EventType.WebEvent, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.