UNPKG

@botonic/react

Version:

Build Chatbots using React

33 lines 2.01 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { INPUT } from '@botonic/core'; import { truncateText } from '../util'; import { renderComponent } from '../util/react'; import { generateWebviewUrlWithParams } from '../util/webviews'; import { Message } from './message'; import { WHATSAPP_MAX_BODY_CHARS, WHATSAPP_MAX_BUTTON_CHARS, WHATSAPP_MAX_FOOTER_CHARS, WHATSAPP_MAX_HEADER_CHARS, } from './multichannel/whatsapp/constants'; import { convertToMarkdownMeta } from './multichannel/whatsapp/markdown-meta'; const serialize = _whatsappCTAUrlButtonProps => { // TODO: Implement to have data persistence in localStorage, not needed for this WhatsApp development return {}; }; export const WhatsappCTAUrlButton = (props) => { const renderBrowser = () => { // Return a dummy message for browser const message = `${JSON.stringify(props)}`; return (_jsx(Message, Object.assign({ json: serialize(message) }, props, { type: INPUT.WHATSAPP_CTA_URL_BUTTON }, { children: message }))); }; const renderNode = () => { const validatedProps = Object.assign(Object.assign({}, props), { header: props.header ? truncateText(props.header, WHATSAPP_MAX_HEADER_CHARS) : undefined, body: truncateText(convertToMarkdownMeta(props.body), WHATSAPP_MAX_BODY_CHARS), footer: props.footer ? truncateText(convertToMarkdownMeta(props.footer), WHATSAPP_MAX_FOOTER_CHARS) : undefined, displayText: truncateText(props.displayText, WHATSAPP_MAX_BUTTON_CHARS), url: 'webview' in props ? generateWebviewUrlWithParams(props.webview, props.params) : props.url }); return ( // @ts-ignore Property 'message' does not exist on type 'JSX.IntrinsicElements'. _jsx("message", Object.assign({}, validatedProps, { type: INPUT.WHATSAPP_CTA_URL_BUTTON }))); }; return renderComponent({ renderBrowser, renderNode }); }; //# sourceMappingURL=whatsapp-cta-url-button.js.map