@botpress/webchat 0.2.4 → 0.2.5
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/core/api.d.ts +1 -2
- package/dist/core/api.js +6 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -9
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +19 -5
- package/dist/utils/storage.d.ts +4 -5
- package/dist/utils/storage.js +23 -11
- package/package.json +1 -1
package/dist/core/api.d.ts
CHANGED
|
@@ -5,10 +5,9 @@ import { BotInfo, uuid } from '../typings';
|
|
|
5
5
|
import BpSocket from './socket';
|
|
6
6
|
export default class WebchatApi {
|
|
7
7
|
private socket;
|
|
8
|
-
private axios;
|
|
9
|
-
private axiosConfig;
|
|
10
8
|
constructor(socket: BpSocket);
|
|
11
9
|
fetchBotInfo(mediaFileServiceUrl: string): Promise<BotInfo | undefined>;
|
|
10
|
+
listCurrentConversationMessages(limit?: number): Promise<Message[]>;
|
|
12
11
|
fetchConversations(): Promise<RecentConversation[]>;
|
|
13
12
|
fetchConversation(conversationId: uuid): Promise<{
|
|
14
13
|
messages: Message[];
|
package/dist/core/api.js
CHANGED
|
@@ -29,6 +29,11 @@ class WebchatApi {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
+
listCurrentConversationMessages(limit) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return this.socket.socket.listMessages(limit);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
32
37
|
fetchConversations() {
|
|
33
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
39
|
try {
|
|
@@ -37,7 +42,7 @@ class WebchatApi {
|
|
|
37
42
|
for (const conversation of conversations) {
|
|
38
43
|
const limit = 1;
|
|
39
44
|
yield this.socket.socket.switchConversation(conversation.id);
|
|
40
|
-
const lastMessages = yield this.
|
|
45
|
+
const lastMessages = yield this.listCurrentConversationMessages(limit);
|
|
41
46
|
if (lastMessages.length >= limit) {
|
|
42
47
|
conversation.lastMessage = lastMessages[0];
|
|
43
48
|
}
|
|
@@ -125,7 +130,6 @@ class WebchatApi {
|
|
|
125
130
|
data.append('file', file);
|
|
126
131
|
data.append('conversationId', conversationId);
|
|
127
132
|
data.append('payload', payload);
|
|
128
|
-
return this.axios.post('/messages/files', data, this.axiosConfig);
|
|
129
133
|
});
|
|
130
134
|
}
|
|
131
135
|
// TODO: Fix this
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,12 +30,7 @@ exports.Fullscreen = Fullscreen;
|
|
|
30
30
|
class ExposedWebChat extends react_1.default.Component {
|
|
31
31
|
constructor(props) {
|
|
32
32
|
super(props);
|
|
33
|
-
|
|
34
|
-
window.BP_STORAGE = new storage_1.default({
|
|
35
|
-
clientId,
|
|
36
|
-
encryptionKey,
|
|
37
|
-
useSessionStorage
|
|
38
|
-
});
|
|
33
|
+
window.BP_STORAGE = new storage_1.default(props.config);
|
|
39
34
|
this.state = {
|
|
40
35
|
store: new store_1.RootStore({ fullscreen: props.fullscreen }, props.config)
|
|
41
36
|
};
|
|
@@ -44,9 +39,8 @@ class ExposedWebChat extends react_1.default.Component {
|
|
|
44
39
|
const store = this.state.store;
|
|
45
40
|
const { botUILanguage: locale } = store;
|
|
46
41
|
return (react_1.default.createElement(mobx_react_1.Provider, { store: store },
|
|
47
|
-
react_1.default.createElement(react_intl_1.IntlProvider, { locale: locale, messages: translations_1.translations[locale], defaultLocale: translations_1.defaultLocale },
|
|
48
|
-
react_1.default.createElement(
|
|
49
|
-
react_1.default.createElement(main_1.default, Object.assign({ store: store }, this.props))))));
|
|
42
|
+
react_1.default.createElement(react_intl_1.IntlProvider, { locale: locale, messages: translations_1.translations[locale || translations_1.defaultLocale], defaultLocale: translations_1.defaultLocale },
|
|
43
|
+
react_1.default.createElement(main_1.default, Object.assign({ store: store }, this.props)))));
|
|
50
44
|
}
|
|
51
45
|
}
|
|
52
46
|
exports.ExposedWebChat = ExposedWebChat;
|
package/dist/store/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare class RootStore {
|
|
|
24
24
|
delayedMessages: QueuedMessage[];
|
|
25
25
|
constructor(options: {
|
|
26
26
|
fullscreen: boolean;
|
|
27
|
-
}, config
|
|
27
|
+
}, config?: Config);
|
|
28
28
|
setIntlProvider(provider: IntlShape): void;
|
|
29
29
|
setSocket(socket: BpSocket): void;
|
|
30
30
|
get isConversationStarted(): boolean;
|
package/dist/store/index.js
CHANGED
|
@@ -37,7 +37,9 @@ class RootStore {
|
|
|
37
37
|
this.delayedMessages = [];
|
|
38
38
|
this.composer = new composer_1.default(this);
|
|
39
39
|
this.view = new view_1.default(this, options.fullscreen);
|
|
40
|
-
|
|
40
|
+
if (config) {
|
|
41
|
+
this.updateConfig(config);
|
|
42
|
+
}
|
|
41
43
|
this.botUILanguage = (0, translations_1.getUserLocale)();
|
|
42
44
|
}
|
|
43
45
|
setIntlProvider(provider) {
|
|
@@ -51,8 +53,8 @@ class RootStore {
|
|
|
51
53
|
return !!((_a = this.currentConversation) === null || _a === void 0 ? void 0 : _a.messages.length);
|
|
52
54
|
}
|
|
53
55
|
get botName() {
|
|
54
|
-
var _a;
|
|
55
|
-
return this.config.botName || ((
|
|
56
|
+
var _a, _b;
|
|
57
|
+
return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.botName) || ((_b = this.botInfo) === null || _b === void 0 ? void 0 : _b.name) || 'Bot';
|
|
56
58
|
}
|
|
57
59
|
get hasBotInfoDescription() {
|
|
58
60
|
var _a;
|
|
@@ -297,8 +299,20 @@ class RootStore {
|
|
|
297
299
|
return;
|
|
298
300
|
}
|
|
299
301
|
let info = `Conversation Id: ${conversation.id}\nCreated on: ${formatDate(conversation.createdOn)}\nUser: ${conversation.userId}\n-----------------`;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
+
const messages = yield this.api.listCurrentConversationMessages(500);
|
|
303
|
+
for (const message of (0, orderBy_1.default)(messages, 'sentOn', 'desc')) {
|
|
304
|
+
const payload = message.payload;
|
|
305
|
+
if (payload.type === 'session_reset') {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
info += `\n[${formatDate(message.sentOn)}] ${message.authorId ? 'User' : this.config.botId || 'Bot'}: Event (${payload.type}): ${payload.text ||
|
|
309
|
+
payload.audio ||
|
|
310
|
+
payload.image ||
|
|
311
|
+
payload.video ||
|
|
312
|
+
payload.file ||
|
|
313
|
+
payload.message ||
|
|
314
|
+
payload.title ||
|
|
315
|
+
''}`;
|
|
302
316
|
}
|
|
303
317
|
const blobFile = new Blob([info]);
|
|
304
318
|
(0, utils_1.downloadFile)(`conversation-${conversation.id}`, blobFile);
|
package/dist/utils/storage.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Config } from '../typings';
|
|
2
|
-
export declare type StorageConfig = Pick<Config, 'clientId' | 'encryptionKey' | 'useSessionStorage'>;
|
|
3
2
|
export declare class BPStorage {
|
|
4
|
-
private _config
|
|
3
|
+
private _config?;
|
|
5
4
|
private _storage;
|
|
6
|
-
constructor(config
|
|
7
|
-
get config():
|
|
8
|
-
set config(config:
|
|
5
|
+
constructor(config?: Config);
|
|
6
|
+
get config(): Config | undefined;
|
|
7
|
+
set config(config: Config | undefined);
|
|
9
8
|
private serialize;
|
|
10
9
|
private deserialize;
|
|
11
10
|
private getStorageKey;
|
package/dist/utils/storage.js
CHANGED
|
@@ -11,7 +11,7 @@ const js_cookie_1 = __importDefault(require("js-cookie"));
|
|
|
11
11
|
class BPStorage {
|
|
12
12
|
constructor(config) {
|
|
13
13
|
this.serialize = (value) => {
|
|
14
|
-
var _a;
|
|
14
|
+
var _a, _b;
|
|
15
15
|
if (value === null || value === undefined) {
|
|
16
16
|
throw new Error('[Storage] Cannot store null or undefined values');
|
|
17
17
|
}
|
|
@@ -23,47 +23,48 @@ class BPStorage {
|
|
|
23
23
|
else {
|
|
24
24
|
str = JSON.stringify(value);
|
|
25
25
|
}
|
|
26
|
-
if ((_a = this.config
|
|
26
|
+
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.encryptionKey) === null || _b === void 0 ? void 0 : _b.length) {
|
|
27
27
|
str = aes_1.default.encrypt(str, this.config.encryptionKey).toString();
|
|
28
28
|
}
|
|
29
29
|
return str;
|
|
30
30
|
}
|
|
31
|
-
catch (
|
|
31
|
+
catch (_c) {
|
|
32
32
|
console.error('[Storage] Error parsing value', value);
|
|
33
33
|
return '';
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
this.deserialize = (strValue) => {
|
|
37
|
-
var _a;
|
|
37
|
+
var _a, _b;
|
|
38
38
|
if (strValue === null || strValue === undefined) {
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
41
41
|
try {
|
|
42
|
-
if ((_a = this.config
|
|
42
|
+
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.encryptionKey) === null || _b === void 0 ? void 0 : _b.length) {
|
|
43
43
|
strValue = aes_1.default.decrypt(strValue, this.config.encryptionKey).toString(enc_utf8_1.default);
|
|
44
44
|
}
|
|
45
45
|
return JSON.parse(strValue);
|
|
46
46
|
}
|
|
47
|
-
catch (
|
|
47
|
+
catch (_c) {
|
|
48
48
|
return undefined;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
this.getStorageKey = (key) => {
|
|
52
|
-
var _a, _b;
|
|
52
|
+
var _a, _b, _c;
|
|
53
53
|
const rawKey = `bp-chat-${key}`;
|
|
54
54
|
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.encryptionKey) === null || _b === void 0 ? void 0 : _b.length) {
|
|
55
55
|
return `${rawKey}-${(0, sha256_1.default)(`${this.config.clientId}-${this.config.encryptionKey}`).toString()}`;
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
return `${rawKey}-${this.config.clientId}`;
|
|
58
|
+
return `${rawKey}-${(_c = this.config) === null || _c === void 0 ? void 0 : _c.clientId}`;
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
this.getDriver = () => {
|
|
62
|
+
var _a;
|
|
62
63
|
if (this._storage) {
|
|
63
64
|
return this._storage;
|
|
64
65
|
}
|
|
65
66
|
try {
|
|
66
|
-
const storage = this.config.useSessionStorage === true && typeof sessionStorage !== 'undefined' ? sessionStorage : localStorage;
|
|
67
|
+
const storage = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.useSessionStorage) === true && typeof sessionStorage !== 'undefined' ? sessionStorage : localStorage;
|
|
67
68
|
const tempKey = '__storage_test__';
|
|
68
69
|
storage.setItem(tempKey, tempKey);
|
|
69
70
|
storage.removeItem(tempKey);
|
|
@@ -73,15 +74,20 @@ class BPStorage {
|
|
|
73
74
|
return (this._storage = 'cookie');
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
|
-
|
|
77
|
+
if (config) {
|
|
78
|
+
this._config = config;
|
|
79
|
+
}
|
|
77
80
|
}
|
|
78
81
|
get config() {
|
|
79
82
|
return this._config;
|
|
80
83
|
}
|
|
81
84
|
set config(config) {
|
|
82
|
-
this._config =
|
|
85
|
+
this._config = config;
|
|
83
86
|
}
|
|
84
87
|
set(key, value) {
|
|
88
|
+
if (!this.config) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
85
91
|
try {
|
|
86
92
|
const driver = this.getDriver();
|
|
87
93
|
driver !== 'cookie'
|
|
@@ -93,6 +99,9 @@ class BPStorage {
|
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
get(key) {
|
|
102
|
+
if (!this.config) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
96
105
|
try {
|
|
97
106
|
const driver = this.getDriver();
|
|
98
107
|
return driver !== 'cookie'
|
|
@@ -104,6 +113,9 @@ class BPStorage {
|
|
|
104
113
|
}
|
|
105
114
|
}
|
|
106
115
|
del(key) {
|
|
116
|
+
if (!this.config) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
107
119
|
try {
|
|
108
120
|
const driver = this.getDriver();
|
|
109
121
|
driver !== 'cookie' ? driver.removeItem(this.getStorageKey(key)) : js_cookie_1.default.remove(this.getStorageKey(key));
|