diff --git a/packages/botonic-plugin-flow-builder/src/index.ts b/packages/botonic-plugin-flow-builder/src/index.ts index 3b23b0d088..60b8c259ce 100644 --- a/packages/botonic-plugin-flow-builder/src/index.ts +++ b/packages/botonic-plugin-flow-builder/src/index.ts @@ -68,7 +68,7 @@ export default class BotonicPluginFlowBuilder implements Plugin { this.trackEvent = options.trackEvent this.getKnowledgeBaseResponse = options.getKnowledgeBaseResponse this.smartIntentsConfig = { - ...(options.smartIntentsConfig || {}), + ...options?.smartIntentsConfig, use_latest: jsonVersion === FlowBuilderJSONVersion.LATEST, } const customFunctions = options.customFunctions || {} diff --git a/packages/botonic-plugin-flow-builder/src/user-input/smart-intent.ts b/packages/botonic-plugin-flow-builder/src/user-input/smart-intent.ts index bbb5d5e8b2..60ef7eba92 100644 --- a/packages/botonic-plugin-flow-builder/src/user-input/smart-intent.ts +++ b/packages/botonic-plugin-flow-builder/src/user-input/smart-intent.ts @@ -11,26 +11,17 @@ export interface SmartIntentsInferenceParams { num_smart_intents_to_use?: number } export class SmartIntentsApi { - public cmsApi: FlowBuilderApi - public currentRequest: ActionRequest - public smartIntentsConfig: Partial - constructor( - cmsApi: FlowBuilderApi, - request: ActionRequest, - smartIntentsConfig: Partial - ) { - this.currentRequest = request - this.cmsApi = cmsApi - this.smartIntentsConfig = smartIntentsConfig - } + public cmsApi: FlowBuilderApi, + public currentRequest: ActionRequest, + public smartIntentsConfig: Partial + ) {} async getNodeByInput(): Promise { - if (!this.currentRequest.input.data) return undefined const smartIntentNodes = this.cmsApi.getSmartIntentNodes() if (!smartIntentNodes.length) return undefined - const params: SmartIntentsInferenceParams = { + const params = { bot_id: this.currentRequest.session.bot.id, text: this.currentRequest.input.data, ...this.smartIntentsConfig, diff --git a/packages/botonic-plugin-flow-builder/tests/__mocks__/smart-intent.ts b/packages/botonic-plugin-flow-builder/tests/__mocks__/smart-intent.ts index 8498997f0a..57865359dc 100644 --- a/packages/botonic-plugin-flow-builder/tests/__mocks__/smart-intent.ts +++ b/packages/botonic-plugin-flow-builder/tests/__mocks__/smart-intent.ts @@ -11,6 +11,6 @@ export function mockSmartIntent(intentName?: string) { // Change the implementation of getInference getInferenceSpy.mockImplementation(async () => { - return intentName ? { data: { intent_name: intentName } } : undefined + return intentName ? { data: { smart_intent_title: intentName } } : undefined }) } diff --git a/packages/botonic-plugin-flow-builder/tests/smart-intent.test.ts b/packages/botonic-plugin-flow-builder/tests/smart-intent.test.ts index ecd89e36ec..1a448281a1 100644 --- a/packages/botonic-plugin-flow-builder/tests/smart-intent.test.ts +++ b/packages/botonic-plugin-flow-builder/tests/smart-intent.test.ts @@ -34,7 +34,7 @@ describe('Check the contents returned by the plugin when match a smart intent', request, flowBuilderPlugin ) - + console.log({ contents }) expect((contents[0] as FlowText).text).toBe( 'Message explaining how to add a bag' )