UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

52 lines 2.53 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { isDev, isWebchat, isWhatsapp } from '@botonic/core'; import { CustomRatingMessage, Text, WhatsappButtonList, } from '@botonic/react'; import { getFlowBuilderPlugin } from '../helpers'; 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.code = ''; this.text = ''; this.sendButtonText = ''; this.ratingType = 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 => FlowButton.fromRating(button)); newRating.openListButtonText = this.getTextByLocale(locale, cmsText.content.open_list_button_text); return newRating; } toBotonic(id, request) { const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins); const customRatingMessageEnabled = flowBuilderPlugin.customRatingMessageEnabled; if (isWhatsapp(request.session)) { return (_jsx(WhatsappButtonList, { body: this.text, button: this.openListButtonText, sections: [ { rows: this.buttons.map(button => ({ id: button.payload, title: button.text, })), }, ] })); } if ((isWebchat(request.session) || isDev(request.session)) && customRatingMessageEnabled) { const payloads = this.buttons .map(button => button.payload) .slice() .reverse(); return (_jsx(CustomRatingMessage, { payloads: payloads, messageText: this.text, buttonText: this.sendButtonText, ratingType: this.ratingType })); } return (_jsxs(Text, { children: [this.text, this.buttons.map((button, buttonIndex) => button.renderButton(buttonIndex))] }, id)); } } //# sourceMappingURL=flow-rating.js.map