UNPKG

@botonic/react

Version:

Build Chatbots using React

63 lines 3.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Multichannel = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const core_1 = require("@botonic/core"); const react_2 = require("react"); const contexts_1 = require("../../contexts"); const react_3 = require("../../util/react"); const text_1 = require("../text"); const multichannel_button_1 = require("./multichannel-button"); const multichannel_carousel_1 = require("./multichannel-carousel"); const multichannel_context_1 = require("./multichannel-context"); const multichannel_reply_1 = require("./multichannel-reply"); const multichannel_text_1 = require("./multichannel-text"); const multichannel_utils_1 = require("./multichannel-utils"); const constants_1 = require("./whatsapp/constants"); const Multichannel = props => { const requestContext = (0, react_2.useContext)(contexts_1.RequestContext); if (!(0, core_1.isWhatsapp)(requestContext.session) && !(0, core_1.isFacebook)(requestContext.session) && !(0, core_1.isInstagram)(requestContext.session)) { return props.children; } if ((0, core_1.isFacebook)(requestContext.session) || (0, core_1.isInstagram)(requestContext.session)) { const newChildren = (0, react_3.deepMapWithIndex)(props.children, child => { if ((0, multichannel_utils_1.isNodeText)(child)) { return ((0, react_1.createElement)(multichannel_text_1.MultichannelText, { ...child.props, key: child.key }, child.props.children)); } return child; }); return newChildren; } let newChildren = (0, react_3.deepMapWithIndex)(props.children, (child, index) => { if ((0, multichannel_utils_1.isNodeButton)(child)) { return ((0, react_1.createElement)(multichannel_button_1.MultichannelButton, { ...child.props, key: child.key }, child.props.children)); } if ((0, multichannel_utils_1.isNodeReply)(child)) { return ((0, react_1.createElement)(multichannel_reply_1.MultichannelReply, { ...child.props, key: child.key }, child.props.children)); } if ((0, multichannel_utils_1.isNodeText)(child)) { return ((0, react_1.createElement)(multichannel_text_1.MultichannelText, { ...child.props, ...props.text, key: child.key, ...(props.messageSeparator && index > 0 && { newline: props.messageSeparator }) }, child.props.children)); } if ((0, multichannel_utils_1.isNodeCarousel)(child)) { return ((0, react_1.createElement)(multichannel_carousel_1.MultichannelCarousel, { ...child.props, ...props.carousel, key: child.key }, child.props.children)); } return child; }); if (props.messageSeparator != null) { newChildren = newChildren.map((c, index) => index > 0 && typeof c === 'string' ? props.messageSeparator + c : c); newChildren = ((0, jsx_runtime_1.jsx)(text_1.Text, { ...constants_1.MULTICHANNEL_WHATSAPP_PROPS, children: newChildren }, props.key)); } return ((0, jsx_runtime_1.jsx)(multichannel_context_1.MultichannelContext.Provider, { value: { currentIndex: props.firstIndex, boldIndex: props.boldIndex, indexSeparator: props.indexSeparator, messageSeparator: props.messageSeparator, }, children: newChildren })); }; exports.Multichannel = Multichannel; //# sourceMappingURL=multichannel.js.map