@botpress/webchat 0.2.3 → 0.3.0
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/README.md +31 -0
- package/dist/components/Composer.d.ts +4 -5
- package/dist/components/Composer.js +13 -23
- package/dist/components/Container.d.ts +1 -1
- package/dist/components/Container.js +1 -6
- package/dist/components/ConversationList.d.ts +1 -1
- package/dist/components/ConversationList.js +5 -46
- package/dist/components/Header.d.ts +1 -3
- package/dist/components/Header.js +17 -64
- package/dist/components/VoiceRecorder.js +6 -2
- package/dist/components/common/{Avatar.d.ts → Avatar/index.d.ts} +0 -0
- package/dist/components/common/Avatar/index.js +13 -0
- package/dist/components/common/{BotInfo.d.ts → BotInfo/index.d.ts} +3 -3
- package/dist/components/common/BotInfo/index.js +102 -0
- package/dist/components/common/ConfirmDialog/index.d.ts +11 -0
- package/dist/components/common/ConfirmDialog/index.js +78 -0
- package/dist/components/common/Dialog/index.d.ts +17 -0
- package/dist/components/common/Dialog/index.js +57 -0
- package/dist/components/common/ToolTip/index.d.ts +10 -0
- package/dist/components/common/ToolTip/index.js +163 -0
- package/dist/components/common/ToolTip/utils.d.ts +15 -0
- package/dist/components/common/ToolTip/utils.js +78 -0
- package/dist/components/messages/InlineFeedback.d.ts +2 -1
- package/dist/components/messages/Message.js +2 -25
- package/dist/components/messages/MessageGroup.d.ts +1 -13
- package/dist/components/messages/MessageGroup.js +6 -40
- package/dist/components/messages/MessageList.d.ts +1 -1
- package/dist/components/messages/MessageList.js +8 -31
- package/dist/core/api.d.ts +4 -18
- package/dist/core/api.js +25 -150
- package/dist/core/constants.d.ts +4 -32
- package/dist/core/constants.js +18 -32
- package/dist/core/socket.d.ts +1 -12
- package/dist/core/socket.js +7 -73
- package/dist/{components/Stylesheet.d.ts → icons/Cancel.d.ts} +2 -2
- package/dist/icons/Cancel.js +10 -0
- package/dist/icons/Microphone.d.ts +5 -0
- package/dist/icons/Microphone.js +12 -0
- package/dist/index.d.ts +2 -8
- package/dist/index.js +9 -29
- package/dist/main.d.ts +2 -2
- package/dist/main.js +100 -168
- package/dist/store/composer.js +3 -6
- package/dist/store/index.d.ts +8 -18
- package/dist/store/index.js +98 -136
- package/dist/store/view.d.ts +3 -6
- package/dist/store/view.js +6 -23
- package/dist/translations/index.d.ts +3 -1
- package/dist/translations/index.js +44 -4
- package/dist/typings.d.ts +121 -71
- package/dist/utils/analytics.d.ts +5 -0
- package/dist/utils/analytics.js +37 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +27 -0
- package/dist/utils/storage.d.ts +16 -0
- package/dist/utils/storage.js +129 -0
- package/package.json +4 -3
- package/dist/components/ContextMenu.d.ts +0 -2
- package/dist/components/ContextMenu.js +0 -33
- package/dist/components/OverridableComponent.d.ts +0 -24
- package/dist/components/OverridableComponent.js +0 -50
- package/dist/components/Stylesheet.js +0 -7
- package/dist/components/common/Avatar.js +0 -29
- package/dist/components/common/BotInfo.js +0 -110
- package/dist/icons/CloseChat.d.ts +0 -6
- package/dist/icons/CloseChat.js +0 -9
- package/dist/icons/Send.d.ts +0 -6
- package/dist/icons/Send.js +0 -8
- package/dist/utils.d.ts +0 -8
- package/dist/utils.js +0 -111
package/dist/store/index.js
CHANGED
|
@@ -19,28 +19,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.RootStore = void 0;
|
|
22
|
+
const axios_1 = __importDefault(require("axios"));
|
|
22
23
|
const is_before_1 = __importDefault(require("date-fns/is_before"));
|
|
23
24
|
const is_valid_1 = __importDefault(require("date-fns/is_valid"));
|
|
24
25
|
const merge_1 = __importDefault(require("lodash/merge"));
|
|
26
|
+
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
25
27
|
const mobx_1 = require("mobx");
|
|
26
28
|
const api_1 = __importDefault(require("../core/api"));
|
|
27
29
|
const main_1 = require("../main");
|
|
28
30
|
const translations_1 = require("../translations");
|
|
29
31
|
const utils_1 = require("../utils");
|
|
32
|
+
const analytics_1 = require("../utils/analytics");
|
|
30
33
|
const composer_1 = __importDefault(require("./composer"));
|
|
31
34
|
const view_1 = __importDefault(require("./view"));
|
|
32
|
-
const chosenLocale = (0, translations_1.getUserLocale)();
|
|
33
35
|
class RootStore {
|
|
34
36
|
constructor(options, config) {
|
|
35
37
|
this.conversations = [];
|
|
36
38
|
this.isBotTyping = mobx_1.observable.box(false);
|
|
37
|
-
this.botUILanguage = chosenLocale;
|
|
38
39
|
this.delayedMessages = [];
|
|
39
40
|
this.composer = new composer_1.default(this);
|
|
40
41
|
this.view = new view_1.default(this, options.fullscreen);
|
|
41
42
|
if (config) {
|
|
42
43
|
this.updateConfig(config);
|
|
43
44
|
}
|
|
45
|
+
this.botUILanguage = (0, translations_1.getUserLocale)();
|
|
44
46
|
}
|
|
45
47
|
setIntlProvider(provider) {
|
|
46
48
|
this.intl = provider;
|
|
@@ -56,20 +58,16 @@ class RootStore {
|
|
|
56
58
|
var _a, _b;
|
|
57
59
|
return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.botName) || ((_b = this.botInfo) === null || _b === void 0 ? void 0 : _b.name) || 'Bot';
|
|
58
60
|
}
|
|
59
|
-
get isEmulator() {
|
|
60
|
-
var _a;
|
|
61
|
-
return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.isEmulator) || false;
|
|
62
|
-
}
|
|
63
61
|
get hasBotInfoDescription() {
|
|
64
62
|
var _a;
|
|
65
|
-
return !!((_a = this.config.
|
|
63
|
+
return !!((_a = this.config.botConversationDescription) === null || _a === void 0 ? void 0 : _a.length);
|
|
66
64
|
}
|
|
67
65
|
get botAvatarUrl() {
|
|
68
66
|
var _a, _b, _c;
|
|
69
67
|
return ((_b = (_a = this.botInfo) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.avatarUrl) || ((_c = this.config) === null || _c === void 0 ? void 0 : _c.avatarUrl) || undefined;
|
|
70
68
|
}
|
|
71
69
|
get rtl() {
|
|
72
|
-
return (0,
|
|
70
|
+
return (0, translations_1.isRTLLocale)(this.preferredLanguage);
|
|
73
71
|
}
|
|
74
72
|
get escapeHTML() {
|
|
75
73
|
var _a, _b;
|
|
@@ -77,7 +75,7 @@ class RootStore {
|
|
|
77
75
|
}
|
|
78
76
|
get currentMessages() {
|
|
79
77
|
var _a;
|
|
80
|
-
return (_a = this.currentConversation) === null || _a === void 0 ? void 0 : _a.messages;
|
|
78
|
+
return ((_a = this.currentConversation) === null || _a === void 0 ? void 0 : _a.messages) || [];
|
|
81
79
|
}
|
|
82
80
|
get currentConversationId() {
|
|
83
81
|
var _a;
|
|
@@ -88,7 +86,9 @@ class RootStore {
|
|
|
88
86
|
window.parent.postMessage({ name, chatId, payload }, '*');
|
|
89
87
|
}
|
|
90
88
|
updateMessages(messages) {
|
|
91
|
-
this.currentConversation
|
|
89
|
+
if (this.currentConversation) {
|
|
90
|
+
this.currentConversation.messages = messages;
|
|
91
|
+
}
|
|
92
92
|
}
|
|
93
93
|
updateLastMessage(conversationId, message) {
|
|
94
94
|
for (const conversation of this.conversations) {
|
|
@@ -99,30 +99,27 @@ class RootStore {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
clearMessages() {
|
|
102
|
-
this.currentConversation
|
|
102
|
+
if (this.currentConversation) {
|
|
103
|
+
this.currentConversation.messages = [];
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
106
|
deleteConversation() {
|
|
105
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
if (this.
|
|
107
|
-
yield this.api.
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (!this.config.isEmulator || !messageId) {
|
|
115
|
-
return;
|
|
108
|
+
if (this.currentConversationId) {
|
|
109
|
+
yield this.api.deleteConversation(this.currentConversationId);
|
|
110
|
+
const index = this.conversations.findIndex((c) => c.id === this.currentConversationId);
|
|
111
|
+
if (index > -1) {
|
|
112
|
+
this.conversations.splice(index, 1);
|
|
113
|
+
}
|
|
114
|
+
this.resetConversation();
|
|
115
|
+
yield this.fetchConversation();
|
|
116
116
|
}
|
|
117
|
-
const messages = yield this.api.listByIncomingEvent(messageId);
|
|
118
|
-
this.view.setHighlightedMessages(messages);
|
|
119
|
-
window.parent.postMessage({ action: 'load-event', payload: { messageId, isManual } }, '*');
|
|
120
117
|
});
|
|
121
118
|
}
|
|
122
119
|
addEventToConversation(event) {
|
|
123
120
|
var _a;
|
|
124
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
if (this.isInitialized && this.currentConversationId !== event.conversationId) {
|
|
122
|
+
if (!this.currentConversation || (this.isInitialized && this.currentConversationId !== event.conversationId)) {
|
|
126
123
|
yield this.fetchConversations();
|
|
127
124
|
yield this.fetchConversation(event.conversationId);
|
|
128
125
|
return;
|
|
@@ -142,7 +139,7 @@ class RootStore {
|
|
|
142
139
|
}
|
|
143
140
|
updateTyping(event) {
|
|
144
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
if (this.isInitialized && this.currentConversationId !== event.conversationId) {
|
|
142
|
+
if (!this.currentConversation || (this.isInitialized && this.currentConversationId !== event.conversationId)) {
|
|
146
143
|
yield this.fetchConversations();
|
|
147
144
|
yield this.fetchConversation(event.conversationId);
|
|
148
145
|
return;
|
|
@@ -160,41 +157,45 @@ class RootStore {
|
|
|
160
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
158
|
try {
|
|
162
159
|
yield this.fetchConversations();
|
|
163
|
-
yield this.fetchConversation(
|
|
160
|
+
yield this.fetchConversation();
|
|
164
161
|
(0, mobx_1.runInAction)('-> setInitialized', () => {
|
|
165
162
|
this.isInitialized = true;
|
|
166
163
|
this.postMessage('webchatReady');
|
|
167
164
|
});
|
|
168
165
|
}
|
|
169
166
|
catch (err) {
|
|
170
|
-
console.error('Error while fetching data, creating new
|
|
167
|
+
console.error('Error while fetching data, creating new conversation...', err);
|
|
171
168
|
yield this.createConversation();
|
|
172
169
|
}
|
|
173
|
-
|
|
170
|
+
this.fetchLanguage();
|
|
174
171
|
});
|
|
175
172
|
}
|
|
176
173
|
fetchBotInfo() {
|
|
177
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
|
|
179
|
-
(0, mobx_1.runInAction)('-> setBotInfo', () => {
|
|
180
|
-
this.botInfo = botInfo;
|
|
181
|
-
});
|
|
182
|
-
this.mergeConfig({
|
|
183
|
-
extraStylesheet: botInfo.extraStylesheet,
|
|
184
|
-
disableNotificationSound: botInfo.disableNotificationSound
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
fetchPreferences() {
|
|
189
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
// TODO: where to fetch this from? Can this just be set in the frontend?
|
|
191
|
-
const preferences = { language: 'en' }; // await this.api.fetchPreferences()
|
|
192
|
-
if (!preferences.language) {
|
|
175
|
+
if (!this.config.mediaFileServiceUrl) {
|
|
193
176
|
return;
|
|
194
177
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
178
|
+
try {
|
|
179
|
+
const { data } = yield axios_1.default.get(this.config.mediaFileServiceUrl);
|
|
180
|
+
if (!data) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
(0, mobx_1.runInAction)('-> setBotInfo', () => {
|
|
184
|
+
this.botInfo = data;
|
|
185
|
+
});
|
|
186
|
+
this.mergeConfig({
|
|
187
|
+
disableNotificationSound: data.disableNotificationSound
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
console.error('Error while loading bot info', err);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
fetchLanguage() {
|
|
196
|
+
const language = (0, translations_1.getUserLocale)(this.config.locale);
|
|
197
|
+
(0, mobx_1.runInAction)('-> setPreferredLanguage', () => {
|
|
198
|
+
this.updateBotUILanguage(language);
|
|
198
199
|
});
|
|
199
200
|
}
|
|
200
201
|
/** Fetches the list of conversation, and update the corresponding config values */
|
|
@@ -240,7 +241,7 @@ class RootStore {
|
|
|
240
241
|
this.composer.updateMessage('');
|
|
241
242
|
try {
|
|
242
243
|
yield this.sendData({ type: 'text', text: userMessage });
|
|
243
|
-
(0,
|
|
244
|
+
(0, analytics_1.trackMessage)('sent');
|
|
244
245
|
this.composer.addMessageToHistory(userMessage);
|
|
245
246
|
}
|
|
246
247
|
catch (e) {
|
|
@@ -266,24 +267,12 @@ class RootStore {
|
|
|
266
267
|
return newId;
|
|
267
268
|
});
|
|
268
269
|
}
|
|
269
|
-
setReference() {
|
|
270
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
-
return this.api.setReference(this.config.reference, this.currentConversationId);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
270
|
resetConversation() {
|
|
275
271
|
this.currentConversation = undefined;
|
|
276
272
|
}
|
|
277
|
-
resetSession() {
|
|
278
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
-
this.composer.setLocked(false);
|
|
280
|
-
return this.api.resetSession(this.currentConversationId);
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
273
|
extractFeedback(messages) {
|
|
284
274
|
return __awaiter(this, void 0, void 0, function* () {
|
|
285
275
|
const feedbackMessageIds = messages.filter((x) => x.payload && x.payload.collectFeedback).map((x) => x.id);
|
|
286
|
-
// TODO: store feedback somewhere
|
|
287
276
|
const feedbackInfo = feedbackMessageIds.map((x) => ({ messageId: x, feedback: 1 }));
|
|
288
277
|
(0, mobx_1.runInAction)('-> setFeedbackInfo', () => {
|
|
289
278
|
this.messageFeedbacks = feedbackInfo;
|
|
@@ -298,41 +287,55 @@ class RootStore {
|
|
|
298
287
|
downloadConversation() {
|
|
299
288
|
return __awaiter(this, void 0, void 0, function* () {
|
|
300
289
|
try {
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
290
|
+
const formatDate = (date) => {
|
|
291
|
+
return new Date(date).toLocaleString();
|
|
292
|
+
};
|
|
293
|
+
const conversation = this.currentConversation;
|
|
294
|
+
if (!conversation) {
|
|
295
|
+
console.warn('Cannot download the current conversation as it is undefined.');
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
let info = `Conversation Id: ${conversation.id}\nCreated on: ${formatDate(conversation.createdOn)}\nUser: ${conversation.userId}\n-----------------`;
|
|
299
|
+
const messages = yield this.api.listCurrentConversationMessages(500);
|
|
300
|
+
for (const message of (0, orderBy_1.default)(messages, 'sentOn', 'desc')) {
|
|
301
|
+
const payload = message.payload;
|
|
302
|
+
if (payload.type === 'session_reset') {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
info += `\n[${formatDate(message.sentOn)}] ${message.authorId ? 'User' : this.config.botName || 'Bot'}: Event (${payload.type}): ${payload.text ||
|
|
306
|
+
payload.audio ||
|
|
307
|
+
payload.image ||
|
|
308
|
+
payload.video ||
|
|
309
|
+
payload.file ||
|
|
310
|
+
payload.message ||
|
|
311
|
+
payload.title ||
|
|
312
|
+
''}`;
|
|
313
|
+
}
|
|
314
|
+
const blobFile = new Blob([info]);
|
|
315
|
+
(0, utils_1.downloadFile)(`conversation-${conversation.id}`, blobFile);
|
|
304
316
|
}
|
|
305
317
|
catch (err) {
|
|
306
|
-
console.error('Error trying to download conversation');
|
|
318
|
+
console.error('Error trying to download conversation', err);
|
|
307
319
|
}
|
|
308
320
|
});
|
|
309
321
|
}
|
|
310
322
|
/** Sends an event or a message, depending on how the backend manages those types */
|
|
311
323
|
sendData(data) {
|
|
312
324
|
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
-
if (!this.isInitialized) {
|
|
325
|
+
if (!this.isInitialized || !this.currentConversationId) {
|
|
314
326
|
console.warn('[webchat] Cannot send data until the webchat is ready');
|
|
315
327
|
return;
|
|
316
328
|
}
|
|
317
|
-
// TODO: this can't work. We can't create events directly
|
|
318
|
-
/*
|
|
319
|
-
if (!constants.MESSAGE_TYPES.includes(data.type)) {
|
|
320
|
-
return this.api.sendEvent(data, this.currentConversationId)
|
|
321
|
-
}
|
|
322
|
-
*/
|
|
323
329
|
const message = yield this.api.sendMessage(data, this.currentConversationId);
|
|
324
330
|
this.updateLastMessage(this.currentConversationId, message);
|
|
325
331
|
});
|
|
326
332
|
}
|
|
327
|
-
uploadFile(title, payload, file) {
|
|
328
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
-
yield this.api.uploadFile(file, payload, this.currentConversationId);
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
333
|
/** Sends a message of type voice */
|
|
333
334
|
sendVoiceMessage(voice, ext) {
|
|
334
335
|
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
-
|
|
336
|
+
if (this.currentConversationId) {
|
|
337
|
+
return this.api.sendVoiceMessage(voice, ext, this.currentConversationId);
|
|
338
|
+
}
|
|
336
339
|
});
|
|
337
340
|
}
|
|
338
341
|
/** Use this method to replace a value or add a new config */
|
|
@@ -341,47 +344,34 @@ class RootStore {
|
|
|
341
344
|
this._applyConfig();
|
|
342
345
|
}
|
|
343
346
|
/** This replaces all the configurations by this object */
|
|
344
|
-
updateConfig(config
|
|
347
|
+
updateConfig(config) {
|
|
345
348
|
this.config = config;
|
|
346
349
|
this._applyConfig();
|
|
347
350
|
}
|
|
348
351
|
_applyConfig() {
|
|
352
|
+
window.BP_STORAGE.config = this.config;
|
|
349
353
|
this.config.layoutWidth && this.view.setLayoutWidth(this.config.layoutWidth);
|
|
350
354
|
this.config.containerWidth && this.view.setContainerWidth(this.config.containerWidth);
|
|
351
|
-
this.view.disableAnimations = this.config.disableAnimations;
|
|
355
|
+
this.view.disableAnimations = !!this.config.disableAnimations;
|
|
352
356
|
this.config.showPoweredBy ? this.view.showPoweredBy() : this.view.hidePoweredBy();
|
|
353
357
|
document.title = this.config.botName || 'Botpress Webchat';
|
|
354
|
-
// TODO: can't work at the moment
|
|
355
|
-
// this.api.updateUserId(this.config.userId!)
|
|
356
358
|
if (!this.isInitialized) {
|
|
357
|
-
window.USE_SESSION_STORAGE = this.config.useSessionStorage;
|
|
359
|
+
window.USE_SESSION_STORAGE = !!this.config.useSessionStorage;
|
|
358
360
|
}
|
|
359
361
|
else if (window.USE_SESSION_STORAGE !== this.config.useSessionStorage) {
|
|
360
362
|
console.warn('[WebChat] "useSessionStorage" value cannot be altered once the webchat is initialized');
|
|
361
363
|
}
|
|
362
|
-
const locale =
|
|
364
|
+
const locale = (0, translations_1.getUserLocale)(this.config.locale);
|
|
363
365
|
this.updateBotUILanguage(locale);
|
|
364
366
|
document.documentElement.setAttribute('lang', locale);
|
|
365
367
|
this.publishConfigChanged();
|
|
366
368
|
}
|
|
367
|
-
/** When this method is used, the user ID is changed in the configuration, then the socket is updated */
|
|
368
|
-
setUserId(userId) {
|
|
369
|
-
this.config.userId = userId;
|
|
370
|
-
this.resetConversation();
|
|
371
|
-
// this.api.updateUserId(userId)
|
|
372
|
-
this.publishConfigChanged();
|
|
373
|
-
}
|
|
374
369
|
publishConfigChanged() {
|
|
375
370
|
this.postMessage('configChanged', JSON.stringify(this.config, undefined, 2));
|
|
376
371
|
}
|
|
377
|
-
setMessageWrapper(messageWrapper) {
|
|
378
|
-
this.messageWrapper = messageWrapper;
|
|
379
|
-
}
|
|
380
372
|
updatePreferredLanguage(lang) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
yield this.api.updateUserPreferredLanguage(lang);
|
|
384
|
-
});
|
|
373
|
+
this.preferredLanguage = lang;
|
|
374
|
+
(0, translations_1.setUserLocale)(lang);
|
|
385
375
|
}
|
|
386
376
|
/** Starts a timer to remove the typing animation when it's completed */
|
|
387
377
|
_startTypingTimer() {
|
|
@@ -390,7 +380,8 @@ class RootStore {
|
|
|
390
380
|
}
|
|
391
381
|
this.isBotTyping.set(true);
|
|
392
382
|
this._typingInterval = setInterval(() => {
|
|
393
|
-
|
|
383
|
+
var _a;
|
|
384
|
+
const typeUntil = new Date((_a = this.currentConversation) === null || _a === void 0 ? void 0 : _a.typingUntil);
|
|
394
385
|
if (!typeUntil || !(0, is_valid_1.default)(typeUntil) || (0, is_before_1.default)(typeUntil, new Date())) {
|
|
395
386
|
this._expireTyping();
|
|
396
387
|
}
|
|
@@ -402,20 +393,24 @@ class RootStore {
|
|
|
402
393
|
_expireTyping() {
|
|
403
394
|
this.emptyDelayedMessagesQueue(true);
|
|
404
395
|
this.isBotTyping.set(false);
|
|
405
|
-
this.currentConversation
|
|
396
|
+
if (this.currentConversation) {
|
|
397
|
+
this.currentConversation.typingUntil = undefined;
|
|
398
|
+
}
|
|
406
399
|
clearInterval(this._typingInterval);
|
|
407
400
|
this._typingInterval = undefined;
|
|
408
401
|
}
|
|
409
402
|
updateBotUILanguage(lang) {
|
|
410
403
|
lang = (0, translations_1.getUserLocale)(lang); // Ensure language is supported
|
|
411
404
|
(0, mobx_1.runInAction)('-> setBotUILanguage', () => {
|
|
412
|
-
var _a;
|
|
413
405
|
this.botUILanguage = lang;
|
|
414
406
|
this.preferredLanguage = lang;
|
|
415
|
-
(
|
|
407
|
+
(0, translations_1.setUserLocale)(lang);
|
|
416
408
|
});
|
|
417
409
|
}
|
|
418
410
|
emptyDelayedMessagesQueue(removeAll) {
|
|
411
|
+
if (!this.currentConversation) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
419
414
|
while (this.delayedMessages.length) {
|
|
420
415
|
const message = this.delayedMessages[0];
|
|
421
416
|
if (removeAll || (0, is_before_1.default)(message.showAt, new Date())) {
|
|
@@ -427,7 +422,7 @@ class RootStore {
|
|
|
427
422
|
}
|
|
428
423
|
}
|
|
429
424
|
}
|
|
430
|
-
/** Returns the current conversation ID, or the last one
|
|
425
|
+
/** Returns the current conversation ID, or the last one. */
|
|
431
426
|
_getCurrentConvoId() {
|
|
432
427
|
if (this.currentConversationId) {
|
|
433
428
|
return this.currentConversationId;
|
|
@@ -435,15 +430,6 @@ class RootStore {
|
|
|
435
430
|
if (!this.conversations.length) {
|
|
436
431
|
return;
|
|
437
432
|
}
|
|
438
|
-
// TODO: these settings need to be set in the frontend
|
|
439
|
-
/*
|
|
440
|
-
const lifeTimeMargin = Date.now() - ms(this.config.recentConversationLifetime)
|
|
441
|
-
const isConversationExpired =
|
|
442
|
-
new Date(this.conversations[0].lastMessage?.sentOn || this.conversations[0].createdOn).getTime() < lifeTimeMargin
|
|
443
|
-
if (isConversationExpired && this.config.startNewConvoOnTimeout) {
|
|
444
|
-
return
|
|
445
|
-
}
|
|
446
|
-
*/
|
|
447
433
|
return this.conversations[0].id;
|
|
448
434
|
}
|
|
449
435
|
}
|
|
@@ -468,9 +454,6 @@ __decorate([
|
|
|
468
454
|
__decorate([
|
|
469
455
|
mobx_1.observable
|
|
470
456
|
], RootStore.prototype, "messageFeedbacks", void 0);
|
|
471
|
-
__decorate([
|
|
472
|
-
mobx_1.observable
|
|
473
|
-
], RootStore.prototype, "messageWrapper", void 0);
|
|
474
457
|
__decorate([
|
|
475
458
|
mobx_1.observable
|
|
476
459
|
], RootStore.prototype, "botUILanguage", void 0);
|
|
@@ -486,9 +469,6 @@ __decorate([
|
|
|
486
469
|
__decorate([
|
|
487
470
|
mobx_1.computed
|
|
488
471
|
], RootStore.prototype, "botName", null);
|
|
489
|
-
__decorate([
|
|
490
|
-
mobx_1.computed
|
|
491
|
-
], RootStore.prototype, "isEmulator", null);
|
|
492
472
|
__decorate([
|
|
493
473
|
mobx_1.computed
|
|
494
474
|
], RootStore.prototype, "hasBotInfoDescription", null);
|
|
@@ -522,9 +502,6 @@ __decorate([
|
|
|
522
502
|
__decorate([
|
|
523
503
|
mobx_1.action.bound
|
|
524
504
|
], RootStore.prototype, "deleteConversation", null);
|
|
525
|
-
__decorate([
|
|
526
|
-
mobx_1.action.bound
|
|
527
|
-
], RootStore.prototype, "loadEventInDebugger", null);
|
|
528
505
|
__decorate([
|
|
529
506
|
mobx_1.action.bound
|
|
530
507
|
], RootStore.prototype, "addEventToConversation", null);
|
|
@@ -539,7 +516,7 @@ __decorate([
|
|
|
539
516
|
], RootStore.prototype, "fetchBotInfo", null);
|
|
540
517
|
__decorate([
|
|
541
518
|
mobx_1.action.bound
|
|
542
|
-
], RootStore.prototype, "
|
|
519
|
+
], RootStore.prototype, "fetchLanguage", null);
|
|
543
520
|
__decorate([
|
|
544
521
|
mobx_1.action.bound
|
|
545
522
|
], RootStore.prototype, "fetchConversations", null);
|
|
@@ -555,15 +532,9 @@ __decorate([
|
|
|
555
532
|
__decorate([
|
|
556
533
|
mobx_1.action.bound
|
|
557
534
|
], RootStore.prototype, "createConversation", null);
|
|
558
|
-
__decorate([
|
|
559
|
-
mobx_1.action.bound
|
|
560
|
-
], RootStore.prototype, "setReference", null);
|
|
561
535
|
__decorate([
|
|
562
536
|
mobx_1.action.bound
|
|
563
537
|
], RootStore.prototype, "resetConversation", null);
|
|
564
|
-
__decorate([
|
|
565
|
-
mobx_1.action.bound
|
|
566
|
-
], RootStore.prototype, "resetSession", null);
|
|
567
538
|
__decorate([
|
|
568
539
|
mobx_1.action.bound
|
|
569
540
|
], RootStore.prototype, "extractFeedback", null);
|
|
@@ -576,9 +547,6 @@ __decorate([
|
|
|
576
547
|
__decorate([
|
|
577
548
|
mobx_1.action.bound
|
|
578
549
|
], RootStore.prototype, "sendData", null);
|
|
579
|
-
__decorate([
|
|
580
|
-
mobx_1.action.bound
|
|
581
|
-
], RootStore.prototype, "uploadFile", null);
|
|
582
550
|
__decorate([
|
|
583
551
|
mobx_1.action.bound
|
|
584
552
|
], RootStore.prototype, "sendVoiceMessage", null);
|
|
@@ -588,15 +556,9 @@ __decorate([
|
|
|
588
556
|
__decorate([
|
|
589
557
|
mobx_1.action.bound
|
|
590
558
|
], RootStore.prototype, "updateConfig", null);
|
|
591
|
-
__decorate([
|
|
592
|
-
mobx_1.action.bound
|
|
593
|
-
], RootStore.prototype, "setUserId", null);
|
|
594
559
|
__decorate([
|
|
595
560
|
mobx_1.action.bound
|
|
596
561
|
], RootStore.prototype, "publishConfigChanged", null);
|
|
597
|
-
__decorate([
|
|
598
|
-
mobx_1.action.bound
|
|
599
|
-
], RootStore.prototype, "setMessageWrapper", null);
|
|
600
562
|
__decorate([
|
|
601
563
|
mobx_1.action.bound
|
|
602
564
|
], RootStore.prototype, "updatePreferredLanguage", null);
|
package/dist/store/view.d.ts
CHANGED
|
@@ -17,13 +17,11 @@ declare class ViewStore {
|
|
|
17
17
|
customButtons: CustomButton[];
|
|
18
18
|
customActions: CustomAction[];
|
|
19
19
|
disableAnimations: boolean;
|
|
20
|
-
highlightedMessages: string[];
|
|
21
20
|
constructor(rootStore: RootStore, fullscreen: boolean);
|
|
22
|
-
get showConversationsButton(): boolean;
|
|
21
|
+
get showConversationsButton(): boolean | undefined;
|
|
23
22
|
get showBotInfoButton(): boolean;
|
|
24
|
-
get showDownloadButton(): boolean;
|
|
25
|
-
get showDeleteConversationButton(): boolean;
|
|
26
|
-
get showResetButton(): boolean;
|
|
23
|
+
get showDownloadButton(): boolean | undefined;
|
|
24
|
+
get showDeleteConversationButton(): boolean | undefined;
|
|
27
25
|
get showCloseButton(): boolean;
|
|
28
26
|
get showWidgetButton(): boolean;
|
|
29
27
|
get hasUnreadMessages(): boolean;
|
|
@@ -51,7 +49,6 @@ declare class ViewStore {
|
|
|
51
49
|
addCustomAction(newAction: CustomAction): void;
|
|
52
50
|
removeCustomAction(actionId: string): void;
|
|
53
51
|
addHeaderButton(newButton: CustomButton): void;
|
|
54
|
-
setHighlightedMessages(ids: string[]): void;
|
|
55
52
|
/** Updates one or multiple properties of a specific button */
|
|
56
53
|
updateHeaderButton(buttonId: string, newProps: Partial<CustomButton>): void;
|
|
57
54
|
removeHeaderButton(buttonId: string): void;
|
package/dist/store/view.js
CHANGED
|
@@ -26,7 +26,6 @@ class ViewStore {
|
|
|
26
26
|
this.customButtons = [];
|
|
27
27
|
this.customActions = [];
|
|
28
28
|
this.disableAnimations = false;
|
|
29
|
-
this.highlightedMessages = [];
|
|
30
29
|
this.rootStore = rootStore;
|
|
31
30
|
this.isFullscreen = fullscreen;
|
|
32
31
|
this.activeView = fullscreen ? 'side' : 'widget';
|
|
@@ -36,8 +35,8 @@ class ViewStore {
|
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
get showConversationsButton() {
|
|
39
|
-
var _a
|
|
40
|
-
return
|
|
38
|
+
var _a;
|
|
39
|
+
return (_a = this.rootStore.config) === null || _a === void 0 ? void 0 : _a.showConversationsButton;
|
|
41
40
|
}
|
|
42
41
|
get showBotInfoButton() {
|
|
43
42
|
return !this.isConversationsDisplayed && this.rootStore.botInfo && this.rootStore.botInfo.showBotInfoPage;
|
|
@@ -48,10 +47,6 @@ class ViewStore {
|
|
|
48
47
|
get showDeleteConversationButton() {
|
|
49
48
|
return (!this.isConversationsDisplayed && !this.isBotInfoDisplayed && this.rootStore.config.enableConversationDeletion);
|
|
50
49
|
}
|
|
51
|
-
get showResetButton() {
|
|
52
|
-
var _a;
|
|
53
|
-
return !this.isConversationsDisplayed && !this.isBotInfoDisplayed && ((_a = this.rootStore.config) === null || _a === void 0 ? void 0 : _a.enableReset);
|
|
54
|
-
}
|
|
55
50
|
get showCloseButton() {
|
|
56
51
|
return !this.isFullscreen;
|
|
57
52
|
}
|
|
@@ -151,9 +146,6 @@ class ViewStore {
|
|
|
151
146
|
}
|
|
152
147
|
this.customButtons.push(newButton);
|
|
153
148
|
}
|
|
154
|
-
setHighlightedMessages(ids) {
|
|
155
|
-
this.highlightedMessages = ids;
|
|
156
|
-
}
|
|
157
149
|
/** Updates one or multiple properties of a specific button */
|
|
158
150
|
updateHeaderButton(buttonId, newProps) {
|
|
159
151
|
const button = this.customButtons.find((btn) => btn.id === buttonId);
|
|
@@ -171,7 +163,7 @@ class ViewStore {
|
|
|
171
163
|
this._updateTransitions({ widgetTransition: 'fadeOut' });
|
|
172
164
|
setTimeout(() => {
|
|
173
165
|
this._updateTransitions({ sideTransition: 'fadeIn' });
|
|
174
|
-
}, constants_1.default.
|
|
166
|
+
}, constants_1.default.ANIMATION_DURATION + 10);
|
|
175
167
|
this._endAnimation('side');
|
|
176
168
|
this.rootStore.postMessage('webchatOpened');
|
|
177
169
|
}
|
|
@@ -188,7 +180,7 @@ class ViewStore {
|
|
|
188
180
|
if (!this.activeView || this.activeView === 'side') {
|
|
189
181
|
setTimeout(() => {
|
|
190
182
|
this._updateTransitions({ widgetTransition: 'fadeIn' });
|
|
191
|
-
}, constants_1.default.
|
|
183
|
+
}, constants_1.default.ANIMATION_DURATION + 10);
|
|
192
184
|
}
|
|
193
185
|
this._endAnimation('widget');
|
|
194
186
|
this.rootStore.postMessage('webchatClosed');
|
|
@@ -198,13 +190,13 @@ class ViewStore {
|
|
|
198
190
|
(0, mobx_1.runInAction)(() => {
|
|
199
191
|
this.activeView = finalView;
|
|
200
192
|
});
|
|
201
|
-
}, constants_1.default.
|
|
193
|
+
}, constants_1.default.ANIMATION_DURATION);
|
|
202
194
|
setTimeout(() => {
|
|
203
195
|
this._updateTransitions({
|
|
204
196
|
widgetTransition: undefined,
|
|
205
197
|
sideTransition: this.transitions.sideTransition === 'fadeIn' ? 'fadeIn' : undefined
|
|
206
198
|
});
|
|
207
|
-
}, constants_1.default.
|
|
199
|
+
}, constants_1.default.ANIMATION_DURATION * 2.1);
|
|
208
200
|
}
|
|
209
201
|
_updateTransitions({ widgetTransition, sideTransition }) {
|
|
210
202
|
this.transitions = { widgetTransition, sideTransition };
|
|
@@ -260,9 +252,6 @@ __decorate([
|
|
|
260
252
|
__decorate([
|
|
261
253
|
mobx_1.observable
|
|
262
254
|
], ViewStore.prototype, "disableAnimations", void 0);
|
|
263
|
-
__decorate([
|
|
264
|
-
mobx_1.observable
|
|
265
|
-
], ViewStore.prototype, "highlightedMessages", void 0);
|
|
266
255
|
__decorate([
|
|
267
256
|
mobx_1.computed
|
|
268
257
|
], ViewStore.prototype, "showConversationsButton", null);
|
|
@@ -275,9 +264,6 @@ __decorate([
|
|
|
275
264
|
__decorate([
|
|
276
265
|
mobx_1.computed
|
|
277
266
|
], ViewStore.prototype, "showDeleteConversationButton", null);
|
|
278
|
-
__decorate([
|
|
279
|
-
mobx_1.computed
|
|
280
|
-
], ViewStore.prototype, "showResetButton", null);
|
|
281
267
|
__decorate([
|
|
282
268
|
mobx_1.computed
|
|
283
269
|
], ViewStore.prototype, "showCloseButton", null);
|
|
@@ -353,9 +339,6 @@ __decorate([
|
|
|
353
339
|
__decorate([
|
|
354
340
|
mobx_1.action.bound
|
|
355
341
|
], ViewStore.prototype, "addHeaderButton", null);
|
|
356
|
-
__decorate([
|
|
357
|
-
mobx_1.action.bound
|
|
358
|
-
], ViewStore.prototype, "setHighlightedMessages", null);
|
|
359
342
|
__decorate([
|
|
360
343
|
mobx_1.action.bound
|
|
361
344
|
], ViewStore.prototype, "updateHeaderButton", null);
|
|
@@ -4,4 +4,6 @@ declare const translations: {
|
|
|
4
4
|
[lang: string]: any;
|
|
5
5
|
};
|
|
6
6
|
declare const getUserLocale: (manualLocale?: Locale) => string;
|
|
7
|
-
|
|
7
|
+
declare const setUserLocale: (locale: Locale) => void;
|
|
8
|
+
declare const isRTLLocale: (locale?: string | undefined) => boolean;
|
|
9
|
+
export { translations, DEFAULT_LOCALE as defaultLocale, getUserLocale, setUserLocale, isRTLLocale };
|