UNPKG

@botonic/plugin-flow-builder

Version:

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

85 lines 3.83 kB
import { __awaiter } from "tslib"; import { MAIN_FLOW_NAME } from '../constants'; import { FlowBotAction } from '../content-fields'; import { inputHasTextOrTranscript } from '../utils/input'; import { getContentsByAiAgentFromUserInput } from './ai-agent-from-user-input'; import { getContentsByKnowledgeBase } from './knowledge-bases'; import { getContentsByPayload } from './payload'; export function getContentsByFirstInteraction(fbContext) { return __awaiter(this, void 0, void 0, function* () { const { flowBuilderPlugin, botonicContext } = fbContext; const firstInteractionContents = yield flowBuilderPlugin.getStartContents(); // If the first interaction has a FlowBotAction, it should be the last content // and avoid to render the match with keywords,intents or knowledge base if (firstInteractionContents.at(-1) instanceof FlowBotAction) { return firstInteractionContents; } if (botonicContext.input.nluResolution || inputHasTextOrTranscript(botonicContext.input)) { const contentsByUserInput = yield getContentsByUserInput(fbContext); return [...firstInteractionContents, ...contentsByUserInput]; } return firstInteractionContents; }); } function getContentsByUserInput(_a) { return __awaiter(this, arguments, void 0, function* ({ cmsApi, flowBuilderPlugin, botonicContext, resolvedLocale, }) { var _b; const payloadByNlu = (_b = botonicContext.input.nluResolution) === null || _b === void 0 ? void 0 : _b.payload; if (payloadByNlu) { botonicContext.input.payload = payloadByNlu; const conversationStartId = getConversationStartId(cmsApi); if (botonicContext.input.payload === conversationStartId) { return []; } const contentsByKeywordsOrIntents = yield getContentsByPayload({ cmsApi, flowBuilderPlugin, botonicContext, resolvedLocale, }); const hasRepeatedContent = yield checkRepeatedContents(flowBuilderPlugin, contentsByKeywordsOrIntents); if (hasRepeatedContent) { return []; } if (contentsByKeywordsOrIntents.length > 0) { return contentsByKeywordsOrIntents; } } const knowledgeBaseContents = yield getContentsByKnowledgeBase({ cmsApi, flowBuilderPlugin, botonicContext, resolvedLocale, }); if (knowledgeBaseContents.length > 0) { return knowledgeBaseContents; } if (!flowBuilderPlugin.disableAIAgentInFirstInteraction) { const aiAgentContents = yield getContentsByAiAgentFromUserInput({ cmsApi, flowBuilderPlugin, botonicContext, resolvedLocale, }); if (aiAgentContents.length > 0) { return aiAgentContents; } } return []; }); } function getConversationStartId(cmsApi) { var _a; const conversationStartId = (_a = cmsApi.flow.flows.find(flow => flow.name === MAIN_FLOW_NAME)) === null || _a === void 0 ? void 0 : _a.start_node_id; return conversationStartId; } function checkRepeatedContents(flowBuilderPlugin, contentsByKeywordsOrIntents) { return __awaiter(this, void 0, void 0, function* () { const startContents = yield flowBuilderPlugin.getStartContents(); const contentIds = new Set(contentsByKeywordsOrIntents.map(content => content.id)); const hasRepeatedContent = startContents.some(content => contentIds.has(content.id)); return hasRepeatedContent; }); } //# sourceMappingURL=first-interaction.js.map