@botonic/plugin-flow-builder
Version:
Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.
58 lines • 2.44 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 { RatingType } from './hubtype-fields';
export class FlowRating extends ContentFieldsBase {
constructor() {
super(...arguments);
this.text = '';
this.sendButtonText = '';
this.type = RatingType.Stars;
this.buttons = [];
this.openListButtonText = '';
}
static fromHubtypeCMS(cmsText, locale) {
const newRating = new FlowRating(cmsText.id);
newRating.code = cmsText.code;
newRating.text = this.getTextByLocale(locale, cmsText.content.text);
newRating.sendButtonText = this.getTextByLocale(locale, cmsText.content.send_button_text);
newRating.type = cmsText.content.rating_type;
newRating.buttons = cmsText.content.buttons.map(button => FlowButton.fromRating(button));
newRating.openListButtonText = this.getTextByLocale(locale, cmsText.content.open_list_button_text);
newRating.followUp = cmsText.follow_up;
return newRating;
}
trackFlow(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
yield trackOneContent(botonicContext, this);
});
}
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 replacedText = this.replaceVariables(this.text, botonicContext);
return BotServerMessageFactory.createRating({
text: replacedText,
type: this.type,
buttons: this.buttons.map(button => {
var _a;
return ({
title: button.text,
payload: button.payload,
value: (_a = button.ratingValue) !== null && _a !== void 0 ? _a : 0,
});
}),
sendButtonText: this.sendButtonText,
openListButtonText: this.openListButtonText,
});
});
}
}
//# sourceMappingURL=flow-rating.js.map