@botpress/webchat 0.2.4 → 0.3.1

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 (57) hide show
  1. package/README.md +31 -0
  2. package/dist/components/Composer.d.ts +4 -5
  3. package/dist/components/Composer.js +16 -25
  4. package/dist/components/Container.js +1 -4
  5. package/dist/components/ConversationList.d.ts +1 -1
  6. package/dist/components/ConversationList.js +5 -46
  7. package/dist/components/Header.d.ts +1 -3
  8. package/dist/components/Header.js +7 -37
  9. package/dist/components/common/BotInfo/index.d.ts +1 -1
  10. package/dist/components/common/BotInfo/index.js +4 -14
  11. package/dist/components/messages/InlineFeedback.d.ts +2 -1
  12. package/dist/components/messages/Message.js +3 -6
  13. package/dist/components/messages/MessageGroup.d.ts +1 -5
  14. package/dist/components/messages/MessageGroup.js +4 -7
  15. package/dist/components/messages/MessageList.d.ts +1 -1
  16. package/dist/components/messages/MessageList.js +7 -29
  17. package/dist/core/api.d.ts +2 -7
  18. package/dist/core/api.js +5 -29
  19. package/dist/core/constants.d.ts +4 -32
  20. package/dist/core/constants.js +18 -32
  21. package/dist/core/socket.d.ts +1 -7
  22. package/dist/core/socket.js +8 -30
  23. package/dist/index.d.ts +3 -9
  24. package/dist/index.js +8 -35
  25. package/dist/main.d.ts +2 -2
  26. package/dist/main.js +84 -135
  27. package/dist/store/composer.js +1 -1
  28. package/dist/store/index.d.ts +5 -9
  29. package/dist/store/index.js +43 -66
  30. package/dist/store/view.d.ts +3 -4
  31. package/dist/store/view.js +6 -13
  32. package/dist/translations/index.d.ts +2 -1
  33. package/dist/translations/index.js +36 -1
  34. package/dist/typings.d.ts +123 -55
  35. package/dist/utils/analytics.d.ts +5 -0
  36. package/dist/utils/analytics.js +37 -0
  37. package/dist/utils/index.d.ts +3 -0
  38. package/dist/utils/index.js +27 -0
  39. package/dist/utils/storage.d.ts +4 -5
  40. package/dist/utils/storage.js +23 -11
  41. package/package.json +4 -4
  42. package/dist/components/ContextMenu.d.ts +0 -2
  43. package/dist/components/ContextMenu.js +0 -24
  44. package/dist/components/OverridableComponent.d.ts +0 -24
  45. package/dist/components/OverridableComponent.js +0 -50
  46. package/dist/components/Stylesheet.d.ts +0 -5
  47. package/dist/components/Stylesheet.js +0 -7
  48. package/dist/components/common/MoreOptions/index.d.ts +0 -21
  49. package/dist/components/common/MoreOptions/index.js +0 -60
  50. package/dist/components/common/Overlay/index.d.ts +0 -7
  51. package/dist/components/common/Overlay/index.js +0 -36
  52. package/dist/icons/CloseChat.d.ts +0 -6
  53. package/dist/icons/CloseChat.js +0 -9
  54. package/dist/icons/Send.d.ts +0 -6
  55. package/dist/icons/Send.js +0 -8
  56. package/dist/utils.d.ts +0 -8
  57. package/dist/utils.js +0 -111
package/dist/core/api.js CHANGED
@@ -8,24 +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
- const axios_1 = __importDefault(require("axios"));
16
12
  const uuid_1 = require("uuid");
17
13
  class WebchatApi {
18
14
  constructor(socket) {
19
15
  this.socket = socket;
20
16
  }
21
- fetchBotInfo(mediaFileServiceUrl) {
17
+ listCurrentConversationMessages(limit) {
22
18
  return __awaiter(this, void 0, void 0, function* () {
23
19
  try {
24
- const { data } = yield axios_1.default.get(mediaFileServiceUrl);
25
- return data;
20
+ return this.socket.socket.listMessages(limit);
26
21
  }
27
22
  catch (err) {
28
- console.error('Error while loading bot info', err);
23
+ console.error('An error occurred while listing the messages of the current conversation', err);
29
24
  }
30
25
  });
31
26
  }
@@ -37,8 +32,8 @@ class WebchatApi {
37
32
  for (const conversation of conversations) {
38
33
  const limit = 1;
39
34
  yield this.socket.socket.switchConversation(conversation.id);
40
- const lastMessages = yield this.socket.socket.listMessages(limit);
41
- if (lastMessages.length >= limit) {
35
+ const lastMessages = yield this.listCurrentConversationMessages(limit);
36
+ if (lastMessages && lastMessages.length >= limit) {
42
37
  conversation.lastMessage = lastMessages[0];
43
38
  }
44
39
  }
@@ -63,16 +58,6 @@ class WebchatApi {
63
58
  }
64
59
  });
65
60
  }
66
- // TODO: Fis this
67
- resetSession(conversationId) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- try {
70
- }
71
- catch (err) {
72
- console.error('Error while resetting conversation', err);
73
- }
74
- });
75
- }
76
61
  createConversation() {
77
62
  return __awaiter(this, void 0, void 0, function* () {
78
63
  try {
@@ -119,15 +104,6 @@ class WebchatApi {
119
104
  return this.socket.socket.sendFeedback(messageId, feedback);
120
105
  });
121
106
  }
122
- uploadFile(file, payload, conversationId) {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- const data = new FormData();
125
- data.append('file', file);
126
- data.append('conversationId', conversationId);
127
- data.append('payload', payload);
128
- return this.axios.post('/messages/files', data, this.axiosConfig);
129
- });
130
- }
131
107
  // TODO: Fix this
