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.78 kB
import { __awaiter, __rest } from "tslib"; import { EventAction } from '@botonic/shared'; import { v7 as uuidv7 } from 'uuid'; import { HtNodeWithContentType, } from './content-fields/hubtype-fields'; import { getFlowBuilderPlugin } from './utils'; export function trackEvent(botonicContext, eventAction, args) { return __awaiter(this, void 0, void 0, function* () { const flowBuilderPlugin = getFlowBuilderPlugin(botonicContext.plugins); if (flowBuilderPlugin.trackEvent) { yield flowBuilderPlugin.trackEvent(botonicContext, eventAction, args !== null && args !== void 0 ? args : {}); } return; }); } export function trackFlowContent(botonicContext, contents) { return __awaiter(this, void 0, void 0, function* () { const flowBuilderPlugin = getFlowBuilderPlugin(botonicContext.plugins); const cmsApi = flowBuilderPlugin.cmsApi; for (const content of contents) { yield trackOneContent(botonicContext, content, cmsApi); } }); } export function trackOneContent(botonicContext, content, cmsApi) { return __awaiter(this, void 0, void 0, function* () { if (!cmsApi) { const flowBuilderPlugin = getFlowBuilderPlugin(botonicContext.plugins); cmsApi = flowBuilderPlugin.cmsApi; } const nodeContent = cmsApi.getNodeById(content.id); if (nodeContent.type !== HtNodeWithContentType.KNOWLEDGE_BASE && nodeContent.type !== HtNodeWithContentType.AI_AGENT) { const event = yield getContentEventArgs(botonicContext, nodeContent); const { action } = event, eventArgs = __rest(event, ["action"]); yield trackEvent(botonicContext, action, eventArgs); } }); } function setSessionFlowThreadId(botonicContext, flowThreadId) { return __awaiter(this, void 0, void 0, function* () { if (botonicContext.session.flowThreadId !== flowThreadId) { yield botonicContext.updateBotSession({ flowThreadId }); } }); } function getContentEventArgs(botonicContext, nodeContent) { return __awaiter(this, void 0, void 0, function* () { var _a; const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = yield getCommonFlowContentEventArgs(botonicContext, nodeContent); return { action: EventAction.FlowNode, flowId, flowName, flowNodeId, flowNodeContentId, flowThreadId, flowNodeIsMeaningful: (_a = nodeContent.is_meaningful) !== null && _a !== void 0 ? _a : false, }; }); } function getCommonFlowContentEventArgs(botonicContext, nodeContent) { return __awaiter(this, void 0, void 0, function* () { var _a; const flowBuilderPlugin = getFlowBuilderPlugin(botonicContext.plugins); const flowName = flowBuilderPlugin.getFlowName(nodeContent.flow_id); const flowThreadId = (_a = botonicContext.session.flowThreadId) !== null && _a !== void 0 ? _a : uuidv7(); yield setSessionFlowThreadId(botonicContext, flowThreadId); return { flowThreadId, flowId: nodeContent.flow_id, flowName, flowNodeId: nodeContent.id, flowNodeContentId: nodeContent.code, }; }); } export function getCommonFlowContentEventArgsForContentId(botonicContext, id) { return __awaiter(this, void 0, void 0, function* () { const flowBuilderPlugin = getFlowBuilderPlugin(botonicContext.plugins); const cmsApi = flowBuilderPlugin.cmsApi; const nodeContent = cmsApi.getNodeById(id); return yield getCommonFlowContentEventArgs(botonicContext, nodeContent); }); } //# sourceMappingURL=tracking.js.map