@botonic/plugin-flow-builder
Version:
Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.
66 lines • 2.88 kB
JavaScript
import { __awaiter } from "tslib";
import { BotServerMessageFactory, } from '@botonic/core';
import { trackOneContent } from '../tracking';
import { ContentFieldsBase } from './content-fields-base';
import { FlowButton } from './flow-button';
import { FlowElement } from './flow-element';
const DEFAULT_TEXT_MESSAGE = 'These are the options';
export class FlowCarousel extends ContentFieldsBase {
constructor() {
super(...arguments);
this.whatsappText = '';
this.elements = [];
}
static fromHubtypeCMS(component, locale, cmsApi) {
const newCarousel = new FlowCarousel(component.id);
newCarousel.code = component.code;
newCarousel.elements = component.content.elements.map(element => FlowElement.fromHubtypeCMS(element, locale, cmsApi));
newCarousel.whatsappText = this.getTextByLocale(locale, component.content.whatsapp_text);
newCarousel.followUp = component.follow_up;
return newCarousel;
}
trackFlow(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
yield trackOneContent(botonicContext, this);
for (const element of this.elements) {
yield element.trackFlow(botonicContext);
}
});
}
static fromAIAgent(id, carouselMessage, botonicContext) {
var _a;
const carousel = new FlowCarousel(id);
carousel.whatsappText = (_a = carouselMessage.content.text) !== null && _a !== void 0 ? _a : '';
carousel.elements = carouselMessage.content.elements.map((element, index) => {
const flowElement = new FlowElement(`${id}-${index}`);
flowElement.title = element.title;
flowElement.subtitle = element.subtitle;
flowElement.image = element.image;
flowElement.button = FlowButton.fromAIAgent({
id: `${id}-${index}-btn`,
text: element.button.text,
url: element.button.url,
target: element.button.target,
payload: element.button.payload,
});
return flowElement;
});
return carousel.toBotonic(botonicContext);
}
processContent(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
yield this.trackFlow(botonicContext);
return this.filterContent(botonicContext, this);
});
}
toBotonic(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
const botonicElements = this.elements.map(element => element.addElementToBotonic(botonicContext));
return BotServerMessageFactory.createCarousel({
text: this.whatsappText || DEFAULT_TEXT_MESSAGE,
elements: botonicElements,
});
});
}
}
//# sourceMappingURL=flow-carousel.js.map