@botonic/plugin-flow-builder
Version:
Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.
61 lines • 2.88 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 FlowCountryConditional extends ContentFieldsBase {
constructor() {
super(...arguments);
this.resultMapping = [];
this.conditionalResult = undefined;
}
static fromHubtypeCMS(component, botonicContext) {
const newCountryConditional = new FlowCountryConditional(component.id);
newCountryConditional.code = component.code;
newCountryConditional.resultMapping = component.content.result_mapping;
newCountryConditional.setConditionalResult(botonicContext);
return newCountryConditional;
}
setConditionalResult(botonicContext) {
const country = botonicContext.session.user.country;
const conditionalResult = this.resultMapping.find(rMap => rMap.result === country) ||
this.resultMapping.find(rMap => rMap.result === 'default');
if (!conditionalResult) {
throw new Error(`No conditional result found for node ${this.code} with country: ${country}`);
}
this.conditionalResult = conditionalResult;
this.followUp = conditionalResult.target;
}
trackFlow(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = yield getCommonFlowContentEventArgsForContentId(botonicContext, this.id);
if (!((_a = this.conditionalResult) === null || _a === void 0 ? void 0 : _a.result)) {
console.warn(`Tracking event for node ${this.code} but no conditional result found`);
}
const eventCountryConditional = {
action: EventAction.ConditionalCountry,
flowThreadId,
flowId,
flowName,
flowNodeId,
flowNodeContentId,
flowNodeIsMeaningful: false,
country: (_c = (_b = this.conditionalResult) === null || _b === void 0 ? void 0 : _b.result) !== null && _c !== void 0 ? _c : '',
};
const { action } = eventCountryConditional, eventArgs = __rest(eventCountryConditional, ["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-country-conditional.js.map