@botonic/react
Version:
Build Chatbots using React
42 lines • 1.96 kB
JavaScript
;
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 };
};
/*
Reference: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/media-card-carousel-templates
*/
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, { json: serialize(message), ...props, type: core_1.INPUT.TEXT, children: message }));
};
const getCards = (cards) => {
cards.forEach((card, index) => {
if (!card.cardIndex) {
card.cardIndex = index;
}
card.buttons?.forEach((button, index) => {
if (!button.buttonIndex) {
button.buttonIndex = index;
}
});
});
return (0, functional_1.toSnakeCaseKeys)(cards);
};
const renderNode = () => {
return (
// @ts-expect-error Property 'message' does not exist on type 'JSX.IntrinsicElements'.
(0, jsx_runtime_1.jsx)("message", { ...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