UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

56 lines 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowRating = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const core_1 = require("@botonic/core"); const react_1 = require("@botonic/react"); const helpers_1 = require("../helpers"); const content_fields_base_1 = require("./content-fields-base"); const flow_button_1 = require("./flow-button"); const hubtype_fields_1 = require("./hubtype-fields"); class FlowRating extends content_fields_base_1.ContentFieldsBase { constructor() { super(...arguments); this.code = ''; this.text = ''; this.sendButtonText = ''; this.ratingType = hubtype_fields_1.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.ratingType = cmsText.content.rating_type; newRating.buttons = cmsText.content.buttons.map(button => flow_button_1.FlowButton.fromRating(button)); newRating.openListButtonText = this.getTextByLocale(locale, cmsText.content.open_list_button_text); return newRating; } toBotonic(id, request) { const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins); const customRatingMessageEnabled = flowBuilderPlugin.customRatingMessageEnabled; if ((0, core_1.isWhatsapp)(request.session)) { return ((0, jsx_runtime_1.jsx)(react_1.WhatsappButtonList, { body: this.text, button: this.openListButtonText, sections: [ { rows: this.buttons.map(button => ({ id: button.payload, title: button.text, })), }, ] })); } if (((0, core_1.isWebchat)(request.session) || (0, core_1.isDev)(request.session)) && customRatingMessageEnabled) { const payloads = this.buttons .map(button => button.payload) .slice() .reverse(); return ((0, jsx_runtime_1.jsx)(react_1.CustomRatingMessage, { payloads: payloads, messageText: this.text, buttonText: this.sendButtonText, ratingType: this.ratingType })); } return ((0, jsx_runtime_1.jsxs)(react_1.Text, { children: [this.text, this.buttons.map((button, buttonIndex) => button.renderButton(buttonIndex))] }, id)); } } exports.FlowRating = FlowRating; //# sourceMappingURL=flow-rating.js.map