@botpress/webchat 0.1.0 → 0.2.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.
@@ -23,6 +23,7 @@ export default class WebchatApi {
23
23
  } | undefined>;
24
24
  resetSession(conversationId: uuid): Promise<void>;
25
25
  createConversation(): Promise<uuid | undefined>;
26
+ startConversation(): Promise<void>;
26
27
  downloadConversation(conversationId: uuid): Promise<any>;
27
28
  sendMessage(payload: any, conversationId: uuid): Promise<Message | undefined>;
28
29
  deleteMessages(conversationId: uuid): Promise<void>;
package/dist/core/api.js CHANGED
@@ -23,6 +23,7 @@ class WebchatApi {
23
23
  if (data && typeof data === 'string' && data.includes('BP_CONV_NOT_FOUND')) {
24
24
  console.error('Conversation not found, starting a new one...');
25
25
  yield this.createConversation();
26
+ yield this.startConversation();
26
27
  }
27
28
  });
28
29
  }
@@ -79,7 +80,7 @@ class WebchatApi {
79
80
  try {
80
81
  const conversation = yield this.socket.socket.getConversation(conversationId);
81
82
  this.socket.socket.switchConversation(conversation.id);
82
- const messages = yield this.socket.socket.listMessages();
83
+ const messages = (yield this.socket.socket.listMessages()).filter((x) => x.payload.type !== 'visit');
83
84
  return Object.assign(Object.assign({}, conversation), { messages });
84
85
  }
85
86
  catch (err) {
@@ -108,6 +109,16 @@ class WebchatApi {
108
109
  }
109
110
  });
110
111
  }
112
+ startConversation() {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ try {
115
+ yield this.socket.socket.startConversation();
116
+ }
117
+ catch (err) {
118
+ console.error('Error in start conversation', err);
119
+ }
120
+ });
121
+ }
111
122
  downloadConversation(conversationId) {
112
123
  return __awaiter(this, void 0, void 0, function* () {
113
124
  try {
@@ -152,7 +163,7 @@ class WebchatApi {
152
163
  sendFeedback(feedback, messageId) {
153
164
  return __awaiter(this, void 0, void 0, function* () {
154
165
  try {
155
- return this.axios.post('/saveFeedback', { messageId, target: this.userId, feedback }, this.axiosConfig);
166
+ return this.socket.socket.sendFeedback(messageId, feedback);
156
167
  }
157
168
  catch (err) {
158
169
  yield this.handleApiError(err);
package/dist/main.js CHANGED
@@ -27,7 +27,7 @@ const socket_1 = __importDefault(require("./core/socket"));
27
27
  const Chat_1 = __importDefault(require("./icons/Chat"));
28
28
  const utils_1 = require("./utils");
29
29
  const _values = (obj) => Object.keys(obj).map((x) => obj[x]);
30
- const DEFAULT_TYPING_DELAY = 500;
30
+ const DEFAULT_TYPING_DELAY = 1000;
31
31
  class Web extends react_1.default.Component {
32
32
  constructor(props) {
33
33
  super(props);
@@ -62,7 +62,6 @@ declare class RootStore {
62
62
  setReference(): Promise<void>;
63
63
  resetConversation(): void;
64
64
  resetSession(): Promise<void>;
65
- sendUserVisit(): Promise<void>;
66
65
  extractFeedback(messages: Message[]): Promise<void>;
67
66
  sendFeedback(feedback: number, messageId: string): Promise<void>;
68
67
  downloadConversation(): Promise<void>;
@@ -166,7 +166,6 @@ class RootStore {
166
166
  yield this.createConversation();
167
167
  }
168
168
  yield this.fetchPreferences();
169
- yield this.sendUserVisit();
170
169
  });
171
170
  }
172
171
  fetchBotInfo() {
@@ -256,6 +255,7 @@ class RootStore {
256
255
  createConversation() {
257
256
  return __awaiter(this, void 0, void 0, function* () {
258
257
  const newId = yield this.api.createConversation();
258
+ yield this.api.startConversation();
259
259
  yield this.fetchConversations();
260
260
  yield this.fetchConversation(newId);
261
261
  return newId;
@@ -275,16 +275,6 @@ class RootStore {
275
275
  return this.api.resetSession(this.currentConversationId);
276
276
  });
277
277
  }
278
- sendUserVisit() {
279
- return __awaiter(this, void 0, void 0, function* () {
280
- yield this.sendData({
281
- type: 'visit',
282
- text: 'User visit',
283
- timezone: -(new Date().getTimezoneOffset() / 60),
284
- language: (0, translations_1.getUserLocale)()
285
- });
286
- });
287
- }
288
278
  extractFeedback(messages) {
289
279
  return __awaiter(this, void 0, void 0, function* () {
290
280
  const feedbackMessageIds = messages.filter((x) => x.payload && x.payload.collectFeedback).map((x) => x.id);
@@ -564,9 +554,6 @@ __decorate([
564
554
  __decorate([
565
555
  mobx_1.action.bound
566
556
  ], RootStore.prototype, "resetSession", null);
567
- __decorate([
568
- mobx_1.action.bound
569
- ], RootStore.prototype, "sendUserVisit", null);
570
557
  __decorate([
571
558
  mobx_1.action.bound
572
559
  ], RootStore.prototype, "extractFeedback", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/webchat",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "source": "src/index.tsx",
@@ -24,12 +24,12 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@blueprintjs/core": "^3.23.1",
27
- "@botpress/messaging-components": "0.1.0",
28
- "@botpress/messaging-socket": "0.1.0",
27
+ "@botpress/messaging-components": "0.2.0",
28
+ "@botpress/messaging-socket": "1.1.0",
29
29
  "@formatjs/intl-pluralrules": "^4.1.6",
30
30
  "@formatjs/intl-utils": "^3.8.4",
31
31
  "@juggle/resize-observer": "^3.0.2",
32
- "axios": "^0.24.0",
32
+ "axios": "^0.25.0",
33
33
  "classnames": "^2.3.1",
34
34
  "date-fns": "^1.30.1",
35
35
  "lodash": "^4.17.21",