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