UNPKG

@botonic/plugin-flow-builder

Version:

Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.

69 lines 3.45 kB
import { __awaiter, __rest } from "tslib"; import { NluType } from '@botonic/core'; import { EventAction } from '@botonic/shared'; import { SmartIntentClient } from '../services/smart-intent-client'; import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking'; export class SmartIntentsApi { constructor(cmsApi, botonicContext, smartIntentsConfig, userTextOrTranscript, flowId) { this.cmsApi = cmsApi; this.botonicContext = botonicContext; this.smartIntentsConfig = smartIntentsConfig; this.userTextOrTranscript = userTextOrTranscript; this.flowId = flowId; } getNodeByInput() { return __awaiter(this, void 0, void 0, function* () { var _a, _b; if (!this.userTextOrTranscript) return undefined; const smartIntentNodes = this.cmsApi.getSmartIntentNodes(); if (!smartIntentNodes.length) return undefined; const smartIntentClient = new SmartIntentClient(this.botonicContext); const requestData = { bot_id: this.botonicContext.session.bot.id, text: this.userTextOrTranscript, num_smart_intents_to_use: this.smartIntentsConfig.numSmartIntentsToUse, use_latest: this.resolveUseLatest(), }; try { const response = yield smartIntentClient.getInference(requestData); const smartIntentNode = smartIntentNodes.find(smartIntentNode => smartIntentNode.content.title === response.smart_intent_title); if (smartIntentNode) { const targetPayload = this.cmsApi.getPayload(smartIntentNode.target); this.botonicContext.input.nluResolution = { type: NluType.SmartIntent, matchedValue: smartIntentNode.content.title, payload: targetPayload, }; const { flowId, flowName, flowNodeId, flowNodeContentId } = yield getCommonFlowContentEventArgsForContentId(this.botonicContext, smartIntentNode.id); const event = { action: EventAction.IntentSmart, nluIntentSmartTitle: response.smart_intent_title, nluIntentSmartNumUsed: response.smart_intents_used.length, nluIntentSmartMessageId: (_a = this.botonicContext.input.dbId) !== null && _a !== void 0 ? _a : '', userInput: this.userTextOrTranscript, flowThreadId: (_b = this.botonicContext.session.flowThreadId) !== null && _b !== void 0 ? _b : undefined, flowId, flowName, flowNodeContentId, flowNodeId, }; const { action } = event, eventArgs = __rest(event, ["action"]); yield trackEvent(this.botonicContext, action, eventArgs); return smartIntentNode; } } catch (e) { console.error(e); } return undefined; }); } resolveUseLatest() { if (this.botonicContext.session.isTestIntegration) return false; return this.smartIntentsConfig.useLatest; } } //# sourceMappingURL=smart-intent.js.map