@botonic/react
Version:
Build Chatbots using React
36 lines • 1.65 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { INPUT } from '@botonic/core';
import { toSnakeCaseKeys } from '../util/functional';
import { renderComponent } from '../util/react';
import { Message } from './message';
const serialize = (message) => {
return { text: message };
};
export const WhatsappMediaCarousel = (props) => {
const renderBrowser = () => {
// Return a dummy message for browser
const message = `WhatsApp Media Carousel would be sent to the user.`;
return (_jsx(Message, Object.assign({ json: serialize(message) }, props, { type: 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 toSnakeCaseKeys(cards);
};
const renderNode = () => {
return (
// @ts-ignore Property 'message' does not exist on type 'JSX.IntrinsicElements'.
_jsx("message", Object.assign({}, props, { bodyParameters: JSON.stringify(toSnakeCaseKeys(props.bodyParameters)), cards: JSON.stringify(getCards(props.cards)), templateName: props.templateName, templateLanguage: props.templateLanguage, type: INPUT.WHATSAPP_MEDIA_CAROUSEL })));
};
return renderComponent({ renderBrowser, renderNode });
};
//# sourceMappingURL=whatsapp-media-carousel.js.map