132
108
  sendVoiceMessage(voice, ext, conversationId) {
133
109
  return __awaiter(this, void 0, void 0, function* () {
@@ -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,16 +3,10 @@ import { Config } from '../typings';
3
3
  export default class BpSocket {
4
4
  socket: MessagingSocket;
5
5
  private chatId;
6
- private waitingForUser?;
7
- onClear: (event: any) => void;
8
6
  onMessage: (event: any) => void;
9
- onTyping: (event: any) => void;
10
- onData: (event: any) => void;
11
- onUserIdChanged: (userId: string) => void;
12
7
  constructor(config: Config);
13
8
  setup(): void;
14
9
  sendPayload(payload: any): Promise<Message>;
15
10
  postToParent: (_type: string, payload: any) => void;
16
- /** Waits until the VISITOR ID and VISITOR SOCKET ID is set */
17
- waitForUserId(): Promise<void>;
11
+ connect(): Promise<void>;
18
12
  }
@@ -14,23 +14,14 @@ class BpSocket {
14
14
  constructor(config) {
15
15
  this.postToParent = (_type, payload) => {
16
16
  var _a;
17
- // we could filter on event type if necessary
18
17
  (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage(Object.assign(Object.assign({}, payload), { chatId: this.chatId }), '*');
19
18
  };
20
19
  this.chatId = config.chatId;
21
20
  this.socket = new messaging_socket_1.MessagingSocket({ url: config.messagingUrl, clientId: config.clientId });
21
+ window.websocket = this.socket;
22
22
  }
23
23
  setup() {
24
24
  this.socket.on('message', this.onMessage);
25
- /*
26
- this.events.on('guest.webchat.clear', this.onClear)
27
- this.events.on('guest.webchat.message', this.onMessage)
28
- this.events.on('guest.webchat.typing', this.onTyping)
29
- this.events.on('guest.webchat.data', this.onData)
30
- */
31
- // firehose events to parent page
32
- // TODO: why do we need this
33
- // this.events.onAny(this.postToParent)
34
25
  }
35
26
  sendPayload(payload) {
36
27
  return __awaiter(this, void 0, void 0, function* () {
@@ -39,28 +30,15 @@ class BpSocket {
39
30
  return message;
40
31
  });
41
32
  }
42
- /** Waits until the VISITOR ID and VISITOR SOCKET ID is set */
43
- waitForUserId() {
33
+ connect() {
44
34
  return __awaiter(this, void 0, void 0, function* () {
45
- if (this.waitingForUser) {
46
- return this.waitingForUser;
35
+ const creds = window.BP_STORAGE.get('creds');
36
+ yield this.socket.connect(creds);
37
+ if (this.socket.userId) {
38
+ const userId = this.socket.userId;
39
+ window.BP_STORAGE.set('creds', this.socket.creds);
40
+ this.postToParent('', { userId });
47
41
  }
48
- this.waitingForUser = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
49
- const creds = window.BP_STORAGE.get('creds');
50
- yield this.socket.connect(creds);
51
- if (this.socket.userId) {
52
- const userId = this.socket.userId;
53
- window.BP_STORAGE.set('creds', this.socket.creds);
54
- this.onUserIdChanged(userId);
55
- this.postToParent('', { userId });
56
- resolve();
57
- }
58
- else {
59
- this.waitingForUser = undefined;
60
- reject();
61
- }
62
- }));
63
- return this.waitingForUser;
64
42
  });
65
43
  }
66
44
  }
package/dist/index.d.ts CHANGED
@@ -1,23 +1,17 @@
1
1
  import React from 'react';
2
2
  import { RootStore } from './store';
3
3
  import { Config } from './typings';
4
- export declare const Embedded: (props: any) => ExposedWebChat;
5
- export declare const Fullscreen: (props: any) => ExposedWebChat;
6
4
  interface State {
7
5
  store: RootStore;
8
6
  }
9
7
  interface Props {
10
- config: Config;
8
+ config?: Config;
11
9
  fullscreen?: boolean;
12
10
  }
13
11
  export declare class ExposedWebChat extends React.Component<Props, State> {
14
12
  constructor(props: Props);
15
13
  render(): JSX.Element;
16
14
  }
17
- /**
18
- * @deprecated Since the way views are handled has changed, we're also exporting views in lowercase.
19
- * https://botpress.com/docs/developers/migrate/
20
- */
21
- export { Embedded as embedded } from '.';
22
- export { Fullscreen as fullscreen } from '.';
15
+ export declare const Embedded: (props: Props) => ExposedWebChat;
16
+ export declare const Fullscreen: (props: Props) => ExposedWebChat;
23
17
  export * from './typings';
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.fullscreen = exports.embedded = exports.ExposedWebChat = exports.Fullscreen = exports.Embedded = void 0;
16
+ exports.Fullscreen = exports.Embedded = exports.ExposedWebChat = void 0;
17
17
  const mobx_1 = require("mobx");
18
18
  const mobx_react_1 = require("mobx-react");
19
19
  const react_1 = __importDefault(require("react"));
@@ -23,19 +23,10 @@ const store_1 = require("./store");
23
23
  const translations_1 = require("./translations");
24
24
  const storage_1 = __importDefault(require("./utils/storage"));
25
25
  (0, mobx_1.configure)({ enforceActions: 'observed' });
26
- const Embedded = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: false }));
27
- exports.Embedded = Embedded;
28
- const Fullscreen = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: true }));
29
- exports.Fullscreen = Fullscreen;
30
26
  class ExposedWebChat extends react_1.default.Component {
31
27
  constructor(props) {
32
28
  super(props);
33
- const { clientId, encryptionKey, useSessionStorage } = props.config;
34
- window.BP_STORAGE = new storage_1.default({
35
- clientId,
36
- encryptionKey,
37
- useSessionStorage
38
- });
29
+ window.BP_STORAGE = new storage_1.default(props.config);
39
30
  this.state = {
40
31
  store: new store_1.RootStore({ fullscreen: props.fullscreen }, props.config)
41
32
  };
@@ -44,32 +35,14 @@ class ExposedWebChat extends react_1.default.Component {
44
35
  const store = this.state.store;
45
36
  const { botUILanguage: locale } = store;
46
37
  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(react_1.default.Fragment, null,
49
- react_1.default.createElement(main_1.default, Object.assign({ store: store }, this.props))))));
38
+ react_1.default.createElement(react_intl_1.IntlProvider, { locale: locale, messages: translations_1.translations[locale || translations_1.defaultLocale], defaultLocale: translations_1.defaultLocale },
39
+ react_1.default.createElement(main_1.default, Object.assign({}, this.props)))));
50
40
  }
