@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.
Files changed (70) hide show
  1. package/README.md +31 -0
  2. package/dist/components/Composer.d.ts +4 -5
  3. package/dist/components/Composer.js +13 -23
  4. package/dist/components/Container.d.ts +1 -1
  5. package/dist/components/Container.js +1 -6
  6. package/dist/components/ConversationList.d.ts +1 -1
  7. package/dist/components/ConversationList.js +5 -46
  8. package/dist/components/Header.d.ts +1 -3
  9. package/dist/components/Header.js +17 -64
  10. package/dist/components/VoiceRecorder.js +6 -2
  11. package/dist/components/common/{Avatar.d.ts → Avatar/index.d.ts} +0 -0
  12. package/dist/components/common/Avatar/index.js +13 -0
  13. package/dist/components/common/{BotInfo.d.ts → BotInfo/index.d.ts} +3 -3
  14. package/dist/components/common/BotInfo/index.js +102 -0
  15. package/dist/components/common/ConfirmDialog/index.d.ts +11 -0
  16. package/dist/components/common/ConfirmDialog/index.js +78 -0
  17. package/dist/components/common/Dialog/index.d.ts +17 -0
  18. package/dist/components/common/Dialog/index.js +57 -0
  19. package/dist/components/common/ToolTip/index.d.ts +10 -0
  20. package/dist/components/common/ToolTip/index.js +163 -0
  21. package/dist/components/common/ToolTip/utils.d.ts +15 -0
  22. package/dist/components/common/ToolTip/utils.js +78 -0
  23. package/dist/components/messages/InlineFeedback.d.ts +2 -1
  24. package/dist/components/messages/Message.js +2 -25
  25. package/dist/components/messages/MessageGroup.d.ts +1 -13
  26. package/dist/components/messages/MessageGroup.js +6 -40
  27. package/dist/components/messages/MessageList.d.ts +1 -1
  28. package/dist/components/messages/MessageList.js +8 -31
  29. package/dist/core/api.d.ts +4 -18
  30. package/dist/core/api.js +25 -150
  31. package/dist/core/constants.d.ts +4 -32
  32. package/dist/core/constants.js +18 -32
  33. package/dist/core/socket.d.ts +1 -12
  34. package/dist/core/socket.js +7 -73
  35. package/dist/{components/Stylesheet.d.ts → icons/Cancel.d.ts} +2 -2
  36. package/dist/icons/Cancel.js +10 -0
  37. package/dist/icons/Microphone.d.ts +5 -0
  38. package/dist/icons/Microphone.js +12 -0
  39. package/dist/index.d.ts +2 -8
  40. package/dist/index.js +9 -29
  41. package/dist/main.d.ts +2 -2
  42. package/dist/main.js +100 -168
  43. package/dist/store/composer.js +3 -6
  44. package/dist/store/index.d.ts +8 -18
  45. package/dist/store/index.js +98 -136
  46. package/dist/store/view.d.ts +3 -6
  47. package/dist/store/view.js +6 -23
  48. package/dist/translations/index.d.ts +3 -1
  49. package/dist/translations/index.js +44 -4
  50. package/dist/typings.d.ts +121 -71
  51. package/dist/utils/analytics.d.ts +5 -0
  52. package/dist/utils/analytics.js +37 -0
  53. package/dist/utils/index.d.ts +3 -0
  54. package/dist/utils/index.js +27 -0
  55. package/dist/utils/storage.d.ts +16 -0
  56. package/dist/utils/storage.js +129 -0
  57. package/package.json +4 -3
  58. package/dist/components/ContextMenu.d.ts +0 -2
  59. package/dist/components/ContextMenu.js +0 -33
  60. package/dist/components/OverridableComponent.d.ts +0 -24
  61. package/dist/components/OverridableComponent.js +0 -50
  62. package/dist/components/Stylesheet.js +0 -7
  63. package/dist/components/common/Avatar.js +0 -29
  64. package/dist/components/common/BotInfo.js +0 -110
  65. package/dist/icons/CloseChat.d.ts +0 -6
  66. package/dist/icons/CloseChat.js +0 -9
  67. package/dist/icons/Send.d.ts +0 -6
  68. package/dist/icons/Send.js +0 -8
  69. package/dist/utils.d.ts +0 -8
  70. package/dist/utils.js +0 -111
