@botonic/react 0.36.0-alpha.0 → 0.36.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/audio.d.ts +8 -7
- package/lib/cjs/components/audio.js +7 -4
- package/lib/cjs/components/audio.js.map +1 -1
- package/lib/cjs/components/{button.d.ts → button/index.d.ts} +4 -5
- package/lib/cjs/components/{button.js → button/index.js} +26 -57
- package/lib/cjs/components/button/index.js.map +1 -0
- package/lib/cjs/components/button/styles.d.ts +2 -0
- package/lib/cjs/components/button/styles.js +40 -0
- package/lib/cjs/components/button/styles.js.map +1 -0
- package/lib/cjs/components/buttons-disabler.d.ts +20 -23
- package/lib/cjs/components/buttons-disabler.js +11 -26
- package/lib/cjs/components/buttons-disabler.js.map +1 -1
- package/lib/cjs/components/carousel.d.ts +8 -9
- package/lib/cjs/components/carousel.js +28 -24
- package/lib/cjs/components/carousel.js.map +1 -1
- package/lib/cjs/components/custom-message.d.ts +16 -12
- package/lib/cjs/components/custom-message.js +3 -9
- package/lib/cjs/components/custom-message.js.map +1 -1
- package/lib/cjs/components/document.d.ts +8 -7
- package/lib/cjs/components/document.js +5 -5
- package/lib/cjs/components/document.js.map +1 -1
- package/lib/cjs/components/element.d.ts +7 -3
- package/lib/cjs/components/element.js +12 -12
- package/lib/cjs/components/element.js.map +1 -1
- package/lib/cjs/components/handoff.d.ts +1 -1
- package/lib/cjs/components/handoff.js +2 -2
- package/lib/cjs/components/handoff.js.map +1 -1
- package/lib/cjs/components/image.d.ts +8 -7
- package/lib/cjs/components/image.js +6 -6
- package/lib/cjs/components/image.js.map +1 -1
- package/lib/cjs/components/index-types.d.ts +31 -132
- package/lib/cjs/components/index.d.ts +8 -2
- package/lib/cjs/components/index.js +16 -3
- package/lib/cjs/components/index.js.map +1 -1
- package/lib/cjs/components/message/index.js +9 -8
- package/lib/cjs/components/message/index.js.map +1 -1
- package/lib/cjs/components/message/message-feedback.d.ts +1 -1
- package/lib/cjs/components/message/message-feedback.js +9 -20
- package/lib/cjs/components/message/message-feedback.js.map +1 -1
- package/lib/cjs/components/message/message-footer.d.ts +1 -1
- package/lib/cjs/components/message/message-footer.js +4 -4
- package/lib/cjs/components/message/message-footer.js.map +1 -1
- package/lib/cjs/components/message/message-image.js +3 -3
- package/lib/cjs/components/message/message-image.js.map +1 -1
- package/lib/cjs/components/message/styles.d.ts +11 -11
- package/lib/cjs/components/message/timestamps.d.ts +1 -1
- package/lib/cjs/components/message/timestamps.js +3 -3
- package/lib/cjs/components/message/timestamps.js.map +1 -1
- package/lib/cjs/components/multichannel/index-types.d.ts +0 -4
- package/lib/cjs/components/multichannel/multichannel-button.d.ts +1 -1
- package/lib/cjs/components/multichannel/multichannel-button.js +5 -5
- package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-carousel.d.ts +1 -1
- package/lib/cjs/components/multichannel/multichannel-carousel.js +59 -62
- package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-context.d.ts +0 -3
- package/lib/cjs/components/multichannel/multichannel-context.js +0 -3
- package/lib/cjs/components/multichannel/multichannel-context.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-reply.d.ts +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.d.ts +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.js +19 -15
- package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-utils.d.ts +9 -15
- package/lib/cjs/components/multichannel/multichannel-utils.js +48 -27
- package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel.js +7 -7
- package/lib/cjs/components/multichannel/multichannel.js.map +1 -1
- package/lib/cjs/components/multichannel/whatsapp/constants.d.ts +11 -0
- package/lib/cjs/components/multichannel/whatsapp/constants.js +13 -0
- package/lib/cjs/components/multichannel/whatsapp/constants.js.map +1 -0
- package/lib/cjs/components/pic.d.ts +8 -5
- package/lib/cjs/components/pic.js +8 -8
- package/lib/cjs/components/pic.js.map +1 -1
- package/lib/cjs/components/raw.d.ts +1 -1
- package/lib/cjs/components/reply.d.ts +7 -6
- package/lib/cjs/components/reply.js +13 -7
- package/lib/cjs/components/reply.js.map +1 -1
- package/lib/cjs/components/subtitle.d.ts +9 -5
- package/lib/cjs/components/subtitle.js +6 -7
- package/lib/cjs/components/subtitle.js.map +1 -1
- package/lib/cjs/components/text.d.ts +1 -1
- package/lib/cjs/components/title.d.ts +9 -5
- package/lib/cjs/components/title.js +6 -7
- package/lib/cjs/components/title.js.map +1 -1
- package/lib/cjs/components/video.d.ts +8 -7
- package/lib/cjs/components/video.js +2 -3
- package/lib/cjs/components/video.js.map +1 -1
- package/lib/cjs/components/webchat-settings.d.ts +18 -2
- package/lib/cjs/components/webchat-settings.js +2 -2
- package/lib/cjs/components/webchat-settings.js.map +1 -1
- package/lib/cjs/components/whatsapp-button-list.js +6 -6
- package/lib/cjs/components/whatsapp-button-list.js.map +1 -1
- package/lib/cjs/components/whatsapp-catalog.d.ts +6 -0
- package/lib/cjs/components/whatsapp-catalog.js +25 -0
- package/lib/cjs/components/whatsapp-catalog.js.map +1 -0
- package/lib/cjs/components/whatsapp-cta-url-button.js +6 -6
- package/lib/cjs/components/whatsapp-cta-url-button.js.map +1 -1
- package/lib/cjs/components/whatsapp-media-carousel.d.ts +46 -0
- package/lib/cjs/components/whatsapp-media-carousel.js +40 -0
- package/lib/cjs/components/whatsapp-media-carousel.js.map +1 -0
- package/lib/cjs/components/whatsapp-product-carousel.d.ts +32 -0
- package/lib/cjs/components/whatsapp-product-carousel.js +34 -0
- package/lib/cjs/components/whatsapp-product-carousel.js.map +1 -0
- package/lib/cjs/components/whatsapp-product-list.d.ts +15 -0
- package/lib/cjs/components/whatsapp-product-list.js +26 -0
- package/lib/cjs/components/whatsapp-product-list.js.map +1 -0
- package/lib/cjs/components/whatsapp-product.d.ts +7 -0
- package/lib/cjs/components/whatsapp-product.js +25 -0
- package/lib/cjs/components/whatsapp-product.js.map +1 -0
- package/lib/cjs/constants.d.ts +0 -18
- package/lib/cjs/constants.js +1 -19
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/contexts.d.ts +3 -8
- package/lib/cjs/contexts.js +11 -77
- package/lib/cjs/contexts.js.map +1 -1
- package/lib/cjs/dev-app.d.ts +7 -0
- package/lib/cjs/dev-app.js +8 -13
- package/lib/cjs/dev-app.js.map +1 -1
- package/lib/cjs/index-types.d.ts +85 -77
- package/lib/cjs/index-types.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/msg-to-botonic.d.ts +1 -1
- package/lib/cjs/msg-to-botonic.js +9 -12
- package/lib/cjs/msg-to-botonic.js.map +1 -1
- package/lib/cjs/react-bot.d.ts +16 -6
- package/lib/cjs/react-bot.js +5 -6
- package/lib/cjs/react-bot.js.map +1 -1
- package/lib/cjs/shared/styles.d.ts +2 -2
- package/lib/cjs/time-zone-to-country-code.d.ts +1 -0
- package/lib/cjs/time-zone-to-country-code.js +108 -0
- package/lib/cjs/time-zone-to-country-code.js.map +1 -0
- package/lib/cjs/util/error-boundary.d.ts +1 -1
- package/lib/cjs/util/functional.d.ts +3 -0
- package/lib/cjs/util/functional.js +30 -0
- package/lib/cjs/util/functional.js.map +1 -0
- package/lib/cjs/util/react.d.ts +1 -1
- package/lib/cjs/util/webchat.d.ts +19 -6
- package/lib/cjs/util/webchat.js +44 -8
- package/lib/cjs/util/webchat.js.map +1 -1
- package/lib/cjs/webchat/chat-area/index.d.ts +1 -1
- package/lib/cjs/webchat/chat-area/index.js +3 -3
- package/lib/cjs/webchat/chat-area/index.js.map +1 -1
- package/lib/cjs/webchat/chat-area/styles.d.ts +1 -1
- package/lib/cjs/webchat/components/common.d.ts +1 -1
- package/lib/cjs/webchat/components/conditional-animation.d.ts +1 -1
- package/lib/cjs/webchat/components/conditional-animation.js +3 -3
- package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
- package/lib/cjs/webchat/components/opened-persistent-menu.d.ts +1 -1
- package/lib/cjs/webchat/components/opened-persistent-menu.js +6 -6
- package/lib/cjs/webchat/components/opened-persistent-menu.js.map +1 -1
- package/lib/{esm/webchat → cjs/webchat/context}/actions.d.ts +4 -1
- package/lib/cjs/webchat/{actions.js → context/actions.js} +4 -0
- package/lib/cjs/webchat/context/actions.js.map +1 -0
- package/lib/cjs/webchat/context/index.d.ts +5 -0
- package/lib/cjs/webchat/context/index.js +83 -0
- package/lib/cjs/webchat/context/index.js.map +1 -0
- package/lib/cjs/webchat/{messages-reducer.d.ts → context/messages-reducer.d.ts} +1 -1
- package/lib/cjs/webchat/{messages-reducer.js → context/messages-reducer.js} +3 -1
- package/lib/cjs/webchat/context/messages-reducer.js.map +1 -0
- package/lib/cjs/webchat/context/types.d.ts +83 -0
- package/lib/cjs/webchat/context/types.js +3 -0
- package/lib/cjs/webchat/context/types.js.map +1 -0
- package/lib/cjs/webchat/context/use-webchat.d.ts +46 -0
- package/lib/cjs/webchat/{hooks → context}/use-webchat.js +53 -47
- package/lib/cjs/webchat/context/use-webchat.js.map +1 -0
- package/lib/cjs/webchat/{webchat-reducer.d.ts → context/webchat-reducer.d.ts} +1 -1
- package/lib/cjs/webchat/{webchat-reducer.js → context/webchat-reducer.js} +4 -0
- package/lib/cjs/webchat/context/webchat-reducer.js.map +1 -0
- package/lib/cjs/webchat/cover-component/index.d.ts +6 -0
- package/lib/cjs/webchat/cover-component/index.js +21 -0
- package/lib/cjs/webchat/cover-component/index.js.map +1 -0
- package/lib/cjs/webchat/header/default-header.d.ts +1 -0
- package/lib/cjs/webchat/header/default-header.js +25 -0
- package/lib/cjs/webchat/header/default-header.js.map +1 -0
- package/lib/cjs/webchat/header/index.d.ts +2 -0
- package/lib/cjs/webchat/header/index.js +23 -0
- package/lib/cjs/webchat/header/index.js.map +1 -0
- package/lib/cjs/webchat/header/styles.d.ts +7 -0
- package/lib/cjs/webchat/header/styles.js +63 -0
- package/lib/cjs/webchat/header/styles.js.map +1 -0
- package/lib/cjs/webchat/hooks/index.d.ts +0 -1
- package/lib/cjs/webchat/hooks/index.js +1 -4
- package/lib/cjs/webchat/hooks/index.js.map +1 -1
- package/lib/cjs/webchat/hooks/use-previous.d.ts +1 -1
- package/lib/cjs/webchat/hooks/use-previous.js.map +1 -1
- package/lib/cjs/webchat/hooks/use-scroll-to-bottom.d.ts +6 -4
- package/lib/cjs/webchat/hooks/use-scroll-to-bottom.js.map +1 -1
- package/lib/cjs/webchat/hooks/use-scrollbar-controller.js +16 -16
- package/lib/cjs/webchat/hooks/use-scrollbar-controller.js.map +1 -1
- package/lib/cjs/webchat/hooks/use-typing.d.ts +1 -1
- package/lib/cjs/webchat/hooks/use-webchat-dimensions.js +4 -4
- package/lib/cjs/webchat/hooks/use-webchat-dimensions.js.map +1 -1
- package/lib/cjs/webchat/hooks/use-webchat-resizer.js +6 -6
- package/lib/cjs/webchat/hooks/use-webchat-resizer.js.map +1 -1
- package/lib/cjs/webchat/index-types.d.ts +2 -56
- package/lib/cjs/webchat/index.d.ts +1 -0
- package/lib/cjs/webchat/index.js +3 -1
- package/lib/cjs/webchat/index.js.map +1 -1
- package/lib/cjs/webchat/input-panel/attachment.d.ts +1 -2
- package/lib/cjs/webchat/input-panel/attachment.js +7 -6
- package/lib/cjs/webchat/input-panel/attachment.js.map +1 -1
- package/lib/cjs/webchat/input-panel/emoji-picker.d.ts +1 -2
- package/lib/cjs/webchat/input-panel/emoji-picker.js +7 -6
- package/lib/cjs/webchat/input-panel/emoji-picker.js.map +1 -1
- package/lib/cjs/webchat/input-panel/index.d.ts +2 -5
- package/lib/cjs/webchat/input-panel/index.js +10 -5
- package/lib/cjs/webchat/input-panel/index.js.map +1 -1
- package/lib/cjs/webchat/input-panel/opened-emoji-picker.d.ts +1 -1
- package/lib/cjs/webchat/input-panel/persistent-menu.d.ts +1 -2
- package/lib/cjs/webchat/input-panel/persistent-menu.js +6 -5
- package/lib/cjs/webchat/input-panel/persistent-menu.js.map +1 -1
- package/lib/cjs/webchat/input-panel/send-button.d.ts +1 -1
- package/lib/cjs/webchat/input-panel/send-button.js +5 -4
- package/lib/cjs/webchat/input-panel/send-button.js.map +1 -1
- package/lib/cjs/webchat/input-panel/styles.d.ts +3 -3
- package/lib/cjs/webchat/input-panel/textarea.d.ts +2 -4
- package/lib/cjs/webchat/input-panel/textarea.js +16 -6
- package/lib/cjs/webchat/input-panel/textarea.js.map +1 -1
- package/lib/cjs/webchat/message-list/index.d.ts +1 -1
- package/lib/cjs/webchat/message-list/index.js +64 -38
- package/lib/cjs/webchat/message-list/index.js.map +1 -1
- package/lib/cjs/webchat/message-list/intro-message.d.ts +1 -1
- package/lib/cjs/webchat/message-list/intro-message.js +3 -3
- package/lib/cjs/webchat/message-list/intro-message.js.map +1 -1
- package/lib/cjs/webchat/message-list/scroll-button.d.ts +1 -0
- package/lib/cjs/webchat/message-list/styles.d.ts +5 -5
- package/lib/cjs/webchat/message-list/styles.js +4 -3
- package/lib/cjs/webchat/message-list/styles.js.map +1 -1
- package/lib/cjs/webchat/message-list/unread-messages-banner.js +2 -2
- package/lib/cjs/webchat/message-list/unread-messages-banner.js.map +1 -1
- package/lib/cjs/webchat/message-list/use-notifications.js +6 -6
- package/lib/cjs/webchat/message-list/use-notifications.js.map +1 -1
- package/lib/cjs/webchat/replies/index.d.ts +1 -0
- package/lib/cjs/webchat/replies/index.js +32 -0
- package/lib/cjs/webchat/replies/index.js.map +1 -0
- package/lib/cjs/webchat/replies/styles.d.ts +8 -0
- package/lib/cjs/webchat/replies/styles.js +25 -0
- package/lib/cjs/webchat/replies/styles.js.map +1 -0
- package/lib/cjs/webchat/session-view.d.ts +1 -1
- package/lib/cjs/webchat/session-view.js +4 -4
- package/lib/cjs/webchat/session-view.js.map +1 -1
- package/lib/cjs/webchat/styles.d.ts +4 -0
- package/lib/cjs/webchat/styles.js +65 -0
- package/lib/cjs/webchat/styles.js.map +1 -0
- package/lib/cjs/webchat/theme/default-theme.d.ts +2 -0
- package/lib/cjs/webchat/theme/default-theme.js +104 -0
- package/lib/cjs/webchat/theme/default-theme.js.map +1 -0
- package/lib/cjs/webchat/theme/types.d.ts +214 -0
- package/lib/cjs/webchat/theme/types.js +3 -0
- package/lib/cjs/webchat/theme/types.js.map +1 -0
- package/lib/cjs/webchat/tracking.d.ts +10 -0
- package/lib/cjs/webchat/tracking.js +39 -1
- package/lib/cjs/webchat/tracking.js.map +1 -1
- package/lib/cjs/webchat/trigger-button/index.d.ts +1 -0
- package/lib/cjs/webchat/trigger-button/index.js +5 -5
- package/lib/cjs/webchat/trigger-button/index.js.map +1 -1
- package/lib/cjs/webchat/trigger-button/styles.d.ts +3 -3
- package/lib/cjs/webchat/typing-indicator/index.d.ts +3 -1
- package/lib/cjs/webchat/typing-indicator/index.js +4 -3
- package/lib/cjs/webchat/typing-indicator/index.js.map +1 -1
- package/lib/cjs/webchat/typing-indicator/styles.d.ts +4 -3
- package/lib/cjs/webchat/typing-indicator/styles.js +6 -3
- package/lib/cjs/webchat/typing-indicator/styles.js.map +1 -1
- package/lib/cjs/webchat/webchat-dev.d.ts +3 -3
- package/lib/cjs/webchat/webchat-dev.js +2 -2
- package/lib/cjs/webchat/webchat-dev.js.map +1 -1
- package/lib/cjs/webchat/webchat.d.ts +4 -2
- package/lib/cjs/webchat/webchat.js +110 -148
- package/lib/cjs/webchat/webchat.js.map +1 -1
- package/lib/cjs/webchat/webview/header.d.ts +1 -0
- package/lib/cjs/webchat/webview/header.js +16 -0
- package/lib/cjs/webchat/webview/header.js.map +1 -0
- package/lib/cjs/webchat/webview/index.d.ts +1 -0
- package/lib/cjs/webchat/webview/index.js +36 -0
- package/lib/cjs/webchat/webview/index.js.map +1 -0
- package/lib/cjs/webchat/webview/styles.d.ts +7 -0
- package/lib/cjs/webchat/webview/styles.js +60 -0
- package/lib/cjs/webchat/webview/styles.js.map +1 -0
- package/lib/cjs/webchat-app.d.ts +95 -86
- package/lib/cjs/webchat-app.js +164 -72
- package/lib/cjs/webchat-app.js.map +1 -1
- package/lib/cjs/webview-app.js +54 -12
- package/lib/cjs/webview-app.js.map +1 -1
- package/lib/esm/components/audio.d.ts +8 -7
- package/lib/esm/components/audio.js +7 -4
- package/lib/esm/components/audio.js.map +1 -1
- package/lib/esm/components/{button.d.ts → button/index.d.ts} +4 -5
- package/lib/esm/components/{button.js → button/index.js} +26 -56
- package/lib/esm/components/button/index.js.map +1 -0
- package/lib/esm/components/button/styles.d.ts +2 -0
- package/lib/esm/components/button/styles.js +36 -0
- package/lib/esm/components/button/styles.js.map +1 -0
- package/lib/esm/components/buttons-disabler.d.ts +20 -23
- package/lib/esm/components/buttons-disabler.js +11 -26
- package/lib/esm/components/buttons-disabler.js.map +1 -1
- package/lib/esm/components/carousel.d.ts +8 -9
- package/lib/esm/components/carousel.js +27 -23
- package/lib/esm/components/carousel.js.map +1 -1
- package/lib/esm/components/custom-message.d.ts +16 -12
- package/lib/esm/components/custom-message.js +3 -9
- package/lib/esm/components/custom-message.js.map +1 -1
- package/lib/esm/components/document.d.ts +8 -7
- package/lib/esm/components/document.js +4 -4
- package/lib/esm/components/document.js.map +1 -1
- package/lib/esm/components/element.d.ts +7 -3
- package/lib/esm/components/element.js +10 -10
- package/lib/esm/components/element.js.map +1 -1
- package/lib/esm/components/handoff.d.ts +1 -1
- package/lib/esm/components/handoff.js +1 -1
- package/lib/esm/components/handoff.js.map +1 -1
- package/lib/esm/components/image.d.ts +8 -7
- package/lib/esm/components/image.js +5 -5
- package/lib/esm/components/image.js.map +1 -1
- package/lib/esm/components/index-types.d.ts +31 -132
- package/lib/esm/components/index.d.ts +8 -2
- package/lib/esm/components/index.js +8 -2
- package/lib/esm/components/index.js.map +1 -1
- package/lib/esm/components/message/index.js +7 -6
- package/lib/esm/components/message/index.js.map +1 -1
- package/lib/esm/components/message/message-feedback.d.ts +1 -1
- package/lib/esm/components/message/message-feedback.js +10 -21
- package/lib/esm/components/message/message-feedback.js.map +1 -1
- package/lib/esm/components/message/message-footer.d.ts +1 -1
- package/lib/esm/components/message/message-footer.js +3 -3
- package/lib/esm/components/message/message-footer.js.map +1 -1
- package/lib/esm/components/message/message-image.js +2 -2
- package/lib/esm/components/message/message-image.js.map +1 -1
- package/lib/esm/components/message/styles.d.ts +11 -11
- package/lib/esm/components/message/timestamps.d.ts +1 -1
- package/lib/esm/components/message/timestamps.js +2 -2
- package/lib/esm/components/message/timestamps.js.map +1 -1
- package/lib/esm/components/multichannel/index-types.d.ts +0 -4
- package/lib/esm/components/multichannel/multichannel-button.d.ts +1 -1
- package/lib/esm/components/multichannel/multichannel-button.js +2 -2
- package/lib/esm/components/multichannel/multichannel-button.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-carousel.d.ts +1 -1
- package/lib/esm/components/multichannel/multichannel-carousel.js +62 -65
- package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-context.d.ts +0 -3
- package/lib/esm/components/multichannel/multichannel-context.js +0 -3
- package/lib/esm/components/multichannel/multichannel-context.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-reply.d.ts +1 -1
- package/lib/esm/components/multichannel/multichannel-text.d.ts +1 -1
- package/lib/esm/components/multichannel/multichannel-text.js +9 -5
- package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-utils.d.ts +9 -15
- package/lib/esm/components/multichannel/multichannel-utils.js +40 -24
- package/lib/esm/components/multichannel/multichannel-utils.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel.js +7 -7
- package/lib/esm/components/multichannel/multichannel.js.map +1 -1
- package/lib/esm/components/multichannel/whatsapp/constants.d.ts +11 -0
- package/lib/esm/components/multichannel/whatsapp/constants.js +10 -0
- package/lib/esm/components/multichannel/whatsapp/constants.js.map +1 -0
- package/lib/esm/components/pic.d.ts +8 -5
- package/lib/esm/components/pic.js +6 -6
- package/lib/esm/components/pic.js.map +1 -1
- package/lib/esm/components/raw.d.ts +1 -1
- package/lib/esm/components/reply.d.ts +7 -6
- package/lib/esm/components/reply.js +13 -7
- package/lib/esm/components/reply.js.map +1 -1
- package/lib/esm/components/subtitle.d.ts +9 -5
- package/lib/esm/components/subtitle.js +4 -5
- package/lib/esm/components/subtitle.js.map +1 -1
- package/lib/esm/components/text.d.ts +1 -1
- package/lib/esm/components/title.d.ts +9 -5
- package/lib/esm/components/title.js +4 -5
- package/lib/esm/components/title.js.map +1 -1
- package/lib/esm/components/video.d.ts +8 -7
- package/lib/esm/components/video.js +2 -3
- package/lib/esm/components/video.js.map +1 -1
- package/lib/esm/components/webchat-settings.d.ts +18 -2
- package/lib/esm/components/webchat-settings.js +1 -1
- package/lib/esm/components/webchat-settings.js.map +1 -1
- package/lib/esm/components/whatsapp-button-list.js +6 -6
- package/lib/esm/components/whatsapp-button-list.js.map +1 -1
- package/lib/esm/components/whatsapp-catalog.d.ts +6 -0
- package/lib/esm/components/whatsapp-catalog.js +21 -0
- package/lib/esm/components/whatsapp-catalog.js.map +1 -0
- package/lib/esm/components/whatsapp-cta-url-button.js +3 -3
- package/lib/esm/components/whatsapp-cta-url-button.js.map +1 -1
- package/lib/esm/components/whatsapp-media-carousel.d.ts +46 -0
- package/lib/esm/components/whatsapp-media-carousel.js +36 -0
- package/lib/esm/components/whatsapp-media-carousel.js.map +1 -0
- package/lib/esm/components/whatsapp-product-carousel.d.ts +32 -0
- package/lib/esm/components/whatsapp-product-carousel.js +30 -0
- package/lib/esm/components/whatsapp-product-carousel.js.map +1 -0
- package/lib/esm/components/whatsapp-product-list.d.ts +15 -0
- package/lib/esm/components/whatsapp-product-list.js +22 -0
- package/lib/esm/components/whatsapp-product-list.js.map +1 -0
- package/lib/esm/components/whatsapp-product.d.ts +7 -0
- package/lib/esm/components/whatsapp-product.js +21 -0
- package/lib/esm/components/whatsapp-product.js.map +1 -0
- package/lib/esm/constants.d.ts +0 -18
- package/lib/esm/constants.js +0 -18
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/contexts.d.ts +3 -8
- package/lib/esm/contexts.js +10 -76
- package/lib/esm/contexts.js.map +1 -1
- package/lib/esm/dev-app.d.ts +7 -0
- package/lib/esm/dev-app.js +8 -13
- package/lib/esm/dev-app.js.map +1 -1
- package/lib/esm/index-types.d.ts +85 -77
- package/lib/esm/index-types.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/msg-to-botonic.d.ts +1 -1
- package/lib/esm/msg-to-botonic.js +8 -11
- package/lib/esm/msg-to-botonic.js.map +1 -1
- package/lib/esm/react-bot.d.ts +16 -6
- package/lib/esm/react-bot.js +5 -6
- package/lib/esm/react-bot.js.map +1 -1
- package/lib/esm/shared/styles.d.ts +2 -2
- package/lib/esm/time-zone-to-country-code.d.ts +1 -0
- package/lib/esm/time-zone-to-country-code.js +105 -0
- package/lib/esm/time-zone-to-country-code.js.map +1 -0
- package/lib/esm/util/error-boundary.d.ts +1 -1
- package/lib/esm/util/functional.d.ts +3 -0
- package/lib/esm/util/functional.js +26 -0
- package/lib/esm/util/functional.js.map +1 -0
- package/lib/esm/util/react.d.ts +1 -1
- package/lib/esm/util/webchat.d.ts +19 -6
- package/lib/esm/util/webchat.js +42 -7
- package/lib/esm/util/webchat.js.map +1 -1
- package/lib/esm/webchat/chat-area/index.d.ts +1 -1
- package/lib/esm/webchat/chat-area/index.js +2 -2
- package/lib/esm/webchat/chat-area/index.js.map +1 -1
- package/lib/esm/webchat/chat-area/styles.d.ts +1 -1
- package/lib/esm/webchat/components/common.d.ts +1 -1
- package/lib/esm/webchat/components/conditional-animation.d.ts +1 -1
- package/lib/esm/webchat/components/conditional-animation.js +2 -2
- package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
- package/lib/esm/webchat/components/opened-persistent-menu.d.ts +1 -1
- package/lib/esm/webchat/components/opened-persistent-menu.js +3 -3
- package/lib/esm/webchat/components/opened-persistent-menu.js.map +1 -1
- package/lib/{cjs/webchat → esm/webchat/context}/actions.d.ts +4 -1
- package/lib/esm/webchat/{actions.js → context/actions.js} +4 -0
- package/lib/esm/webchat/context/actions.js.map +1 -0
- package/lib/esm/webchat/context/index.d.ts +5 -0
- package/lib/esm/webchat/context/index.js +79 -0
- package/lib/esm/webchat/context/index.js.map +1 -0
- package/lib/esm/webchat/{messages-reducer.d.ts → context/messages-reducer.d.ts} +1 -1
- package/lib/esm/webchat/{messages-reducer.js → context/messages-reducer.js} +3 -1
- package/lib/esm/webchat/context/messages-reducer.js.map +1 -0
- package/lib/esm/webchat/context/types.d.ts +83 -0
- package/lib/esm/webchat/context/types.js +2 -0
- package/lib/esm/webchat/context/types.js.map +1 -0
- package/lib/esm/webchat/context/use-webchat.d.ts +46 -0
- package/lib/esm/webchat/{hooks → context}/use-webchat.js +51 -45
- package/lib/esm/webchat/context/use-webchat.js.map +1 -0
- package/lib/esm/webchat/{webchat-reducer.d.ts → context/webchat-reducer.d.ts} +1 -1
- package/lib/esm/webchat/{webchat-reducer.js → context/webchat-reducer.js} +4 -0
- package/lib/esm/webchat/context/webchat-reducer.js.map +1 -0
- package/lib/esm/webchat/cover-component/index.d.ts +6 -0
- package/lib/esm/webchat/cover-component/index.js +17 -0
- package/lib/esm/webchat/cover-component/index.js.map +1 -0
- package/lib/esm/webchat/header/default-header.d.ts +1 -0
- package/lib/esm/webchat/header/default-header.js +21 -0
- package/lib/esm/webchat/header/default-header.js.map +1 -0
- package/lib/esm/webchat/header/index.d.ts +2 -0
- package/lib/esm/webchat/header/index.js +20 -0
- package/lib/esm/webchat/header/index.js.map +1 -0
- package/lib/esm/webchat/header/styles.d.ts +7 -0
- package/lib/esm/webchat/header/styles.js +59 -0
- package/lib/esm/webchat/header/styles.js.map +1 -0
- package/lib/esm/webchat/hooks/index.d.ts +0 -1
- package/lib/esm/webchat/hooks/index.js +0 -1
- package/lib/esm/webchat/hooks/index.js.map +1 -1
- package/lib/esm/webchat/hooks/use-previous.d.ts +1 -1
- package/lib/esm/webchat/hooks/use-previous.js.map +1 -1
- package/lib/esm/webchat/hooks/use-scroll-to-bottom.d.ts +6 -4
- package/lib/esm/webchat/hooks/use-scroll-to-bottom.js.map +1 -1
- package/lib/esm/webchat/hooks/use-scrollbar-controller.js +16 -16
- package/lib/esm/webchat/hooks/use-scrollbar-controller.js.map +1 -1
- package/lib/esm/webchat/hooks/use-typing.d.ts +1 -1
- package/lib/esm/webchat/hooks/use-webchat-dimensions.js +4 -4
- package/lib/esm/webchat/hooks/use-webchat-dimensions.js.map +1 -1
- package/lib/esm/webchat/hooks/use-webchat-resizer.js +6 -6
- package/lib/esm/webchat/hooks/use-webchat-resizer.js.map +1 -1
- package/lib/esm/webchat/index-types.d.ts +2 -56
- package/lib/esm/webchat/index.d.ts +1 -0
- package/lib/esm/webchat/index.js +1 -0
- package/lib/esm/webchat/index.js.map +1 -1
- package/lib/esm/webchat/input-panel/attachment.d.ts +1 -2
- package/lib/esm/webchat/input-panel/attachment.js +8 -7
- package/lib/esm/webchat/input-panel/attachment.js.map +1 -1
- package/lib/esm/webchat/input-panel/emoji-picker.d.ts +1 -2
- package/lib/esm/webchat/input-panel/emoji-picker.js +8 -7
- package/lib/esm/webchat/input-panel/emoji-picker.js.map +1 -1
- package/lib/esm/webchat/input-panel/index.d.ts +2 -5
- package/lib/esm/webchat/input-panel/index.js +9 -4
- package/lib/esm/webchat/input-panel/index.js.map +1 -1
- package/lib/esm/webchat/input-panel/opened-emoji-picker.d.ts +1 -1
- package/lib/esm/webchat/input-panel/persistent-menu.d.ts +1 -2
- package/lib/esm/webchat/input-panel/persistent-menu.js +7 -6
- package/lib/esm/webchat/input-panel/persistent-menu.js.map +1 -1
- package/lib/esm/webchat/input-panel/send-button.d.ts +1 -1
- package/lib/esm/webchat/input-panel/send-button.js +6 -5
- package/lib/esm/webchat/input-panel/send-button.js.map +1 -1
- package/lib/esm/webchat/input-panel/styles.d.ts +3 -3
- package/lib/esm/webchat/input-panel/textarea.d.ts +2 -4
- package/lib/esm/webchat/input-panel/textarea.js +16 -6
- package/lib/esm/webchat/input-panel/textarea.js.map +1 -1
- package/lib/esm/webchat/message-list/index.d.ts +1 -1
- package/lib/esm/webchat/message-list/index.js +62 -37
- package/lib/esm/webchat/message-list/index.js.map +1 -1
- package/lib/esm/webchat/message-list/intro-message.d.ts +1 -1
- package/lib/esm/webchat/message-list/intro-message.js +2 -2
- package/lib/esm/webchat/message-list/intro-message.js.map +1 -1
- package/lib/esm/webchat/message-list/scroll-button.d.ts +1 -0
- package/lib/esm/webchat/message-list/styles.d.ts +5 -5
- package/lib/esm/webchat/message-list/styles.js +4 -3
- package/lib/esm/webchat/message-list/styles.js.map +1 -1
- package/lib/esm/webchat/message-list/unread-messages-banner.js +1 -1
- package/lib/esm/webchat/message-list/unread-messages-banner.js.map +1 -1
- package/lib/esm/webchat/message-list/use-notifications.js +5 -5
- package/lib/esm/webchat/message-list/use-notifications.js.map +1 -1
- package/lib/esm/webchat/replies/index.d.ts +1 -0
- package/lib/esm/webchat/replies/index.js +28 -0
- package/lib/esm/webchat/replies/index.js.map +1 -0
- package/lib/esm/webchat/replies/styles.d.ts +8 -0
- package/lib/esm/webchat/replies/styles.js +21 -0
- package/lib/esm/webchat/replies/styles.js.map +1 -0
- package/lib/esm/webchat/session-view.d.ts +1 -1
- package/lib/esm/webchat/session-view.js +2 -2
- package/lib/esm/webchat/session-view.js.map +1 -1
- package/lib/esm/webchat/styles.d.ts +4 -0
- package/lib/esm/webchat/styles.js +61 -0
- package/lib/esm/webchat/styles.js.map +1 -0
- package/lib/esm/webchat/theme/default-theme.d.ts +2 -0
- package/lib/esm/webchat/theme/default-theme.js +101 -0
- package/lib/esm/webchat/theme/default-theme.js.map +1 -0
- package/lib/esm/webchat/theme/types.d.ts +214 -0
- package/lib/esm/webchat/theme/types.js +2 -0
- package/lib/esm/webchat/theme/types.js.map +1 -0
- package/lib/esm/webchat/tracking.d.ts +10 -0
- package/lib/esm/webchat/tracking.js +37 -0
- package/lib/esm/webchat/tracking.js.map +1 -1
- package/lib/esm/webchat/trigger-button/index.d.ts +1 -0
- package/lib/esm/webchat/trigger-button/index.js +4 -4
- package/lib/esm/webchat/trigger-button/index.js.map +1 -1
- package/lib/esm/webchat/trigger-button/styles.d.ts +3 -3
- package/lib/esm/webchat/typing-indicator/index.d.ts +3 -1
- package/lib/esm/webchat/typing-indicator/index.js +5 -2
- package/lib/esm/webchat/typing-indicator/index.js.map +1 -1
- package/lib/esm/webchat/typing-indicator/styles.d.ts +4 -3
- package/lib/esm/webchat/typing-indicator/styles.js +5 -2
- package/lib/esm/webchat/typing-indicator/styles.js.map +1 -1
- package/lib/esm/webchat/webchat-dev.d.ts +3 -3
- package/lib/esm/webchat/webchat-dev.js +1 -1
- package/lib/esm/webchat/webchat-dev.js.map +1 -1
- package/lib/esm/webchat/webchat.d.ts +4 -2
- package/lib/esm/webchat/webchat.js +110 -148
- package/lib/esm/webchat/webchat.js.map +1 -1
- package/lib/esm/webchat/webview/header.d.ts +1 -0
- package/lib/esm/webchat/webview/header.js +12 -0
- package/lib/esm/webchat/webview/header.js.map +1 -0
- package/lib/esm/webchat/webview/index.d.ts +1 -0
- package/lib/esm/webchat/webview/index.js +32 -0
- package/lib/esm/webchat/webview/index.js.map +1 -0
- package/lib/esm/webchat/webview/styles.d.ts +7 -0
- package/lib/esm/webchat/webview/styles.js +56 -0
- package/lib/esm/webchat/webview/styles.js.map +1 -0
- package/lib/esm/webchat-app.d.ts +95 -86
- package/lib/esm/webchat-app.js +165 -73
- package/lib/esm/webchat-app.js.map +1 -1
- package/lib/esm/webview-app.js +55 -13
- package/lib/esm/webview-app.js.map +1 -1
- package/package.json +23 -18
- package/src/components/{audio.jsx → audio.tsx} +10 -4
- package/src/components/{button.tsx → button/index.tsx} +26 -104
- package/src/components/button/styles.ts +38 -0
- package/src/components/{buttons-disabler.js → buttons-disabler.ts} +35 -39
- package/src/components/{carousel.jsx → carousel.tsx} +60 -36
- package/src/components/{custom-message.jsx → custom-message.tsx} +19 -7
- package/src/components/{document.jsx → document.tsx} +5 -3
- package/src/components/{element.jsx → element.tsx} +12 -14
- package/src/components/handoff.jsx +1 -1
- package/src/components/{image.jsx → image.tsx} +13 -6
- package/src/components/index-types.ts +24 -119
- package/src/components/index.ts +23 -2
- package/src/components/message/index.jsx +7 -10
- package/src/components/message/message-feedback.tsx +10 -27
- package/src/components/message/message-footer.tsx +3 -3
- package/src/components/message/message-image.tsx +2 -5
- package/src/components/message/timestamps.tsx +2 -3
- package/src/components/multichannel/index-types.ts +0 -4
- package/src/components/multichannel/multichannel-button.jsx +2 -2
- package/src/components/multichannel/multichannel-carousel.jsx +96 -94
- package/src/components/multichannel/multichannel-context.jsx +0 -3
- package/src/components/multichannel/multichannel-text.jsx +12 -6
- package/src/components/multichannel/multichannel-utils.js +45 -27
- package/src/components/multichannel/multichannel.jsx +12 -7
- package/src/components/multichannel/whatsapp/constants.ts +10 -0
- package/src/components/{pic.jsx → pic.tsx} +12 -5
- package/src/components/{reply.jsx → reply.tsx} +12 -12
- package/src/components/{subtitle.jsx → subtitle.tsx} +10 -10
- package/src/components/{title.jsx → title.tsx} +8 -6
- package/src/components/{video.jsx → video.tsx} +3 -2
- package/src/components/webchat-settings.tsx +22 -2
- package/src/components/whatsapp-button-list.tsx +6 -6
- package/src/components/whatsapp-catalog.tsx +42 -0
- package/src/components/whatsapp-cta-url-button.tsx +6 -3
- package/src/components/whatsapp-media-carousel.tsx +104 -0
- package/src/components/whatsapp-product-carousel.tsx +83 -0
- package/src/components/whatsapp-product-list.tsx +56 -0
- package/src/components/whatsapp-product.tsx +44 -0
- package/src/constants.js +0 -19
- package/src/contexts.tsx +14 -87
- package/src/dev-app.jsx +6 -30
- package/src/index-types.ts +100 -84
- package/src/index.ts +1 -5
- package/src/msg-to-botonic.jsx +8 -12
- package/src/react-bot.tsx +51 -0
- package/src/time-zone-to-country-code.ts +104 -0
- package/src/util/functional.ts +31 -0
- package/src/util/webchat.ts +102 -0
- package/src/webchat/chat-area/index.tsx +2 -4
- package/src/webchat/components/conditional-animation.jsx +3 -3
- package/src/webchat/components/opened-persistent-menu.jsx +3 -4
- package/src/webchat/{actions.ts → context/actions.ts} +4 -0
- package/src/webchat/context/index.tsx +82 -0
- package/src/webchat/{messages-reducer.ts → context/messages-reducer.ts} +4 -2
- package/src/webchat/context/types.ts +91 -0
- package/src/webchat/{hooks → context}/use-webchat.ts +104 -53
- package/src/webchat/{webchat-reducer.ts → context/webchat-reducer.ts} +5 -1
- package/src/webchat/cover-component/index.tsx +31 -0
- package/src/webchat/global.d.ts +3 -0
- package/src/webchat/header/default-header.tsx +64 -0
- package/src/webchat/header/index.tsx +37 -0
- package/src/webchat/header/styles.ts +66 -0
- package/src/webchat/hooks/index.ts +0 -1
- package/src/webchat/hooks/use-previous.ts +1 -1
- package/src/webchat/hooks/use-scroll-to-bottom.ts +8 -2
- package/src/webchat/hooks/use-scrollbar-controller.ts +22 -17
- package/src/webchat/hooks/use-typing.ts +1 -1
- package/src/webchat/hooks/use-webchat-dimensions.ts +4 -4
- package/src/webchat/hooks/use-webchat-resizer.ts +6 -6
- package/src/webchat/index-types.ts +2 -63
- package/src/webchat/index.ts +1 -0
- package/src/webchat/input-panel/attachment.tsx +6 -17
- package/src/webchat/input-panel/emoji-picker.tsx +6 -16
- package/src/webchat/input-panel/index.tsx +9 -16
- package/src/webchat/input-panel/persistent-menu.tsx +6 -16
- package/src/webchat/input-panel/send-button.tsx +4 -10
- package/src/webchat/input-panel/textarea.tsx +22 -15
- package/src/webchat/message-list/index.tsx +78 -49
- package/src/webchat/message-list/intro-message.tsx +2 -3
- package/src/webchat/message-list/styles.ts +4 -3
- package/src/webchat/message-list/unread-messages-banner.tsx +1 -1
- package/src/webchat/message-list/use-notifications.ts +5 -9
- package/src/webchat/replies/index.tsx +47 -0
- package/src/webchat/replies/styles.ts +28 -0
- package/src/webchat/session-view.jsx +2 -2
- package/src/webchat/styles.ts +65 -0
- package/src/webchat/theme/default-theme.ts +102 -0
- package/src/webchat/theme/theme.d.ts +8 -0
- package/src/webchat/theme/types.ts +206 -0
- package/src/webchat/tracking.ts +59 -0
- package/src/webchat/trigger-button/index.tsx +4 -6
- package/src/webchat/typing-indicator/index.tsx +20 -12
- package/src/webchat/typing-indicator/styles.ts +7 -3
- package/src/webchat/webchat-dev.jsx +1 -1
- package/src/webchat/{webchat.jsx → webchat.tsx} +191 -243
- package/src/webchat/webview/header.tsx +22 -0
- package/src/webchat/webview/index.tsx +66 -0
- package/src/webchat/webview/styles.ts +62 -0
- package/src/webchat-app.tsx +575 -0
- package/src/webview-app.tsx +60 -16
- package/lib/cjs/components/button.js.map +0 -1
- package/lib/cjs/webchat/actions.js.map +0 -1
- package/lib/cjs/webchat/header.d.ts +0 -3
- package/lib/cjs/webchat/header.js +0 -86
- package/lib/cjs/webchat/header.js.map +0 -1
- package/lib/cjs/webchat/hooks/use-webchat.d.ts +0 -46
- package/lib/cjs/webchat/hooks/use-webchat.js.map +0 -1
- package/lib/cjs/webchat/messages-reducer.js.map +0 -1
- package/lib/cjs/webchat/replies.d.ts +0 -1
- package/lib/cjs/webchat/replies.js +0 -47
- package/lib/cjs/webchat/replies.js.map +0 -1
- package/lib/cjs/webchat/webchat-reducer.js.map +0 -1
- package/lib/cjs/webchat/webview.d.ts +0 -2
- package/lib/cjs/webchat/webview.js +0 -75
- package/lib/cjs/webchat/webview.js.map +0 -1
- package/lib/esm/components/button.js.map +0 -1
- package/lib/esm/webchat/actions.js.map +0 -1
- package/lib/esm/webchat/header.d.ts +0 -3
- package/lib/esm/webchat/header.js +0 -81
- package/lib/esm/webchat/header.js.map +0 -1
- package/lib/esm/webchat/hooks/use-webchat.d.ts +0 -46
- package/lib/esm/webchat/hooks/use-webchat.js.map +0 -1
- package/lib/esm/webchat/messages-reducer.js.map +0 -1
- package/lib/esm/webchat/replies.d.ts +0 -1
- package/lib/esm/webchat/replies.js +0 -42
- package/lib/esm/webchat/replies.js.map +0 -1
- package/lib/esm/webchat/webchat-reducer.js.map +0 -1
- package/lib/esm/webchat/webview.d.ts +0 -2
- package/lib/esm/webchat/webview.js +0 -70
- package/lib/esm/webchat/webview.js.map +0 -1
- package/src/react-bot.jsx +0 -38
- package/src/util/webchat.js +0 -57
- package/src/webchat/header.jsx +0 -149
- package/src/webchat/replies.jsx +0 -64
- package/src/webchat/webview.jsx +0 -105
- package/src/webchat-app.jsx +0 -389
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
import { HubtypeService, INPUT, ServerConfig } from '@botonic/core'
|
|
2
|
+
import merge from 'lodash.merge'
|
|
3
|
+
import React, { createRef } from 'react'
|
|
4
|
+
import { createRoot, Root } from 'react-dom/client'
|
|
5
|
+
|
|
6
|
+
import { BlockInputOption, WebchatSettingsProps } from './components'
|
|
7
|
+
import { WEBCHAT } from './constants'
|
|
8
|
+
import { CloseWebviewOptions } from './contexts'
|
|
9
|
+
import {
|
|
10
|
+
ActionRequest,
|
|
11
|
+
Event,
|
|
12
|
+
EventArgs,
|
|
13
|
+
OnStateChangeArgs,
|
|
14
|
+
OnUserInputArgs,
|
|
15
|
+
SENDERS,
|
|
16
|
+
Typing,
|
|
17
|
+
WebchatArgs,
|
|
18
|
+
WebchatMessage,
|
|
19
|
+
WebchatRef,
|
|
20
|
+
} from './index-types'
|
|
21
|
+
import { msgToBotonic } from './msg-to-botonic'
|
|
22
|
+
import { isShadowDOMSupported, onDOMLoaded } from './util/dom'
|
|
23
|
+
import { defaultTheme } from './webchat/theme/default-theme'
|
|
24
|
+
import {
|
|
25
|
+
CoverComponentOptions,
|
|
26
|
+
PersistentMenuOptionsTheme,
|
|
27
|
+
WebchatTheme,
|
|
28
|
+
} from './webchat/theme/types'
|
|
29
|
+
import { Webchat } from './webchat/webchat'
|
|
30
|
+
|
|
31
|
+
export class WebchatApp {
|
|
32
|
+
public theme?: Partial<WebchatTheme>
|
|
33
|
+
public persistentMenu?: PersistentMenuOptionsTheme
|
|
34
|
+
public coverComponent?: CoverComponentOptions
|
|
35
|
+
public blockInputs?: BlockInputOption[]
|
|
36
|
+
public enableEmojiPicker?: boolean
|
|
37
|
+
public enableAttachments?: boolean
|
|
38
|
+
public enableUserInput?: boolean
|
|
39
|
+
public enableAnimations?: boolean
|
|
40
|
+
public hostId?: string
|
|
41
|
+
public shadowDOM?: boolean | (() => boolean)
|
|
42
|
+
public defaultDelay?: number
|
|
43
|
+
public defaultTyping?: number
|
|
44
|
+
public storage?: Storage | null
|
|
45
|
+
public storageKey: string
|
|
46
|
+
public onInit?: (app: WebchatApp, args: any) => void
|
|
47
|
+
public onOpen?: (app: WebchatApp, args: any) => void
|
|
48
|
+
public onClose?: (app: WebchatApp, args: any) => void
|
|
49
|
+
public onMessage?: (app: WebchatApp, message: WebchatMessage) => void
|
|
50
|
+
public onTrackEvent?: (
|
|
51
|
+
request: ActionRequest,
|
|
52
|
+
eventName: string,
|
|
53
|
+
args?: EventArgs
|
|
54
|
+
) => Promise<void>
|
|
55
|
+
public onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
|
|
56
|
+
public appId?: string
|
|
57
|
+
public visibility?: boolean | (() => boolean) | 'dynamic'
|
|
58
|
+
public server?: ServerConfig
|
|
59
|
+
public webchatRef: React.RefObject<WebchatRef | null>
|
|
60
|
+
|
|
61
|
+
private reactRoot: Root | null = null
|
|
62
|
+
private host: (HTMLElement | null) | ShadowRoot = null
|
|
63
|
+
private hubtypeService: HubtypeService
|
|
64
|
+
|
|
65
|
+
constructor({
|
|
66
|
+
theme,
|
|
67
|
+
persistentMenu,
|
|
68
|
+
coverComponent,
|
|
69
|
+
blockInputs,
|
|
70
|
+
enableEmojiPicker,
|
|
71
|
+
enableAttachments,
|
|
72
|
+
enableUserInput,
|
|
73
|
+
enableAnimations,
|
|
74
|
+
hostId = WEBCHAT.DEFAULTS.HOST_ID,
|
|
75
|
+
shadowDOM = false,
|
|
76
|
+
defaultDelay,
|
|
77
|
+
defaultTyping,
|
|
78
|
+
storage,
|
|
79
|
+
storageKey,
|
|
80
|
+
onInit,
|
|
81
|
+
onOpen,
|
|
82
|
+
onClose,
|
|
83
|
+
onMessage,
|
|
84
|
+
onTrackEvent,
|
|
85
|
+
onConnectionChange,
|
|
86
|
+
appId,
|
|
87
|
+
visibility,
|
|
88
|
+
server,
|
|
89
|
+
}: WebchatArgs) {
|
|
90
|
+
this.theme = theme
|
|
91
|
+
this.persistentMenu = persistentMenu
|
|
92
|
+
this.coverComponent = coverComponent
|
|
93
|
+
this.blockInputs = blockInputs
|
|
94
|
+
this.enableEmojiPicker = enableEmojiPicker
|
|
95
|
+
this.enableAttachments = enableAttachments
|
|
96
|
+
this.enableUserInput = enableUserInput
|
|
97
|
+
this.enableAnimations = enableAnimations
|
|
98
|
+
|
|
99
|
+
this.shadowDOM = Boolean(
|
|
100
|
+
typeof shadowDOM === 'function' ? shadowDOM() : shadowDOM
|
|
101
|
+
)
|
|
102
|
+
if (this.shadowDOM && !isShadowDOMSupported()) {
|
|
103
|
+
console.warn('[botonic] ShadowDOM not supported on this browser')
|
|
104
|
+
this.shadowDOM = false
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.hostId = hostId || WEBCHAT.DEFAULTS.HOST_ID
|
|
108
|
+
this.defaultDelay = defaultDelay
|
|
109
|
+
this.defaultTyping = defaultTyping
|
|
110
|
+
this.storage = storage === undefined ? localStorage : storage
|
|
111
|
+
this.storageKey = storageKey || WEBCHAT.DEFAULTS.STORAGE_KEY
|
|
112
|
+
this.onInit = onInit
|
|
113
|
+
this.onOpen = onOpen
|
|
114
|
+
this.onClose = onClose
|
|
115
|
+
this.onMessage = onMessage
|
|
116
|
+
this.onTrackEvent = onTrackEvent
|
|
117
|
+
this.onConnectionChange = onConnectionChange
|
|
118
|
+
this.visibility = visibility
|
|
119
|
+
this.server = server
|
|
120
|
+
this.webchatRef = createRef<WebchatRef>()
|
|
121
|
+
this.appId = appId
|
|
122
|
+
|
|
123
|
+
this.host = null
|
|
124
|
+
this.reactRoot = null
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
createRootElement(host: HTMLElement | null) {
|
|
128
|
+
// Create root element <div id='root'> if not exists
|
|
129
|
+
// Create shadowDOM to root element if needed
|
|
130
|
+
if (host) {
|
|
131
|
+
if (host.id && this.hostId) {
|
|
132
|
+
if (host.id != this.hostId) {
|
|
133
|
+
console.warn(
|
|
134
|
+
`[botonic] Host ID "${host.id}" don't match 'hostId' option: ${this.hostId}. Using value: ${host.id}.`
|
|
135
|
+
)
|
|
136
|
+
this.hostId = host.id
|
|
137
|
+
}
|
|
138
|
+
} else if (host.id) {
|
|
139
|
+
this.hostId = host.id
|
|
140
|
+
} else if (this.hostId) {
|
|
141
|
+
host.id = this.hostId
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
host = this.hostId ? document.getElementById(this.hostId) : null
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!host) {
|
|
148
|
+
host = document.createElement('div')
|
|
149
|
+
host.id = this.hostId!
|
|
150
|
+
if (document.body.firstChild) {
|
|
151
|
+
document.body.insertBefore(host, document.body.firstChild)
|
|
152
|
+
} else {
|
|
153
|
+
document.body.appendChild(host)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
this.host = this.shadowDOM ? host.attachShadow({ mode: 'open' }) : host
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
getReactMountNode(
|
|
160
|
+
node?: (HTMLElement | null) | ShadowRoot
|
|
161
|
+
): Element | DocumentFragment {
|
|
162
|
+
if (!node) {
|
|
163
|
+
node = this.host
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (node === null) {
|
|
167
|
+
throw new Error('Host element not found')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// TODO: Review logic of ShadowRoot
|
|
171
|
+
if ('shadowRoot' in node && node.shadowRoot !== null) {
|
|
172
|
+
return node.shadowRoot
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return node
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
onInitWebchat(...args: [any]) {
|
|
179
|
+
this.onInit && this.onInit(this, ...args)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
onOpenWebchat(...args: [any]) {
|
|
183
|
+
this.onOpen && this.onOpen(this, ...args)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
onCloseWebchat(...args: [any]) {
|
|
187
|
+
this.onClose && this.onClose(this, ...args)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async onUserInput({ user, input }: OnUserInputArgs): Promise<void> {
|
|
191
|
+
if (!user) return
|
|
192
|
+
|
|
193
|
+
this.onMessage &&
|
|
194
|
+
this.onMessage(this, {
|
|
195
|
+
...input,
|
|
196
|
+
sentBy: SENDERS.user,
|
|
197
|
+
isUnread: false,
|
|
198
|
+
} as unknown as WebchatMessage)
|
|
199
|
+
this.hubtypeService.postMessage(user, {
|
|
200
|
+
...input,
|
|
201
|
+
// TODO: Review if this is correct add sent_by or this is added in backend
|
|
202
|
+
// sent_by: 'message_sent_by_user',
|
|
203
|
+
})
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async onTrackEventWebchat(
|
|
208
|
+
request: ActionRequest,
|
|
209
|
+
eventName: string,
|
|
210
|
+
args?: EventArgs
|
|
211
|
+
): Promise<void> {
|
|
212
|
+
if (this.onTrackEvent) {
|
|
213
|
+
await this.onTrackEvent(request, eventName, args)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async onConnectionRegained() {
|
|
218
|
+
return this.hubtypeService.onConnectionRegained()
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
onStateChange(args: OnStateChangeArgs) {
|
|
222
|
+
const { user, messagesJSON } = args
|
|
223
|
+
const lastMessage = messagesJSON[messagesJSON.length - 1]
|
|
224
|
+
const lastMessageId = lastMessage && lastMessage.id
|
|
225
|
+
const lastMessageUpdateDate = this.getLastMessageUpdate()
|
|
226
|
+
|
|
227
|
+
if (this.hubtypeService) {
|
|
228
|
+
this.hubtypeService.lastMessageId = lastMessageId
|
|
229
|
+
this.hubtypeService.lastMessageUpdateDate = lastMessageUpdateDate
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!this.hubtypeService) {
|
|
233
|
+
this.hubtypeService = new HubtypeService({
|
|
234
|
+
appId: this.appId!,
|
|
235
|
+
user,
|
|
236
|
+
lastMessageId,
|
|
237
|
+
lastMessageUpdateDate,
|
|
238
|
+
onEvent: (event: any) => this.onServiceEvent(event),
|
|
239
|
+
unsentInputs: () =>
|
|
240
|
+
this.webchatRef.current
|
|
241
|
+
?.getMessages()
|
|
242
|
+
.filter(msg => msg.ack === 0 && msg.unsentInput) || [],
|
|
243
|
+
server: this.server,
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
onServiceEvent(event: Event) {
|
|
249
|
+
if (event.action === 'connectionChange') {
|
|
250
|
+
this.onConnectionChange && this.onConnectionChange(this, event.online)
|
|
251
|
+
this.webchatRef.current?.setOnline(event.online)
|
|
252
|
+
} else if (event.action === 'update_message_info' && event.message?.id) {
|
|
253
|
+
this.updateMessageInfo(event.message.id, event.message)
|
|
254
|
+
} else if (event.message?.type === 'update_webchat_settings') {
|
|
255
|
+
this.updateWebchatSettings(event.message.data)
|
|
256
|
+
} else if (event.message?.type === 'sender_action') {
|
|
257
|
+
this.setTyping(event.message.data === Typing.On)
|
|
258
|
+
} else {
|
|
259
|
+
// TODO: onMessage function should receive a WebchatMessage
|
|
260
|
+
// and message.type is typed as enum of INPUT
|
|
261
|
+
// INPUT not contain 'update_webchat_settings' or 'sender_action'
|
|
262
|
+
// so we need to cast it to unknown to avoid type error
|
|
263
|
+
this.onMessage &&
|
|
264
|
+
this.onMessage(this, {
|
|
265
|
+
sentBy: SENDERS.bot,
|
|
266
|
+
...event.message,
|
|
267
|
+
} as unknown as WebchatMessage)
|
|
268
|
+
this.addBotMessage(event.message)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
updateUser(user: any) {
|
|
273
|
+
this.webchatRef.current?.updateUser(user)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
setSystemLocale(locale: string) {
|
|
277
|
+
this.webchatRef.current?.updateUser({ system_locale: locale })
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
setUserLocale(locale: string) {
|
|
281
|
+
this.webchatRef.current?.updateUser({ locale })
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
setUserCountry(country: string) {
|
|
285
|
+
this.webchatRef.current?.updateUser({ country })
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
addBotMessage(message: any) {
|
|
289
|
+
message.ack = 0
|
|
290
|
+
message.isUnread = true
|
|
291
|
+
message.sentBy = message.sent_by?.split('message_sent_by_')[1]
|
|
292
|
+
delete message.sent_by
|
|
293
|
+
const response = msgToBotonic(message, this.theme?.message?.customTypes)
|
|
294
|
+
|
|
295
|
+
this.webchatRef.current?.addBotResponse({
|
|
296
|
+
response,
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
addBotText(text: string) {
|
|
301
|
+
this.addBotMessage({ type: INPUT.TEXT, data: text })
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
addUserMessage(message: any) {
|
|
305
|
+
this.webchatRef.current?.addUserMessage(message)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
addUserText(text: string) {
|
|
309
|
+
this.addUserMessage({ type: INPUT.TEXT, data: text })
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
addUserPayload(payload: string) {
|
|
313
|
+
this.addUserMessage({ type: INPUT.POSTBACK, payload })
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
setTyping(typing: boolean) {
|
|
317
|
+
this.webchatRef.current?.setTyping(typing)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
open() {
|
|
321
|
+
this.webchatRef.current?.openWebchat()
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
close() {
|
|
325
|
+
this.webchatRef.current?.closeWebchat()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async closeWebview(options?: CloseWebviewOptions) {
|
|
329
|
+
await this.webchatRef.current?.closeWebview(options)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// TODO: Remove this function because we have open and close functions
|
|
333
|
+
toggle() {
|
|
334
|
+
this.webchatRef.current?.toggleWebchat()
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
openCoverComponent() {
|
|
338
|
+
this.webchatRef.current?.openCoverComponent()
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
closeCoverComponent() {
|
|
342
|
+
this.webchatRef.current?.closeCoverComponent()
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
renderCustomComponent(_customComponent: any) {
|
|
346
|
+
this.webchatRef.current?.renderCustomComponent(_customComponent)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
unmountCustomComponent() {
|
|
350
|
+
this.webchatRef.current?.unmountCustomComponent()
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// TODO: Remove this function because we have openCoverComponent and closeCoverComponent functions
|
|
354
|
+
toggleCoverComponent() {
|
|
355
|
+
this.webchatRef.current?.toggleCoverComponent()
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
getMessages() {
|
|
359
|
+
return this.webchatRef.current?.getMessages()
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
clearMessages() {
|
|
363
|
+
this.webchatRef.current?.clearMessages()
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async getVisibility() {
|
|
367
|
+
return this.resolveWebchatVisibility({
|
|
368
|
+
appId: this.appId!,
|
|
369
|
+
visibility: this.visibility,
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
getLastMessageUpdate() {
|
|
374
|
+
return this.webchatRef.current?.getLastMessageUpdate()
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
updateMessageInfo(msgId: string, messageInfo: any) {
|
|
378
|
+
return this.webchatRef.current?.updateMessageInfo(msgId, messageInfo)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
updateWebchatSettings(settings: WebchatSettingsProps) {
|
|
382
|
+
return this.webchatRef.current?.updateWebchatSettings(settings)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
createInitialTheme(optionsAtRuntime: WebchatArgs = {}) {
|
|
386
|
+
const theme = merge(defaultTheme, this.theme, optionsAtRuntime.theme)
|
|
387
|
+
|
|
388
|
+
if (theme.animations === undefined) {
|
|
389
|
+
theme.animations = {}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
theme.animations.enable =
|
|
393
|
+
theme.animations.enable ??
|
|
394
|
+
optionsAtRuntime.enableAnimations ??
|
|
395
|
+
this.enableAnimations
|
|
396
|
+
|
|
397
|
+
theme.coverComponent =
|
|
398
|
+
theme.coverComponent ??
|
|
399
|
+
optionsAtRuntime.coverComponent ??
|
|
400
|
+
this.coverComponent
|
|
401
|
+
|
|
402
|
+
theme.userInput = this.createInitialThemeUserInput(theme, optionsAtRuntime)
|
|
403
|
+
|
|
404
|
+
return theme
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
createInitialThemeUserInput(
|
|
408
|
+
theme: WebchatTheme,
|
|
409
|
+
optionsAtRuntime: WebchatArgs = {}
|
|
410
|
+
) {
|
|
411
|
+
if (!theme.userInput) theme.userInput = {}
|
|
412
|
+
|
|
413
|
+
// Set main userInput properties
|
|
414
|
+
theme.userInput = {
|
|
415
|
+
...theme.userInput,
|
|
416
|
+
enable:
|
|
417
|
+
theme.userInput.enable ??
|
|
418
|
+
optionsAtRuntime.enableUserInput ??
|
|
419
|
+
this.enableUserInput,
|
|
420
|
+
persistentMenu:
|
|
421
|
+
theme.userInput.persistentMenu ??
|
|
422
|
+
optionsAtRuntime.persistentMenu ??
|
|
423
|
+
this.persistentMenu,
|
|
424
|
+
blockInputs:
|
|
425
|
+
theme.userInput.blockInputs ??
|
|
426
|
+
optionsAtRuntime.blockInputs ??
|
|
427
|
+
this.blockInputs,
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Set emoji picker properties
|
|
431
|
+
theme.userInput.emojiPicker = {
|
|
432
|
+
...(theme.userInput.emojiPicker || {}),
|
|
433
|
+
enable:
|
|
434
|
+
theme.userInput.emojiPicker?.enable ??
|
|
435
|
+
optionsAtRuntime.enableEmojiPicker ??
|
|
436
|
+
this.enableEmojiPicker,
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Set attachments properties
|
|
440
|
+
theme.userInput.attachments = {
|
|
441
|
+
...(theme.userInput.attachments || {}),
|
|
442
|
+
enable:
|
|
443
|
+
theme.userInput.attachments?.enable ??
|
|
444
|
+
optionsAtRuntime.enableAttachments ??
|
|
445
|
+
this.enableAttachments,
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return theme.userInput
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
getComponent(host: HTMLDivElement, optionsAtRuntime: WebchatArgs = {}) {
|
|
452
|
+
let {
|
|
453
|
+
theme = {},
|
|
454
|
+
defaultDelay,
|
|
455
|
+
defaultTyping,
|
|
456
|
+
storage,
|
|
457
|
+
storageKey,
|
|
458
|
+
onInit,
|
|
459
|
+
onOpen,
|
|
460
|
+
onClose,
|
|
461
|
+
onMessage,
|
|
462
|
+
onConnectionChange,
|
|
463
|
+
onTrackEvent,
|
|
464
|
+
appId,
|
|
465
|
+
visibility,
|
|
466
|
+
server,
|
|
467
|
+
hostId,
|
|
468
|
+
...webchatOptions
|
|
469
|
+
} = optionsAtRuntime
|
|
470
|
+
theme = this.createInitialTheme(optionsAtRuntime)
|
|
471
|
+
defaultDelay = defaultDelay || this.defaultDelay
|
|
472
|
+
defaultTyping = defaultTyping || this.defaultTyping
|
|
473
|
+
server = server || this.server
|
|
474
|
+
this.storage = storage || this.storage
|
|
475
|
+
this.storageKey = storageKey || this.storageKey
|
|
476
|
+
this.onInit = onInit || this.onInit
|
|
477
|
+
this.onOpen = onOpen || this.onOpen
|
|
478
|
+
this.onClose = onClose || this.onClose
|
|
479
|
+
this.onMessage = onMessage || this.onMessage
|
|
480
|
+
this.onTrackEvent = onTrackEvent || this.onTrackEvent
|
|
481
|
+
this.onConnectionChange = onConnectionChange || this.onConnectionChange
|
|
482
|
+
this.visibility = visibility || this.visibility
|
|
483
|
+
this.appId = appId || this.appId
|
|
484
|
+
this.hostId = hostId || this.hostId
|
|
485
|
+
this.createRootElement(host)
|
|
486
|
+
|
|
487
|
+
return (
|
|
488
|
+
<Webchat
|
|
489
|
+
{...webchatOptions}
|
|
490
|
+
ref={this.webchatRef}
|
|
491
|
+
host={this.host}
|
|
492
|
+
shadowDOM={this.shadowDOM}
|
|
493
|
+
theme={theme as WebchatTheme}
|
|
494
|
+
storage={this.storage}
|
|
495
|
+
storageKey={this.storageKey}
|
|
496
|
+
defaultDelay={defaultDelay}
|
|
497
|
+
defaultTyping={defaultTyping}
|
|
498
|
+
onInit={(...args: [any]) => this.onInitWebchat(...args)}
|
|
499
|
+
onOpen={(...args: [any]) => this.onOpenWebchat(...args)}
|
|
500
|
+
onClose={(...args: [any]) => this.onCloseWebchat(...args)}
|
|
501
|
+
onUserInput={(...args: [any]) => this.onUserInput(...args)}
|
|
502
|
+
onStateChange={(args: OnStateChangeArgs) => {
|
|
503
|
+
this.onStateChange(args)
|
|
504
|
+
}}
|
|
505
|
+
onTrackEvent={(
|
|
506
|
+
request: ActionRequest,
|
|
507
|
+
eventName: string,
|
|
508
|
+
args?: EventArgs
|
|
509
|
+
) => this.onTrackEventWebchat(request, eventName, args)}
|
|
510
|
+
server={server}
|
|
511
|
+
/>
|
|
512
|
+
)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async isWebchatVisible(appId: string): Promise<boolean> {
|
|
516
|
+
try {
|
|
517
|
+
const { status } = await HubtypeService.getWebchatVisibility(appId)
|
|
518
|
+
return status === 200
|
|
519
|
+
} catch (e) {
|
|
520
|
+
return false
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
isOnline() {
|
|
525
|
+
return this.webchatRef.current?.isOnline()
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
async resolveWebchatVisibility(
|
|
529
|
+
optionsAtRuntime?: WebchatArgs
|
|
530
|
+
): Promise<boolean> {
|
|
531
|
+
if (!optionsAtRuntime) {
|
|
532
|
+
// If optionsAtRuntime is not provided, always render the webchat
|
|
533
|
+
return true
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
let { appId, visibility } = optionsAtRuntime
|
|
537
|
+
visibility = visibility || this.visibility
|
|
538
|
+
|
|
539
|
+
if (visibility === undefined || visibility === true) {
|
|
540
|
+
return true
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (typeof visibility === 'function' && visibility()) {
|
|
544
|
+
return true
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (
|
|
548
|
+
appId &&
|
|
549
|
+
visibility === 'dynamic' &&
|
|
550
|
+
(await this.isWebchatVisible(appId))
|
|
551
|
+
) {
|
|
552
|
+
return true
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
return false
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
destroy() {
|
|
559
|
+
if (this.hubtypeService) this.hubtypeService.destroyPusher()
|
|
560
|
+
this.reactRoot?.unmount()
|
|
561
|
+
if (this.storage) this.storage.removeItem(this.storageKey)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
async render(dest: HTMLDivElement, optionsAtRuntime?: WebchatArgs) {
|
|
565
|
+
onDOMLoaded(async () => {
|
|
566
|
+
const isVisible = await this.resolveWebchatVisibility(optionsAtRuntime)
|
|
567
|
+
if (isVisible) {
|
|
568
|
+
const webchatComponent = this.getComponent(dest, optionsAtRuntime)
|
|
569
|
+
const container = this.getReactMountNode(dest)
|
|
570
|
+
this.reactRoot = createRoot(container)
|
|
571
|
+
this.reactRoot.render(webchatComponent)
|
|
572
|
+
}
|
|
573
|
+
})
|
|
574
|
+
}
|
|
575
|
+
}
|
package/src/webview-app.tsx
CHANGED
|
@@ -1,25 +1,70 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import {
|
|
2
|
+
import { params2queryString, PROVIDER, Session } from '@botonic/core'
|
|
3
3
|
import axios from 'axios'
|
|
4
4
|
import React from 'react'
|
|
5
|
-
import {
|
|
5
|
+
import { createRoot } from 'react-dom/client'
|
|
6
6
|
import { BrowserRouter, Route } from 'react-router-dom'
|
|
7
7
|
|
|
8
8
|
import { CloseWebviewOptions, WebviewRequestContext } from './contexts'
|
|
9
9
|
|
|
10
|
+
enum WebviewUrlParams {
|
|
11
|
+
Context = 'context',
|
|
12
|
+
BotId = 'bot_id',
|
|
13
|
+
UserId = 'user_id',
|
|
14
|
+
HubtypeApiUrl = 'hubtype_api_url',
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
class App extends React.Component {
|
|
18
|
+
private url: URL
|
|
19
|
+
private botId: string
|
|
20
|
+
private userId: string
|
|
21
|
+
private hubtypeApiUrl: string
|
|
22
|
+
private state: { session: Session; params: Record<string, string> }
|
|
23
|
+
|
|
11
24
|
constructor(props) {
|
|
12
25
|
super(props)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
this.url = new URL(window.location.href)
|
|
27
|
+
this.botId = this.url.searchParams.get(WebviewUrlParams.BotId)
|
|
28
|
+
this.userId = this.url.searchParams.get(WebviewUrlParams.UserId)
|
|
29
|
+
this.hubtypeApiUrl =
|
|
30
|
+
this.url.searchParams.get(WebviewUrlParams.HubtypeApiUrl) ||
|
|
31
|
+
'https://api.hubtype.com'
|
|
32
|
+
this.state = {
|
|
33
|
+
session: null,
|
|
34
|
+
params: {},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async componentDidMount() {
|
|
39
|
+
try {
|
|
40
|
+
const session = await this.getSessionFromUrl()
|
|
41
|
+
const params = this.getParamsFromUrl()
|
|
42
|
+
this.setState({ session, params })
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('Error getting bot session context from url', error)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getSessionFromUrl() {
|
|
49
|
+
const url = `${this.hubtypeApiUrl}/external/v2/conversational_apps/${this.botId}/users/${this.userId}/context/`
|
|
50
|
+
const response = await axios.get(url)
|
|
51
|
+
return response.data
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getParamsFromUrl() {
|
|
55
|
+
const keysToExclude = [
|
|
56
|
+
WebviewUrlParams.Context,
|
|
57
|
+
WebviewUrlParams.BotId,
|
|
58
|
+
WebviewUrlParams.UserId,
|
|
59
|
+
WebviewUrlParams.HubtypeApiUrl,
|
|
60
|
+
]
|
|
61
|
+
const params = Array.from(this.url.searchParams.entries())
|
|
62
|
+
.filter(([key, _]) => !keysToExclude.includes(key))
|
|
16
63
|
.reduce((o, [key, value]) => {
|
|
17
64
|
o[key] = value
|
|
18
65
|
return o
|
|
19
66
|
}, {})
|
|
20
|
-
|
|
21
|
-
const session = JSON.parse(urlContext || '{}')
|
|
22
|
-
this.state = { session, params }
|
|
67
|
+
return params
|
|
23
68
|
}
|
|
24
69
|
|
|
25
70
|
async close(options?: CloseWebviewOptions) {
|
|
@@ -36,10 +81,9 @@ class App extends React.Component {
|
|
|
36
81
|
|
|
37
82
|
const session = this.state.session
|
|
38
83
|
try {
|
|
39
|
-
const
|
|
40
|
-
const url = `${baseUrl}/v1/bots/${session.bot.id}/send_postback/`
|
|
84
|
+
const url = `${this.hubtypeApiUrl}/v1/bots/${this.botId}/send_postback/`
|
|
41
85
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
42
|
-
const data = { payload: payload, chat_id:
|
|
86
|
+
const data = { payload: payload, chat_id: this.userId }
|
|
43
87
|
await axios.post(url, data)
|
|
44
88
|
} catch (e) {
|
|
45
89
|
console.log(e)
|
|
@@ -86,8 +130,6 @@ class App extends React.Component {
|
|
|
86
130
|
|
|
87
131
|
render() {
|
|
88
132
|
const webviewRequestContext = {
|
|
89
|
-
getString: (stringId: string) =>
|
|
90
|
-
getString(this.props.locales, this.state.session.__locale, stringId),
|
|
91
133
|
session: this.state.session || {},
|
|
92
134
|
params: this.state.params || {},
|
|
93
135
|
closeWebview: this.close.bind(this),
|
|
@@ -110,11 +152,13 @@ export class WebviewApp {
|
|
|
110
152
|
}
|
|
111
153
|
|
|
112
154
|
render(dest) {
|
|
113
|
-
|
|
155
|
+
const component = (
|
|
114
156
|
<BrowserRouter>
|
|
115
157
|
<App webviews={this.webviews} locales={this.locales} />
|
|
116
|
-
</BrowserRouter
|
|
117
|
-
dest
|
|
158
|
+
</BrowserRouter>
|
|
118
159
|
)
|
|
160
|
+
const container = dest
|
|
161
|
+
const reactRoot = createRoot(container)
|
|
162
|
+
reactRoot.render(component)
|
|
119
163
|
}
|
|
120
164
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../../src/components/button.tsx"],"names":[],"mappings":";;;;;AAAA,wCAAqC;AACrC,iCAAmD;AACnD,kFAAsC;AAEtC,4CAA8C;AAC9C,0CAA4C;AAC5C,qDAAkD;AAClD,yCAA+C;AAC/C,+CAA+D;AAC/D,yDAAoD;AAGpD,MAAM,YAAY,GAAG,2BAAM,CAAC,MAAM,CAAA;;;;;;;;;;;;sBAYZ,kBAAM,CAAC,cAAc;;;;;;;;CAQ1C,CAAA;AAEY,QAAA,cAAc,GAAG,2BAAM,CAAC,GAAG,CAAA;;CAEvC,CAAA;AAEM,MAAM,MAAM,GAAG,CAAC,KAAkB,EAAE,EAAE;IAC3C,MAAM,EACJ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,aAAa,GACd,GAAG,IAAA,kBAAU,EAAC,yBAAc,CAAC,CAAA;IAC9B,MAAM,CAAC,KAAK,EAAE,QA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