@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
55 lines • 2.29 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { Button, Reply } from '@botonic/react';
import { SOURCE_INFO_SEPARATOR } from '../constants';
import { ContentFieldsBase } from './content-fields-base';
import { HtButtonStyle } from './hubtype-fields';
export class FlowButton extends ContentFieldsBase {
constructor() {
super(...arguments);
this.text = '';
}
static fromHubtypeCMS(cmsButton, locale, cmsApi) {
const urlId = this.getUrlId(cmsButton, locale);
const newButton = new FlowButton(cmsButton.id);
newButton.text = this.getTextByLocale(locale, cmsButton.text);
if (cmsButton.target) {
newButton.payload = cmsApi.getPayload(cmsButton.target);
}
if (cmsButton.url && urlId) {
const urlNode = cmsApi.getNodeById(urlId);
newButton.url = urlNode.content.url;
}
return newButton;
}
static fromAIAgent(button) {
const newButton = new FlowButton(button.id);
newButton.text = button.text;
newButton.payload = button.payload;
newButton.url = button.url;
return newButton;
}
static fromRating(button) {
var _a;
const newButton = new FlowButton(button.id);
newButton.text = button.text;
newButton.payload = button.payload;
newButton.target = (_a = button.target) === null || _a === void 0 ? void 0 : _a.id;
return newButton;
}
static getUrlId(cmsButton, locale) {
var _a;
return (_a = cmsButton.url.find(url => url.locale === locale)) === null || _a === void 0 ? void 0 : _a.id;
}
renderButton(buttonIndex, buttonStyle) {
if (buttonStyle === HtButtonStyle.QUICK_REPLY) {
return (_jsx(Reply, Object.assign({ payload: this.getButtonPayload(buttonIndex) }, { children: this.text }), this.id));
}
return (_jsx(Button, Object.assign({ url: this.url, payload: this.getButtonPayload(buttonIndex), target: this.target, webview: this.webview }, { children: this.text }), this.id));
}
getButtonPayload(buttonIndex) {
return this.payload
? `${this.payload}${SOURCE_INFO_SEPARATOR}${buttonIndex}`
: undefined;
}
}
//# sourceMappingURL=flow-button.js.map