@botonic/plugin-flow-builder
Version:
Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.
59 lines • 2.71 kB
JavaScript
import { __awaiter, __rest } from "tslib";
import { EventAction } from '@botonic/shared';
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, botonicContext) {
const newChannelConditional = new FlowChannelConditional(component.id);
newChannelConditional.code = component.code;
newChannelConditional.resultMapping = component.content.result_mapping;
newChannelConditional.setConditionalResult(botonicContext);
return newChannelConditional;
}
setConditionalResult(botonicContext) {
const provider = botonicContext.session.provider;
const conditionalResult = this.resultMapping.find(rMap => rMap.result === provider) ||
this.resultMapping.find(rMap => rMap.result === 'default');
if (!(conditionalResult === null || conditionalResult === void 0 ? void 0 : conditionalResult.result)) {
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(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = yield getCommonFlowContentEventArgsForContentId(botonicContext, 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(botonicContext, action, eventArgs);
});
}
processContent(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
yield this.trackFlow(botonicContext);
return this.filterContent(botonicContext, this);
});
}
toBotonic() {
return __awaiter(this, void 0, void 0, function* () {
return;
});
}
}
//# sourceMappingURL=flow-channel-conditional.js.map