@@ -17,22 +17,6 @@ class MessageList extends react_1.default.Component {
17
17
  constructor() {
18
18
  super(...arguments);
19
19
  this.state = { showNewMessageIndicator: false, manualScroll: false };
20
- this.handleKeyDown = (e) => {
21
- if (!this.props.enableArrowNavigation) {
22
- return;
23
- }
24
- const maxScroll = this.messagesDiv.scrollHeight - this.messagesDiv.clientHeight;
25
- const shouldFocusNext = e.key === 'ArrowRight' || (e.key === 'ArrowDown' && this.messagesDiv.scrollTop === maxScroll);
26
- const shouldFocusPrevious = e.key === 'ArrowLeft' || (e.key === 'ArrowUp' && this.messagesDiv.scrollTop === 0);
27
- if (shouldFocusNext) {
28
- this.messagesDiv.blur();
29
- this.props.focusNext();
30
- }
31
- if (shouldFocusPrevious) {
32
- this.messagesDiv.blur();
33
- this.props.focusPrevious();
34
- }
35
- };
36
20
  this.shouldDisplayMessage = (m) => {
37
21
  return m.payload.type !== 'postback';
38
22
  };
@@ -60,7 +44,7 @@ class MessageList extends react_1.default.Component {
60
44
  });
61
45
  }
62
46
  // this should account for keyboard rendering as it triggers a resize of the messagesDiv
