UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

82 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCommonFlowContentEventArgsForContentId = exports.trackOneContent = exports.trackFlowContent = exports.trackEvent = void 0; const tslib_1 = require("tslib"); const core_1 = require("@botonic/core"); const uuid_1 = require("uuid"); const hubtype_fields_1 = require("./content-fields/hubtype-fields"); const helpers_1 = require("./helpers"); function trackEvent(request, eventAction, args) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins); if (flowBuilderPlugin.trackEvent) { yield flowBuilderPlugin.trackEvent(request, eventAction, args); } return; }); } exports.trackEvent = trackEvent; function trackFlowContent(request, contents) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins); const cmsApi = flowBuilderPlugin.cmsApi; for (const content of contents) { yield trackOneContent(request, content, cmsApi); } }); } exports.trackFlowContent = trackFlowContent; function trackOneContent(request, content, cmsApi) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (!cmsApi) { const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins); cmsApi = flowBuilderPlugin.cmsApi; } const nodeContent = cmsApi.getNodeById(content.id); if (nodeContent.type !== hubtype_fields_1.HtNodeWithContentType.KNOWLEDGE_BASE && nodeContent.type !== hubtype_fields_1.HtNodeWithContentType.AI_AGENT) { const event = getContentEventArgs(request, nodeContent); const { action } = event, eventArgs = tslib_1.__rest(event, ["action"]); yield trackEvent(request, action, eventArgs); } }); } exports.trackOneContent = trackOneContent; function setSessionFlowThreadId(request, flowThreadId) { request.session.flow_thread_id = flowThreadId; } function getContentEventArgs(request, nodeContent) { var _a; const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgs(request, nodeContent); setSessionFlowThreadId(request, flowThreadId); return { action: core_1.EventAction.FlowNode, flowId, flowName, flowNodeId, flowNodeContentId, flowThreadId, flowNodeIsMeaningful: (_a = nodeContent.is_meaningful) !== null && _a !== void 0 ? _a : false, }; } function getCommonFlowContentEventArgs(request, nodeContent) { var _a, _b; const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins); const flowName = flowBuilderPlugin.getFlowName(nodeContent.flow_id); const flowThreadId = (_a = request.session.flow_thread_id) !== null && _a !== void 0 ? _a : (0, uuid_1.v7)(); return { flowThreadId, flowId: nodeContent.flow_id, flowName, flowNodeId: nodeContent.id, flowNodeContentId: (_b = nodeContent.code) !== null && _b !== void 0 ? _b : '', }; } function getCommonFlowContentEventArgsForContentId(request, contentId) { const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins); const cmsApi = flowBuilderPlugin.cmsApi; const nodeContent = cmsApi.getNodeById(contentId); return getCommonFlowContentEventArgs(request, nodeContent); } exports.getCommonFlowContentEventArgsForContentId = getCommonFlowContentEventArgsForContentId; //# sourceMappingURL=tracking.js.map