@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
59 lines • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("@botonic/react");
const constants_1 = require("../constants");
const content_fields_base_1 = require("./content-fields-base");
const hubtype_fields_1 = require("./hubtype-fields");
class FlowButton extends content_fields_base_1.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 === hubtype_fields_1.HtButtonStyle.QUICK_REPLY) {
return ((0, jsx_runtime_1.jsx)(react_1.Reply, Object.assign({ payload: this.getButtonPayload(buttonIndex) }, { children: this.text }), this.id));
}
return ((0, jsx_runtime_1.jsx)(react_1.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}${constants_1.SOURCE_INFO_SEPARATOR}${buttonIndex}`
: undefined;
}
}
exports.FlowButton = FlowButton;
//# sourceMappingURL=flow-button.js.map