@botonic/react
Version:
Build Chatbots using React
37 lines • 2.28 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.WhatsappCTAUrlButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const core_1 = require("@botonic/core");
const util_1 = require("../util");
const react_1 = require("../util/react");
const webviews_1 = require("../util/webviews");
const message_1 = require("./message");
const constants_1 = require("./multichannel/whatsapp/constants");
const markdown_meta_1 = require("./multichannel/whatsapp/markdown-meta");
const serialize = _whatsappCTAUrlButtonProps => {
// TODO: Implement to have data persistence in localStorage, not needed for this WhatsApp development
return {};
};
const WhatsappCTAUrlButton = (props) => {
const renderBrowser = () => {
// Return a dummy message for browser
const message = `${JSON.stringify(props)}`;
return ((0, jsx_runtime_1.jsx)(message_1.Message, Object.assign({ json: serialize(message) }, props, { type: core_1.INPUT.WHATSAPP_CTA_URL_BUTTON }, { children: message })));
};
const renderNode = () => {
const validatedProps = Object.assign(Object.assign({}, props), { header: props.header
? (0, util_1.truncateText)(props.header, constants_1.WHATSAPP_MAX_HEADER_CHARS)
: undefined, body: (0, util_1.truncateText)((0, markdown_meta_1.convertToMarkdownMeta)(props.body), constants_1.WHATSAPP_MAX_BODY_CHARS), footer: props.footer
? (0, util_1.truncateText)((0, markdown_meta_1.convertToMarkdownMeta)(props.footer), constants_1.WHATSAPP_MAX_FOOTER_CHARS)
: undefined, displayText: (0, util_1.truncateText)(props.displayText, constants_1.WHATSAPP_MAX_BUTTON_CHARS), url: 'webview' in props
? (0, webviews_1.generateWebviewUrlWithParams)(props.webview, props.params)
: props.url });
return (
// @ts-ignore Property 'message' does not exist on type 'JSX.IntrinsicElements'.
(0, jsx_runtime_1.jsx)("message", Object.assign({}, validatedProps, { type: core_1.INPUT.WHATSAPP_CTA_URL_BUTTON })));
};
return (0, react_1.renderComponent)({ renderBrowser, renderNode });
};
exports.WhatsappCTAUrlButton = WhatsappCTAUrlButton;
//# sourceMappingURL=whatsapp-cta-url-button.js.map
;