@botpress/webchat 0.5.1 → 1.0.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/dist/App.d.ts +10 -0
- package/dist/Utils/colors.d.ts +18 -0
- package/dist/Utils/eventEmitter.d.ts +12 -0
- package/dist/Utils/index.d.ts +2 -0
- package/dist/client/MessagingClient.d.ts +27 -0
- package/dist/client/adapters/Audio.d.ts +19 -0
- package/dist/client/adapters/Card.d.ts +188 -0
- package/dist/client/adapters/Carousel.d.ts +147 -0
- package/dist/client/adapters/Choice.d.ts +45 -0
- package/dist/client/adapters/Dropdown.d.ts +46 -0
- package/dist/client/adapters/File.d.ts +19 -0
- package/dist/client/adapters/Image.d.ts +19 -0
- package/dist/client/adapters/Location.d.ts +27 -0
- package/dist/client/adapters/Message.d.ts +433 -0
- package/dist/client/adapters/Text.d.ts +20 -0
- package/dist/client/adapters/Utils.d.ts +5 -0
- package/dist/client/adapters/Video.d.ts +19 -0
- package/dist/client/adapters/Voice.d.ts +15 -0
- package/dist/client/adapters/index.d.ts +12 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/components/Avatar.d.ts +6 -0
- package/dist/components/Block.d.ts +4 -0
- package/dist/components/Composer.d.ts +12 -14
- package/dist/components/Container.d.ts +2 -12
- package/dist/components/Header.d.ts +36 -26
- package/dist/components/LoadingIndicator.d.ts +2 -0
- package/dist/components/Message.d.ts +7 -0
- package/dist/components/MessageList.d.ts +2 -0
- package/dist/components/Modal.d.ts +17 -0
- package/dist/components/RestartConversation.d.ts +5 -0
- package/dist/components/Webchat.d.ts +6 -0
- package/dist/components/dev-tools/DevTools.d.ts +1 -0
- package/dist/components/dev-tools/configuration.d.ts +2 -0
- package/dist/components/dev-tools/helpers.d.ts +5 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/components/renderers/Audio.d.ts +3 -0
- package/dist/components/renderers/Bubble.d.ts +5 -0
- package/dist/components/renderers/Button.d.ts +4 -0
- package/dist/components/renderers/Carousel.d.ts +3 -0
- package/dist/components/renderers/Column.d.ts +5 -0
- package/dist/components/renderers/Dropdown.d.ts +5 -0
- package/dist/components/renderers/File.d.ts +3 -0
- package/dist/components/renderers/Image.d.ts +3 -0
- package/dist/components/renderers/Location.d.ts +3 -0
- package/dist/components/renderers/Row.d.ts +5 -0
- package/dist/components/renderers/Text.d.ts +4 -0
- package/dist/components/renderers/Video.d.ts +3 -0
- package/dist/components/renderers/index.d.ts +2 -0
- package/dist/contexts/ComposerContext.d.ts +8 -0
- package/dist/contexts/MessageContext.d.ts +8 -0
- package/dist/contexts/ModalContext.d.ts +14 -0
- package/dist/contexts/WebchatContext.d.ts +56 -0
- package/dist/contexts/index.d.ts +4 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useImageSize.d.ts +2 -0
- package/dist/hooks/useRefresh.d.ts +10 -0
- package/dist/hooks/useWebchatStore.d.ts +30 -0
- package/dist/index.d.ts +3 -17
- package/dist/index.js +43569 -48
- package/dist/index.umd.cjs +702 -0
- package/dist/main.d.ts +11 -13
- package/dist/providers/ModalProvider.d.ts +8 -0
- package/dist/providers/WebchatProvider.d.ts +13 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/theme.d.ts +3371 -0
- package/dist/services/clipboard.d.ts +1 -0
- package/dist/services/images.d.ts +2 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/toast.d.ts +17 -0
- package/dist/themes/dawn.d.ts +2 -0
- package/dist/themes/duskTheme.d.ts +2 -0
- package/dist/themes/eggplant.d.ts +2 -0
- package/dist/themes/galaxy.d.ts +2 -0
- package/dist/themes/index.d.ts +6 -0
- package/dist/themes/midnight.d.ts +2 -0
- package/dist/themes/prism.d.ts +2 -0
- package/dist/twind.config.d.ts +9 -0
- package/dist/types/block-type.d.ts +93 -0
- package/dist/types/image.d.ts +11 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +61 -49
- package/README.md +0 -41
- package/assets/fonts/roboto/roboto.woff2 +0 -0
- package/assets/fonts/roboto/roboto500.woff2 +0 -0
- package/assets/fonts/roboto.css +0 -128
- package/assets/notification.mp3 +0 -0
- package/dist/components/Composer.js +0 -118
- package/dist/components/Container.js +0 -62
- package/dist/components/ConversationList.d.ts +0 -10
- package/dist/components/ConversationList.js +0 -41
- package/dist/components/Footer.d.ts +0 -3
- package/dist/components/Footer.js +0 -21
- package/dist/components/Header.js +0 -181
- package/dist/components/VoiceRecorder.d.ts +0 -10
- package/dist/components/VoiceRecorder.js +0 -137
- package/dist/components/common/Avatar/index.d.ts +0 -9
- package/dist/components/common/Avatar/index.js +0 -13
- package/dist/components/common/BotInfo/index.d.ts +0 -10
- package/dist/components/common/BotInfo/index.js +0 -107
- package/dist/components/common/BotInfo/style.scss +0 -88
- package/dist/components/common/ConfirmDialog/index.d.ts +0 -11
- package/dist/components/common/ConfirmDialog/index.js +0 -78
- package/dist/components/common/ConfirmDialog/style.module.scss +0 -48
- package/dist/components/common/Dialog/index.d.ts +0 -17
- package/dist/components/common/Dialog/index.js +0 -57
- package/dist/components/common/Dialog/style.module.scss +0 -29
- package/dist/components/common/ToolTip/index.d.ts +0 -10
- package/dist/components/common/ToolTip/index.js +0 -163
- package/dist/components/common/ToolTip/style.module.scss +0 -108
- package/dist/components/common/ToolTip/utils.d.ts +0 -15
- package/dist/components/common/ToolTip/utils.js +0 -78
- package/dist/components/common/variables.scss +0 -38
- package/dist/components/messages/InlineFeedback.d.ts +0 -11
- package/dist/components/messages/InlineFeedback.js +0 -56
- package/dist/components/messages/Message.d.ts +0 -11
- package/dist/components/messages/Message.js +0 -106
- package/dist/components/messages/MessageGroup.d.ts +0 -23
- package/dist/components/messages/MessageGroup.js +0 -63
- package/dist/components/messages/MessageList.d.ts +0 -10
- package/dist/components/messages/MessageList.js +0 -148
- package/dist/core/api.d.ts +0 -23
- package/dist/core/api.js +0 -117
- package/dist/core/constants.d.ts +0 -14
- package/dist/core/constants.js +0 -29
- package/dist/core/socket.d.ts +0 -14
- package/dist/core/socket.js +0 -57
- package/dist/declaration.d.ts +0 -2
- package/dist/declaration.js +0 -1
- package/dist/fonts/roboto.d.ts +0 -4
- package/dist/fonts/roboto.js +0 -9
- package/dist/globals.d.ts +0 -7
- package/dist/globals.js +0 -2
- package/dist/icons/Add.d.ts +0 -6
- package/dist/icons/Add.js +0 -10
- package/dist/icons/Cancel.d.ts +0 -5
- package/dist/icons/Cancel.js +0 -10
- package/dist/icons/Chat.d.ts +0 -6
- package/dist/icons/Chat.js +0 -9
- package/dist/icons/Close.d.ts +0 -3
- package/dist/icons/Close.js +0 -10
- package/dist/icons/Delete.d.ts +0 -3
- package/dist/icons/Delete.js +0 -11
- package/dist/icons/Download.d.ts +0 -3
- package/dist/icons/Download.js +0 -10
- package/dist/icons/Email.d.ts +0 -3
- package/dist/icons/Email.js +0 -8
- package/dist/icons/Information.d.ts +0 -3
- package/dist/icons/Information.js +0 -12
- package/dist/icons/List.d.ts +0 -3
- package/dist/icons/List.js +0 -15
- package/dist/icons/Microphone.d.ts +0 -5
- package/dist/icons/Microphone.js +0 -12
- package/dist/icons/Phone.d.ts +0 -3
- package/dist/icons/Phone.js +0 -8
- package/dist/icons/Reload.d.ts +0 -3
- package/dist/icons/Reload.js +0 -10
- package/dist/icons/ThumbsDown.d.ts +0 -3
- package/dist/icons/ThumbsDown.js +0 -11
- package/dist/icons/ThumbsUp.d.ts +0 -3
- package/dist/icons/ThumbsUp.js +0 -11
- package/dist/icons/Website.d.ts +0 -3
- package/dist/icons/Website.js +0 -8
- package/dist/main.js +0 -336
- package/dist/store/composer.d.ts +0 -17
- package/dist/store/composer.js +0 -98
- package/dist/store/index.d.ts +0 -89
- package/dist/store/index.js +0 -604
- package/dist/store/view.d.ts +0 -61
- package/dist/store/view.js +0 -365
- package/dist/translations/ar.json +0 -30
- package/dist/translations/de.json +0 -32
- package/dist/translations/en.json +0 -40
- package/dist/translations/es.json +0 -19
- package/dist/translations/fr.json +0 -40
- package/dist/translations/index.d.ts +0 -9
- package/dist/translations/index.js +0 -95
- package/dist/translations/it.json +0 -38
- package/dist/translations/pt.json +0 -19
- package/dist/translations/ru.json +0 -24
- package/dist/translations/uk.json +0 -24
- package/dist/typings.d.ts +0 -410
- package/dist/typings.js +0 -2
- package/dist/utils/analytics.d.ts +0 -5
- package/dist/utils/analytics.js +0 -37
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +0 -27
- package/dist/utils/storage.d.ts +0 -16
- package/dist/utils/storage.js +0 -129
- package/dist/utils/webchatEvents.d.ts +0 -2
- package/dist/utils/webchatEvents.js +0 -14
package/dist/main.js
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.DEFAULT_TYPING_DELAY = void 0;
|
|
35
|
-
const classnames_1 = __importDefault(require("classnames"));
|
|
36
|
-
const debounce_1 = __importDefault(require("lodash/debounce"));
|
|
37
|
-
const mobx_1 = require("mobx");
|
|
38
|
-
const mobx_react_1 = require("mobx-react");
|
|
39
|
-
const query_string_1 = __importDefault(require("query-string"));
|
|
40
|
-
const react_1 = __importDefault(require("react"));
|
|
41
|
-
const react_intl_1 = require("react-intl");
|
|
42
|
-
const Container_1 = __importDefault(require("./components/Container"));
|
|
43
|
-
const constants_1 = __importDefault(require("./core/constants"));
|
|
44
|
-
const socket_1 = __importDefault(require("./core/socket"));
|
|
45
|
-
const Chat_1 = __importDefault(require("./icons/Chat"));
|
|
46
|
-
const utils_1 = require("./utils");
|
|
47
|
-
const analytics_1 = require("./utils/analytics");
|
|
48
|
-
const webchatEvents_1 = require("./utils/webchatEvents");
|
|
49
|
-
exports.DEFAULT_TYPING_DELAY = 1000;
|
|
50
|
-
class Web extends react_1.default.Component {
|
|
51
|
-
constructor(props) {
|
|
52
|
-
super(props);
|
|
53
|
-
this.hasBeenInitialized = false;
|
|
54
|
-
this.isCurrentConversation = (event) => {
|
|
55
|
-
return this.props.currentConversationId === event.conversationId;
|
|
56
|
-
};
|
|
57
|
-
this.handleKeyDown = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
var _a;
|
|
59
|
-
if (!((_a = this.props.config) === null || _a === void 0 ? void 0 : _a.closeOnEscape)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (e.key === 'Escape') {
|
|
63
|
-
this.props.hideChat();
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
this.handleIframeApi = ({ data }) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
switch (data.action) {
|
|
68
|
-
case 'configure':
|
|
69
|
-
return this.props.updateConfig(Object.assign({}, constants_1.default.DEFAULT_CONFIG, data.payload));
|
|
70
|
-
case 'mergeConfig':
|
|
71
|
-
this.props.mergeConfig(data.payload);
|
|
72
|
-
const oldUserId = this.socket.socket.userId;
|
|
73
|
-
yield this.socket.reload(data.payload);
|
|
74
|
-
if (this.socket.socket.userId !== oldUserId) {
|
|
75
|
-
this.props.resetConversation();
|
|
76
|
-
yield this.props.initializeChat();
|
|
77
|
-
}
|
|
78
|
-
return;
|
|
79
|
-
case 'sendPayload':
|
|
80
|
-
return this.props.sendData(data.payload);
|
|
81
|
-
case 'event':
|
|
82
|
-
const { type, text, conversationId } = data.payload;
|
|
83
|
-
if (type === 'show') {
|
|
84
|
-
this.props.showChat();
|
|
85
|
-
(0, analytics_1.trackWebchatState)('show');
|
|
86
|
-
}
|
|
87
|
-
else if (type === 'hide') {
|
|
88
|
-
this.props.hideChat();
|
|
89
|
-
(0, analytics_1.trackWebchatState)('hide');
|
|
90
|
-
}
|
|
91
|
-
else if (type === 'toggle') {
|
|
92
|
-
this.props.displayWidgetView ? this.props.showChat() : this.props.hideChat();
|
|
93
|
-
(0, analytics_1.trackWebchatState)('toggle');
|
|
94
|
-
}
|
|
95
|
-
else if (type === 'message') {
|
|
96
|
-
yield this.props.sendMessage(text);
|
|
97
|
-
}
|
|
98
|
-
else if (type === 'loadConversation') {
|
|
99
|
-
yield this.props.fetchConversation(conversationId);
|
|
100
|
-
}
|
|
101
|
-
else if (type === 'createConversation') {
|
|
102
|
-
yield this.props.createConversation();
|
|
103
|
-
}
|
|
104
|
-
else if (type === 'toggleBotInfo') {
|
|
105
|
-
this.props.toggleBotInfo();
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
yield this.props.sendData({ type, payload: data.payload });
|
|
109
|
-
}
|
|
110
|
-
default:
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
this.handleNewMessage = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
var _b, _c, _d;
|
|
116
|
-
if (!this.isCurrentConversation(event)) {
|
|
117
|
-
// don't do anything, it's a message from another conversation
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (event.authorId === undefined) {
|
|
121
|
-
const value = (event.payload.type === 'typing' ? event.payload.value : undefined) || exports.DEFAULT_TYPING_DELAY;
|
|
122
|
-
yield this.handleTyping(Object.assign(Object.assign({}, event), { timeInMs: value }));
|
|
123
|
-
}
|
|
124
|
-
if (((_b = event.payload) === null || _b === void 0 ? void 0 : _b.type) === 'visit') {
|
|
125
|
-
// don't do anything, it's the system message
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (((_c = this.props.currentConversation) === null || _c === void 0 ? void 0 : _c.userId) !== event.authorId) {
|
|
129
|
-
(0, analytics_1.trackMessage)('received');
|
|
130
|
-
(0, webchatEvents_1.postMessageToParent)('MESSAGE.RECEIVED', event, this.props.config.chatId);
|
|
131
|
-
// This is to handle a special case for the emulator, setting the selected css class to the last message group
|
|
132
|
-
// This needs a rethinking
|
|
133
|
-
if (event.id) {
|
|
134
|
-
(_d = this.props.store) === null || _d === void 0 ? void 0 : _d.setSelectedMessage(event.id);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
this.props.updateLastMessage(event.conversationId, event);
|
|
138
|
-
yield this.props.addEventToConversation(event);
|
|
139
|
-
// there's no focus on the actual conversation
|
|
140
|
-
if (!document.hasFocus() || this.props.activeView !== 'side') {
|
|
141
|
-
yield this.playSound();
|
|
142
|
-
this.props.incrementUnread();
|
|
143
|
-
}
|
|
144
|
-
this.handleResetUnreadCount();
|
|
145
|
-
});
|
|
146
|
-
this.handleTyping = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
yield this.props.updateTyping(event);
|
|
148
|
-
});
|
|
149
|
-
this.playSound = (0, debounce_1.default)(() => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
var _e;
|
|
151
|
-
const disableNotificationSound = this.config.disableNotificationSound || ((_e = this.props.config) === null || _e === void 0 ? void 0 : _e.disableNotificationSound);
|
|
152
|
-
if (disableNotificationSound || this.audio.readyState < 2) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
yield this.audio.play();
|
|
156
|
-
}), constants_1.default.MIN_TIME_BETWEEN_SOUNDS);
|
|
157
|
-
this.handleResetUnreadCount = () => {
|
|
158
|
-
if (document.hasFocus() && this.props.activeView === 'side') {
|
|
159
|
-
this.props.resetUnread();
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
(0, analytics_1.initializeAnalytics)();
|
|
163
|
-
}
|
|
164
|
-
componentDidMount() {
|
|
165
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
this.audio = new Audio(require('url:../assets/notification.mp3'));
|
|
167
|
-
this.props.setIntlProvider(this.props.intl);
|
|
168
|
-
window.store = this.props.store;
|
|
169
|
-
window.addEventListener('message', this.handleIframeApi);
|
|
170
|
-
window.addEventListener('keydown', this.handleKeyDown);
|
|
171
|
-
yield this.loadConfig();
|
|
172
|
-
yield this.initializeIfChatDisplayed();
|
|
173
|
-
this.props.setLoadingCompleted();
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
componentWillUnmount() {
|
|
177
|
-
window.removeEventListener('message', this.handleIframeApi);
|
|
178
|
-
window.removeEventListener('keydown', this.handleKeyDown);
|
|
179
|
-
}
|
|
180
|
-
componentDidUpdate() {
|
|
181
|
-
if (this.config) {
|
|
182
|
-
void this.initializeIfChatDisplayed();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
initializeIfChatDisplayed() {
|
|
186
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
if (this.hasBeenInitialized) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (this.props.activeView === 'side' || this.props.isFullscreen) {
|
|
191
|
-
this.hasBeenInitialized = true;
|
|
192
|
-
if (this.isLazySocket() || !this.socket) {
|
|
193
|
-
yield this.initializeSocket();
|
|
194
|
-
}
|
|
195
|
-
yield this.socket.connect();
|
|
196
|
-
this.props.setSocket(this.socket);
|
|
197
|
-
yield this.props.initializeChat();
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
loadConfig() {
|
|
202
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
this.config = this.extractConfig();
|
|
204
|
-
this.props.updateConfig(this.config);
|
|
205
|
-
// is this necessary ?
|
|
206
|
-
if (this.config.containerWidth) {
|
|
207
|
-
(0, webchatEvents_1.postMessageToParent)('UI.RESIZE', this.config.containerWidth, this.config.chatId);
|
|
208
|
-
}
|
|
209
|
-
yield this.props.fetchBotInfo();
|
|
210
|
-
if (!this.isLazySocket()) {
|
|
211
|
-
yield this.initializeSocket();
|
|
212
|
-
}
|
|
213
|
-
this.setupObserver();
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
extractConfig() {
|
|
217
|
-
let userConfig = Object.assign({}, constants_1.default.DEFAULT_CONFIG, this.props.config);
|
|
218
|
-
const { options } = query_string_1.default.parse(location.search);
|
|
219
|
-
if (!options || typeof options !== 'string') {
|
|
220
|
-
console.warn(`Cannot decode option. Invalid format: ${typeof options}, expecting 'string'.`);
|
|
221
|
-
return userConfig;
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
const parsedOptions = JSON.parse(decodeURIComponent(options));
|
|
225
|
-
userConfig = Object.assign(userConfig, parsedOptions.config);
|
|
226
|
-
return userConfig;
|
|
227
|
-
}
|
|
228
|
-
catch (err) {
|
|
229
|
-
// TODO: Handle those errors so they don't directly bubble up to the users
|
|
230
|
-
throw new Error(`An error occurred while extracting the configurations ${err}`);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
initializeSocket() {
|
|
234
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
this.socket = new socket_1.default(this.config);
|
|
236
|
-
this.socket.onMessage = this.handleNewMessage;
|
|
237
|
-
this.socket.setup();
|
|
238
|
-
yield this.socket.connect();
|
|
239
|
-
this.props.setSocket(this.socket);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
setupObserver() {
|
|
243
|
-
(0, mobx_1.observe)(this.props.dimensions, 'container', (data) => {
|
|
244
|
-
if (data.newValue) {
|
|
245
|
-
// is this necessary ?
|
|
246
|
-
(0, webchatEvents_1.postMessageToParent)('UI.RESIZE', data.newValue, this.config.chatId);
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
isLazySocket() {
|
|
251
|
-
var _a;
|
|
252
|
-
if (this.config.lazySocket !== undefined) {
|
|
253
|
-
return this.config.lazySocket;
|
|
254
|
-
}
|
|
255
|
-
return (_a = this.props.botInfo) === null || _a === void 0 ? void 0 : _a.lazySocket;
|
|
256
|
-
}
|
|
257
|
-
renderWidget() {
|
|
258
|
-
if (!this.props.showWidgetButton) {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
return (react_1.default.createElement("button", { className: (0, classnames_1.default)('bpw-widget-btn', 'bpw-floating-button', {
|
|
262
|
-
[`bpw-anim-${this.props.widgetTransition}` || 'none']: true
|
|
263
|
-
}), "aria-label": this.props.intl.formatMessage({ id: 'widget.toggle' }), onClick: this.props.showChat.bind(this) },
|
|
264
|
-
react_1.default.createElement(Chat_1.default, null),
|
|
265
|
-
this.props.hasUnreadMessages && react_1.default.createElement("span", { className: 'bpw-floating-button-unread' }, this.props.unreadCount)));
|
|
266
|
-
}
|
|
267
|
-
applyAndRenderStyle() {
|
|
268
|
-
var _a, _b, _c;
|
|
269
|
-
const parentClass = (0, classnames_1.default)(`bp-widget-web bp-widget-${this.props.activeView}`, {
|
|
270
|
-
'bp-widget-hidden': !this.props.showWidgetButton && this.props.displayWidgetView,
|
|
271
|
-
[(_a = this.props.config) === null || _a === void 0 ? void 0 : _a.className]: !!((_b = this.props.config) === null || _b === void 0 ? void 0 : _b.className)
|
|
272
|
-
});
|
|
273
|
-
if (this.parentClass !== parentClass) {
|
|
274
|
-
this.parentClass = parentClass;
|
|
275
|
-
(0, webchatEvents_1.postMessageToParent)('UI.SET-CLASS', parentClass, this.config.chatId);
|
|
276
|
-
}
|
|
277
|
-
const stylesheet = this.props.config.stylesheet;
|
|
278
|
-
const extraStylesheet = (_c = this.props.botInfo) === null || _c === void 0 ? void 0 : _c.extraStylesheet;
|
|
279
|
-
const RobotoFont = react_1.default.lazy(() => Promise.resolve().then(() => __importStar(require('./fonts/roboto'))));
|
|
280
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
281
|
-
!!(stylesheet === null || stylesheet === void 0 ? void 0 : stylesheet.length) && react_1.default.createElement("link", { rel: "stylesheet", type: "text/css", href: stylesheet }),
|
|
282
|
-
react_1.default.createElement(react_1.default.Suspense, { fallback: react_1.default.createElement(react_1.default.Fragment, null) }, !utils_1.isIE && react_1.default.createElement(RobotoFont, null)),
|
|
283
|
-
!!(extraStylesheet === null || extraStylesheet === void 0 ? void 0 : extraStylesheet.length) && react_1.default.createElement("link", { rel: "stylesheet", type: "text/css", href: extraStylesheet })));
|
|
284
|
-
}
|
|
285
|
-
render() {
|
|
286
|
-
if (!this.props.isWebchatReady) {
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
return (react_1.default.createElement("div", { onFocus: this.handleResetUnreadCount },
|
|
290
|
-
this.applyAndRenderStyle(),
|
|
291
|
-
react_1.default.createElement("h1", { id: "tchat-label", className: "sr-only", tabIndex: -1 }, this.props.intl.formatMessage({
|
|
292
|
-
id: 'widget.title',
|
|
293
|
-
defaultMessage: 'Chat window'
|
|
294
|
-
})),
|
|
295
|
-
this.props.displayWidgetView ? this.renderWidget() : react_1.default.createElement(Container_1.default, null)));
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
exports.default = (0, mobx_react_1.inject)(({ store }) => ({
|
|
299
|
-
store,
|
|
300
|
-
config: store.config,
|
|
301
|
-
sendData: store.sendData,
|
|
302
|
-
initializeChat: store.initializeChat,
|
|
303
|
-
botInfo: store.botInfo,
|
|
304
|
-
fetchBotInfo: store.fetchBotInfo,
|
|
305
|
-
updateConfig: store.updateConfig,
|
|
306
|
-
mergeConfig: store.mergeConfig,
|
|
307
|
-
addEventToConversation: store.addEventToConversation,
|
|
308
|
-
clearMessages: store.clearMessages,
|
|
309
|
-
updateTyping: store.updateTyping,
|
|
310
|
-
sendMessage: store.sendMessage,
|
|
311
|
-
updateBotUILanguage: store.updateBotUILanguage,
|
|
312
|
-
isWebchatReady: store.view.isWebchatReady,
|
|
313
|
-
showWidgetButton: store.view.showWidgetButton,
|
|
314
|
-
hasUnreadMessages: store.view.hasUnreadMessages,
|
|
315
|
-
unreadCount: store.view.unreadCount,
|
|
316
|
-
resetUnread: store.view.resetUnread,
|
|
317
|
-
incrementUnread: store.view.incrementUnread,
|
|
318
|
-
activeView: store.view.activeView,
|
|
319
|
-
isFullscreen: store.view.isFullscreen,
|
|
320
|
-
showChat: store.view.showChat,
|
|
321
|
-
hideChat: store.view.hideChat,
|
|
322
|
-
toggleBotInfo: store.view.toggleBotInfo,
|
|
323
|
-
dimensions: store.view.dimensions,
|
|
324
|
-
widgetTransition: store.view.widgetTransition,
|
|
325
|
-
displayWidgetView: store.view.displayWidgetView,
|
|
326
|
-
setLoadingCompleted: store.view.setLoadingCompleted,
|
|
327
|
-
sendFeedback: store.sendFeedback,
|
|
328
|
-
updateLastMessage: store.updateLastMessage,
|
|
329
|
-
fetchConversation: store.fetchConversation,
|
|
330
|
-
createConversation: store.createConversation,
|
|
331
|
-
setIntlProvider: store.setIntlProvider,
|
|
332
|
-
setSocket: store.setSocket,
|
|
333
|
-
currentConversation: store.currentConversation,
|
|
334
|
-
currentConversationId: store.currentConversationId,
|
|
335
|
-
resetConversation: store.resetConversation
|
|
336
|
-
}))((0, react_intl_1.injectIntl)((0, mobx_react_1.observer)(Web)));
|
package/dist/store/composer.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RootStore } from '.';
|
|
2
|
-
declare class ComposerStore {
|
|
3
|
-
private rootStore;
|
|
4
|
-
message: string;
|
|
5
|
-
locked: boolean;
|
|
6
|
-
hidden: boolean;
|
|
7
|
-
private _sentHistory;
|
|
8
|
-
private _sentHistoryIndex;
|
|
9
|
-
constructor(rootStore: RootStore);
|
|
10
|
-
get composerPlaceholder(): string | undefined;
|
|
11
|
-
updateMessage(msg: string): void;
|
|
12
|
-
addMessageToHistory(text: string): void;
|
|
13
|
-
recallHistory(direction: string): void;
|
|
14
|
-
setLocked(locked: boolean): void;
|
|
15
|
-
setHidden(hidden: boolean): void;
|
|
16
|
-
}
|
|
17
|
-
export default ComposerStore;
|
package/dist/store/composer.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const last_1 = __importDefault(require("lodash/last"));
|
|
13
|
-
const takeRight_1 = __importDefault(require("lodash/takeRight"));
|
|
14
|
-
const mobx_1 = require("mobx");
|
|
15
|
-
const constants_1 = __importDefault(require("../core/constants"));
|
|
16
|
-
const HISTORY_UP = 'ArrowUp';
|
|
17
|
-
const SENT_HISTORY_KEY = 'sent-history';
|
|
18
|
-
class ComposerStore {
|
|
19
|
-
constructor(rootStore) {
|
|
20
|
-
this.message = '';
|
|
21
|
-
this.locked = false;
|
|
22
|
-
this.hidden = false;
|
|
23
|
-
this._sentHistory = [];
|
|
24
|
-
this._sentHistoryIndex = 0;
|
|
25
|
-
this.rootStore = rootStore;
|
|
26
|
-
this._sentHistory = window.BP_STORAGE.get(SENT_HISTORY_KEY) || [];
|
|
27
|
-
}
|
|
28
|
-
get composerPlaceholder() {
|
|
29
|
-
var _a;
|
|
30
|
-
return (_a = this.rootStore.config) === null || _a === void 0 ? void 0 : _a.composerPlaceholder;
|
|
31
|
-
}
|
|
32
|
-
updateMessage(msg) {
|
|
33
|
-
this.message = msg;
|
|
34
|
-
}
|
|
35
|
-
addMessageToHistory(text) {
|
|
36
|
-
if ((0, last_1.default)(this._sentHistory) !== text) {
|
|
37
|
-
this._sentHistory.push(text);
|
|
38
|
-
this._sentHistoryIndex = 0;
|
|
39
|
-
if (this.rootStore.config.enablePersistHistory) {
|
|
40
|
-
window.BP_STORAGE.set(SENT_HISTORY_KEY, (0, takeRight_1.default)(this._sentHistory, constants_1.default.SENT_HISTORY_SIZE));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
recallHistory(direction) {
|
|
45
|
-
if (!this._sentHistory.length) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
let newIndex = direction === HISTORY_UP ? this._sentHistoryIndex - 1 : this._sentHistoryIndex + 1;
|
|
49
|
-
if (newIndex < 0) {
|
|
50
|
-
newIndex = this._sentHistory.length - 1;
|
|
51
|
-
}
|
|
52
|
-
else if (newIndex >= this._sentHistory.length) {
|
|
53
|
-
newIndex = 0;
|
|
54
|
-
}
|
|
55
|
-
this.updateMessage(this._sentHistory[newIndex]);
|
|
56
|
-
this._sentHistoryIndex = newIndex;
|
|
57
|
-
}
|
|
58
|
-
setLocked(locked) {
|
|
59
|
-
this.locked = !!locked;
|
|
60
|
-
}
|
|
61
|
-
setHidden(hidden) {
|
|
62
|
-
this.hidden = hidden;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
__decorate([
|
|
66
|
-
mobx_1.observable
|
|
67
|
-
], ComposerStore.prototype, "message", void 0);
|
|
68
|
-
__decorate([
|
|
69
|
-
mobx_1.observable
|
|
70
|
-
], ComposerStore.prototype, "locked", void 0);
|
|
71
|
-
__decorate([
|
|
72
|
-
mobx_1.observable
|
|
73
|
-
], ComposerStore.prototype, "hidden", void 0);
|
|
74
|
-
__decorate([
|
|
75
|
-
mobx_1.observable
|
|
76
|
-
], ComposerStore.prototype, "_sentHistory", void 0);
|
|
77
|
-
__decorate([
|
|
78
|
-
mobx_1.observable
|
|
79
|
-
], ComposerStore.prototype, "_sentHistoryIndex", void 0);
|
|
80
|
-
__decorate([
|
|
81
|
-
mobx_1.computed
|
|
82
|
-
], ComposerStore.prototype, "composerPlaceholder", null);
|
|
83
|
-
__decorate([
|
|
84
|
-
mobx_1.action.bound
|
|
85
|
-
], ComposerStore.prototype, "updateMessage", null);
|
|
86
|
-
__decorate([
|
|
87
|
-
mobx_1.action.bound
|
|
88
|
-
], ComposerStore.prototype, "addMessageToHistory", null);
|
|
89
|
-
__decorate([
|
|
90
|
-
mobx_1.action.bound
|
|
91
|
-
], ComposerStore.prototype, "recallHistory", null);
|
|
92
|
-
__decorate([
|
|
93
|
-
mobx_1.action.bound
|
|
94
|
-
], ComposerStore.prototype, "setLocked", null);
|
|
95
|
-
__decorate([
|
|
96
|
-
mobx_1.action.bound
|
|
97
|
-
], ComposerStore.prototype, "setHidden", null);
|
|
98
|
-
exports.default = ComposerStore;
|
package/dist/store/index.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IntlShape } from 'react-intl';
|
|
3
|
-
import BpSocket from '../core/socket';
|
|
4
|
-
import { BotInfo, Config, CurrentConversation, EventFeedback, Message, QueuedMessage, RecentConversation, uuid } from '../typings';
|
|
5
|
-
import ComposerStore from './composer';
|
|
6
|
-
import ViewStore from './view';
|
|
7
|
-
/** Includes the definitions of all store classes */
|
|
8
|
-
export declare type StoreDef = Partial<RootStore> & Partial<ViewStore> & Partial<ComposerStore> & Partial<Config>;
|
|
9
|
-
declare class RootStore {
|
|
10
|
-
composer: ComposerStore;
|
|
11
|
-
view: ViewStore;
|
|
12
|
-
private _typingInterval;
|
|
13
|
-
private api;
|
|
14
|
-
conversations: RecentConversation[];
|
|
15
|
-
currentConversation?: CurrentConversation;
|
|
16
|
-
selectedMessageId?: string;
|
|
17
|
-
botInfo: BotInfo;
|
|
18
|
-
config: Config;
|
|
19
|
-
preferredLanguage: string;
|
|
20
|
-
isInitialized: boolean;
|
|
21
|
-
messageFeedbacks: EventFeedback[];
|
|
22
|
-
intl: IntlShape;
|
|
23
|
-
isBotTyping: import("mobx").IObservableValue<boolean>;
|
|
24
|
-
botUILanguage: string;
|
|
25
|
-
delayedMessages: QueuedMessage[];
|
|
26
|
-
constructor(options: {
|
|
27
|
-
fullscreen: boolean;
|
|
28
|
-
}, config?: Config);
|
|
29
|
-
setIntlProvider(provider: IntlShape): void;
|
|
30
|
-
setSocket(socket: BpSocket): void;
|
|
31
|
-
setSelectedMessage(messageId: string): void;
|
|
32
|
-
get isConversationStarted(): boolean;
|
|
33
|
-
get botName(): string;
|
|
34
|
-
get hasBotInfoDescription(): boolean;
|
|
35
|
-
get botAvatarUrl(): string | undefined;
|
|
36
|
-
get coverPictureUrl(): string | undefined;
|
|
37
|
-
get description(): string | undefined;
|
|
38
|
-
get website(): string | undefined;
|
|
39
|
-
get phoneNumber(): string | undefined;
|
|
40
|
-
get termsConditions(): string | undefined;
|
|
41
|
-
get privacyPolicy(): string | undefined;
|
|
42
|
-
get emailAddress(): string | undefined;
|
|
43
|
-
get rtl(): boolean;
|
|
44
|
-
get escapeHTML(): boolean;
|
|
45
|
-
get currentMessages(): Message[];
|
|
46
|
-
get currentConversationId(): uuid | undefined;
|
|
47
|
-
updateMessages(messages: Message[]): void;
|
|
48
|
-
updateLastMessage(conversationId: string, message?: Message): void;
|
|
49
|
-
clearMessages(): void;
|
|
50
|
-
deleteConversation(): Promise<void>;
|
|
51
|
-
addEventToConversation(event: Message): Promise<void>;
|
|
52
|
-
updateTyping(event: Message): Promise<void>;
|
|
53
|
-
/** Loads the initial state, for the first time or when the user ID is changed. */
|
|
54
|
-
initializeChat(): Promise<void>;
|
|
55
|
-
fetchBotInfo(): Promise<void>;
|
|
56
|
-
fetchLanguage(): void;
|
|
57
|
-
/** Fetches the list of conversation, and update the corresponding config values */
|
|
58
|
-
fetchConversations(): Promise<void>;
|
|
59
|
-
/** Fetch the specified conversation ID, or try to fetch a valid one from the list */
|
|
60
|
-
fetchConversation(convoId?: uuid): Promise<uuid | undefined>;
|
|
61
|
-
/** Sends the specified message, or fetch the message in the composer */
|
|
62
|
-
sendMessage(textMessage?: string): Promise<void>;
|
|
63
|
-
/** Sends an event to start conversation & hide the bot info page */
|
|
64
|
-
startConversation(): Promise<void>;
|
|
65
|
-
/** Creates a new conversation and switches to it */
|
|
66
|
-
createConversation(): Promise<uuid>;
|
|
67
|
-
resetConversation(): void;
|
|
68
|
-
extractFeedback(messages: Message[]): Promise<void>;
|
|
69
|
-
sendFeedback(feedback: number, messageId: string): Promise<void>;
|
|
70
|
-
downloadConversation(): Promise<void>;
|
|
71
|
-
/** Sends an event or a message, depending on how the backend manages those types */
|
|
72
|
-
sendData(data: any): Promise<Message | void>;
|
|
73
|
-
/** Sends a message of type voice */
|
|
74
|
-
sendVoiceMessage(voice: Buffer, ext: string): Promise<void>;
|
|
75
|
-
/** Use this method to replace a value or add a new config */
|
|
76
|
-
mergeConfig(config: Partial<Config>): void;
|
|
77
|
-
/** This replaces all the configurations by this object */
|
|
78
|
-
updateConfig(config: Config): void;
|
|
79
|
-
private _applyConfig;
|
|
80
|
-
updatePreferredLanguage(lang: string): void;
|
|
81
|
-
/** Starts a timer to remove the typing animation when it's completed */
|
|
82
|
-
private _startTypingTimer;
|
|
83
|
-
private _expireTyping;
|
|
84
|
-
updateBotUILanguage(lang: string): void;
|
|
85
|
-
private emptyDelayedMessagesQueue;
|
|
86
|
-
/** Returns the current conversation ID, or the last one. */
|
|
87
|
-
private _getCurrentConvoId;
|
|
88
|
-
}
|
|
89
|
-
export { RootStore };
|