Skip to content

Commit

Permalink
plugin-hubtype-analytics: add user input in nlu events (#2848)
Browse files Browse the repository at this point in the history
## Description

add userInput as a required attribute in all nlu events (keyword, smart
intent, intent and knowledge base)
  • Loading branch information
Iru89 committed Jun 11, 2024
1 parent 21fc646 commit 69f33f6
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ async function trackKnowledgeBase(
knowledgebaseSourcesIds,
knowledgebaseChunksIds,
knowledgebaseMessageId,
userInput: request.input.data,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async function trackIntentEvent(
nluIntentConfidence: request.input.confidence,
nluIntentThreshold: intentNode?.content.confidence,
nluIntentMessageId: request.input.message_id,
userInput: request.input.data,
}
await trackEvent(request, EventAction.Intent, eventArgs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class KeywordMatcher {
nluKeywordName: this.matchedKeyword,
nluKeywordIsRegex: this.isRegExp,
nluKeywordMessageId: this.request.input.message_id,
userInput: this.request.input.data,
}
await trackEvent(this.request, EventAction.Keyword, eventArgs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class SmartIntentsApi {
nluIntentSmartTitle: response.data.smart_intent_title,
nluIntentSmartNumUsed: response.data.smart_intents_used.length,
nluIntentSmartMessageId: this.currentRequest.input.message_id,
userInput: this.currentRequest.input.data,
})
return smartIntentNode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class HtEventIntentSmart extends HtEvent {
nlu_intent_smart_title: string
nlu_intent_smart_num_used: number
nlu_intent_smart_message_id: string
user_input: string

constructor(event: EventIntentSmart, requestData: RequestData) {
super(event, requestData)
Expand All @@ -13,5 +14,6 @@ export class HtEventIntentSmart extends HtEvent {
this.nlu_intent_smart_title = event.nluIntentSmartTitle
this.nlu_intent_smart_num_used = event.nluIntentSmartNumUsed
this.nlu_intent_smart_message_id = event.nluIntentSmartMessageId
this.user_input = event.userInput
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class HtEventIntent extends HtEvent {
nlu_intent_confidence: number
nlu_intent_threshold: number
nlu_intent_message_id: string
user_input: string

constructor(event: EventIntent, requestData: RequestData) {
super(event, requestData)
Expand All @@ -15,5 +16,6 @@ export class HtEventIntent extends HtEvent {
this.nlu_intent_confidence = event.nluIntentConfidence
this.nlu_intent_threshold = event.nluIntentThreshold
this.nlu_intent_message_id = event.nluIntentMessageId
this.user_input = event.userInput
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class HtEventKeyword extends HtEvent {
nlu_keyword_name: string
nlu_keyword_is_regex: boolean
nlu_keyword_message_id: string
user_input: string

constructor(event: EventKeyword, requestData: RequestData) {
super(event, requestData)
Expand All @@ -15,5 +16,6 @@ export class HtEventKeyword extends HtEvent {
this.nlu_keyword_name = event.nluKeywordName
this.nlu_keyword_is_regex = event.nluKeywordIsRegex || false
this.nlu_keyword_message_id = event.nluKeywordMessageId
this.user_input = event.userInput
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class HtEventKnowledgeBase extends HtEvent {
knowledgebase_sources_ids: string[]
knowledgebase_chunks_ids: string[]
knowledgebase_message_id: string
user_input: string

constructor(event: EventKnowledgeBase, requestData: RequestData) {
super(event, requestData)
Expand All @@ -22,5 +23,6 @@ export class HtEventKnowledgeBase extends HtEvent {
this.knowledgebase_sources_ids = event.knowledgebaseSourcesIds
this.knowledgebase_chunks_ids = event.knowledgebaseChunksIds
this.knowledgebase_message_id = event.knowledgebaseMessageId
this.user_input = event.userInput
}
}
4 changes: 4 additions & 0 deletions packages/botonic-plugin-hubtype-analytics/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface EventIntent extends HtBaseEventProps {
nluIntentConfidence: number
nluIntentThreshold: number
nluIntentMessageId: string
userInput: string
}

export interface EventKeyword extends HtBaseEventProps {
Expand All @@ -82,13 +83,15 @@ export interface EventKeyword extends HtBaseEventProps {
nluKeywordName: string
nluKeywordIsRegex?: boolean
nluKeywordMessageId: string
userInput: string
}

export interface EventIntentSmart extends HtBaseEventProps {
action: EventAction.IntentSmart
nluIntentSmartTitle: string
nluIntentSmartNumUsed: number
nluIntentSmartMessageId: string
userInput: string
}

export interface EventKnowledgeBase extends HtBaseEventProps {
Expand All @@ -98,6 +101,7 @@ export interface EventKnowledgeBase extends HtBaseEventProps {
knowledgebaseSourcesIds: string[]
knowledgebaseChunksIds: string[]
knowledgebaseMessageId: string
userInput: string
}

export enum KnowledgebaseFailReason {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Create nlu intent smart events', () => {
nluIntentSmartTitle: 'ADD_A_BAG',
nluIntentSmartNumUsed: 2,
nluIntentSmartMessageId: 'messageId',
userInput: 'Add a bag',
})

expect(htEvent).toEqual({
Expand All @@ -20,6 +21,7 @@ describe('Create nlu intent smart events', () => {
nlu_intent_smart_title: 'ADD_A_BAG',
nlu_intent_smart_num_used: 2,
nlu_intent_smart_message_id: 'messageId',
user_input: 'Add a bag',
type: EventType.BotEvent,
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Create nlu intent classic events', () => {
nluIntentConfidence: 0.7,
nluIntentThreshold: 0.6,
nluIntentMessageId: 'nluIntentMessageId',
userInput: 'Add a bag',
})

expect(htEvent).toEqual({
Expand All @@ -22,6 +23,7 @@ describe('Create nlu intent classic events', () => {
nlu_intent_confidence: 0.7,
nlu_intent_threshold: 0.6,
nlu_intent_message_id: 'nluIntentMessageId',
user_input: 'Add a bag',
type: EventType.BotEvent,
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Create nlu keyword events', () => {
nluKeywordName: 'hello',
nluKeywordIsRegex: false,
nluKeywordMessageId: 'messageId',
userInput: 'hello',
})

expect(htEvent).toEqual({
Expand All @@ -22,6 +23,7 @@ describe('Create nlu keyword events', () => {
nlu_keyword_name: 'hello',
nlu_keyword_is_regex: false,
nlu_keyword_message_id: 'messageId',
user_input: 'hello',
type: EventType.BotEvent,
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('Create knowledge base events', () => {
knowledgebaseSourcesIds: ['sourceId1', 'sourceId2'],
knowledgebaseChunksIds: ['cunkId1', 'chunkId2', 'chunkId3'],
knowledgebaseMessageId: 'knowledgebaseMessageId',
userInput: 'What is Flow Builder?',
})

expect(htEvent).toEqual({
Expand All @@ -27,6 +28,7 @@ describe('Create knowledge base events', () => {
knowledgebase_sources_ids: ['sourceId1', 'sourceId2'],
knowledgebase_chunks_ids: ['cunkId1', 'chunkId2', 'chunkId3'],
knowledgebase_message_id: 'knowledgebaseMessageId',
user_input: 'What is Flow Builder?',
type: EventType.BotEvent,
})
})
Expand All @@ -39,6 +41,7 @@ describe('Create knowledge base events', () => {
knowledgebaseSourcesIds: ['sourceId1', 'sourceId2'],
knowledgebaseChunksIds: ['cunkId1', 'chunkId2', 'chunkId3'],
knowledgebaseMessageId: 'knowledgebaseMessageId',
userInput: 'What is Flow Builder?',
})

expect(htEvent).toEqual({
Expand All @@ -52,6 +55,7 @@ describe('Create knowledge base events', () => {
knowledgebase_sources_ids: ['sourceId1', 'sourceId2'],
knowledgebase_chunks_ids: ['cunkId1', 'chunkId2', 'chunkId3'],
knowledgebase_message_id: 'knowledgebaseMessageId',
user_input: 'What is Flow Builder?',
type: EventType.BotEvent,
})
})
Expand Down

0 comments on commit 69f33f6

Please sign in to comment.