51
41
  }
52
42
  exports.ExposedWebChat = ExposedWebChat;
53
- // TODO: what does this observer do?
54
43
  const Wrapper = (0, mobx_react_1.observer)(ExposedWebChat);
55
- /**
56
- * @deprecated Since the way views are handled has changed, we're also exporting views in lowercase.
57
- * https://botpress.com/docs/developers/migrate/
58
- */
59
- var _1 = require(".");
60
- Object.defineProperty(exports, "embedded", { enumerable: true, get: function () { return _1.Embedded; } });
61
- var _2 = require(".");
62
- Object.defineProperty(exports, "fullscreen", { enumerable: true, get: function () { return _2.Fullscreen; } });
44
+ const Embedded = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: false }));
45
+ exports.Embedded = Embedded;
46
+ const Fullscreen = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: true }));
47
+ exports.Fullscreen = Fullscreen;
63
48
  __exportStar(require("./typings"), exports);
64
- // TODO: export this
65
- /*
66
- export {
67
- Carousel,
68
- QuickReplies,
69
- LoginPrompt,
70
- Text,
71
- FileMessage,
72
- FileInput,
73
- Button
74
- } from './components/messages/renderer'
75
- */
package/dist/main.d.ts CHANGED
@@ -9,5 +9,5 @@ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omi
9
9
  } & import("mobx-react").IWrappedComponent<unknown>;
10
10
  export default _default;
11
11
  declare type MainProps = {
12
- store: RootStore;
13
- } & WrappedComponentProps & Pick<StoreDef, 'config' | 'initializeChat' | 'botInfo' | 'fetchBotInfo' | 'sendMessage' | 'setUserId' | 'sendData' | 'intl' | 'updateTyping' | 'updateBotUILanguage' | 'hideChat' | 'showChat' | 'toggleBotInfo' | 'widgetTransition' | 'activeView' | 'isFullscreen' | 'unreadCount' | 'hasUnreadMessages' | 'showWidgetButton' | 'addEventToConversation' | 'clearMessages' | 'updateConfig' | 'mergeConfig' | 'isWebchatReady' | 'incrementUnread' | 'displayWidgetView' | 'resetUnread' | 'setLoadingCompleted' | 'dimensions' | 'updateLastMessage'>;
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'>;