Skip to content

Commit

Permalink
refactor: apply suggestions, simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
vanbasten17 committed May 17, 2024
1 parent 80b82c4 commit 5fbd872
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/botonic-plugin-flow-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SmartIntentsInferenceParams>

constructor(
cmsApi: FlowBuilderApi,
request: ActionRequest,
smartIntentsConfig: Partial<SmartIntentsInferenceParams>
) {
this.currentRequest = request
this.cmsApi = cmsApi
this.smartIntentsConfig = smartIntentsConfig
}
public cmsApi: FlowBuilderApi,
public currentRequest: ActionRequest,
public smartIntentsConfig: Partial<SmartIntentsInferenceParams>
) {}

async getNodeByInput(): Promise<HtSmartIntentNode | undefined> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down

0 comments on commit 5fbd872

Please sign in to comment.