UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

66 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.trackFlowContent = exports.trackEvent = exports.KnowledgebaseFailReason = exports.EventAction = void 0; const tslib_1 = require("tslib"); const uuid_1 = require("uuid"); const hubtype_fields_1 = require("./content-fields/hubtype-fields"); const helpers_1 = require("./helpers"); 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 = exports.EventAction || (exports.EventAction = {})); var KnowledgebaseFailReason; (function (KnowledgebaseFailReason) { KnowledgebaseFailReason["NoKnowledge"] = "no_knowledge"; KnowledgebaseFailReason["Hallucination"] = "hallucination"; })(KnowledgebaseFailReason = exports.KnowledgebaseFailReason || (exports.KnowledgebaseFailReason = {})); 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) { var _a; 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) { const nodeContent = cmsApi.getNodeById(content.id); if (nodeContent.type !== hubtype_fields_1.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); } } }); } exports.trackFlowContent = trackFlowContent; function getContentEventArgs(request, contentInfo) { var _a; const flowThreadId = (_a = request.session.flow_thread_id) !== null && _a !== void 0 ? _a : (0, uuid_1.v7)(); 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