@botonic/react
Version:
Build Chatbots using React
89 lines • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buttonTypes = void 0;
exports.isMultichannelButton = isMultichannelButton;
exports.isMultichannelReply = isMultichannelReply;
exports.isNodeText = isNodeText;
exports.isNodeButton = isNodeButton;
exports.isNodeCarousel = isNodeCarousel;
exports.isNodeReply = isNodeReply;
exports.isNodePic = isNodePic;
exports.isNodeTitle = isNodeTitle;
exports.isNodeSubtitle = isNodeSubtitle;
exports.elementHasUrl = elementHasUrl;
exports.elementHasPostback = elementHasPostback;
exports.elementHasWebview = elementHasWebview;
exports.getButtonType = getButtonType;
exports.getFilteredElements = getFilteredElements;
exports.getMultichannelButtons = getMultichannelButtons;
exports.getMultichannelReplies = getMultichannelReplies;
const constants_1 = require("../constants");
function isMultichannelButton(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.MultichannelButton;
}
function isMultichannelReply(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.MultichannelReply;
}
function isNodeText(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.Text;
}
function isNodeButton(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.Button;
}
function isNodeCarousel(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.Carousel;
}
function isNodeReply(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.Reply;
}
function isNodePic(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.Pic;
}
function isNodeTitle(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.Title;
}
function isNodeSubtitle(node) {
return node?.type?.displayName === constants_1.COMPONENT_DISPLAY_NAMES.Subtitle;
}
function elementHasUrl(element) {
return element?.props?.url;
}
function elementHasPostback(element) {
return element?.props?.payload || element?.props?.path;
}
function elementHasWebview(element) {
return element?.props?.webview;
}
exports.buttonTypes = {
POSTBACK: 'postback',
URL: 'url',
WEBVIEW: 'webview',
};
function getButtonType(multichannelButton) {
if (elementHasUrl(multichannelButton)) {
return exports.buttonTypes.URL;
}
if (elementHasPostback(multichannelButton)) {
return exports.buttonTypes.POSTBACK;
}
if (elementHasWebview(multichannelButton)) {
return exports.buttonTypes.WEBVIEW;
}
return undefined;
}
function getFilteredElements(node, filter) {
const elements = [];
for (const n of node) {
if (filter(n)) {
elements.push(n);
}
}
return elements;
}
function getMultichannelButtons(node) {
return getFilteredElements(node, isMultichannelButton);
}
function getMultichannelReplies(node) {
return getFilteredElements(node, isMultichannelReply);
}
//# sourceMappingURL=multichannel-utils.js.map