@botonic/react 0.22.0-alpha.0 → 0.22.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/app.d.ts +2 -0
- package/lib/cjs/app.js +10 -0
- package/lib/cjs/app.js.map +1 -0
- package/lib/cjs/botonic-tester.d.ts +18 -0
- package/lib/cjs/botonic-tester.js +70 -0
- package/lib/cjs/botonic-tester.js.map +1 -0
- package/lib/cjs/components/audio.d.ts +8 -0
- package/lib/cjs/components/audio.js +27 -0
- package/lib/cjs/components/audio.js.map +1 -0
- package/lib/cjs/components/button.d.ts +15 -0
- package/lib/cjs/components/button.js +156 -0
- package/lib/cjs/components/button.js.map +1 -0
- package/lib/cjs/components/buttons-disabler.d.ts +24 -0
- package/lib/cjs/components/buttons-disabler.js +88 -0
- package/lib/cjs/components/buttons-disabler.js.map +1 -0
- package/lib/cjs/components/carousel.d.ts +10 -0
- package/lib/cjs/components/carousel.js +120 -0
- package/lib/cjs/components/carousel.js.map +1 -0
- package/lib/cjs/components/components.d.ts +12 -0
- package/lib/{components → cjs/components}/components.js +6 -11
- package/lib/cjs/components/components.js.map +1 -0
- package/lib/cjs/components/custom-message.d.ts +43 -0
- package/lib/cjs/components/custom-message.js +65 -0
- package/lib/cjs/components/custom-message.js.map +1 -0
- package/lib/cjs/components/document.d.ts +8 -0
- package/lib/cjs/components/document.js +50 -0
- package/lib/cjs/components/document.js.map +1 -0
- package/lib/cjs/components/element.d.ts +4 -0
- package/lib/cjs/components/element.js +55 -0
- package/lib/cjs/components/element.js.map +1 -0
- package/lib/cjs/components/handoff.d.ts +1 -0
- package/lib/cjs/components/handoff.js +58 -0
- package/lib/cjs/components/handoff.js.map +1 -0
- package/lib/cjs/components/image.d.ts +8 -0
- package/lib/cjs/components/image.js +42 -0
- package/lib/cjs/components/image.js.map +1 -0
- package/lib/cjs/components/index.d.ts +20 -0
- package/lib/cjs/components/index.js +44 -0
- package/lib/cjs/components/index.js.map +1 -0
- package/lib/cjs/components/location.d.ts +11 -0
- package/lib/cjs/components/location.js +38 -0
- package/lib/cjs/components/location.js.map +1 -0
- package/lib/cjs/components/markdown.d.ts +7 -0
- package/lib/cjs/components/markdown.js +162 -0
- package/lib/cjs/components/markdown.js.map +1 -0
- package/lib/cjs/components/message-template.d.ts +1 -0
- package/lib/cjs/components/message-template.js +15 -0
- package/lib/cjs/components/message-template.js.map +1 -0
- package/lib/cjs/components/message.d.ts +1 -0
- package/lib/cjs/components/message.js +206 -0
- package/lib/cjs/components/message.js.map +1 -0
- package/lib/cjs/components/multichannel/facebook/facebook.d.ts +17 -0
- package/lib/cjs/components/multichannel/facebook/facebook.js +47 -0
- package/lib/cjs/components/multichannel/facebook/facebook.js.map +1 -0
- package/lib/cjs/components/multichannel/index.d.ts +6 -0
- package/lib/cjs/components/multichannel/index.js +14 -0
- package/lib/cjs/components/multichannel/index.js.map +1 -0
- package/lib/cjs/components/multichannel/multichannel-button.d.ts +1 -0
- package/lib/cjs/components/multichannel/multichannel-button.js +77 -0
- package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -0
- package/lib/cjs/components/multichannel/multichannel-carousel.d.ts +1 -0
- package/lib/cjs/components/multichannel/multichannel-carousel.js +95 -0
- package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -0
- package/lib/cjs/components/multichannel/multichannel-context.d.ts +11 -0
- package/lib/cjs/components/multichannel/multichannel-context.js +16 -0
- package/lib/cjs/components/multichannel/multichannel-context.js.map +1 -0
- package/lib/cjs/components/multichannel/multichannel-reply.d.ts +1 -0
- package/lib/cjs/components/multichannel/multichannel-reply.js +24 -0
- package/lib/cjs/components/multichannel/multichannel-reply.js.map +1 -0
- package/lib/cjs/components/multichannel/multichannel-text.d.ts +1 -0
- package/lib/cjs/components/multichannel/multichannel-text.js +147 -0
- package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -0
- package/lib/cjs/components/multichannel/multichannel-utils.d.ts +24 -0
- package/lib/cjs/components/multichannel/multichannel-utils.js +83 -0
- package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -0
- package/lib/cjs/components/multichannel/multichannel.d.ts +1 -0
- package/lib/cjs/components/multichannel/multichannel.js +72 -0
- package/lib/cjs/components/multichannel/multichannel.js.map +1 -0
- package/lib/cjs/components/pic.d.ts +6 -0
- package/lib/cjs/components/pic.js +29 -0
- package/lib/cjs/components/pic.js.map +1 -0
- package/lib/cjs/components/raw.d.ts +9 -0
- package/lib/cjs/components/raw.js +53 -0
- package/lib/cjs/components/raw.js.map +1 -0
- package/lib/cjs/components/reply.d.ts +9 -0
- package/lib/cjs/components/reply.js +57 -0
- package/lib/cjs/components/reply.js.map +1 -0
- package/lib/cjs/components/share-button.d.ts +1 -0
- package/lib/cjs/components/share-button.js +15 -0
- package/lib/cjs/components/share-button.js.map +1 -0
- package/lib/cjs/components/subtitle.d.ts +6 -0
- package/lib/cjs/components/subtitle.js +25 -0
- package/lib/cjs/components/subtitle.js.map +1 -0
- package/lib/cjs/components/text.d.ts +8 -0
- package/lib/cjs/components/text.js +50 -0
- package/lib/cjs/components/text.js.map +1 -0
- package/lib/cjs/components/timestamps.d.ts +10 -0
- package/lib/cjs/components/timestamps.js +54 -0
- package/lib/cjs/components/timestamps.js.map +1 -0
- package/lib/cjs/components/title.d.ts +6 -0
- package/lib/cjs/components/title.js +21 -0
- package/lib/cjs/components/title.js.map +1 -0
- package/lib/cjs/components/video.d.ts +8 -0
- package/lib/cjs/components/video.js +34 -0
- package/lib/cjs/components/video.js.map +1 -0
- package/lib/cjs/components/webchat-settings.d.ts +10 -0
- package/lib/cjs/components/webchat-settings.js +78 -0
- package/lib/cjs/components/webchat-settings.js.map +1 -0
- package/lib/cjs/components/whatsapp-template.d.ts +1 -0
- package/lib/cjs/components/whatsapp-template.js +26 -0
- package/lib/cjs/components/whatsapp-template.js.map +1 -0
- package/lib/cjs/constants.d.ts +168 -0
- package/lib/cjs/constants.js +190 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/contexts.d.ts +69 -0
- package/lib/cjs/contexts.js +38 -0
- package/lib/cjs/contexts.js.map +1 -0
- package/lib/cjs/dev-app.d.ts +30 -0
- package/lib/cjs/dev-app.js +71 -0
- package/lib/cjs/dev-app.js.map +1 -0
- package/lib/cjs/index.d.ts +10 -0
- package/lib/cjs/index.js +28 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/message-utils.d.ts +19 -0
- package/lib/cjs/message-utils.js +61 -0
- package/lib/cjs/message-utils.js.map +1 -0
- package/lib/cjs/msg-to-botonic.d.ts +18 -0
- package/lib/cjs/msg-to-botonic.js +160 -0
- package/lib/cjs/msg-to-botonic.js.map +1 -0
- package/lib/cjs/node-app.d.ts +12 -0
- package/lib/cjs/node-app.js +25 -0
- package/lib/cjs/node-app.js.map +1 -0
- package/lib/cjs/react-bot.d.ts +8 -0
- package/lib/cjs/react-bot.js +35 -0
- package/lib/cjs/react-bot.js.map +1 -0
- package/lib/cjs/util/dom.d.ts +13 -0
- package/lib/cjs/util/dom.js +55 -0
- package/lib/cjs/util/dom.js.map +1 -0
- package/lib/cjs/util/environment.d.ts +6 -0
- package/lib/cjs/util/environment.js +68 -0
- package/lib/cjs/util/environment.js.map +1 -0
- package/lib/cjs/util/error-boundary.d.ts +40 -0
- package/lib/cjs/util/error-boundary.js +46 -0
- package/lib/cjs/util/error-boundary.js.map +1 -0
- package/lib/cjs/util/index.d.ts +0 -0
- package/lib/cjs/util/index.js +2 -0
- package/lib/cjs/util/index.js.map +1 -0
- package/lib/cjs/util/logs.d.ts +2 -0
- package/lib/cjs/util/logs.js +20 -0
- package/lib/cjs/util/logs.js.map +1 -0
- package/lib/cjs/util/objects.d.ts +3 -0
- package/lib/cjs/util/objects.js +44 -0
- package/lib/cjs/util/objects.js.map +1 -0
- package/lib/cjs/util/react.d.ts +12 -0
- package/lib/cjs/util/react.js +42 -0
- package/lib/cjs/util/react.js.map +1 -0
- package/lib/cjs/util/regexs.d.ts +2 -0
- package/lib/cjs/util/regexs.js +23 -0
- package/lib/cjs/util/regexs.js.map +1 -0
- package/lib/cjs/util/webchat.d.ts +11 -0
- package/lib/cjs/util/webchat.js +62 -0
- package/lib/cjs/util/webchat.js.map +1 -0
- package/lib/cjs/webchat/actions.d.ts +23 -0
- package/lib/cjs/webchat/actions.js +27 -0
- package/lib/cjs/webchat/actions.js.map +1 -0
- package/lib/cjs/webchat/components/attachment.d.ts +5 -0
- package/lib/cjs/webchat/components/attachment.js +32 -0
- package/lib/cjs/webchat/components/attachment.js.map +1 -0
- package/lib/cjs/webchat/components/common.d.ts +1 -0
- package/lib/cjs/webchat/components/common.js +13 -0
- package/lib/cjs/webchat/components/common.js.map +1 -0
- package/lib/cjs/webchat/components/conditional-animation.d.ts +1 -0
- package/lib/cjs/webchat/components/conditional-animation.js +18 -0
- package/lib/cjs/webchat/components/conditional-animation.js.map +1 -0
- package/lib/cjs/webchat/components/emoji-picker.d.ts +5 -0
- package/lib/cjs/webchat/components/emoji-picker.js +52 -0
- package/lib/cjs/webchat/components/emoji-picker.js.map +1 -0
- package/lib/cjs/webchat/components/persistent-menu.d.ts +10 -0
- package/lib/cjs/webchat/components/persistent-menu.js +59 -0
- package/lib/cjs/webchat/components/persistent-menu.js.map +1 -0
- package/lib/cjs/webchat/components/send-button.d.ts +3 -0
- package/lib/cjs/webchat/components/send-button.js +24 -0
- package/lib/cjs/webchat/components/send-button.js.map +1 -0
- package/lib/cjs/webchat/components/styled-scrollbar.d.ts +1 -0
- package/lib/cjs/webchat/components/styled-scrollbar.js +54 -0
- package/lib/cjs/webchat/components/styled-scrollbar.js.map +1 -0
- package/lib/cjs/webchat/components/typing-indicator.d.ts +1 -0
- package/lib/cjs/webchat/components/typing-indicator.js +14 -0
- package/lib/cjs/webchat/components/typing-indicator.js.map +1 -0
- package/lib/cjs/webchat/devices/device-adapter.d.ts +12 -0
- package/lib/cjs/webchat/devices/device-adapter.js +47 -0
- package/lib/cjs/webchat/devices/device-adapter.js.map +1 -0
- package/lib/cjs/webchat/devices/index.d.ts +11 -0
- package/lib/cjs/webchat/devices/index.js +23 -0
- package/lib/cjs/webchat/devices/index.js.map +1 -0
- package/lib/cjs/webchat/devices/scrollbar-controller.d.ts +12 -0
- package/lib/cjs/webchat/devices/scrollbar-controller.js +103 -0
- package/lib/cjs/webchat/devices/scrollbar-controller.js.map +1 -0
- package/lib/cjs/webchat/devices/webchat-resizer.d.ts +9 -0
- package/lib/cjs/webchat/devices/webchat-resizer.js +47 -0
- package/lib/cjs/webchat/devices/webchat-resizer.js.map +1 -0
- package/lib/cjs/webchat/header.d.ts +3 -0
- package/lib/cjs/webchat/header.js +95 -0
- package/lib/cjs/webchat/header.js.map +1 -0
- package/lib/cjs/webchat/hooks.d.ts +80 -0
- package/lib/cjs/webchat/hooks.js +218 -0
- package/lib/cjs/webchat/hooks.js.map +1 -0
- package/lib/cjs/webchat/index.d.ts +6 -0
- package/lib/cjs/webchat/index.js +17 -0
- package/lib/cjs/webchat/index.js.map +1 -0
- package/lib/cjs/webchat/message-list.d.ts +1 -0
- package/lib/cjs/webchat/message-list.js +46 -0
- package/lib/cjs/webchat/message-list.js.map +1 -0
- package/lib/cjs/webchat/messages-reducer.d.ts +1 -0
- package/lib/cjs/webchat/messages-reducer.js +58 -0
- package/lib/cjs/webchat/messages-reducer.js.map +1 -0
- package/lib/cjs/webchat/replies.d.ts +1 -0
- package/lib/cjs/webchat/replies.js +46 -0
- package/lib/cjs/webchat/replies.js.map +1 -0
- package/lib/cjs/webchat/session-view.d.ts +1 -0
- package/lib/cjs/webchat/session-view.js +124 -0
- package/lib/cjs/webchat/session-view.js.map +1 -0
- package/lib/cjs/webchat/use-storage-state-hook.d.ts +1 -0
- package/lib/cjs/webchat/use-storage-state-hook.js +32 -0
- package/lib/cjs/webchat/use-storage-state-hook.js.map +1 -0
- package/lib/cjs/webchat/webchat-dev.d.ts +7 -0
- package/lib/cjs/webchat/webchat-dev.js +64 -0
- package/lib/cjs/webchat/webchat-dev.js.map +1 -0
- package/lib/cjs/webchat/webchat-reducer.d.ts +1 -0
- package/lib/cjs/webchat/webchat-reducer.js +48 -0
- package/lib/cjs/webchat/webchat-reducer.js.map +1 -0
- package/lib/cjs/webchat/webchat.d.ts +3 -0
- package/lib/cjs/webchat/webchat.js +704 -0
- package/lib/cjs/webchat/webchat.js.map +1 -0
- package/lib/cjs/webchat/webview.d.ts +2 -0
- package/lib/cjs/webchat/webview.js +92 -0
- package/lib/cjs/webchat/webview.js.map +1 -0
- package/lib/cjs/webchat-app.d.ts +99 -0
- package/lib/cjs/webchat-app.js +269 -0
- package/lib/cjs/webchat-app.js.map +1 -0
- package/lib/cjs/webview-app.d.ts +7 -0
- package/lib/cjs/webview-app.js +103 -0
- package/lib/cjs/webview-app.js.map +1 -0
- package/lib/esm/app.d.ts +2 -0
- package/lib/esm/app.js +6 -0
- package/lib/esm/app.js.map +1 -0
- package/lib/esm/assets/attachment-icon.svg +7 -0
- package/lib/esm/assets/audio.svg +4 -0
- package/lib/esm/assets/botonic_react_logo100x100.png +0 -0
- package/lib/esm/assets/document.svg +3 -0
- package/lib/esm/assets/emojiButton.svg +6 -0
- package/lib/esm/assets/image.svg +4 -0
- package/lib/esm/assets/leftArrow.svg +3 -0
- package/lib/esm/assets/menuButton.svg +3 -0
- package/lib/esm/assets/rightArrow.svg +3 -0
- package/lib/esm/assets/send-button.svg +1 -0
- package/lib/esm/assets/video.svg +3 -0
- package/lib/esm/botonic-tester.d.ts +18 -0
- package/lib/esm/botonic-tester.js +64 -0
- package/lib/esm/botonic-tester.js.map +1 -0
- package/lib/esm/components/audio.d.ts +8 -0
- package/lib/esm/components/audio.js +22 -0
- package/lib/esm/components/audio.js.map +1 -0
- package/lib/esm/components/button.d.ts +15 -0
- package/lib/esm/components/button.js +151 -0
- package/lib/esm/components/button.js.map +1 -0
- package/lib/esm/components/buttons-disabler.d.ts +24 -0
- package/lib/esm/components/buttons-disabler.js +84 -0
- package/lib/esm/components/buttons-disabler.js.map +1 -0
- package/lib/esm/components/carousel.d.ts +9 -0
- package/lib/esm/components/carousel.js +115 -0
- package/lib/esm/components/carousel.js.map +1 -0
- package/lib/esm/components/components.d.ts +12 -0
- package/lib/esm/components/components.js +17 -0
- package/lib/esm/components/components.js.map +1 -0
- package/lib/esm/components/custom-message.d.ts +43 -0
- package/lib/esm/components/custom-message.js +61 -0
- package/lib/esm/components/custom-message.js.map +1 -0
- package/lib/esm/components/document.d.ts +8 -0
- package/lib/esm/components/document.js +45 -0
- package/lib/esm/components/document.js.map +1 -0
- package/lib/esm/components/element.d.ts +4 -0
- package/lib/esm/components/element.js +50 -0
- package/lib/esm/components/element.js.map +1 -0
- package/lib/esm/components/handoff.d.ts +1 -0
- package/lib/esm/components/handoff.js +53 -0
- package/lib/esm/components/handoff.js.map +1 -0
- package/lib/esm/components/image.d.ts +8 -0
- package/lib/esm/components/image.js +37 -0
- package/lib/esm/components/image.js.map +1 -0
- package/lib/esm/components/index.d.ts +19 -0
- package/lib/esm/components/index.js +21 -0
- package/lib/esm/components/index.js.map +1 -0
- package/lib/esm/components/location.d.ts +11 -0
- package/lib/esm/components/location.js +33 -0
- package/lib/esm/components/location.js.map +1 -0
- package/lib/esm/components/markdown.d.ts +7 -0
- package/lib/esm/components/markdown.js +152 -0
- package/lib/esm/components/markdown.js.map +1 -0
- package/lib/esm/components/message-template.d.ts +1 -0
- package/lib/esm/components/message-template.js +10 -0
- package/lib/esm/components/message-template.js.map +1 -0
- package/lib/esm/components/message.d.ts +1 -0
- package/lib/esm/components/message.js +202 -0
- package/lib/esm/components/message.js.map +1 -0
- package/lib/esm/components/multichannel/facebook/facebook.d.ts +17 -0
- package/lib/esm/components/multichannel/facebook/facebook.js +43 -0
- package/lib/esm/components/multichannel/facebook/facebook.js.map +1 -0
- package/lib/esm/components/multichannel/index.d.ts +6 -0
- package/lib/esm/components/multichannel/index.js +11 -0
- package/lib/esm/components/multichannel/index.js.map +1 -0
- package/lib/esm/components/multichannel/multichannel-button.d.ts +1 -0
- package/lib/esm/components/multichannel/multichannel-button.js +72 -0
- package/lib/esm/components/multichannel/multichannel-button.js.map +1 -0
- package/lib/esm/components/multichannel/multichannel-carousel.d.ts +1 -0
- package/lib/esm/components/multichannel/multichannel-carousel.js +90 -0
- package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -0
- package/lib/esm/components/multichannel/multichannel-context.d.ts +11 -0
- package/lib/esm/components/multichannel/multichannel-context.js +12 -0
- package/lib/esm/components/multichannel/multichannel-context.js.map +1 -0
- package/lib/esm/components/multichannel/multichannel-reply.d.ts +1 -0
- package/lib/esm/components/multichannel/multichannel-reply.js +19 -0
- package/lib/esm/components/multichannel/multichannel-reply.js.map +1 -0
- package/lib/esm/components/multichannel/multichannel-text.d.ts +1 -0
- package/lib/esm/components/multichannel/multichannel-text.js +142 -0
- package/lib/esm/components/multichannel/multichannel-text.js.map +1 -0
- package/lib/esm/components/multichannel/multichannel-utils.d.ts +24 -0
- package/lib/esm/components/multichannel/multichannel-utils.js +67 -0
- package/lib/esm/components/multichannel/multichannel-utils.js.map +1 -0
- package/lib/esm/components/multichannel/multichannel.d.ts +1 -0
- package/lib/esm/components/multichannel/multichannel.js +67 -0
- package/lib/esm/components/multichannel/multichannel.js.map +1 -0
- package/lib/esm/components/pic.d.ts +6 -0
- package/lib/esm/components/pic.js +24 -0
- package/lib/esm/components/pic.js.map +1 -0
- package/lib/esm/components/raw.d.ts +9 -0
- package/lib/esm/components/raw.js +48 -0
- package/lib/esm/components/raw.js.map +1 -0
- package/lib/esm/components/reply.d.ts +9 -0
- package/lib/esm/components/reply.js +52 -0
- package/lib/esm/components/reply.js.map +1 -0
- package/lib/esm/components/share-button.d.ts +1 -0
- package/lib/esm/components/share-button.js +10 -0
- package/lib/esm/components/share-button.js.map +1 -0
- package/lib/esm/components/subtitle.d.ts +6 -0
- package/lib/esm/components/subtitle.js +20 -0
- package/lib/esm/components/subtitle.js.map +1 -0
- package/lib/esm/components/text.d.ts +8 -0
- package/lib/esm/components/text.js +45 -0
- package/lib/esm/components/text.js.map +1 -0
- package/lib/esm/components/timestamps.d.ts +10 -0
- package/lib/esm/components/timestamps.js +48 -0
- package/lib/esm/components/timestamps.js.map +1 -0
- package/lib/esm/components/title.d.ts +6 -0
- package/lib/esm/components/title.js +16 -0
- package/lib/esm/components/title.js.map +1 -0
- package/lib/esm/components/video.d.ts +8 -0
- package/lib/esm/components/video.js +29 -0
- package/lib/esm/components/video.js.map +1 -0
- package/lib/esm/components/webchat-settings.d.ts +10 -0
- package/lib/esm/components/webchat-settings.js +72 -0
- package/lib/esm/components/webchat-settings.js.map +1 -0
- package/lib/esm/components/whatsapp-template.d.ts +1 -0
- package/lib/esm/components/whatsapp-template.js +21 -0
- package/lib/esm/components/whatsapp-template.js.map +1 -0
- package/lib/esm/constants.d.ts +168 -0
- package/lib/esm/constants.js +186 -0
- package/lib/esm/constants.js.map +1 -0
- package/lib/esm/contexts.d.ts +69 -0
- package/lib/esm/contexts.js +34 -0
- package/lib/esm/contexts.js.map +1 -0
- package/lib/esm/dev-app.d.ts +30 -0
- package/lib/esm/dev-app.js +67 -0
- package/lib/esm/dev-app.js.map +1 -0
- package/lib/esm/index.d.ts +9 -0
- package/lib/esm/index.js +11 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/message-utils.d.ts +18 -0
- package/lib/esm/message-utils.js +41 -0
- package/lib/esm/message-utils.js.map +1 -0
- package/lib/esm/msg-to-botonic.d.ts +18 -0
- package/lib/esm/msg-to-botonic.js +154 -0
- package/lib/esm/msg-to-botonic.js.map +1 -0
- package/lib/esm/node-app.d.ts +12 -0
- package/lib/esm/node-app.js +21 -0
- package/lib/esm/node-app.js.map +1 -0
- package/lib/esm/react-bot.d.ts +7 -0
- package/lib/esm/react-bot.js +30 -0
- package/lib/esm/react-bot.js.map +1 -0
- package/lib/esm/util/dom.d.ts +13 -0
- package/lib/esm/util/dom.js +46 -0
- package/lib/esm/util/dom.js.map +1 -0
- package/lib/esm/util/environment.d.ts +6 -0
- package/lib/esm/util/environment.js +61 -0
- package/lib/esm/util/environment.js.map +1 -0
- package/lib/esm/util/error-boundary.d.ts +40 -0
- package/lib/esm/util/error-boundary.js +41 -0
- package/lib/esm/util/error-boundary.js.map +1 -0
- package/lib/esm/util/index.d.ts +0 -0
- package/lib/esm/util/index.js +2 -0
- package/lib/esm/util/index.js.map +1 -0
- package/lib/esm/util/logs.d.ts +2 -0
- package/lib/esm/util/logs.js +15 -0
- package/lib/esm/util/logs.js.map +1 -0
- package/lib/esm/util/objects.d.ts +3 -0
- package/lib/esm/util/objects.js +38 -0
- package/lib/esm/util/objects.js.map +1 -0
- package/lib/esm/util/react.d.ts +12 -0
- package/lib/esm/util/react.js +34 -0
- package/lib/esm/util/react.js.map +1 -0
- package/lib/esm/util/regexs.d.ts +2 -0
- package/lib/esm/util/regexs.js +18 -0
- package/lib/esm/util/regexs.js.map +1 -0
- package/lib/esm/util/webchat.d.ts +11 -0
- package/lib/esm/util/webchat.js +53 -0
- package/lib/esm/util/webchat.js.map +1 -0
- package/lib/esm/webchat/actions.d.ts +23 -0
- package/lib/esm/webchat/actions.js +24 -0
- package/lib/esm/webchat/actions.js.map +1 -0
- package/lib/esm/webchat/components/attachment.d.ts +5 -0
- package/lib/esm/webchat/components/attachment.js +27 -0
- package/lib/esm/webchat/components/attachment.js.map +1 -0
- package/lib/esm/webchat/components/common.d.ts +1 -0
- package/lib/esm/webchat/components/common.js +8 -0
- package/lib/esm/webchat/components/common.js.map +1 -0
- package/lib/esm/webchat/components/conditional-animation.d.ts +1 -0
- package/lib/esm/webchat/components/conditional-animation.js +13 -0
- package/lib/esm/webchat/components/conditional-animation.js.map +1 -0
- package/lib/esm/webchat/components/emoji-picker.d.ts +5 -0
- package/lib/esm/webchat/components/emoji-picker.js +46 -0
- package/lib/esm/webchat/components/emoji-picker.js.map +1 -0
- package/lib/esm/webchat/components/persistent-menu.d.ts +10 -0
- package/lib/esm/webchat/components/persistent-menu.js +53 -0
- package/lib/esm/webchat/components/persistent-menu.js.map +1 -0
- package/lib/esm/webchat/components/send-button.d.ts +3 -0
- package/lib/esm/webchat/components/send-button.js +19 -0
- package/lib/esm/webchat/components/send-button.js.map +1 -0
- package/lib/esm/webchat/components/styled-scrollbar.d.ts +1 -0
- package/lib/esm/webchat/components/styled-scrollbar.js +50 -0
- package/lib/esm/webchat/components/styled-scrollbar.js.map +1 -0
- package/lib/esm/webchat/components/styled-scrollbar.scss +12 -0
- package/lib/esm/webchat/components/typing-indicator.d.ts +1 -0
- package/lib/esm/webchat/components/typing-indicator.js +9 -0
- package/lib/esm/webchat/components/typing-indicator.js.map +1 -0
- package/lib/esm/webchat/components/typing-indicator.scss +38 -0
- package/lib/esm/webchat/devices/device-adapter.d.ts +12 -0
- package/lib/esm/webchat/devices/device-adapter.js +43 -0
- package/lib/esm/webchat/devices/device-adapter.js.map +1 -0
- package/lib/esm/webchat/devices/index.d.ts +11 -0
- package/lib/esm/webchat/devices/index.js +18 -0
- package/lib/esm/webchat/devices/index.js.map +1 -0
- package/lib/esm/webchat/devices/scrollbar-controller.d.ts +12 -0
- package/lib/esm/webchat/devices/scrollbar-controller.js +99 -0
- package/lib/esm/webchat/devices/scrollbar-controller.js.map +1 -0
- package/lib/esm/webchat/devices/webchat-resizer.d.ts +9 -0
- package/lib/esm/webchat/devices/webchat-resizer.js +43 -0
- package/lib/esm/webchat/devices/webchat-resizer.js.map +1 -0
- package/lib/esm/webchat/header.d.ts +3 -0
- package/lib/esm/webchat/header.js +89 -0
- package/lib/esm/webchat/header.js.map +1 -0
- package/lib/esm/webchat/hooks.d.ts +80 -0
- package/lib/esm/webchat/hooks.js +210 -0
- package/lib/esm/webchat/hooks.js.map +1 -0
- package/lib/esm/webchat/index.d.ts +6 -0
- package/lib/esm/webchat/index.js +11 -0
- package/lib/esm/webchat/index.js.map +1 -0
- package/lib/esm/webchat/message-list.d.ts +1 -0
- package/lib/esm/webchat/message-list.js +41 -0
- package/lib/esm/webchat/message-list.js.map +1 -0
- package/lib/esm/webchat/messages-reducer.d.ts +1 -0
- package/lib/esm/webchat/messages-reducer.js +54 -0
- package/lib/esm/webchat/messages-reducer.js.map +1 -0
- package/lib/esm/webchat/replies.d.ts +1 -0
- package/lib/esm/webchat/replies.js +41 -0
- package/lib/esm/webchat/replies.js.map +1 -0
- package/lib/esm/webchat/session-view.d.ts +1 -0
- package/lib/esm/webchat/session-view.js +119 -0
- package/lib/esm/webchat/session-view.js.map +1 -0
- package/lib/esm/webchat/use-storage-state-hook.d.ts +1 -0
- package/lib/esm/webchat/use-storage-state-hook.js +28 -0
- package/lib/esm/webchat/use-storage-state-hook.js.map +1 -0
- package/lib/esm/webchat/webchat-dev.d.ts +7 -0
- package/lib/esm/webchat/webchat-dev.js +60 -0
- package/lib/esm/webchat/webchat-dev.js.map +1 -0
- package/lib/esm/webchat/webchat-reducer.d.ts +1 -0
- package/lib/esm/webchat/webchat-reducer.js +44 -0
- package/lib/esm/webchat/webchat-reducer.js.map +1 -0
- package/lib/esm/webchat/webchat.d.ts +3 -0
- package/lib/esm/webchat/webchat.js +699 -0
- package/lib/esm/webchat/webchat.js.map +1 -0
- package/lib/esm/webchat/webview.d.ts +2 -0
- package/lib/esm/webchat/webview.js +86 -0
- package/lib/esm/webchat/webview.js.map +1 -0
- package/lib/esm/webchat-app.d.ts +98 -0
- package/lib/esm/webchat-app.js +265 -0
- package/lib/esm/webchat-app.js.map +1 -0
- package/lib/esm/webchat.template.html +37 -0
- package/lib/esm/webview-app.d.ts +7 -0
- package/lib/esm/webview-app.js +98 -0
- package/lib/esm/webview-app.js.map +1 -0
- package/lib/esm/webview.template.html +39 -0
- package/package.json +27 -20
- package/src/components/audio.jsx +2 -0
- package/src/components/document.jsx +2 -0
- package/src/components/image.jsx +2 -0
- package/src/components/location.jsx +2 -2
- package/src/components/pic.jsx +3 -1
- package/src/components/video.jsx +2 -0
- package/src/index.js +1 -1
- package/src/msg-to-botonic.jsx +1 -1
- package/src/util/environment.js +31 -2
- package/src/{webview.jsx → webview-app.tsx} +7 -1
- package/lib/app.js +0 -19
- package/lib/app.js.map +0 -1
- package/lib/botonic-tester.js +0 -224
- package/lib/botonic-tester.js.map +0 -1
- package/lib/components/audio.js +0 -48
- package/lib/components/audio.js.map +0 -1
- package/lib/components/button.js +0 -224
- package/lib/components/button.js.map +0 -1
- package/lib/components/buttons-disabler.js +0 -133
- package/lib/components/buttons-disabler.js.map +0 -1
- package/lib/components/carousel.js +0 -194
- package/lib/components/carousel.js.map +0 -1
- package/lib/components/components.js.map +0 -1
- package/lib/components/custom-message.js +0 -131
- package/lib/components/custom-message.js.map +0 -1
- package/lib/components/document.js +0 -76
- package/lib/components/document.js.map +0 -1
- package/lib/components/element.js +0 -69
- package/lib/components/element.js.map +0 -1
- package/lib/components/handoff.js +0 -69
- package/lib/components/handoff.js.map +0 -1
- package/lib/components/image.js +0 -91
- package/lib/components/image.js.map +0 -1
- package/lib/components/index.d.ts +0 -228
- package/lib/components/index.js +0 -193
- package/lib/components/index.js.map +0 -1
- package/lib/components/location.js +0 -69
- package/lib/components/location.js.map +0 -1
- package/lib/components/markdown.js +0 -108
- package/lib/components/markdown.js.map +0 -1
- package/lib/components/message-template.js +0 -36
- package/lib/components/message-template.js.map +0 -1
- package/lib/components/message.js +0 -351
- package/lib/components/message.js.map +0 -1
- package/lib/components/multichannel/facebook/facebook.js +0 -96
- package/lib/components/multichannel/facebook/facebook.js.map +0 -1
- package/lib/components/multichannel/index.d.ts +0 -65
- package/lib/components/multichannel/index.js +0 -46
- package/lib/components/multichannel/index.js.map +0 -1
- package/lib/components/multichannel/multichannel-button.js +0 -119
- package/lib/components/multichannel/multichannel-button.js.map +0 -1
- package/lib/components/multichannel/multichannel-carousel.js +0 -143
- package/lib/components/multichannel/multichannel-carousel.js.map +0 -1
- package/lib/components/multichannel/multichannel-context.js +0 -24
- package/lib/components/multichannel/multichannel-context.js.map +0 -1
- package/lib/components/multichannel/multichannel-reply.js +0 -46
- package/lib/components/multichannel/multichannel-reply.js.map +0 -1
- package/lib/components/multichannel/multichannel-text.js +0 -222
- package/lib/components/multichannel/multichannel-text.js.map +0 -1
- package/lib/components/multichannel/multichannel-utils.js +0 -126
- package/lib/components/multichannel/multichannel-utils.js.map +0 -1
- package/lib/components/multichannel/multichannel.js +0 -111
- package/lib/components/multichannel/multichannel.js.map +0 -1
- package/lib/components/pic.js +0 -50
- package/lib/components/pic.js.map +0 -1
- package/lib/components/raw.js +0 -70
- package/lib/components/raw.js.map +0 -1
- package/lib/components/reply.js +0 -107
- package/lib/components/reply.js.map +0 -1
- package/lib/components/share-button.js +0 -36
- package/lib/components/share-button.js.map +0 -1
- package/lib/components/subtitle.js +0 -54
- package/lib/components/subtitle.js.map +0 -1
- package/lib/components/text.js +0 -80
- package/lib/components/text.js.map +0 -1
- package/lib/components/timestamps.js +0 -69
- package/lib/components/timestamps.js.map +0 -1
- package/lib/components/title.js +0 -52
- package/lib/components/title.js.map +0 -1
- package/lib/components/video.js +0 -51
- package/lib/components/video.js.map +0 -1
- package/lib/components/webchat-settings.js +0 -118
- package/lib/components/webchat-settings.js.map +0 -1
- package/lib/components/whatsapp-template.js +0 -53
- package/lib/components/whatsapp-template.js.map +0 -1
- package/lib/constants.js +0 -203
- package/lib/constants.js.map +0 -1
- package/lib/contexts.js +0 -57
- package/lib/contexts.js.map +0 -1
- package/lib/dev-app.js +0 -241
- package/lib/dev-app.js.map +0 -1
- package/lib/index.d.ts +0 -238
- package/lib/index.js +0 -131
- package/lib/index.js.map +0 -1
- package/lib/message-utils.js +0 -149
- package/lib/message-utils.js.map +0 -1
- package/lib/msg-to-botonic.js +0 -199
- package/lib/msg-to-botonic.js.map +0 -1
- package/lib/node-app.js +0 -97
- package/lib/node-app.js.map +0 -1
- package/lib/react-bot.js +0 -167
- package/lib/react-bot.js.map +0 -1
- package/lib/util/dom.js +0 -84
- package/lib/util/dom.js.map +0 -1
- package/lib/util/environment.js +0 -42
- package/lib/util/environment.js.map +0 -1
- package/lib/util/error-boundary.js +0 -105
- package/lib/util/error-boundary.js.map +0 -1
- package/lib/util/index.d.ts +0 -9
- package/lib/util/index.js +0 -2
- package/lib/util/index.js.map +0 -1
- package/lib/util/logs.js +0 -28
- package/lib/util/logs.js.map +0 -1
- package/lib/util/objects.js +0 -60
- package/lib/util/objects.js.map +0 -1
- package/lib/util/react.js +0 -75
- package/lib/util/react.js.map +0 -1
- package/lib/util/regexs.js +0 -31
- package/lib/util/regexs.js.map +0 -1
- package/lib/util/webchat.js +0 -92
- package/lib/util/webchat.js.map +0 -1
- package/lib/webchat/actions.js +0 -53
- package/lib/webchat/actions.js.map +0 -1
- package/lib/webchat/components/attachment.js +0 -68
- package/lib/webchat/components/attachment.js.map +0 -1
- package/lib/webchat/components/common.js +0 -29
- package/lib/webchat/components/common.js.map +0 -1
- package/lib/webchat/components/conditional-animation.js +0 -42
- package/lib/webchat/components/conditional-animation.js.map +0 -1
- package/lib/webchat/components/emoji-picker.js +0 -89
- package/lib/webchat/components/emoji-picker.js.map +0 -1
- package/lib/webchat/components/persistent-menu.js +0 -104
- package/lib/webchat/components/persistent-menu.js.map +0 -1
- package/lib/webchat/components/send-button.js +0 -45
- package/lib/webchat/components/send-button.js.map +0 -1
- package/lib/webchat/components/styled-scrollbar.js +0 -55
- package/lib/webchat/components/styled-scrollbar.js.map +0 -1
- package/lib/webchat/components/typing-indicator.js +0 -27
- package/lib/webchat/components/typing-indicator.js.map +0 -1
- package/lib/webchat/devices/device-adapter.js +0 -82
- package/lib/webchat/devices/device-adapter.js.map +0 -1
- package/lib/webchat/devices/index.js +0 -32
- package/lib/webchat/devices/index.js.map +0 -1
- package/lib/webchat/devices/scrollbar-controller.js +0 -152
- package/lib/webchat/devices/scrollbar-controller.js.map +0 -1
- package/lib/webchat/devices/webchat-resizer.js +0 -76
- package/lib/webchat/devices/webchat-resizer.js.map +0 -1
- package/lib/webchat/header.js +0 -116
- package/lib/webchat/header.js.map +0 -1
- package/lib/webchat/hooks.js +0 -359
- package/lib/webchat/hooks.js.map +0 -1
- package/lib/webchat/index.d.ts +0 -62
- package/lib/webchat/index.js +0 -32
- package/lib/webchat/index.js.map +0 -1
- package/lib/webchat/message-list.js +0 -88
- package/lib/webchat/message-list.js.map +0 -1
- package/lib/webchat/messages-reducer.js +0 -93
- package/lib/webchat/messages-reducer.js.map +0 -1
- package/lib/webchat/replies.js +0 -78
- package/lib/webchat/replies.js.map +0 -1
- package/lib/webchat/session-view.js +0 -106
- package/lib/webchat/session-view.js.map +0 -1
- package/lib/webchat/use-storage-state-hook.js +0 -60
- package/lib/webchat/use-storage-state-hook.js.map +0 -1
- package/lib/webchat/webchat-dev.js +0 -109
- package/lib/webchat/webchat-dev.js.map +0 -1
- package/lib/webchat/webchat-reducer.js +0 -108
- package/lib/webchat/webchat-reducer.js.map +0 -1
- package/lib/webchat/webchat.js +0 -1108
- package/lib/webchat/webchat.js.map +0 -1
- package/lib/webchat/webview.js +0 -122
- package/lib/webchat/webview.js.map +0 -1
- package/lib/webchat-app.js +0 -660
- package/lib/webchat-app.js.map +0 -1
- package/lib/webview.js +0 -231
- package/lib/webview.js.map +0 -1
- /package/lib/{assets → cjs/assets}/attachment-icon.svg +0 -0
- /package/lib/{assets → cjs/assets}/audio.svg +0 -0
- /package/lib/{assets → cjs/assets}/botonic_react_logo100x100.png +0 -0
- /package/lib/{assets → cjs/assets}/document.svg +0 -0
- /package/lib/{assets → cjs/assets}/emojiButton.svg +0 -0
- /package/lib/{assets → cjs/assets}/image.svg +0 -0
- /package/lib/{assets → cjs/assets}/leftArrow.svg +0 -0
- /package/lib/{assets → cjs/assets}/menuButton.svg +0 -0
- /package/lib/{assets → cjs/assets}/rightArrow.svg +0 -0
- /package/lib/{assets → cjs/assets}/send-button.svg +0 -0
- /package/lib/{assets → cjs/assets}/video.svg +0 -0
- /package/lib/{webchat → cjs/webchat}/components/styled-scrollbar.scss +0 -0
- /package/lib/{webchat → cjs/webchat}/components/typing-indicator.scss +0 -0
- /package/lib/{webchat.template.html → cjs/webchat.template.html} +0 -0
- /package/lib/{webview.template.html → cjs/webview.template.html} +0 -0
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import { INPUT, isMobile, params2queryString } from '@botonic/core';
|
|
2
|
+
import { motion } from 'framer-motion';
|
|
3
|
+
import merge from 'lodash.merge';
|
|
4
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
|
5
|
+
import Textarea from 'react-textarea-autosize';
|
|
6
|
+
import styled, { StyleSheetManager } from 'styled-components';
|
|
7
|
+
import { useAsyncEffect } from 'use-async-effect';
|
|
8
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
+
import { Audio, Document, Image, Text, Video } from '../components';
|
|
10
|
+
import { Handoff } from '../components/handoff';
|
|
11
|
+
import { normalizeWebchatSettings } from '../components/webchat-settings';
|
|
12
|
+
import { COLORS, MAX_ALLOWED_SIZE_MB, ROLES, SENDERS, WEBCHAT, } from '../constants';
|
|
13
|
+
import { RequestContext, WebchatContext } from '../contexts';
|
|
14
|
+
import { getFullMimeWhitelist, getMediaType, isAllowedSize, isAudio, isDocument, isImage, isMedia, isText, isVideo, readDataURL, } from '../message-utils';
|
|
15
|
+
import { msgToBotonic } from '../msg-to-botonic';
|
|
16
|
+
import { scrollToBottom } from '../util/dom';
|
|
17
|
+
import { isDev, resolveImage } from '../util/environment';
|
|
18
|
+
import { deserializeRegex, stringifyWithRegexs } from '../util/regexs';
|
|
19
|
+
import { _getThemeProperty, getServerErrorMessage, initSession, shouldKeepSessionOnReload, } from '../util/webchat';
|
|
20
|
+
import { Attachment } from './components/attachment';
|
|
21
|
+
import { EmojiPicker, OpenedEmojiPicker } from './components/emoji-picker';
|
|
22
|
+
import { OpenedPersistentMenu, PersistentMenu, } from './components/persistent-menu';
|
|
23
|
+
import { SendButton } from './components/send-button';
|
|
24
|
+
import { TypingIndicator } from './components/typing-indicator';
|
|
25
|
+
import { DeviceAdapter } from './devices/device-adapter';
|
|
26
|
+
import { StyledWebchatHeader } from './header';
|
|
27
|
+
import { useComponentWillMount, usePrevious, useTyping, useWebchat, } from './hooks';
|
|
28
|
+
import { WebchatMessageList } from './message-list';
|
|
29
|
+
import { WebchatReplies } from './replies';
|
|
30
|
+
import { useStorageState } from './use-storage-state-hook';
|
|
31
|
+
import { WebviewContainer } from './webview';
|
|
32
|
+
export const getParsedAction = botonicAction => {
|
|
33
|
+
const splittedAction = botonicAction.split('create_case:');
|
|
34
|
+
if (splittedAction.length <= 1)
|
|
35
|
+
return undefined;
|
|
36
|
+
return JSON.parse(splittedAction[1]);
|
|
37
|
+
};
|
|
38
|
+
const StyledWebchat = styled.div `
|
|
39
|
+
position: fixed;
|
|
40
|
+
right: 20px;
|
|
41
|
+
bottom: 20px;
|
|
42
|
+
width: ${props => props.width}px;
|
|
43
|
+
height: ${props => props.height}px;
|
|
44
|
+
margin: auto;
|
|
45
|
+
background-color: ${COLORS.SOLID_WHITE};
|
|
46
|
+
border-radius: 10px;
|
|
47
|
+
box-shadow: ${COLORS.SOLID_BLACK_ALPHA_0_2} 0px 0px 12px;
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-direction: column;
|
|
50
|
+
`;
|
|
51
|
+
const StyledTriggerButton = styled.div `
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
position: fixed;
|
|
54
|
+
background: ${COLORS.SOLID_WHITE};
|
|
55
|
+
border-radius: 50%;
|
|
56
|
+
display: flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
width: 65px;
|
|
61
|
+
height: 65px;
|
|
62
|
+
bottom: 20px;
|
|
63
|
+
right: 10px;
|
|
64
|
+
padding: 8px;
|
|
65
|
+
`;
|
|
66
|
+
const UserInputContainer = styled.div `
|
|
67
|
+
min-height: 52px;
|
|
68
|
+
position: relative;
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: flex-start;
|
|
72
|
+
gap: 16px;
|
|
73
|
+
padding: 0px 16px;
|
|
74
|
+
z-index: 1;
|
|
75
|
+
border-top: 1px solid ${COLORS.SOLID_BLACK_ALPHA_0_5};
|
|
76
|
+
`;
|
|
77
|
+
const TextAreaContainer = styled.div `
|
|
78
|
+
display: flex;
|
|
79
|
+
flex: 1 1 auto;
|
|
80
|
+
align-items: center;
|
|
81
|
+
`;
|
|
82
|
+
const TriggerImage = styled.img `
|
|
83
|
+
max-width: 100%;
|
|
84
|
+
max-height: 100%;
|
|
85
|
+
`;
|
|
86
|
+
const ErrorMessageContainer = styled.div `
|
|
87
|
+
position: relative;
|
|
88
|
+
display: flex;
|
|
89
|
+
z-index: 1;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
width: 100%;
|
|
92
|
+
`;
|
|
93
|
+
const ErrorMessage = styled.div `
|
|
94
|
+
position: absolute;
|
|
95
|
+
top: 10px;
|
|
96
|
+
font-size: 14px;
|
|
97
|
+
line-height: 20px;
|
|
98
|
+
padding: 4px 11px;
|
|
99
|
+
display: flex;
|
|
100
|
+
background-color: ${COLORS.ERROR_RED};
|
|
101
|
+
color: ${COLORS.CONCRETE_WHITE};
|
|
102
|
+
border-radius: 5px;
|
|
103
|
+
align-items: center;
|
|
104
|
+
justify-content: center;
|
|
105
|
+
font-family: ${WEBCHAT.DEFAULTS.FONT_FAMILY};
|
|
106
|
+
`;
|
|
107
|
+
const DarkBackgroundMenu = styled.div `
|
|
108
|
+
background: ${COLORS.SOLID_BLACK};
|
|
109
|
+
opacity: 0.3;
|
|
110
|
+
z-index: 1;
|
|
111
|
+
right: 0;
|
|
112
|
+
bottom: 0;
|
|
113
|
+
border-radius: 10px;
|
|
114
|
+
position: absolute;
|
|
115
|
+
width: 100%;
|
|
116
|
+
height: 100%;
|
|
117
|
+
`;
|
|
118
|
+
// eslint-disable-next-line complexity
|
|
119
|
+
export const Webchat = forwardRef((props, ref) => {
|
|
120
|
+
const { webchatState, addMessage, addMessageComponent, updateMessage, updateReplies, updateLatestInput, updateTyping, updateWebview, updateSession, updateLastRoutePath, updateHandoff, updateTheme, updateDevSettings, toggleWebchat, toggleEmojiPicker, togglePersistentMenu, toggleCoverComponent, doRenderCustomComponent, setError, setOnline, clearMessages, openWebviewT, closeWebviewT, updateLastMessageDate, setCurrentAttachment,
|
|
121
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
122
|
+
} = props.webchatHooks || useWebchat();
|
|
123
|
+
const firstUpdate = useRef(true);
|
|
124
|
+
const isOnline = () => webchatState.online;
|
|
125
|
+
const currentDateString = () => new Date().toISOString();
|
|
126
|
+
const theme = merge(webchatState.theme, props.theme);
|
|
127
|
+
const { initialSession, initialDevSettings, onStateChange } = props;
|
|
128
|
+
const getThemeProperty = _getThemeProperty(theme);
|
|
129
|
+
const [customComponent, setCustomComponent] = useState(null);
|
|
130
|
+
const storage = props.storage;
|
|
131
|
+
const storageKey = typeof props.storageKey === 'function'
|
|
132
|
+
? props.storageKey()
|
|
133
|
+
: props.storageKey;
|
|
134
|
+
const [botonicState, saveState] = useStorageState(storage, storageKey);
|
|
135
|
+
const host = props.host || document.body;
|
|
136
|
+
const deviceAdapter = new DeviceAdapter();
|
|
137
|
+
const saveWebchatState = webchatState => {
|
|
138
|
+
storage &&
|
|
139
|
+
saveState(JSON.parse(stringifyWithRegexs({
|
|
140
|
+
messages: webchatState.messagesJSON,
|
|
141
|
+
session: webchatState.session,
|
|
142
|
+
lastRoutePath: webchatState.lastRoutePath,
|
|
143
|
+
devSettings: webchatState.devSettings,
|
|
144
|
+
lastMessageUpdate: webchatState.lastMessageUpdate,
|
|
145
|
+
themeUpdates: webchatState.themeUpdates,
|
|
146
|
+
})));
|
|
147
|
+
};
|
|
148
|
+
const handleAttachment = event => {
|
|
149
|
+
if (!isAllowedSize(event.target.files[0].size)) {
|
|
150
|
+
throw new Error(`The file is too large. A maximum of ${MAX_ALLOWED_SIZE_MB}MB is allowed.`);
|
|
151
|
+
}
|
|
152
|
+
setCurrentAttachment({
|
|
153
|
+
fileName: event.target.files[0].name,
|
|
154
|
+
file: event.target.files[0],
|
|
155
|
+
attachmentType: getMediaType(event.target.files[0].type),
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (webchatState.currentAttachment)
|
|
160
|
+
sendAttachment(webchatState.currentAttachment);
|
|
161
|
+
}, [webchatState.currentAttachment]);
|
|
162
|
+
const sendUserInput = async (input) => {
|
|
163
|
+
props.onUserInput &&
|
|
164
|
+
props.onUserInput({
|
|
165
|
+
user: webchatState.session.user,
|
|
166
|
+
input: input,
|
|
167
|
+
session: webchatState.session,
|
|
168
|
+
lastRoutePath: webchatState.lastRoutePath,
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const sendChatEvent = async (chatEvent) => {
|
|
172
|
+
const chatEventInput = {
|
|
173
|
+
id: uuidv4(),
|
|
174
|
+
type: INPUT.CHAT_EVENT,
|
|
175
|
+
data: chatEvent,
|
|
176
|
+
};
|
|
177
|
+
props.onUserInput &&
|
|
178
|
+
props.onUserInput({
|
|
179
|
+
user: webchatState.session.user,
|
|
180
|
+
input: chatEventInput,
|
|
181
|
+
session: webchatState.session,
|
|
182
|
+
lastRoutePath: webchatState.lastRoutePath,
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
// Load styles stored in window._botonicInsertStyles by Webpack
|
|
186
|
+
useComponentWillMount(() => {
|
|
187
|
+
if (window._botonicInsertStyles && window._botonicInsertStyles.length) {
|
|
188
|
+
for (const botonicStyle of window._botonicInsertStyles) {
|
|
189
|
+
// Injecting styles at head is needed even if we use shadowDOM
|
|
190
|
+
// as some dependencies like simplebar rely on creating ephemeral elements
|
|
191
|
+
// on document.body and assume styles will be available globally
|
|
192
|
+
document.head.appendChild(botonicStyle);
|
|
193
|
+
// injecting styles in host node too so that shadowDOM works
|
|
194
|
+
if (props.shadowDOM)
|
|
195
|
+
host.appendChild(botonicStyle.cloneNode(true));
|
|
196
|
+
}
|
|
197
|
+
delete window._botonicInsertStyles;
|
|
198
|
+
}
|
|
199
|
+
if (props.shadowDOM) {
|
|
200
|
+
// emoji-picker-react injects styles in head, so we need to
|
|
201
|
+
// re-inject them in our host node to make it work with shadowDOM
|
|
202
|
+
for (const style of document.querySelectorAll('style')) {
|
|
203
|
+
if (style.textContent &&
|
|
204
|
+
style.textContent.includes('emoji-picker-react'))
|
|
205
|
+
host.appendChild(style.cloneNode(true));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
// Load initial state from storage
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
let { messages, session, lastRoutePath, devSettings, lastMessageUpdate, themeUpdates, } = botonicState || {};
|
|
212
|
+
session = initSession(session);
|
|
213
|
+
updateSession(session);
|
|
214
|
+
if (shouldKeepSessionOnReload({ initialDevSettings, devSettings })) {
|
|
215
|
+
if (messages) {
|
|
216
|
+
messages.forEach(m => {
|
|
217
|
+
addMessage(m);
|
|
218
|
+
const newComponent = msgToBotonic(Object.assign(Object.assign({}, m), { delay: 0, typing: 0 }), (props.theme.message && props.theme.message.customTypes) ||
|
|
219
|
+
props.theme.customMessageTypes);
|
|
220
|
+
if (newComponent)
|
|
221
|
+
addMessageComponent(newComponent);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (initialSession)
|
|
225
|
+
updateSession(merge(initialSession, session));
|
|
226
|
+
if (lastRoutePath)
|
|
227
|
+
updateLastRoutePath(lastRoutePath);
|
|
228
|
+
}
|
|
229
|
+
else
|
|
230
|
+
updateSession(merge(initialSession, session));
|
|
231
|
+
if (devSettings)
|
|
232
|
+
updateDevSettings(devSettings);
|
|
233
|
+
else if (initialDevSettings)
|
|
234
|
+
updateDevSettings(initialDevSettings);
|
|
235
|
+
if (lastMessageUpdate)
|
|
236
|
+
updateLastMessageDate(lastMessageUpdate);
|
|
237
|
+
if (themeUpdates !== undefined)
|
|
238
|
+
updateTheme(merge(props.theme, themeUpdates), themeUpdates);
|
|
239
|
+
if (props.onInit)
|
|
240
|
+
setTimeout(() => props.onInit(), 100);
|
|
241
|
+
}, []);
|
|
242
|
+
useEffect(() => {
|
|
243
|
+
if (!webchatState.isWebchatOpen)
|
|
244
|
+
return;
|
|
245
|
+
deviceAdapter.init(host);
|
|
246
|
+
scrollToBottom({ behavior: 'auto', host });
|
|
247
|
+
}, [webchatState.isWebchatOpen]);
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
if (onStateChange && typeof onStateChange === 'function')
|
|
250
|
+
onStateChange(webchatState);
|
|
251
|
+
saveWebchatState(webchatState);
|
|
252
|
+
}, [
|
|
253
|
+
webchatState.messagesJSON,
|
|
254
|
+
webchatState.session,
|
|
255
|
+
webchatState.lastRoutePath,
|
|
256
|
+
webchatState.devSettings,
|
|
257
|
+
webchatState.lastMessageUpdate,
|
|
258
|
+
]);
|
|
259
|
+
useAsyncEffect(async () => {
|
|
260
|
+
if (!webchatState.online) {
|
|
261
|
+
setError({
|
|
262
|
+
message: getServerErrorMessage(props.server),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
if (!firstUpdate.current) {
|
|
267
|
+
setError(undefined);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}, [webchatState.online]);
|
|
271
|
+
useTyping({ webchatState, updateTyping, updateMessage, host });
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
updateTheme(merge(props.theme, theme, webchatState.themeUpdates));
|
|
274
|
+
}, [props.theme, webchatState.themeUpdates]);
|
|
275
|
+
const openWebview = (webviewComponent, params) => updateWebview(webviewComponent, params);
|
|
276
|
+
const handleSelectedEmoji = (event, emojiObject) => {
|
|
277
|
+
textArea.current.value += emojiObject.emoji;
|
|
278
|
+
textArea.current.focus();
|
|
279
|
+
};
|
|
280
|
+
const closeWebview = options => {
|
|
281
|
+
updateWebview();
|
|
282
|
+
if (userInputEnabled) {
|
|
283
|
+
textArea.current.focus();
|
|
284
|
+
}
|
|
285
|
+
if (options && options.payload) {
|
|
286
|
+
sendPayload(options.payload);
|
|
287
|
+
}
|
|
288
|
+
else if (options && options.path) {
|
|
289
|
+
let params = '';
|
|
290
|
+
if (options.params)
|
|
291
|
+
params = params2queryString(options.params);
|
|
292
|
+
sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
const handleMenu = () => {
|
|
296
|
+
togglePersistentMenu(!webchatState.isPersistentMenuOpen);
|
|
297
|
+
};
|
|
298
|
+
const handleEmojiClick = () => {
|
|
299
|
+
toggleEmojiPicker(!webchatState.isEmojiPickerOpen);
|
|
300
|
+
};
|
|
301
|
+
const persistentMenuOptions = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.persistentMenu, props.persistentMenu);
|
|
302
|
+
const darkBackgroundMenu = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.darkBackgroundMenu, false);
|
|
303
|
+
const getBlockInputs = (rule, inputData) => {
|
|
304
|
+
const processedInput = rule.preprocess
|
|
305
|
+
? rule.preprocess(inputData)
|
|
306
|
+
: inputData;
|
|
307
|
+
return rule.match.some(regex => {
|
|
308
|
+
if (typeof regex === 'string')
|
|
309
|
+
regex = deserializeRegex(regex);
|
|
310
|
+
return regex.test(processedInput);
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
const checkBlockInput = input => {
|
|
314
|
+
// if is a text we check if it is a serialized RE
|
|
315
|
+
const blockInputs = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.blockInputs, props.blockInputs);
|
|
316
|
+
if (!Array.isArray(blockInputs))
|
|
317
|
+
return false;
|
|
318
|
+
for (const rule of blockInputs) {
|
|
319
|
+
if (getBlockInputs(rule, input.data)) {
|
|
320
|
+
addMessageComponent(<Text id={input.id} from={SENDERS.user} blob={false} style={{
|
|
321
|
+
backgroundColor: COLORS.SCORPION_GRAY,
|
|
322
|
+
borderColor: COLORS.SCORPION_GRAY,
|
|
323
|
+
padding: '8px 12px',
|
|
324
|
+
}}>
|
|
325
|
+
{rule.message}
|
|
326
|
+
</Text>);
|
|
327
|
+
updateReplies(false);
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
};
|
|
333
|
+
const closeMenu = () => {
|
|
334
|
+
togglePersistentMenu(false);
|
|
335
|
+
};
|
|
336
|
+
const persistentMenu = () => {
|
|
337
|
+
return (<OpenedPersistentMenu onClick={closeMenu} options={persistentMenuOptions} borderRadius={webchatState.theme.style.borderRadius || '10px'}/>);
|
|
338
|
+
};
|
|
339
|
+
const getCoverComponent = () => {
|
|
340
|
+
return getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.coverComponent, props.coverComponent &&
|
|
341
|
+
(props.coverComponent.component || props.coverComponent));
|
|
342
|
+
};
|
|
343
|
+
const CoverComponent = getCoverComponent();
|
|
344
|
+
const closeCoverComponent = () => {
|
|
345
|
+
toggleCoverComponent(false);
|
|
346
|
+
};
|
|
347
|
+
useEffect(() => {
|
|
348
|
+
if (!CoverComponent)
|
|
349
|
+
return;
|
|
350
|
+
if (!botonicState ||
|
|
351
|
+
(botonicState.messages && botonicState.messages.length == 0))
|
|
352
|
+
toggleCoverComponent(true);
|
|
353
|
+
}, []);
|
|
354
|
+
const coverComponent = () => {
|
|
355
|
+
const coverComponentProps = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.coverComponentProps, props.coverComponent && props.coverComponent.props);
|
|
356
|
+
if (CoverComponent && webchatState.isCoverComponentOpen)
|
|
357
|
+
return (<CoverComponent closeComponent={closeCoverComponent} {...coverComponentProps}/>);
|
|
358
|
+
return null;
|
|
359
|
+
};
|
|
360
|
+
const messageComponentFromInput = input => {
|
|
361
|
+
let messageComponent = null;
|
|
362
|
+
if (isText(input)) {
|
|
363
|
+
messageComponent = (<Text id={input.id} payload={input.payload} from={SENDERS.user}>
|
|
364
|
+
{input.data}
|
|
365
|
+
</Text>);
|
|
366
|
+
}
|
|
367
|
+
else if (isMedia(input)) {
|
|
368
|
+
const temporaryDisplayUrl = URL.createObjectURL(input.data);
|
|
369
|
+
const mediaProps = {
|
|
370
|
+
id: input.id,
|
|
371
|
+
from: SENDERS.user,
|
|
372
|
+
src: temporaryDisplayUrl,
|
|
373
|
+
};
|
|
374
|
+
if (isImage(input))
|
|
375
|
+
messageComponent = <Image {...mediaProps}/>;
|
|
376
|
+
else if (isAudio(input))
|
|
377
|
+
messageComponent = <Audio {...mediaProps}/>;
|
|
378
|
+
else if (isVideo(input))
|
|
379
|
+
messageComponent = <Video {...mediaProps}/>;
|
|
380
|
+
else if (isDocument(input))
|
|
381
|
+
messageComponent = <Document {...mediaProps}/>;
|
|
382
|
+
}
|
|
383
|
+
return messageComponent;
|
|
384
|
+
};
|
|
385
|
+
const sendInput = async (input) => {
|
|
386
|
+
if (!input || Object.keys(input).length == 0)
|
|
387
|
+
return;
|
|
388
|
+
if (isText(input) && (!input.data || !input.data.trim()))
|
|
389
|
+
return; // in case trim() doesn't work in a browser we can use !/\S/.test(input.data)
|
|
390
|
+
if (isText(input) && checkBlockInput(input))
|
|
391
|
+
return;
|
|
392
|
+
if (!input.id)
|
|
393
|
+
input.id = uuidv4();
|
|
394
|
+
const messageComponent = messageComponentFromInput(input);
|
|
395
|
+
if (messageComponent)
|
|
396
|
+
addMessageComponent(messageComponent);
|
|
397
|
+
if (isMedia(input))
|
|
398
|
+
input.data = await readDataURL(input.data);
|
|
399
|
+
sendUserInput(input);
|
|
400
|
+
updateLatestInput(input);
|
|
401
|
+
isOnline() && updateLastMessageDate(currentDateString());
|
|
402
|
+
updateReplies(false);
|
|
403
|
+
togglePersistentMenu(false);
|
|
404
|
+
toggleEmojiPicker(false);
|
|
405
|
+
};
|
|
406
|
+
/* This is the public API this component exposes to its parents
|
|
407
|
+
https://stackoverflow.com/questions/37949981/call-child-method-from-parent
|
|
408
|
+
*/
|
|
409
|
+
const updateSessionWithUser = userToUpdate => updateSession(merge(webchatState.session, { user: userToUpdate }));
|
|
410
|
+
useImperativeHandle(ref, () => ({
|
|
411
|
+
addBotResponse: ({ response, session, lastRoutePath }) => {
|
|
412
|
+
updateTyping(false);
|
|
413
|
+
if (Array.isArray(response))
|
|
414
|
+
response.map(r => addMessageComponent(r));
|
|
415
|
+
else if (response)
|
|
416
|
+
addMessageComponent(response);
|
|
417
|
+
if (session) {
|
|
418
|
+
updateSession(merge(session, { user: webchatState.session.user }));
|
|
419
|
+
const action = session._botonic_action || '';
|
|
420
|
+
const handoff = action.startsWith('create_case');
|
|
421
|
+
if (handoff && isDev)
|
|
422
|
+
addMessageComponent(<Handoff />);
|
|
423
|
+
updateHandoff(handoff);
|
|
424
|
+
}
|
|
425
|
+
if (lastRoutePath)
|
|
426
|
+
updateLastRoutePath(lastRoutePath);
|
|
427
|
+
updateLastMessageDate(currentDateString());
|
|
428
|
+
},
|
|
429
|
+
setTyping: typing => updateTyping(typing),
|
|
430
|
+
addUserMessage: message => sendInput(message),
|
|
431
|
+
updateUser: updateSessionWithUser,
|
|
432
|
+
openWebchat: () => toggleWebchat(true),
|
|
433
|
+
closeWebchat: () => toggleWebchat(false),
|
|
434
|
+
toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),
|
|
435
|
+
openCoverComponent: () => toggleCoverComponent(true),
|
|
436
|
+
closeCoverComponent: () => toggleCoverComponent(false),
|
|
437
|
+
renderCustomComponent: _customComponent => {
|
|
438
|
+
setCustomComponent(_customComponent);
|
|
439
|
+
doRenderCustomComponent(true);
|
|
440
|
+
},
|
|
441
|
+
unmountCustomComponent: () => doRenderCustomComponent(false),
|
|
442
|
+
toggleCoverComponent: () => toggleCoverComponent(!webchatState.isCoverComponentOpen),
|
|
443
|
+
openWebviewApi: component => openWebviewT(component),
|
|
444
|
+
setError,
|
|
445
|
+
setOnline,
|
|
446
|
+
getMessages: () => webchatState.messagesJSON,
|
|
447
|
+
isOnline,
|
|
448
|
+
clearMessages: () => {
|
|
449
|
+
clearMessages();
|
|
450
|
+
updateReplies(false);
|
|
451
|
+
},
|
|
452
|
+
getLastMessageUpdate: () => webchatState.lastMessageUpdate,
|
|
453
|
+
updateMessageInfo: (msgId, messageInfo) => {
|
|
454
|
+
const messageToUpdate = webchatState.messagesJSON.filter(m => m.id == msgId)[0];
|
|
455
|
+
const updatedMsg = merge(messageToUpdate, messageInfo);
|
|
456
|
+
if (updatedMsg.ack === 1)
|
|
457
|
+
delete updatedMsg.unsentInput;
|
|
458
|
+
updateMessage(updatedMsg);
|
|
459
|
+
},
|
|
460
|
+
updateWebchatSettings: settings => {
|
|
461
|
+
const themeUpdates = normalizeWebchatSettings(settings);
|
|
462
|
+
updateTheme(merge(webchatState.theme, themeUpdates), themeUpdates);
|
|
463
|
+
},
|
|
464
|
+
}));
|
|
465
|
+
const resolveCase = () => {
|
|
466
|
+
updateHandoff(false);
|
|
467
|
+
updateSession(Object.assign(Object.assign({}, webchatState.session), { _botonic_action: null }));
|
|
468
|
+
};
|
|
469
|
+
const prevSession = usePrevious(webchatState.session);
|
|
470
|
+
useEffect(() => {
|
|
471
|
+
// Resume conversation after handoff
|
|
472
|
+
if (prevSession &&
|
|
473
|
+
prevSession._botonic_action &&
|
|
474
|
+
!webchatState.session._botonic_action) {
|
|
475
|
+
const action = getParsedAction(prevSession._botonic_action);
|
|
476
|
+
if (action && action.on_finish)
|
|
477
|
+
sendPayload(action.on_finish);
|
|
478
|
+
}
|
|
479
|
+
}, [webchatState.session._botonic_action]);
|
|
480
|
+
const sendText = async (text, payload) => {
|
|
481
|
+
if (!text)
|
|
482
|
+
return;
|
|
483
|
+
const input = { type: INPUT.TEXT, data: text, payload };
|
|
484
|
+
await sendInput(input);
|
|
485
|
+
};
|
|
486
|
+
const sendPayload = async (payload) => {
|
|
487
|
+
if (!payload)
|
|
488
|
+
return;
|
|
489
|
+
const input = { type: INPUT.POSTBACK, payload };
|
|
490
|
+
await sendInput(input);
|
|
491
|
+
};
|
|
492
|
+
const sendAttachment = async (attachment) => {
|
|
493
|
+
if (attachment.file) {
|
|
494
|
+
const attachmentType = getMediaType(attachment.file.type);
|
|
495
|
+
if (!attachmentType)
|
|
496
|
+
return;
|
|
497
|
+
const input = {
|
|
498
|
+
type: attachmentType,
|
|
499
|
+
data: attachment.file,
|
|
500
|
+
};
|
|
501
|
+
await sendInput(input);
|
|
502
|
+
setCurrentAttachment(undefined);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const sendTextAreaText = () => {
|
|
506
|
+
sendText(textArea.current.value);
|
|
507
|
+
textArea.current.value = '';
|
|
508
|
+
};
|
|
509
|
+
let isTyping = false;
|
|
510
|
+
let typingTimeout = null;
|
|
511
|
+
function clearTimeoutWithReset(reset) {
|
|
512
|
+
const waitTime = 20 * 1000;
|
|
513
|
+
if (typingTimeout)
|
|
514
|
+
clearTimeout(typingTimeout);
|
|
515
|
+
if (reset)
|
|
516
|
+
typingTimeout = setTimeout(stopTyping, waitTime);
|
|
517
|
+
}
|
|
518
|
+
function startTyping() {
|
|
519
|
+
isTyping = true;
|
|
520
|
+
sendChatEvent('typing_on');
|
|
521
|
+
}
|
|
522
|
+
function stopTyping() {
|
|
523
|
+
clearTimeoutWithReset(false);
|
|
524
|
+
isTyping = false;
|
|
525
|
+
sendChatEvent('typing_off');
|
|
526
|
+
}
|
|
527
|
+
const onKeyDown = event => {
|
|
528
|
+
if (event.keyCode === 13 && event.shiftKey === false) {
|
|
529
|
+
event.preventDefault();
|
|
530
|
+
sendTextAreaText();
|
|
531
|
+
stopTyping();
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
const onKeyUp = () => {
|
|
535
|
+
if (textArea.current.value === '') {
|
|
536
|
+
stopTyping();
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (!isTyping) {
|
|
540
|
+
startTyping();
|
|
541
|
+
}
|
|
542
|
+
clearTimeoutWithReset(true);
|
|
543
|
+
};
|
|
544
|
+
const webviewRequestContext = {
|
|
545
|
+
getString: stringId => props.getString(stringId, webchatState.session),
|
|
546
|
+
setLocale: locale => props.getString(locale, webchatState.session),
|
|
547
|
+
session: webchatState.session || {},
|
|
548
|
+
params: webchatState.webviewParams || {},
|
|
549
|
+
closeWebview: closeWebview,
|
|
550
|
+
defaultDelay: props.defaultDelay || 0,
|
|
551
|
+
defaultTyping: props.defaultTyping || 0,
|
|
552
|
+
};
|
|
553
|
+
useEffect(() => {
|
|
554
|
+
if (firstUpdate.current) {
|
|
555
|
+
firstUpdate.current = false;
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (webchatState.isWebchatOpen && props.onOpen)
|
|
559
|
+
props.onOpen();
|
|
560
|
+
if (!webchatState.isWebchatOpen && props.onClose && !firstUpdate.current) {
|
|
561
|
+
props.onClose();
|
|
562
|
+
toggleEmojiPicker(false);
|
|
563
|
+
togglePersistentMenu(false);
|
|
564
|
+
}
|
|
565
|
+
}, [webchatState.isWebchatOpen]);
|
|
566
|
+
const textArea = useRef();
|
|
567
|
+
const getTriggerImage = () => {
|
|
568
|
+
const triggerImage = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage, null);
|
|
569
|
+
if (triggerImage === null) {
|
|
570
|
+
webchatState.theme.triggerButtonImage = WEBCHAT.DEFAULTS.LOGO;
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
return triggerImage;
|
|
574
|
+
};
|
|
575
|
+
const triggerButtonStyle = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.triggerButtonStyle);
|
|
576
|
+
const CustomTriggerButton = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.customTrigger, undefined);
|
|
577
|
+
const triggerButton = () => {
|
|
578
|
+
if (CustomTriggerButton) {
|
|
579
|
+
return <CustomTriggerButton />;
|
|
580
|
+
}
|
|
581
|
+
return (<StyledTriggerButton role={ROLES.TRIGGER_BUTTON} style={Object.assign({}, triggerButtonStyle)}>
|
|
582
|
+
{getTriggerImage() && (<TriggerImage src={resolveImage(getTriggerImage())}/>)}
|
|
583
|
+
</StyledTriggerButton>);
|
|
584
|
+
};
|
|
585
|
+
const webchatMessageList = () => (<WebchatMessageList style={{ flex: 1 }}>
|
|
586
|
+
{webchatState.typing && <TypingIndicator />}
|
|
587
|
+
</WebchatMessageList>);
|
|
588
|
+
const webchatReplies = () => <WebchatReplies replies={webchatState.replies}/>;
|
|
589
|
+
const isUserInputEnabled = () => {
|
|
590
|
+
const isUserInputEnabled = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.enableUserInput, props.enableUserInput !== undefined ? props.enableUserInput : true);
|
|
591
|
+
return isUserInputEnabled && !webchatState.isCoverComponentOpen;
|
|
592
|
+
};
|
|
593
|
+
const userInputEnabled = isUserInputEnabled();
|
|
594
|
+
const userInputArea = () => {
|
|
595
|
+
return (userInputEnabled && (<UserInputContainer style={Object.assign({}, getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.userInputStyle))} className='user-input-container'>
|
|
596
|
+
{webchatState.isEmojiPickerOpen && (<OpenedEmojiPicker height={webchatState.theme.style.height} onEmojiClick={handleSelectedEmoji} onClick={handleEmojiClick}/>)}
|
|
597
|
+
|
|
598
|
+
<PersistentMenu onClick={handleMenu} persistentMenu={props.persistentMenu}/>
|
|
599
|
+
|
|
600
|
+
<TextAreaContainer>
|
|
601
|
+
<Textarea name='text' onFocus={() => deviceAdapter.onFocus(host)} onBlur={() => deviceAdapter.onBlur()} maxRows={4} wrap='soft' maxLength='1000' placeholder={getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.textPlaceholder, WEBCHAT.DEFAULTS.PLACEHOLDER)} autoFocus={true} inputRef={textArea} onKeyDown={e => onKeyDown(e)} onKeyUp={onKeyUp} style={Object.assign({ display: 'flex', fontSize: deviceAdapter.fontSize(14), width: '100%', border: 'none', resize: 'none', overflow: 'auto', outline: 'none', flex: '1 1 auto', padding: 10, paddingLeft: persistentMenuOptions ? 0 : 10, fontFamily: 'inherit' }, getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.userInputBoxStyle))}/>
|
|
602
|
+
</TextAreaContainer>
|
|
603
|
+
|
|
604
|
+
<EmojiPicker enableEmojiPicker={props.enableEmojiPicker} onClick={handleEmojiClick}/>
|
|
605
|
+
|
|
606
|
+
<Attachment enableAttachments={props.enableAttachments} onChange={handleAttachment} accept={getFullMimeWhitelist().join(',')}/>
|
|
607
|
+
|
|
608
|
+
<SendButton onClick={sendTextAreaText}/>
|
|
609
|
+
</UserInputContainer>));
|
|
610
|
+
};
|
|
611
|
+
const webchatWebview = () => (<RequestContext.Provider value={webviewRequestContext}>
|
|
612
|
+
<WebviewContainer style={Object.assign(Object.assign({}, getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.webviewStyle)), mobileStyle)} webview={webchatState.webview}/>
|
|
613
|
+
</RequestContext.Provider>);
|
|
614
|
+
let mobileStyle = {};
|
|
615
|
+
if (isMobile(getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.mobileBreakpoint))) {
|
|
616
|
+
mobileStyle = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.mobileStyle) || {
|
|
617
|
+
width: '100%',
|
|
618
|
+
height: '100%',
|
|
619
|
+
right: 0,
|
|
620
|
+
bottom: 0,
|
|
621
|
+
borderRadius: 0,
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
useEffect(() => {
|
|
625
|
+
// Prod mode
|
|
626
|
+
saveWebchatState(webchatState);
|
|
627
|
+
scrollToBottom({ host });
|
|
628
|
+
}, [webchatState.themeUpdates]);
|
|
629
|
+
// Only needed for dev/serve mode
|
|
630
|
+
const updateWebchatDevSettings = settings => {
|
|
631
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
632
|
+
useEffect(() => {
|
|
633
|
+
const themeUpdates = normalizeWebchatSettings(settings);
|
|
634
|
+
updateTheme(merge(webchatState.theme, themeUpdates), themeUpdates);
|
|
635
|
+
}, [webchatState.messagesJSON]);
|
|
636
|
+
};
|
|
637
|
+
const DarkenBackground = ({ component }) => {
|
|
638
|
+
return (<div>
|
|
639
|
+
{darkBackgroundMenu && (<DarkBackgroundMenu style={{
|
|
640
|
+
borderRadius: webchatState.theme.style.borderRadius,
|
|
641
|
+
}}/>)}
|
|
642
|
+
{component}
|
|
643
|
+
</div>);
|
|
644
|
+
};
|
|
645
|
+
const _renderCustomComponent = () => {
|
|
646
|
+
if (!customComponent)
|
|
647
|
+
return <></>;
|
|
648
|
+
else
|
|
649
|
+
return customComponent;
|
|
650
|
+
};
|
|
651
|
+
const WebchatComponent = (<WebchatContext.Provider value={{
|
|
652
|
+
sendText,
|
|
653
|
+
sendAttachment,
|
|
654
|
+
sendPayload,
|
|
655
|
+
sendInput,
|
|
656
|
+
openWebview,
|
|
657
|
+
resolveCase,
|
|
658
|
+
webchatState,
|
|
659
|
+
getThemeProperty,
|
|
660
|
+
addMessage,
|
|
661
|
+
toggleWebchat,
|
|
662
|
+
updateMessage,
|
|
663
|
+
updateReplies,
|
|
664
|
+
updateLatestInput,
|
|
665
|
+
updateUser: updateSessionWithUser,
|
|
666
|
+
updateWebchatDevSettings: updateWebchatDevSettings,
|
|
667
|
+
}}>
|
|
668
|
+
{!webchatState.isWebchatOpen && (<div onClick={event => {
|
|
669
|
+
toggleWebchat(true);
|
|
670
|
+
event.preventDefault();
|
|
671
|
+
}}>
|
|
672
|
+
{triggerButton()}
|
|
673
|
+
</div>)}
|
|
674
|
+
|
|
675
|
+
{webchatState.isWebchatOpen && (<StyledWebchat
|
|
676
|
+
// TODO: Distinguis between multiple instances of webchat, e.g. `${uniqueId}-botonic-webchat`
|
|
677
|
+
role={ROLES.WEBCHAT} id={WEBCHAT.DEFAULTS.ID} width={webchatState.width} height={webchatState.height} style={Object.assign(Object.assign({}, webchatState.theme.style), mobileStyle)}>
|
|
678
|
+
<StyledWebchatHeader onCloseClick={() => {
|
|
679
|
+
toggleWebchat(false);
|
|
680
|
+
}}/>
|
|
681
|
+
{webchatState.error.message && (<ErrorMessageContainer>
|
|
682
|
+
<ErrorMessage>{webchatState.error.message}</ErrorMessage>
|
|
683
|
+
</ErrorMessageContainer>)}
|
|
684
|
+
{webchatMessageList()}
|
|
685
|
+
{webchatState.replies &&
|
|
686
|
+
Object.keys(webchatState.replies).length > 0 &&
|
|
687
|
+
webchatReplies()}
|
|
688
|
+
{webchatState.isPersistentMenuOpen && (<DarkenBackground component={persistentMenu()}/>)}
|
|
689
|
+
{!webchatState.handoff && userInputArea()}
|
|
690
|
+
{webchatState.webview && webchatWebview()}
|
|
691
|
+
{webchatState.isCoverComponentOpen && coverComponent()}
|
|
692
|
+
{webchatState.isCustomComponentRendered &&
|
|
693
|
+
customComponent &&
|
|
694
|
+
_renderCustomComponent()}
|
|
695
|
+
</StyledWebchat>)}
|
|
696
|
+
</WebchatContext.Provider>);
|
|
697
|
+
return props.shadowDOM ? (<StyleSheetManager target={host}>{WebchatComponent}</StyleSheetManager>) : (WebchatComponent);
|
|
698
|
+
});
|
|
699
|
+
//# sourceMappingURL=webchat.js.map
|