@botpress/webchat 0.3.3 → 0.3.4
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/socket.d.ts +3 -0
- package/dist/core/socket.js +16 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +10 -2
- package/dist/typings.d.ts +7 -0
- package/package.json +1 -1
package/dist/core/socket.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message, MessagingSocket } from '@botpress/messaging-socket';
|
|
2
2
|
import { Config } from '../typings';
|
|
3
3
|
export default class BpSocket {
|
|
4
|
+
private config;
|
|
4
5
|
socket: MessagingSocket;
|
|
5
6
|
private chatId;
|
|
6
7
|
onMessage: (event: any) => void;
|
|
@@ -9,4 +10,6 @@ export default class BpSocket {
|
|
|
9
10
|
sendPayload(payload: any): Promise<Message>;
|
|
10
11
|
postToParent: (_type: string, payload: any) => void;
|
|
11
12
|
connect(): Promise<void>;
|
|
13
|
+
reload(config: Config): Promise<void>;
|
|
14
|
+
private getCreds;
|
|
12
15
|
}
|
package/dist/core/socket.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const messaging_socket_1 = require("@botpress/messaging-socket");
|
|
13
13
|
class BpSocket {
|
|
14
14
|
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
15
16
|
this.postToParent = (_type, payload) => {
|
|
16
17
|
var _a;
|
|
17
18
|
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage(Object.assign(Object.assign({}, payload), { chatId: this.chatId }), '*');
|
|
@@ -32,7 +33,7 @@ class BpSocket {
|
|
|
32
33
|
}
|
|
33
34
|
connect() {
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const creds =
|
|
36
|
+
const creds = this.getCreds();
|
|
36
37
|
yield this.socket.connect(creds);
|
|
37
38
|
if (this.socket.userId) {
|
|
38
39
|
const userId = this.socket.userId;
|
|
@@ -41,5 +42,19 @@ class BpSocket {
|
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
}
|
|
45
|
+
reload(config) {
|
|
46
|
+
var _a;
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
this.config = config;
|
|
49
|
+
const creds = this.getCreds();
|
|
50
|
+
if ((creds === null || creds === void 0 ? void 0 : creds.userId) !== this.socket.userId || (creds === null || creds === void 0 ? void 0 : creds.userToken) !== ((_a = this.socket.creds) === null || _a === void 0 ? void 0 : _a.userToken)) {
|
|
51
|
+
yield this.socket.disconnect();
|
|
52
|
+
yield this.connect();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getCreds() {
|
|
57
|
+
return this.config.customUser || window.BP_STORAGE.get('creds');
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
exports.default = BpSocket;
|
package/dist/main.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omi
|
|
|
10
10
|
export default _default;
|
|
11
11
|
declare type MainProps = {
|
|
12
12
|
store?: RootStore;
|
|
13
|
-
} & WrappedComponentProps & Pick<StoreDef, 'config' | 'initializeChat' | 'botInfo' | 'fetchBotInfo' | 'sendMessage' | 'sendData' | 'intl' | 'updateTyping' | 'updateBotUILanguage' | 'hideChat' | 'showChat' | 'toggleBotInfo' | 'widgetTransition' | 'activeView' | 'isFullscreen' | 'unreadCount' | 'hasUnreadMessages' | 'showWidgetButton' | 'addEventToConversation' | 'clearMessages' | 'updateConfig' | 'mergeConfig' | 'isWebchatReady' | 'incrementUnread' | 'displayWidgetView' | 'resetUnread' | 'setLoadingCompleted' | 'dimensions' | 'updateLastMessage' | 'fetchConversation' | 'setIntlProvider' | 'setSocket' | 'currentConversationId'>;
|
|
13
|
+
} & WrappedComponentProps & Pick<StoreDef, 'config' | 'initializeChat' | 'botInfo' | 'fetchBotInfo' | 'sendMessage' | 'sendData' | 'intl' | 'updateTyping' | 'updateBotUILanguage' | 'hideChat' | 'showChat' | 'toggleBotInfo' | 'widgetTransition' | 'activeView' | 'isFullscreen' | 'unreadCount' | 'hasUnreadMessages' | 'showWidgetButton' | 'addEventToConversation' | 'clearMessages' | 'updateConfig' | 'mergeConfig' | 'isWebchatReady' | 'incrementUnread' | 'displayWidgetView' | 'resetUnread' | 'setLoadingCompleted' | 'dimensions' | 'updateLastMessage' | 'fetchConversation' | 'setIntlProvider' | 'setSocket' | 'currentConversationId' | 'resetConversation'>;
|
package/dist/main.js
CHANGED
|
@@ -68,7 +68,14 @@ class Web extends react_1.default.Component {
|
|
|
68
68
|
case 'configure':
|
|
69
69
|
return this.props.updateConfig(Object.assign({}, constants_1.default.DEFAULT_CONFIG, data.payload));
|
|
70
70
|
case 'mergeConfig':
|
|
71
|
-
|
|
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;
|
|
72
79
|
case 'sendPayload':
|
|
73
80
|
return this.props.sendData(data.payload);
|
|
74
81
|
case 'event':
|
|
@@ -318,5 +325,6 @@ exports.default = (0, mobx_react_1.inject)(({ store }) => ({
|
|
|
318
325
|
fetchConversation: store.fetchConversation,
|
|
319
326
|
setIntlProvider: store.setIntlProvider,
|
|
320
327
|
setSocket: store.setSocket,
|
|
321
|
-
currentConversationId: store.currentConversationId
|
|
328
|
+
currentConversationId: store.currentConversationId,
|
|
329
|
+
resetConversation: store.resetConversation
|
|
322
330
|
}))((0, react_intl_1.injectIntl)((0, mobx_react_1.observer)(Web)));
|
package/dist/typings.d.ts
CHANGED
|
@@ -277,6 +277,13 @@ export interface Config {
|
|
|
277
277
|
* @default ''
|
|
278
278
|
*/
|
|
279
279
|
googleMapsAPIKey?: string;
|
|
280
|
+
/**
|
|
281
|
+
* Allows setting a custom user id
|
|
282
|
+
*/
|
|
283
|
+
customUser?: {
|
|
284
|
+
userId: string;
|
|
285
|
+
userToken: string;
|
|
286
|
+
};
|
|
280
287
|
}
|
|
281
288
|
export interface BotDetails {
|
|
282
289
|
website?: string;
|