63
- this.divSizeObserver = new resize_observer_1.ResizeObserver((0, debounce_1.default)(([divResizeEntry]) => {
47
+ this.divSizeObserver = new resize_observer_1.ResizeObserver((0, debounce_1.default)((_divResizeEntry) => {
64
48
  // we don't need to do anything with the resize entry
65
49
  this.tryScrollToBottom();
66
50
  }, 200, { trailing: true }));
@@ -96,7 +80,7 @@ class MessageList extends react_1.default.Component {
96
80
  react_1.default.createElement("div", { className: 'bpw-small-line' })));
97
81
  }
98
82
  renderAvatar(name, url) {
99
- const avatarSize = this.props.isEmulator ? 20 : 40; // quick fix
83
+ const avatarSize = 40;
100
84
  return react_1.default.createElement(Avatar_1.default, { name: name, avatarUrl: url, height: avatarSize, width: avatarSize });
101
85
  }
102
86
  renderMessageGroups() {
@@ -106,8 +90,7 @@ class MessageList extends react_1.default.Component {
106
90
  let lastDate = undefined;
107
91
  let currentGroup = undefined;
108
92
  messages.forEach((m) => {
109
- var _a, _b;
110
- const speaker = ((_b = (_a = m.payload.channel) === null || _a === void 0 ? void 0 : _a.web) === null || _b === void 0 ? void 0 : _b.userName) || m.authorId;
93
+ const speaker = m.authorId;
111
94
  const date = m.sentOn;
112
95
  // Create a new group if messages are separated by more than X minutes or if different speaker
113
96
  if (speaker !== lastSpeaker ||
@@ -134,24 +117,21 @@ class MessageList extends react_1.default.Component {
134
117
  });
135
118
  }
136
119
  return (react_1.default.createElement("div", null, groups.map((group, i) => {
137
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
120
+ var _a;
138
121
  const lastGroup = groups[i - 1];
139
122
  const lastDate = (_a = lastGroup === null || lastGroup === void 0 ? void 0 : lastGroup[lastGroup.length - 1]) === null || _a === void 0 ? void 0 : _a.sentOn;
140
123
  const groupDate = group === null || group === void 0 ? void 0 : group[0].sentOn;
141
124
  const isDateNeeded = !groups[i - 1] ||
142
125
  (0, difference_in_minutes_1.default)(new Date(groupDate), new Date(lastDate)) > constants_1.default.TIME_BETWEEN_DATES;
143
- const [{ authorId, payload }] = group;
144
- const avatar = authorId
145
- ? this.props.showUserAvatar &&
146
- this.renderAvatar((_c = (_b = payload.channel) === null || _b === void 0 ? void 0 : _b.web) === null || _c === void 0 ? void 0 : _c.userName, (_e = (_d = payload.channel) === null || _d === void 0 ? void 0 : _d.web) === null || _e === void 0 ? void 0 : _e.avatarUrl)
147
- : this.renderAvatar(this.props.botName, ((_g = (_f = payload.channel) === null || _f === void 0 ? void 0 : _f.web) === null || _g === void 0 ? void 0 : _g.avatarUrl) || this.props.botAvatarUrl);
126
+ const [{ authorId }] = group;
127
+ const avatar = !authorId && this.renderAvatar(this.props.botName, this.props.botAvatarUrl);
148
128
  return (react_1.default.createElement("div", { key: i },
149
129
  isDateNeeded && this.renderDate(group[0].sentOn),
150
- react_1.default.createElement(MessageGroup_1.default, { isBot: !authorId, avatar: avatar, userName: (_j = (_h = payload.channel) === null || _h === void 0 ? void 0 : _h.web) === null || _j === void 0 ? void 0 : _j.userName, key: `msg-group-${i}`, isLastGroup: i >= groups.length - 1, messages: group })));
130
+ react_1.default.createElement(MessageGroup_1.default, { isBot: !authorId, avatar: avatar, key: `msg-group-${i}`, isLastGroup: i >= groups.length - 1, messages: group })));
151
131
  })));
152
132
  }
153
133
  render() {
154
- return (react_1.default.createElement("div", { tabIndex: 0, onKeyDown: this.handleKeyDown, className: 'bpw-msg-list', ref: (m) => {
134
+ return (react_1.default.createElement("div", { tabIndex: 0, className: 'bpw-msg-list', ref: (m) => {
155
135
  this.messagesDiv = m;
156
136
  }, onScroll: this.handleScroll },
157
137
  this.state.showNewMessageIndicator && (react_1.default.createElement("div", { className: "bpw-new-messages-indicator", onClick: (e) => this.tryScrollToBottom() },
@@ -163,7 +143,6 @@ class MessageList extends react_1.default.Component {
163
143
  }
164
144
  exports.default = (0, mobx_react_1.inject)(({ store }) => ({
165
145
  intl: store.intl,
166
- isEmulator: store.isEmulator,
167
146
  botName: store.botName,
168
147
  isBotTyping: store.isBotTyping,
169
148
  botAvatarUrl: store.botAvatarUrl,
@@ -171,7 +150,5 @@ exports.default = (0, mobx_react_1.inject)(({ store }) => ({
171
150
  focusPrevious: store.view.focusPrevious,
172
151
  focusNext: store.view.focusNext,
173
152
  focusedArea: store.view.focusedArea,
174
- showUserAvatar: store.config.showUserAvatar,
175
- enableArrowNavigation: store.config.enableArrowNavigation,
176
153
  preferredLanguage: store.preferredLanguage
177
154
  }))((0, react_intl_1.injectIntl)((0, mobx_react_1.observer)(MessageList)));
@@ -1,19 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import { Message } from '@botpress/messaging-socket';
3
- import { RecentConversation } from '..';
4
- import { EventFeedback, uuid } from '../typings';
3
+ import { uuid, RecentConversation } from '../typings';
5
4
  import BpSocket from './socket';
6
5
  export default class WebchatApi {
7
6
  private socket;
8
- private axios;
9
- private axiosConfig;
10
- private userId;
11
7
  constructor(socket: BpSocket);
12
- private get baseUserPayload();
13
- fetchBotInfo(): Promise<any>;
14
- fetchPreferences(): Promise<any>;
15
- updateUserPreferredLanguage(language: string): Promise<void>;
16
- fetchConversations(): Promise<RecentConversation[] | undefined>;
8
+ listCurrentConversationMessages(limit?: number): Promise<Message[] | undefined>;
9
+ fetchConversations(): Promise<RecentConversation[]>;
17
10
  fetchConversation(conversationId: uuid): Promise<{
18
11
  messages: Message[];
19
12
  id?: string | undefined;
@@ -21,17 +14,10 @@ export default class WebchatApi {
21
14
  userId?: string | undefined;
22
15
  createdOn?: Date | undefined;
23
16
  } | undefined>;
24
- resetSession(conversationId: uuid): Promise<void>;
25
17
  createConversation(): Promise<uuid | undefined>;
26
18
  startConversation(): Promise<void>;
27
- downloadConversation(conversationId: uuid): Promise<any>;
28
19
  sendMessage(payload: any, conversationId: uuid): Promise<Message | undefined>;
29
- deleteMessages(conversationId: uuid): Promise<void>;
20
+ deleteConversation(conversationId: uuid): Promise<void>;
30
21
  sendFeedback(feedback: number, messageId: uuid): Promise<void>;
31
- getMessageIdsFeedbackInfo(messageIds: uuid[]): Promise<EventFeedback[] | undefined>;
32
- uploadFile(file: File, payload: string, conversationId: uuid): Promise<void>;
33
22
  sendVoiceMessage(voice: Buffer, ext: string, conversationId: uuid): Promise<void>;
34
- setReference(reference: string, conversationId: uuid): Promise<void>;
35
- listByIncomingEvent(messageId: uuid): Promise<any>;
36
- handleApiError: (error: any) => Promise<void>;
37
23
  }
package/dist/core/api.js CHANGED
@@ -8,79 +8,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const get_1 = __importDefault(require("lodash/get"));
16
12
  const uuid_1 = require("uuid");
17
13
  class WebchatApi {
18
14
  constructor(socket) {
19
15
  this.socket = socket;
20
- this.handleApiError = (error) => __awaiter(this, void 0, void 0, function* () {
21
- // @deprecated 11.9 (replace with proper error management)
22
- const data = (0, get_1.default)(error, 'response.data', {});
23
- if (data && typeof data === 'string' && data.includes('BP_CONV_NOT_FOUND')) {
24
- console.error('Conversation not found, starting a new one...');
25
- yield this.createConversation();
26
- yield this.startConversation();
27
- }
28
- });
29
16
  }
30
- get baseUserPayload() {
31
- return {
32
- webSessionId: window.__BP_VISITOR_SOCKET_ID
33
- };
34
- }
35
- fetchBotInfo() {
17
+ listCurrentConversationMessages(limit) {
36
18
  return __awaiter(this, void 0, void 0, function* () {
37
19
  try {
38
- const { data } = yield this.axios.get('/botInfo', this.axiosConfig);
39
- return data;
20
+ return this.socket.socket.listMessages(limit);
40
21
  }
41
22
  catch (err) {
42
- console.error('Error while loading bot info', err);
43
- }
44
- });
45
- }
46
- fetchPreferences() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- try {
49
- const { data } = yield this.axios.post('/preferences/get', this.baseUserPayload, this.axiosConfig);
50
- return data;
51
- }
52
- catch (err) {
53
- console.error('Error while fetching preferences', err);
54
- }
55
- });
56
- }
57
- updateUserPreferredLanguage(language) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- try {
60
- yield this.axios.post('/preferences', Object.assign(Object.assign({}, this.baseUserPayload), { language }), this.axiosConfig);
61
- }
62
- catch (err) {
63
- console.error('Error in updating user preferred language', err);
23
+ console.error('An error occurred while listing the messages of the current conversation', err);
64
24
  }
65
25
  });
66
26
  }
67
27
  fetchConversations() {
68
28
  return __awaiter(this, void 0, void 0, function* () {
69
29
  try {
70
- const convos = (yield this.socket.socket.listConversations());
30
+ const conversations = (yield this.socket.socket.listConversations());
71
31
  // Add the last message of each conversation
72
- for (const convo of convos) {
32
+ for (const conversation of conversations) {
73
33
  const limit = 1;
74
- yield this.socket.socket.switchConversation(convo.id);
75
- const lastMessages = yield this.socket.socket.listMessages(limit);
76
- if (lastMessages.length >= limit) {
77
- convo.lastMessage = lastMessages[0];
34
+ yield this.socket.socket.switchConversation(conversation.id);
35
+ const lastMessages = yield this.listCurrentConversationMessages(limit);
36
+ if (lastMessages && lastMessages.length >= limit) {
37
+ conversation.lastMessage = lastMessages[0];
78
38
  }
79
39
  }
80
- return convos;
40
+ return conversations;
81
41
  }
82
42
  catch (err) {
83
- console.error('Error while fetching convos', err);
43
+ console.error('Error while fetching users conversations', err);
44
+ return [];
84
45
  }
85
46
  });
86
47
  }
@@ -93,17 +54,7 @@ class WebchatApi {
93
54
  return Object.assign(Object.assign({}, conversation), { messages });
94
55
  }
95
56
  catch (err) {
96
- yield this.handleApiError(err);
97
- }
98
- });
99
- }
100
- resetSession(conversationId) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- try {
103
- yield this.axios.post('/conversations/reset', Object.assign(Object.assign({}, this.baseUserPayload), { conversationId }), this.axiosConfig);
104
- }
105
- catch (err) {
106
- console.error('Error while resetting conversation', err);
57
+ console.error('Error fetching a conversation', err);
107
58
  }
108
59
  });
109
60
  }
@@ -114,7 +65,7 @@ class WebchatApi {
114
65
  return conversation.id;
115
66
  }
116
67
  catch (err) {
117
- console.error('Error in create conversation', err);
68
+ console.error('Error creating conversation', err);
118
69
  }
119
70
  });
120
71
  }
@@ -124,118 +75,42 @@ class WebchatApi {
124
75
  yield this.socket.socket.startConversation();
125
76
  }
126
77
  catch (err) {
127
- console.error('Error in start conversation', err);
78
+ console.error('Error starting conversation', err);
128
79
  }
129
80
  });
130
81
  }
