@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
75 lines • 3.17 kB
JavaScript
import { __awaiter, __rest } from "tslib";
import { EventAction } from '@botonic/core';
import { v7 as uuidv7 } from 'uuid';
import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
import { getFlowBuilderPlugin } from './helpers';
export function trackEvent(request, eventAction, args) {
return __awaiter(this, void 0, void 0, function* () {
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
if (flowBuilderPlugin.trackEvent) {
yield flowBuilderPlugin.trackEvent(request, eventAction, args);
}
return;
});
}
export function trackFlowContent(request, contents) {
return __awaiter(this, void 0, void 0, function* () {
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
const cmsApi = flowBuilderPlugin.cmsApi;
for (const content of contents) {
yield trackOneContent(request, content, cmsApi);
}
});
}
export function trackOneContent(request, content, cmsApi) {
return __awaiter(this, void 0, void 0, function* () {
if (!cmsApi) {
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
cmsApi = flowBuilderPlugin.cmsApi;
}
const nodeContent = cmsApi.getNodeById(content.id);
if (nodeContent.type !== HtNodeWithContentType.KNOWLEDGE_BASE &&
nodeContent.type !== HtNodeWithContentType.AI_AGENT) {
const event = getContentEventArgs(request, nodeContent);
const { action } = event, eventArgs = __rest(event, ["action"]);
yield trackEvent(request, action, eventArgs);
}
});
}
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: 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 = getFlowBuilderPlugin(request.plugins);
const flowName = flowBuilderPlugin.getFlowName(nodeContent.flow_id);
const flowThreadId = (_a = request.session.flow_thread_id) !== null && _a !== void 0 ? _a : uuidv7();
return {
flowThreadId,
flowId: nodeContent.flow_id,
flowName,
flowNodeId: nodeContent.id,
flowNodeContentId: (_b = nodeContent.code) !== null && _b !== void 0 ? _b : '',
};
}
export function getCommonFlowContentEventArgsForContentId(request, contentId) {
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
const cmsApi = flowBuilderPlugin.cmsApi;
const nodeContent = cmsApi.getNodeById(contentId);
return getCommonFlowContentEventArgs(request, nodeContent);
}
//# sourceMappingURL=tracking.js.map