@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
61 lines • 2.64 kB
JavaScript
import { __awaiter } from "tslib";
import { v7 as uuidv7 } from 'uuid';
import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
import { getFlowBuilderPlugin } from './helpers';
export var EventAction;
(function (EventAction) {
EventAction["FlowNode"] = "flow_node";
EventAction["Keyword"] = "nlu_keyword";
EventAction["IntentSmart"] = "nlu_intent_smart";
EventAction["Knowledgebase"] = "knowledgebase";
EventAction["Fallback"] = "fallback";
EventAction["FeedbackCase"] = "feedback_case";
})(EventAction || (EventAction = {}));
export var KnowledgebaseFailReason;
(function (KnowledgebaseFailReason) {
KnowledgebaseFailReason["NoKnowledge"] = "no_knowledge";
KnowledgebaseFailReason["Hallucination"] = "hallucination";
})(KnowledgebaseFailReason || (KnowledgebaseFailReason = {}));
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) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
const cmsApi = flowBuilderPlugin.cmsApi;
for (const content of contents) {
const nodeContent = cmsApi.getNodeById(content.id);
if (nodeContent.type !== HtNodeWithContentType.KNOWLEDGE_BASE) {
const eventArgs = getContentEventArgs(request, {
code: nodeContent.code,
flowId: nodeContent.flow_id,
flowName: flowBuilderPlugin.getFlowName(nodeContent.flow_id),
id: nodeContent.id,
isMeaningful: (_a = nodeContent.is_meaningful) !== null && _a !== void 0 ? _a : false,
});
yield trackEvent(request, EventAction.FlowNode, eventArgs);
}
}
});
}
function getContentEventArgs(request, contentInfo) {
var _a;
const flowThreadId = (_a = request.session.flow_thread_id) !== null && _a !== void 0 ? _a : uuidv7();
request.session.flow_thread_id = flowThreadId;
return {
flowThreadId,
flowId: contentInfo.flowId,
flowName: contentInfo.flowName,
flowNodeId: contentInfo.id,
flowNodeContentId: contentInfo.code,
flowNodeIsMeaningful: contentInfo.isMeaningful,
};
}
//# sourceMappingURL=tracking.js.map