UNPKG

@botonic/react

Version:

Build Chatbots using React

40 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WhatsappMediaCarousel = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const core_1 = require("@botonic/core"); const functional_1 = require("../util/functional"); const react_1 = require("../util/react"); const message_1 = require("./message"); const serialize = (message) => { return { text: message }; }; const WhatsappMediaCarousel = (props) => { const renderBrowser = () => { // Return a dummy message for browser const message = `WhatsApp Media Carousel would be sent to the user.`; return ((0, jsx_runtime_1.jsx)(message_1.Message, Object.assign({ json: serialize(message) }, props, { type: core_1.INPUT.TEXT }, { children: message }))); }; const getCards = (cards) => { cards.forEach((card, index) => { var _a; if (!card.cardIndex) { card.cardIndex = index; } (_a = card.buttons) === null || _a === void 0 ? void 0 : _a.forEach((button, index) => { if (!button.buttonIndex) { button.buttonIndex = index; } }); }); return (0, functional_1.toSnakeCaseKeys)(cards); }; const renderNode = () => { return ( // @ts-ignore Property 'message' does not exist on type 'JSX.IntrinsicElements'. (0, jsx_runtime_1.jsx)("message", Object.assign({}, props, { bodyParameters: JSON.stringify((0, functional_1.toSnakeCaseKeys)(props.bodyParameters)), cards: JSON.stringify(getCards(props.cards)), templateName: props.templateName, templateLanguage: props.templateLanguage, type: core_1.INPUT.WHATSAPP_MEDIA_CAROUSEL }))); }; return (0, react_1.renderComponent)({ renderBrowser, renderNode }); }; exports.WhatsappMediaCarousel = WhatsappMediaCarousel; //# sourceMappingURL=whatsapp-media-carousel.js.map