131
- downloadConversation(conversationId) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- try {
134
- const { data } = yield this.axios.post('/conversations/download/txt', Object.assign(Object.assign({}, this.baseUserPayload), { conversationId }), this.axiosConfig);
135
- return { name: data.name, txt: data.txt };
136
- }
137
- catch (err) {
138
- console.error('Error in download conversation', err);
139
- }
140
- });
141
- }
142
- // TODO: we don't have a /events route available for this
143
- /*
144
- async sendEvent(payload: any, conversationId: uuid): Promise<void> {
145
- try {
146
- return this.axios.post('/events', { ...this.baseUserPayload, conversationId, payload }, this.axiosConfig)
147
- } catch (err) {
148
- await this.handleApiError(err)
149
- }
150
- }
151
- */
152
82
  sendMessage(payload, conversationId) {
153
83
  return __awaiter(this, void 0, void 0, function* () {
154
84
  try {
155
85
  return this.socket.sendPayload(payload);
156
86
  }
157
87
  catch (err) {
158
- yield this.handleApiError(err);
88
+ console.error('Error sending message', err);
159
89
  }
160
90
  });
161
91
  }
162
- deleteMessages(conversationId) {
92
+ deleteConversation(conversationId) {
163
93
  return __awaiter(this, void 0, void 0, function* () {
164
94
  try {
165
- yield this.axios.post('/conversations/messages/delete', Object.assign(Object.assign({}, this.baseUserPayload), { conversationId }), this.axiosConfig);
95
+ yield this.socket.socket.deleteConversation(conversationId);
166
96
  }
167
97
  catch (err) {
168
- yield this.handleApiError(err);
98
+ console.error('Error deleting conversation', err);
169
99
  }
170
100
  });
171
101
  }
172
102
  sendFeedback(feedback, messageId) {
173
103
  return __awaiter(this, void 0, void 0, function* () {
174
- try {
175
- return this.socket.socket.sendFeedback(messageId, feedback);
176
- }
177
- catch (err) {
178
- yield this.handleApiError(err);
179
- }
180
- });
181
- }
182
- getMessageIdsFeedbackInfo(messageIds) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- try {
185
- const { data } = yield this.axios.post('/feedbackInfo', { messageIds, target: this.userId }, this.axiosConfig);
186
- return data;
187
- }
188
- catch (err) {
189
- yield this.handleApiError(err);
190
- }
191
- });
192
- }
193
- uploadFile(file, payload, conversationId) {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- try {
196
- const data = new FormData();
197
- data.append('file', file);
198
- data.append('webSessionId', this.baseUserPayload.webSessionId);
199
- data.append('conversationId', conversationId);
200
- data.append('payload', payload);
201
- return this.axios.post('/messages/files', data, this.axiosConfig);
202
- }
203
- catch (err) {
204
- yield this.handleApiError(err);
205
- }
104
+ return this.socket.socket.sendFeedback(messageId, feedback);
206
105
  });
