diff --git a/packages/botonic-plugin-flow-builder/src/index.ts b/packages/botonic-plugin-flow-builder/src/index.ts index 3b23b0d088..4be0262432 100644 --- a/packages/botonic-plugin-flow-builder/src/index.ts +++ b/packages/botonic-plugin-flow-builder/src/index.ts @@ -36,7 +36,7 @@ import { PayloadParamsBase, } from './types' import { getNodeByUserInput } from './user-input' -import { SmartIntentsInferenceParams } from './user-input/smart-intent' +import { SmartIntentsInferenceConfig } from './user-input/smart-intent' import { resolveGetAccessToken } from './utils' export default class BotonicPluginFlowBuilder implements Plugin { public cmsApi: FlowBuilderApi @@ -44,7 +44,6 @@ export default class BotonicPluginFlowBuilder implements Plugin { private flow?: HtFlowBuilderData private functions: Record private currentRequest: PluginPreRequest - private getAccessToken: (session: Session) => string public getLocale: (session: Session) => string public trackEvent?: ( @@ -55,8 +54,7 @@ export default class BotonicPluginFlowBuilder implements Plugin { public getKnowledgeBaseResponse?: ( request: ActionRequest ) => Promise - - public smartIntentsConfig: Partial + public smartIntentsConfig: SmartIntentsInferenceConfig constructor(readonly options: BotonicPluginFlowBuilderOptions) { const apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD @@ -68,7 +66,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..59cd6a9972 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 @@ -4,37 +4,34 @@ import axios from 'axios' import { FlowBuilderApi } from '../api' import { HtSmartIntentNode } from '../content-fields/hubtype-fields/smart-intent' -export interface SmartIntentsInferenceParams { +export interface SmartIntentsInferenceParams + extends SmartIntentsInferenceConfig { bot_id: string text: string +} + +export interface SmartIntentsInferenceConfig { use_latest: boolean num_smart_intents_to_use?: number } -export class SmartIntentsApi { - public cmsApi: FlowBuilderApi - public currentRequest: ActionRequest - public smartIntentsConfig: Partial +export class SmartIntentsApi { constructor( - cmsApi: FlowBuilderApi, - request: ActionRequest, - smartIntentsConfig: Partial - ) { - this.currentRequest = request - this.cmsApi = cmsApi - this.smartIntentsConfig = smartIntentsConfig - } + public cmsApi: FlowBuilderApi, + public currentRequest: ActionRequest, + public smartIntentsConfig: SmartIntentsInferenceConfig + ) {} 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, - } as SmartIntentsInferenceParams + } try { const response = await this.getInference(params) 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..06ec57f1c2 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,6 @@ describe('Check the contents returned by the plugin when match a smart intent', request, flowBuilderPlugin ) - expect((contents[0] as FlowText).text).toBe( 'Message explaining how to add a bag' )