UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

52 lines 2.36 kB
import { __awaiter, __rest } from "tslib"; import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; import { EventAction } from '@botonic/core'; import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking'; import { ContentFieldsBase } from './content-fields-base'; export class FlowChannelConditional extends 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 __awaiter(this, void 0, void 0, function* () { const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgsForContentId(request, this.id); const eventChannelConditional = { action: EventAction.ConditionalChannel, flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId, flowNodeIsMeaningful: false, channel: this.channelResult, }; const { action } = eventChannelConditional, eventArgs = __rest(eventChannelConditional, ["action"]); yield trackEvent(request, action, eventArgs); }); } toBotonic() { return _jsx(_Fragment, {}); } } //# sourceMappingURL=flow-channel-conditional.js.map