207
106
  }
107
+ // TODO: Fix this
208
108
  sendVoiceMessage(voice, ext, conversationId) {
209
109
  return __awaiter(this, void 0, void 0, function* () {
210
- try {
211
- const audio = {
212
- buffer: voice.toString('base64'),
213
- title: `${(0, uuid_1.v4)()}.${ext}`
214
- };
215
- return this.axios.post('/messages/voice', Object.assign(Object.assign({}, this.baseUserPayload), { conversationId, audio }), this.axiosConfig);
216
- }
217
- catch (err) {
218
- yield this.handleApiError(err);
219
- }
220
- });
221
- }
222
- setReference(reference, conversationId) {
223
- return __awaiter(this, void 0, void 0, function* () {
224
- // TODO: this can't work. We don't have a reference route
225
- try {
226
- return this.axios.post('/conversations/reference', Object.assign(Object.assign({}, this.baseUserPayload), { conversationId, reference }), this.axiosConfig);
227
- }
228
- catch (err) {
229
- yield this.handleApiError(err);
230
- }
231
- });
232
- }
233
- listByIncomingEvent(messageId) {
234
- return __awaiter(this, void 0, void 0, function* () {
235
- const { data: messages } = yield this.axios.get(`/messaging/list-by-incoming-event/${messageId}`, {
236
- baseURL: window['BOT_API_PATH']
237
- });
238
- return messages;
110
+ const audio = {
111
+ buffer: voice.toString('base64'),
112
+ title: `${(0, uuid_1.v4)()}.${ext}`
113
+ };
239
114
  });
240
115
  }
