@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
56 lines • 2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowChannelConditional = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const core_1 = require("@botonic/core");
const tracking_1 = require("../tracking");
const content_fields_base_1 = require("./content-fields-base");
class FlowChannelConditional extends content_fields_base_1.ContentFieldsBase {
constructor() {
super(...arguments);
this.resultMapping = [];
this.conditionalResult = undefined;
this.channelResult = '';
}
static fromHubtypeCMS(component, request) {
const newChannelConditional = new FlowChannelConditional(component.id);
newChannelConditional.code = component.code;
newChannelConditional.resultMapping = component.content.result_mapping;
newChannelConditional.setConditionalResult(request);
return newChannelConditional;
}
setConditionalResult(request) {
const provider = request.session.user.provider;
const conditionalResult = this.resultMapping.find(rMap => rMap.result === provider) ||
this.resultMapping.find(rMap => rMap.result === 'default');
if (!conditionalResult) {
throw new Error(`No conditional result found for node ${this.code} with channel: ${provider}`);
}
this.conditionalResult = conditionalResult;
this.channelResult = conditionalResult.result;
this.followUp = conditionalResult.target;
}
trackFlow(request) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = (0, tracking_1.getCommonFlowContentEventArgsForContentId)(request, this.id);
const eventChannelConditional = {
action: core_1.EventAction.ConditionalChannel,
flowThreadId,
flowId,
flowName,
flowNodeId,
flowNodeContentId,
flowNodeIsMeaningful: false,
channel: this.channelResult,
};
const { action } = eventChannelConditional, eventArgs = tslib_1.__rest(eventChannelConditional, ["action"]);
yield (0, tracking_1.trackEvent)(request, action, eventArgs);
});
}
toBotonic() {
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
}
}
exports.FlowChannelConditional = FlowChannelConditional;
//# sourceMappingURL=flow-channel-conditional.js.map