@botonic/react
Version:
Build Chatbots using React
46 lines • 2.83 kB
JavaScript
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';
export var WhatsappCTAUrlHeaderType;
(function (WhatsappCTAUrlHeaderType) {
WhatsappCTAUrlHeaderType["Document"] = "document";
WhatsappCTAUrlHeaderType["Image"] = "image";
WhatsappCTAUrlHeaderType["Text"] = "text";
WhatsappCTAUrlHeaderType["Video"] = "video";
})(WhatsappCTAUrlHeaderType || (WhatsappCTAUrlHeaderType = {}));
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), { headerType: props.headerType, header: props.headerType === WhatsappCTAUrlHeaderType.Text && props.header
? truncateText(props.header, WHATSAPP_MAX_HEADER_CHARS)
: undefined, headerImage: props.headerType === WhatsappCTAUrlHeaderType.Image
? props.headerImage
: undefined, headerVideo: props.headerType === WhatsappCTAUrlHeaderType.Video
? props.headerVideo
: undefined, headerDocument: props.headerType === WhatsappCTAUrlHeaderType.Document
? props.headerDocument
: 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