241
116
  }
@@ -1,42 +1,14 @@
1
+ import { Config } from '../typings';
1
2
  declare const _default: {
2
- /** These types are sent using the /message/ endpoint */
3
- MESSAGE_TYPES: string[];
4
3
  /** The duration of the hide / show chat */
5
- ANIM_DURATION: number;
4
+ ANIMATION_DURATION: number;
6
5
  MIN_TIME_BETWEEN_SOUNDS: number;
7
- HISTORY_STARTING_POINT: number;
8
- HISTORY_MAX_MESSAGES: number;
6
+ SENT_HISTORY_SIZE: number;
9
7
  /** The number of minutes before a new timestamp is displayed */
10
8
  TIME_BETWEEN_DATES: number;
11
9
  DEFAULT_LAYOUT_WIDTH: number;
12
10
  DEFAULT_CONTAINER_WIDTH: number;
13
- SENT_HISTORY_SIZE: number;
14
11
  /** The default configuration when starting the chat */
15
- DEFAULT_CONFIG: {
16
- userId: undefined;
17
- extraStylesheet: string;
18
- botName: undefined;
19
- botConvoDescription: undefined;
20
- overrides: undefined;
21
- enableReset: boolean;
22
- enableTranscriptDownload: boolean;
23
- enableArrowNavigation: boolean;
24
- showConversationsButton: boolean;
25
- useSessionStorage: boolean;
26
- showUserName: boolean;
27
- showUserAvatar: boolean;
28
- showTimestamp: boolean;
29
- disableAnimations: boolean;
30
- hideWidget: boolean;
31
- externalAuthToken: undefined;
32
- showPoweredBy: boolean;
33
- enablePersistHistory: boolean;
34
- enableResetSessionShortcut: boolean;
35
- enableVoiceComposer: boolean;
36
- enableConversationDeletion: boolean;
37
- closeOnEscape: boolean;
38
- recentConversationLifetime: string;
39
- startNewConvoOnTimeout: boolean;
40
- };
12
+ DEFAULT_CONFIG: Partial<Config>;
41
13
  };
42
14
  export default _default;
@@ -1,43 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const DEFAULT_CONFIG = {
4
+ botName: undefined,
5
+ botConversationDescription: undefined,
6
+ enableTranscriptDownload: true,
7
+ showConversationsButton: true,
8
+ useSessionStorage: false,
9
+ showTimestamp: false,
10
+ disableAnimations: false,
11
+ hideWidget: false,
12
+ showPoweredBy: false,
13
+ enablePersistHistory: true,
14
+ enableVoiceComposer: false,
15
+ enableConversationDeletion: false,
16
+ closeOnEscape: true
17
+ };
3
18
  exports.default = {
4
- /** These types are sent using the /message/ endpoint */
5
- MESSAGE_TYPES: ['text', 'quick_reply', 'form', 'login_prompt', 'visit', 'postback'],
6
19
  /** The duration of the hide / show chat */
7
- ANIM_DURATION: 300,
20
+ ANIMATION_DURATION: 300,
8
21
  MIN_TIME_BETWEEN_SOUNDS: 1000,
9
- HISTORY_STARTING_POINT: -1,
10
- HISTORY_MAX_MESSAGES: 10,
22
+ SENT_HISTORY_SIZE: 20,
11
23
  /** The number of minutes before a new timestamp is displayed */
12
24
  TIME_BETWEEN_DATES: 10,
13
25
  DEFAULT_LAYOUT_WIDTH: 360,
14
26
  DEFAULT_CONTAINER_WIDTH: 360,
15
- SENT_HISTORY_SIZE: 20,
16
27
  /** The default configuration when starting the chat */
17
- DEFAULT_CONFIG: {
18
- userId: undefined,
19
- extraStylesheet: '',
20
- botName: undefined,
21
- botConvoDescription: undefined,
22
- overrides: undefined,
23
- enableReset: true,
24
- enableTranscriptDownload: true,
25
- enableArrowNavigation: false,
26
- showConversationsButton: true,
27
- useSessionStorage: false,
28
- showUserName: false,
29
- showUserAvatar: false,
30
- showTimestamp: false,
31
- disableAnimations: false,
32
- hideWidget: false,
33
- externalAuthToken: undefined,
34
- showPoweredBy: window.SHOW_POWERED_BY,
35
- enablePersistHistory: true,
36
- enableResetSessionShortcut: false,
37
- enableVoiceComposer: false,
38
- enableConversationDeletion: false,
39
- closeOnEscape: true,
40
- recentConversationLifetime: '5h',
41
- startNewConvoOnTimeout: false
42
- }
28
+ DEFAULT_CONFIG
43
29
  };
@@ -3,21 +3,10 @@ import { Config } from '../typings';
3
3
  export default class BpSocket {
4
4
  socket: MessagingSocket;
5
5
  private chatId;
6
- private encryptionKey;
7
- private clientId;
8
- private waitingForUser?;
9
- onClear: (event: any) => void;
10
6
  onMessage: (event: any) => void;
11
- onTyping: (event: any) => void;
12
- onData: (event: any) => void;
13
- onUserIdChanged: (userId: string) => void;
14
7
  constructor(config: Config);
15
8
  setup(): void;
16
9
  sendPayload(payload: any): Promise<Message>;
17
10
  postToParent: (_type: string, payload: any) => void;
18
- /** Waits until the VISITOR ID and VISITOR SOCKET ID is set */
19
- waitForUserId(): Promise<void>;
20
- getStorage<T>(key: string): T | undefined;
21
- setStorage<T>(key: string, object: T): void;
22
- private getStorageKey;
11
+ connect(): Promise<void>;
23
12
  }
@@ -8,37 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  const messaging_socket_1 = require("@botpress/messaging-socket");
16
- const aes_1 = __importDefault(require("crypto-js/aes"));
17
- const enc_utf8_1 = __importDefault(require("crypto-js/enc-utf8"));
18
- const sha256_1 = __importDefault(require("crypto-js/sha256"));
19
13
  class BpSocket {
20
14
  constructor(config) {
21
15
  this.postToParent = (_type, payload) => {
22
16
  var _a;
23
- // we could filter on event type if necessary
24
17
  (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage(Object.assign(Object.assign({}, payload), { chatId: this.chatId }), '*');
25
18
  };
26
19
  this.chatId = config.chatId;
27
- this.encryptionKey = config.encryptionKey;
28
- this.clientId = config.clientId;
29
20
  this.socket = new messaging_socket_1.MessagingSocket({ url: config.messagingUrl, clientId: config.clientId });
30
21
  }
31
22
  setup() {
32
23
  this.socket.on('message', this.onMessage);
33
- /*
34
- this.events.on('guest.webchat.clear', this.onClear)
35
- this.events.on('guest.webchat.message', this.onMessage)
36
- this.events.on('guest.webchat.typing', this.onTyping)
37
- this.events.on('guest.webchat.data', this.onData)
38
- */
39
- // firehose events to parent page
40
- // TODO: why do we need this
41
- // this.events.onAny(this.postToParent)
42
24
  }
43
25
  sendPayload(payload) {
44
26
  return __awaiter(this, void 0, void 0, function* () {
@@ -47,64 +29,16 @@ class BpSocket {
47
29
  return message;
48
30
  });
49
31
  }
50
- /** Waits until the VISITOR ID and VISITOR SOCKET ID is set */
51
- waitForUserId() {
32
+ connect() {
52
33
  return __awaiter(this, void 0, void 0, function* () {
53
- if (this.waitingForUser) {
54
- return this.waitingForUser;
34
+ const creds = window.BP_STORAGE.get('creds');
35
+ yield this.socket.connect(creds);
36
+ if (this.socket.userId) {
37
+ const userId = this.socket.userId;
38
+ window.BP_STORAGE.set('creds', this.socket.creds);
39
+ this.postToParent('', { userId });
55
40
  }
56
- this.waitingForUser = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
57
- const creds = this.getStorage('creds');
58
- yield this.socket.connect(creds);
59
- if (this.socket.userId) {
60
- const userId = this.socket.userId;
61
- this.setStorage('creds', this.socket.creds);
62
- this.onUserIdChanged(userId);
63
- this.postToParent('', { userId });
64
- resolve();
65
- }
66
- else {
67
- this.waitingForUser = undefined;
68
- reject();
69
- }
70
- }));
71
- return this.waitingForUser;
72
41
  });
73
42
  }
74
- getStorage(key) {
75
- var _a;
76
- let stored = localStorage.getItem(this.getStorageKey(key));
77
- if (!stored) {
78
- return undefined;
79
- }
80
- if ((_a = this.encryptionKey) === null || _a === void 0 ? void 0 : _a.length) {
81
- stored = aes_1.default.decrypt(stored, this.encryptionKey).toString(enc_utf8_1.default);
82
- }
83
- try {
84
- const val = JSON.parse(stored);
85
- return val;
86
- }
87
- catch (_b) {
88
- return undefined;
89
- }
90
- }
91
- setStorage(key, object) {
92
- var _a;
93
- let string = JSON.stringify(object);
94
- if ((_a = this.encryptionKey) === null || _a === void 0 ? void 0 : _a.length) {
95
- string = aes_1.default.encrypt(string, this.encryptionKey).toString();
96
- }
97
- localStorage.setItem(this.getStorageKey(key), string);
98
- }
99
- getStorageKey(key) {
100
- var _a;
101
- const rawKey = `bp-chat-${key}`;
102
- if ((_a = this.encryptionKey) === null || _a === void 0 ? void 0 : _a.length) {
103
- return `${rawKey}-${(0, sha256_1.default)(`${this.clientId}-${this.encryptionKey}`).toString()}`;
104
- }
105
- else {
106
- return `${rawKey}-${this.clientId}`;
107
- }
108
- }
109
43
  }
110
44
  exports.default = BpSocket;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- declare const _default: ({ href }: {
3
- href: string;
2
+ declare const _default: ({ fill }: {
3
+ fill?: string | undefined;
4
4
  }) => JSX.Element;
5
5
  export default _default;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ exports.default = ({ fill = 'black' }) => (react_1.default.createElement("i", null,
8
+ react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", version: "1.1", x: "0px", y: "0px", width: "16px", height: "16px", viewBox: "0 0 492 492", fill: `${fill}` },
9
+ react_1.default.createElement("g", null,
10
+ react_1.default.createElement("path", { d: "M300.188,246L484.14,62.04c5.06-5.064,7.852-11.82,7.86-19.024c0-7.208-2.792-13.972-7.86-19.028L468.02,7.872 c-5.068-5.076-11.824-7.856-19.036-7.856c-7.2,0-13.956,2.78-19.024,7.856L246.008,191.82L62.048,7.872 c-5.06-5.076-11.82-7.856-19.028-7.856c-7.2,0-13.96,2.78-19.02,7.856L7.872,23.988c-10.496,10.496-10.496,27.568,0,38.052 L191.828,246L7.872,429.952c-5.064,5.072-7.852,11.828-7.852,19.032c0,7.204,2.788,13.96,7.852,19.028l16.124,16.116 c5.06,5.072,11.824,7.856,19.02,7.856c7.208,0,13.968-2.784,19.028-7.856l183.96-183.952l183.952,183.952 c5.068,5.072,11.824,7.856,19.024,7.856h0.008c7.204,0,13.96-2.784,19.028-7.856l16.12-16.116 c5.06-5.064,7.852-11.824,7.852-19.028c0-7.204-2.792-13.96-7.852-19.028L300.188,246z" })))));
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ declare const _default: ({ fill }: {
3
+ fill?: string | undefined;
4
+ }) => JSX.Element;
5
+ export default _default;