@botpress/webchat 0.0.1 → 0.1.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 (51) hide show
  1. package/dist/components/Composer.d.ts +9 -11
  2. package/dist/components/Composer.js +3 -3
  3. package/dist/components/Container.d.ts +8 -7
  4. package/dist/components/Container.js +4 -4
  5. package/dist/components/ConversationList.d.ts +6 -3
  6. package/dist/components/ConversationList.js +6 -4
  7. package/dist/components/Header.js +3 -3
  8. package/dist/components/OverridableComponent.js +1 -1
  9. package/dist/components/VoiceRecorder.js +9 -9
  10. package/dist/components/common/BotInfo.d.ts +6 -3
  11. package/dist/components/common/BotInfo.js +4 -4
  12. package/dist/components/messages/InlineFeedback.js +2 -2
  13. package/dist/components/messages/Message.d.ts +6 -3
  14. package/dist/components/messages/Message.js +23 -98
  15. package/dist/components/messages/MessageGroup.js +7 -11
  16. package/dist/components/messages/MessageList.d.ts +6 -3
  17. package/dist/components/messages/MessageList.js +8 -8
  18. package/dist/core/api.js +3 -3
  19. package/dist/core/socket.js +1 -2
  20. package/dist/index.d.ts +0 -1
  21. package/dist/index.js +15 -11
  22. package/dist/main.d.ts +8 -7
  23. package/dist/main.js +16 -17
  24. package/dist/store/composer.js +2 -2
  25. package/dist/store/index.d.ts +3 -3
  26. package/dist/store/index.js +18 -19
  27. package/dist/store/view.js +2 -2
  28. package/dist/translations/index.d.ts +1 -2
  29. package/dist/translations/index.js +11 -25
  30. package/dist/utils.js +1 -1
  31. package/package.json +32 -13
  32. package/dist/components/messages/renderer/Button.d.ts +0 -16
  33. package/dist/components/messages/renderer/Button.js +0 -66
  34. package/dist/components/messages/renderer/Carousel.d.ts +0 -21
  35. package/dist/components/messages/renderer/Carousel.js +0 -72
  36. package/dist/components/messages/renderer/Dropdown.d.ts +0 -3
  37. package/dist/components/messages/renderer/Dropdown.js +0 -76
  38. package/dist/components/messages/renderer/FileInput.d.ts +0 -9
  39. package/dist/components/messages/renderer/FileInput.js +0 -32
  40. package/dist/components/messages/renderer/FileMessage.d.ts +0 -3
  41. package/dist/components/messages/renderer/FileMessage.js +0 -53
  42. package/dist/components/messages/renderer/LoginPrompt.d.ts +0 -6
  43. package/dist/components/messages/renderer/LoginPrompt.js +0 -98
  44. package/dist/components/messages/renderer/QuickReplies.d.ts +0 -18
  45. package/dist/components/messages/renderer/QuickReplies.js +0 -73
  46. package/dist/components/messages/renderer/Text.d.ts +0 -11
  47. package/dist/components/messages/renderer/Text.js +0 -71
  48. package/dist/components/messages/renderer/VoiceMessage.d.ts +0 -5
  49. package/dist/components/messages/renderer/VoiceMessage.js +0 -50
  50. package/dist/components/messages/renderer/index.d.ts +0 -8
  51. package/dist/components/messages/renderer/index.js +0 -19
@@ -47,8 +47,7 @@ class BpSocket {
47
47
  }
48
48
  this.waitingForUser = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
49
49
  const creds = this.getStorage('creds');
50
- yield this.socket.connect({ autoLogin: false });
51
- yield this.socket.login(creds);
50
+ yield this.socket.connect(creds);
52
51
  if (this.socket.userId) {
53
52
  const userId = this.socket.userId;
54
53
  this.setStorage('creds', this.socket.creds);
package/dist/index.d.ts CHANGED
@@ -21,4 +21,3 @@ export declare class ExposedWebChat extends React.Component<Props, State> {
21
21
  export { Embedded as embedded } from '.';
22
22
  export { Fullscreen as fullscreen } from '.';
23
23
  export * from './typings';
24
- export { Carousel, QuickReplies, LoginPrompt, Text, FileMessage, FileInput, Button } from './components/messages/renderer';
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.Button = exports.FileInput = exports.FileMessage = exports.Text = exports.LoginPrompt = exports.QuickReplies = exports.Carousel = exports.fullscreen = exports.embedded = exports.ExposedWebChat = exports.Fullscreen = exports.Embedded = void 0;
16
+ exports.fullscreen = exports.embedded = exports.ExposedWebChat = exports.Fullscreen = exports.Embedded = 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"));
@@ -21,7 +21,7 @@ const react_intl_1 = require("react-intl");
21
21
  const main_1 = __importDefault(require("./main"));
22
22
  const store_1 = require("./store");
23
23
  const translations_1 = require("./translations");
24
- mobx_1.configure({ enforceActions: 'observed' });
24
+ (0, mobx_1.configure)({ enforceActions: 'observed' });
25
25
  const Embedded = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: false }));
26
26
  exports.Embedded = Embedded;
27
27
  const Fullscreen = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: true }));
@@ -44,7 +44,7 @@ class ExposedWebChat extends react_1.default.Component {
44
44
  }
45
45
  exports.ExposedWebChat = ExposedWebChat;
46
46
  // TODO: what does this observer do?
47
- const Wrapper = mobx_react_1.observer(ExposedWebChat);
47
+ const Wrapper = (0, mobx_react_1.observer)(ExposedWebChat);
48
48
  /**
49
49
  * @deprecated Since the way views are handled has changed, we're also exporting views in lowercase.
50
50
  * https://botpress.com/docs/developers/migrate/
@@ -54,11 +54,15 @@ Object.defineProperty(exports, "embedded", { enumerable: true, get: function ()
54
54
  var _2 = require(".");
55
55
  Object.defineProperty(exports, "fullscreen", { enumerable: true, get: function () { return _2.Fullscreen; } });
56
56
  __exportStar(require("./typings"), exports);
57
- var renderer_1 = require("./components/messages/renderer");
58
- Object.defineProperty(exports, "Carousel", { enumerable: true, get: function () { return renderer_1.Carousel; } });
59
- Object.defineProperty(exports, "QuickReplies", { enumerable: true, get: function () { return renderer_1.QuickReplies; } });
60
- Object.defineProperty(exports, "LoginPrompt", { enumerable: true, get: function () { return renderer_1.LoginPrompt; } });
61
- Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return renderer_1.Text; } });
62
- Object.defineProperty(exports, "FileMessage", { enumerable: true, get: function () { return renderer_1.FileMessage; } });
63
- Object.defineProperty(exports, "FileInput", { enumerable: true, get: function () { return renderer_1.FileInput; } });
64
- Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return renderer_1.Button; } });
57
+ // TODO: export this
58
+ /*
59
+ export {
60
+ Carousel,
61
+ QuickReplies,
62
+ LoginPrompt,
63
+ Text,
64
+ FileMessage,
65
+ FileInput,
66
+ Button
67
+ } from './components/messages/renderer'
68
+ */
package/dist/main.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- /// <reference types="react-intl" />
2
1
  import React from 'react';
2
+ import { WrappedComponentProps } from 'react-intl';
3
3
  import { RootStore, StoreDef } from './store';
4
- declare const _default: React.ComponentClass<Pick<{
5
- store: RootStore;
6
- } & Pick<StoreDef, "intl" | "isFullscreen" | "unreadCount" | "dimensions" | "activeView" | "showWidgetButton" | "hasUnreadMessages" | "isWebchatReady" | "widgetTransition" | "displayWidgetView" | "incrementUnread" | "resetUnread" | "toggleBotInfo" | "setLoadingCompleted" | "showChat" | "hideChat" | "botInfo" | "config" | "isEmulator" | "clearMessages" | "addEventToConversation" | "updateTyping" | "initializeChat" | "fetchBotInfo" | "sendMessage" | "setReference" | "sendData" | "mergeConfig" | "updateConfig" | "setUserId" | "updateBotUILanguage">, "store" | "isFullscreen" | "unreadCount" | "dimensions" | "activeView" | "showWidgetButton" | "hasUnreadMessages" | "isWebchatReady" | "widgetTransition" | "displayWidgetView" | "incrementUnread" | "resetUnread" | "toggleBotInfo" | "setLoadingCompleted" | "showChat" | "hideChat" | "botInfo" | "config" | "isEmulator" | "clearMessages" | "addEventToConversation" | "updateTyping" | "initializeChat" | "fetchBotInfo" | "sendMessage" | "setReference" | "sendData" | "mergeConfig" | "updateConfig" | "setUserId" | "updateBotUILanguage">, any> & {
7
- WrappedComponent: React.ComponentType<{
8
- store: RootStore;
9
- } & Pick<StoreDef, "intl" | "isFullscreen" | "unreadCount" | "dimensions" | "activeView" | "showWidgetButton" | "hasUnreadMessages" | "isWebchatReady" | "widgetTransition" | "displayWidgetView" | "incrementUnread" | "resetUnread" | "toggleBotInfo" | "setLoadingCompleted" | "showChat" | "hideChat" | "botInfo" | "config" | "isEmulator" | "clearMessages" | "addEventToConversation" | "updateTyping" | "initializeChat" | "fetchBotInfo" | "sendMessage" | "setReference" | "sendData" | "mergeConfig" | "updateConfig" | "setUserId" | "updateBotUILanguage"> & ReactIntl.InjectedIntlProps>;
4
+ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omit<MainProps, "intl"> & {
5
+ forwardedRef?: React.Ref<any> | undefined;
6
+ } & React.RefAttributes<any>> & {
7
+ WrappedComponent: React.ComponentType<MainProps>;
10
8
  } & import("mobx-react").IWrappedComponent<unknown>;
11
9
  export default _default;
10
+ declare type MainProps = {
11
+ store: RootStore;
12
+ } & WrappedComponentProps & Pick<StoreDef, 'config' | 'initializeChat' | 'botInfo' | 'fetchBotInfo' | 'sendMessage' | 'setUserId' | 'sendData' | 'intl' | 'isEmulator' | 'updateTyping' | 'setReference' | 'updateBotUILanguage' | 'hideChat' | 'showChat' | 'toggleBotInfo' | 'widgetTransition' | 'activeView' | 'isFullscreen' | 'unreadCount' | 'hasUnreadMessages' | 'showWidgetButton' | 'addEventToConversation' | 'clearMessages' | 'updateConfig' | 'mergeConfig' | 'isWebchatReady' | 'incrementUnread' | 'displayWidgetView' | 'resetUnread' | 'setLoadingCompleted' | 'dimensions'>;
package/dist/main.js CHANGED
@@ -53,18 +53,18 @@ class Web extends react_1.default.Component {
53
53
  const { type, text } = payload;
54
54
  if (type === 'show') {
55
55
  this.props.showChat();
56
- utils_1.trackWebchatState('show');
56
+ (0, utils_1.trackWebchatState)('show');
57
57
  }
58
58
  else if (type === 'hide') {
59
59
  this.props.hideChat();
60
- utils_1.trackWebchatState('hide');
60
+ (0, utils_1.trackWebchatState)('hide');
61
61
  }
62
62
  else if (type === 'toggle') {
63
63
  this.props.displayWidgetView ? this.props.showChat() : this.props.hideChat();
64
- utils_1.trackWebchatState('toggle');
64
+ (0, utils_1.trackWebchatState)('toggle');
65
65
  }
66
66
  else if (type === 'message') {
67
- utils_1.trackMessage('sent');
67
+ (0, utils_1.trackMessage)('sent');
68
68
  yield this.props.sendMessage(text);
69
69
  }
70
70
  else if (type === 'loadConversation') {
@@ -97,7 +97,7 @@ class Web extends react_1.default.Component {
97
97
  // don't do anything, it's a message from another conversation
98
98
  return;
99
99
  }
100
- utils_1.trackMessage('received');
100
+ (0, utils_1.trackMessage)('received');
101
101
  yield this.props.addEventToConversation(event);
102
102
  // there's no focus on the actual conversation
103
103
  if ((document.hasFocus && !document.hasFocus()) || this.props.activeView !== 'side') {
@@ -127,7 +127,7 @@ class Web extends react_1.default.Component {
127
127
  }
128
128
  this.props.updateBotUILanguage(language);
129
129
  };
130
- this.playSound = debounce_1.default(() => __awaiter(this, void 0, void 0, function* () {
130
+ this.playSound = (0, debounce_1.default)(() => __awaiter(this, void 0, void 0, function* () {
131
131
  // Preference for config object
132
132
  const disableNotificationSound = this.config.disableNotificationSound === undefined
133
133
  ? this.props.config.disableNotificationSound
@@ -143,8 +143,8 @@ class Web extends react_1.default.Component {
143
143
  this.props.resetUnread();
144
144
  }
145
145
  };
146
- utils_1.checkLocationOrigin();
147
- utils_1.initializeAnalytics();
146
+ (0, utils_1.checkLocationOrigin)();
147
+ (0, utils_1.initializeAnalytics)();
148
148
  }
149
149
  componentDidMount() {
150
150
  return __awaiter(this, void 0, void 0, function* () {
@@ -200,7 +200,7 @@ class Web extends react_1.default.Component {
200
200
  this.config = this.extractConfig();
201
201
  if (this.config.exposeStore) {
202
202
  const storePath = this.config.chatId ? `${this.config.chatId}.webchat_store` : 'webchat_store';
203
- set_1.default(window.parent, storePath, this.props.store);
203
+ (0, set_1.default)(window.parent, storePath, this.props.store);
204
204
  }
205
205
  if (this.config.overrides) {
206
206
  this.loadOverrides(this.config.overrides);
@@ -266,7 +266,7 @@ class Web extends react_1.default.Component {
266
266
  }
267
267
  }
268
268
  setupObserver() {
269
- mobx_1.observe(this.props.config, 'userId', (data) => __awaiter(this, void 0, void 0, function* () {
269
+ (0, mobx_1.observe)(this.props.config, 'userId', (data) => __awaiter(this, void 0, void 0, function* () {
270
270
  if (!data.oldValue || data.oldValue === data.newValue) {
271
271
  return;
272
272
  }
@@ -276,12 +276,12 @@ class Web extends react_1.default.Component {
276
276
  yield this.socket.waitForUserId();
277
277
  yield this.props.initializeChat();
278
278
  }));
279
- mobx_1.observe(this.props.config, 'overrides', (data) => {
279
+ (0, mobx_1.observe)(this.props.config, 'overrides', (data) => {
280
280
  if (data.newValue && window.parent) {
281
281
  this.loadOverrides(data.newValue);
282
282
  }
283
283
  });
284
- mobx_1.observe(this.props.dimensions, 'container', (data) => {
284
+ (0, mobx_1.observe)(this.props.dimensions, 'container', (data) => {
285
285
  if (data.newValue && window.parent) {
286
286
  this.postMessageToParent('setWidth', data.newValue);
287
287
  }
@@ -298,7 +298,7 @@ class Web extends react_1.default.Component {
298
298
  if (!this.props.showWidgetButton) {
299
299
  return null;
300
300
  }
301
- return (react_1.default.createElement("button", { className: classnames_1.default('bpw-widget-btn', 'bpw-floating-button', {
301
+ return (react_1.default.createElement("button", { className: (0, classnames_1.default)('bpw-widget-btn', 'bpw-floating-button', {
302
302
  [`bpw-anim-${this.props.widgetTransition}` || 'none']: true
303
303
  }), "aria-label": this.props.intl.formatMessage({ id: 'widget.toggle' }), onClick: this.props.showChat.bind(this) },
304
304
  react_1.default.createElement(Chat_1.default, null),
@@ -306,7 +306,7 @@ class Web extends react_1.default.Component {
306
306
  }
307
307
  applyAndRenderStyle() {
308
308
  const emulatorClass = this.props.isEmulator ? ' emulator' : '';
309
- const parentClass = classnames_1.default(`bp-widget-web bp-widget-${this.props.activeView}${emulatorClass}`, {
309
+ const parentClass = (0, classnames_1.default)(`bp-widget-web bp-widget-${this.props.activeView}${emulatorClass}`, {
310
310
  'bp-widget-hidden': !this.props.showWidgetButton && this.props.displayWidgetView,
311
311
  [this.props.config.className]: !!this.props.config.className
312
312
  });
@@ -334,7 +334,7 @@ class Web extends react_1.default.Component {
334
334
  this.props.displayWidgetView ? this.renderWidget() : react_1.default.createElement(Container_1.default, null)));
335
335
  }
336
336
  }
337
- exports.default = mobx_react_1.inject(({ store }) => ({
337
+ exports.default = (0, mobx_react_1.inject)(({ store }) => ({
338
338
  store,
339
339
  config: store.config,
340
340
  sendData: store.sendData,
@@ -367,5 +367,4 @@ exports.default = mobx_react_1.inject(({ store }) => ({
367
367
  displayWidgetView: store.view.displayWidgetView,
368
368
  setLoadingCompleted: store.view.setLoadingCompleted,
369
369
  sendFeedback: store.sendFeedback
370
- // @ts-ignore
371
- }))(react_intl_1.injectIntl(mobx_react_1.observer(Web)));
370
+ }))((0, react_intl_1.injectIntl)((0, mobx_react_1.observer)(Web)));
@@ -36,11 +36,11 @@ class ComposerStore {
36
36
  }
37
37
  addMessageToHistory(text) {
38
38
  var _a;
39
- if (last_1.default(this._sentHistory) !== text) {
39
+ if ((0, last_1.default)(this._sentHistory) !== text) {
40
40
  this._sentHistory.push(text);
41
41
  this._sentHistoryIndex = 0;
42
42
  if (this.rootStore.config.enablePersistHistory) {
43
- (_a = window.BP_STORAGE) === null || _a === void 0 ? void 0 : _a.set(SENT_HISTORY_KEY, takeRight_1.default(this._sentHistory, constants_1.default.SENT_HISTORY_SIZE));
43
+ (_a = window.BP_STORAGE) === null || _a === void 0 ? void 0 : _a.set(SENT_HISTORY_KEY, (0, takeRight_1.default)(this._sentHistory, constants_1.default.SENT_HISTORY_SIZE));
44
44
  }
45
45
  }
46
46
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { InjectedIntl } from 'react-intl';
2
+ import { IntlShape } from 'react-intl';
3
3
  import BpSocket from '../core/socket';
4
4
  import { BotInfo, Config, CurrentConversation, EventFeedback, Message, MessageWrapper, QueuedMessage, RecentConversation, StudioConnector, uuid } from '../typings';
5
5
  import ComposerStore from './composer';
@@ -18,7 +18,7 @@ declare class RootStore {
18
18
  preferredLanguage: string;
19
19
  isInitialized: boolean;
20
20
  messageFeedbacks: EventFeedback[];
21
- intl: InjectedIntl;
21
+ intl: IntlShape;
22
22
  isBotTyping: import("mobx").IObservableValue<boolean>;
23
23
  /** When a wrapper is defined, every messages are wrapped by the specified component */
24
24
  messageWrapper: MessageWrapper | undefined;
@@ -27,7 +27,7 @@ declare class RootStore {
27
27
  constructor(options: {
28
28
  fullscreen: boolean;
29
29
  }, config?: Config);
30
- setIntlProvider(provider: InjectedIntl): void;
30
+ setIntlProvider(provider: IntlShape): void;
31
31
  setSocket(socket: BpSocket): void;
32
32
  get isConversationStarted(): boolean;
33
33
  get botName(): string;
@@ -28,8 +28,7 @@ const translations_1 = require("../translations");
28
28
  const utils_1 = require("../utils");
29
29
  const composer_1 = __importDefault(require("./composer"));
30
30
  const view_1 = __importDefault(require("./view"));
31
- translations_1.initializeLocale();
32
- const chosenLocale = translations_1.getUserLocale();
31
+ const chosenLocale = (0, translations_1.getUserLocale)();
33
32
  class RootStore {
34
33
  constructor(options, config) {
35
34
  this.conversations = [];
@@ -73,7 +72,7 @@ class RootStore {
73
72
  : undefined));
74
73
  }
75
74
  get rtl() {
76
- return utils_1.isRTLLocale(this.preferredLanguage);
75
+ return (0, utils_1.isRTLLocale)(this.preferredLanguage);
77
76
  }
78
77
  get escapeHTML() {
79
78
  var _a, _b;
@@ -144,7 +143,7 @@ class RootStore {
144
143
  return;
145
144
  }
146
145
  let start = new Date();
147
- if (is_before_1.default(start, this.currentConversation.typingUntil)) {
146
+ if ((0, is_before_1.default)(start, this.currentConversation.typingUntil)) {
148
147
  start = this.currentConversation.typingUntil;
149
148
  }
150
149
  this.currentConversation.typingUntil = new Date(+start + event.timeInMs);
@@ -157,7 +156,7 @@ class RootStore {
157
156
  try {
158
157
  yield this.fetchConversations();
159
158
  yield this.fetchConversation(this.config.conversationId);
160
- mobx_1.runInAction('-> setInitialized', () => {
159
+ (0, mobx_1.runInAction)('-> setInitialized', () => {
161
160
  this.isInitialized = true;
162
161
  this.postMessage('webchatReady');
163
162
  });
@@ -173,7 +172,7 @@ class RootStore {
173
172
  fetchBotInfo() {
174
173
  return __awaiter(this, void 0, void 0, function* () {
175
174
  const botInfo = yield this.api.fetchBotInfo();
176
- mobx_1.runInAction('-> setBotInfo', () => {
175
+ (0, mobx_1.runInAction)('-> setBotInfo', () => {
177
176
  this.botInfo = botInfo;
178
177
  });
179
178
  this.mergeConfig({
@@ -189,7 +188,7 @@ class RootStore {
189
188
  if (!preferences.language) {
190
189
  return;
191
190
  }
192
- mobx_1.runInAction('-> setPreferredLanguage', () => {
191
+ (0, mobx_1.runInAction)('-> setPreferredLanguage', () => {
193
192
  this.updateBotUILanguage(preferences.language);
194
193
  });
195
194
  });
@@ -198,7 +197,7 @@ class RootStore {
198
197
  fetchConversations() {
199
198
  return __awaiter(this, void 0, void 0, function* () {
200
199
  const conversations = yield this.api.fetchConversations();
201
- mobx_1.runInAction('-> setConversations', () => {
200
+ (0, mobx_1.runInAction)('-> setConversations', () => {
202
201
  if (!(conversations === null || conversations === void 0 ? void 0 : conversations.length)) {
203
202
  this.view.showBotInfo();
204
203
  }
@@ -218,7 +217,7 @@ class RootStore {
218
217
  conversation.messages = conversation.messages.sort((a, b) => new Date(a.sentOn).getTime() - new Date(b.sentOn).getTime());
219
218
  yield this.extractFeedback(conversation.messages);
220
219
  }
221
- mobx_1.runInAction('-> setConversation', () => {
220
+ (0, mobx_1.runInAction)('-> setConversation', () => {
222
221
  this.currentConversation = conversation;
223
222
  this.view.hideConversations();
224
223
  });
@@ -237,7 +236,7 @@ class RootStore {
237
236
  this.composer.updateMessage('');
238
237
  try {
239
238
  yield this.sendData({ type: 'text', text: userMessage });
240
- utils_1.trackMessage('sent');
239
+ (0, utils_1.trackMessage)('sent');
241
240
  this.composer.addMessageToHistory(userMessage);
242
241
  }
243
242
  catch (e) {
@@ -282,7 +281,7 @@ class RootStore {
282
281
  type: 'visit',
283
282
  text: 'User visit',
284
283
  timezone: -(new Date().getTimezoneOffset() / 60),
285
- language: translations_1.getUserLocale()
284
+ language: (0, translations_1.getUserLocale)()
286
285
  });
287
286
  });
288
287
  }
@@ -290,7 +289,7 @@ class RootStore {
290
289
  return __awaiter(this, void 0, void 0, function* () {
291
290
  const feedbackMessageIds = messages.filter((x) => x.payload && x.payload.collectFeedback).map((x) => x.id);
292
291
  const feedbackInfo = yield this.api.getMessageIdsFeedbackInfo(feedbackMessageIds);
293
- mobx_1.runInAction('-> setFeedbackInfo', () => {
292
+ (0, mobx_1.runInAction)('-> setFeedbackInfo', () => {
294
293
  this.messageFeedbacks = feedbackInfo;
295
294
  });
296
295
  });
@@ -305,7 +304,7 @@ class RootStore {
305
304
  try {
306
305
  const { txt, name } = yield this.api.downloadConversation(this.currentConversationId);
307
306
  const blobFile = new Blob([txt]);
308
- utils_1.downloadFile(name, blobFile);
307
+ (0, utils_1.downloadFile)(name, blobFile);
309
308
  }
310
309
  catch (err) {
311
310
  console.error('Error trying to download conversation');
@@ -341,7 +340,7 @@ class RootStore {
341
340
  }
342
341
  /** Use this method to replace a value or add a new config */
343
342
  mergeConfig(config) {
344
- this.config = merge_1.default(this.config, config);
343
+ this.config = (0, merge_1.default)(this.config, config);
345
344
  this._applyConfig();
346
345
  }
347
346
  /** This replaces all the configurations by this object */
@@ -363,7 +362,7 @@ class RootStore {
363
362
  else if (window.USE_SESSION_STORAGE !== this.config.useSessionStorage) {
364
363
  console.warn('[WebChat] "useSessionStorage" value cannot be altered once the webchat is initialized');
365
364
  }
366
- const locale = this.config.locale ? translations_1.getUserLocale(this.config.locale) : chosenLocale;
365
+ const locale = this.config.locale ? (0, translations_1.getUserLocale)(this.config.locale) : chosenLocale;
367
366
  this.updateBotUILanguage(locale);
368
367
  document.documentElement.setAttribute('lang', locale);
369
368
  this.publishConfigChanged();
@@ -395,7 +394,7 @@ class RootStore {
395
394
  this.isBotTyping.set(true);
396
395
  this._typingInterval = setInterval(() => {
397
396
  const typeUntil = new Date(this.currentConversation && this.currentConversation.typingUntil);
398
- if (!typeUntil || !is_valid_1.default(typeUntil) || is_before_1.default(typeUntil, new Date())) {
397
+ if (!typeUntil || !(0, is_valid_1.default)(typeUntil) || (0, is_before_1.default)(typeUntil, new Date())) {
399
398
  this._expireTyping();
400
399
  }
401
400
  else {
@@ -411,8 +410,8 @@ class RootStore {
411
410
  this._typingInterval = undefined;
412
411
  }
413
412
  updateBotUILanguage(lang) {
414
- lang = translations_1.getUserLocale(lang); // Ensure language is supported
415
- mobx_1.runInAction('-> setBotUILanguage', () => {
413
+ lang = (0, translations_1.getUserLocale)(lang); // Ensure language is supported
414
+ (0, mobx_1.runInAction)('-> setBotUILanguage', () => {
416
415
  var _a;
417
416
  this.botUILanguage = lang;
418
417
  this.preferredLanguage = lang;
@@ -422,7 +421,7 @@ class RootStore {
422
421
  emptyDelayedMessagesQueue(removeAll) {
423
422
  while (this.delayedMessages.length) {
424
423
  const message = this.delayedMessages[0];
425
- if (removeAll || is_before_1.default(message.showAt, new Date())) {
424
+ if (removeAll || (0, is_before_1.default)(message.showAt, new Date())) {
426
425
  this.currentConversation.messages.push(message.message);
427
426
  this.delayedMessages.shift();
428
427
  }
@@ -157,7 +157,7 @@ class ViewStore {
157
157
  /** Updates one or multiple properties of a specific button */
158
158
  updateHeaderButton(buttonId, newProps) {
159
159
  const button = this.customButtons.find((btn) => btn.id === buttonId);
160
- button && merge_1.default(button, newProps);
160
+ button && (0, merge_1.default)(button, newProps);
161
161
  }
162
162
  removeHeaderButton(buttonId) {
163
163
  this.customButtons = this.customButtons.filter((btn) => btn.id !== buttonId);
@@ -195,7 +195,7 @@ class ViewStore {
195
195
  }
196
196
  _endAnimation(finalView) {
197
197
  setTimeout(() => {
198
- mobx_1.runInAction(() => {
198
+ (0, mobx_1.runInAction)(() => {
199
199
  this.activeView = finalView;
200
200
  });
201
201
  }, constants_1.default.ANIM_DURATION);
@@ -4,5 +4,4 @@ declare const translations: {
4
4
  [lang: string]: any;
5
5
  };
6
6
  declare const getUserLocale: (manualLocale?: Locale) => string;
7
- declare const initializeLocale: () => void;
8
- export { initializeLocale, translations, DEFAULT_LOCALE as defaultLocale, getUserLocale };
7
+ export { translations, DEFAULT_LOCALE as defaultLocale, getUserLocale };
@@ -3,17 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getUserLocale = exports.defaultLocale = exports.translations = exports.initializeLocale = void 0;
7
- const react_intl_1 = require("react-intl");
8
- const ar_1 = __importDefault(require("react-intl/locale-data/ar"));
9
- const de_1 = __importDefault(require("react-intl/locale-data/de"));
10
- const en_1 = __importDefault(require("react-intl/locale-data/en"));
11
- const es_1 = __importDefault(require("react-intl/locale-data/es"));
12
- const fr_1 = __importDefault(require("react-intl/locale-data/fr"));
13
- const it_1 = __importDefault(require("react-intl/locale-data/it"));
14
- const pt_1 = __importDefault(require("react-intl/locale-data/pt"));
15
- const ru_1 = __importDefault(require("react-intl/locale-data/ru"));
16
- const uk_1 = __importDefault(require("react-intl/locale-data/uk"));
6
+ exports.getUserLocale = exports.defaultLocale = exports.translations = void 0;
7
+ require('@formatjs/intl-pluralrules/polyfill');
8
+ require('@formatjs/intl-pluralrules/locale-data/ar');
9
+ require('@formatjs/intl-pluralrules/locale-data/de');
10
+ require('@formatjs/intl-pluralrules/locale-data/en');
11
+ require('@formatjs/intl-pluralrules/locale-data/es');
12
+ require('@formatjs/intl-pluralrules/locale-data/fr');
13
+ require('@formatjs/intl-pluralrules/locale-data/it');
14
+ require('@formatjs/intl-pluralrules/locale-data/pt');
15
+ require('@formatjs/intl-pluralrules/locale-data/ru');
16
+ require('@formatjs/intl-pluralrules/locale-data/uk');
17
17
  const ar_json_1 = __importDefault(require("./ar.json"));
18
18
  const de_json_1 = __importDefault(require("./de.json"));
19
19
  const en_json_1 = __importDefault(require("./en.json"));
@@ -53,17 +53,3 @@ const getUserLocale = (manualLocale = 'browser') => {
53
53
  return translations[browserLocale] ? browserLocale : DEFAULT_LOCALE;
54
54
  };
55
55
  exports.getUserLocale = getUserLocale;
56
- const initializeLocale = () => {
57
- react_intl_1.addLocaleData([
58
- ...en_1.default,
59
- ...fr_1.default,
60
- ...pt_1.default,
61
- ...es_1.default,
62
- ...ar_1.default,
63
- ...ru_1.default,
64
- ...uk_1.default,
65
- ...de_1.default,
66
- ...it_1.default
67
- ]);
68
- };
69
- exports.initializeLocale = initializeLocale;
package/dist/utils.js CHANGED
@@ -70,7 +70,7 @@ const renderUnsafeHTML = (message = '', escaped) => {
70
70
  if (escaped) {
71
71
  message = message.replace(/</g, '&lt;').replace(/>/g, '&gt;');
72
72
  }
73
- const html = snarkdown_1.default(message);
73
+ const html = (0, snarkdown_1.default)(message);
74
74
  return html.replace(/<a href/gi, '<a target="_blank" href');
75
75
  };
76
76
  exports.renderUnsafeHTML = renderUnsafeHTML;
package/package.json CHANGED
@@ -1,29 +1,48 @@
1
1
  {
2
2
  "name": "@botpress/webchat",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "source": "src/index.tsx",
7
7
  "license": "AGPL-3.0",
8
8
  "scripts": {
9
- "build": "yarn --silent && tsc --build",
10
- "watch": "yarn --silent && tsc --build --watch"
9
+ "build": "yarn && yarn run -T tsc --build",
10
+ "watch": "yarn && yarn run -T tsc --build --watch",
11
+ "prepublish": "yarn run -T rimraf dist && yarn --immutable && yarn run -T tsc --build && yarn run -T rimraf dist/.tsbuildinfo"
11
12
  },
12
13
  "files": [
13
14
  "dist"
14
15
  ],
16
+ "devDependencies": {
17
+ "@types/lodash": "^4.14.178",
18
+ "@types/mime": "^2.0.3",
19
+ "@types/node": "^16.11.13",
20
+ "@types/react": "^17.0.38",
21
+ "@types/react-dom": "^17.0.11",
22
+ "@types/uuid": "^8.3.4",
23
+ "prop-types": "^15.8.1"
24
+ },
15
25
  "dependencies": {
16
26
  "@blueprintjs/core": "^3.23.1",
17
- "@botpress/messaging-socket": "0.0.1",
27
+ "@botpress/messaging-components": "0.1.0",
28
+ "@botpress/messaging-socket": "0.1.0",
29
+ "@formatjs/intl-pluralrules": "^4.1.6",
30
+ "@formatjs/intl-utils": "^3.8.4",
18
31
  "@juggle/resize-observer": "^3.0.2",
32
+ "axios": "^0.24.0",
33
+ "classnames": "^2.3.1",
19
34
  "date-fns": "^1.30.1",
20
- "mobx": "4.9.4",
21
- "mobx-react": "^5.4.4",
22
- "query-string": "^7.0.1",
23
- "react-dom": "^16.8.6",
24
- "react-ga": "^2.7.0"
25
- },
26
- "devDependencies": {
27
- "@types/dom-mediacapture-record": "^1.0.7"
35
+ "lodash": "^4.17.21",
36
+ "mime": "^3.0.0",
37
+ "mobx": "5.15.7",
38
+ "mobx-react": "^6.2.1",
39
+ "mobx-react-lite": "2.0.0",
40
+ "query-string": "^7.1.0",
41
+ "react": "^17.0.2",
42
+ "react-dom": "^17.0.2",
43
+ "react-ga": "^2.7.0",
44
+ "react-intl": "^3.12.1",
45
+ "snarkdown": "^2.0.0",
46
+ "uuid": "^8.3.2"
28
47
  }
29
- }
48
+ }
@@ -1,16 +0,0 @@
1
- import { Component } from 'react';
2
- import { HTMLInputEvent, Renderer } from '../../../typings';
3
- /**
4
- * A simple button, with a possibility to be used as a file upload button
5
- *
6
- * @param {object} buttons The list of buttons to display (object with a label and a payload)
7
- * @param {function} onButtonClicked Called when the button is clicked with the label and the payload
8
- * @param {function} onFileUpload This is called when a file is uploaded
9
- */
10
- export declare class Button extends Component<Renderer.Button> {
11
- constructor(props: Renderer.Button);
12
- handleButtonClick: (e: any) => void;
13
- handleFileUpload: (event: HTMLInputEvent) => void;
14
- renderFileUpload(accept: string): JSX.Element;
15
- render(): JSX.Element;
16
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.Button = void 0;
23
- const react_1 = __importStar(require("react"));
24
- const FileInput_1 = require("./FileInput");
25
- /**
26
- * A simple button, with a possibility to be used as a file upload button
27
- *
28
- * @param {object} buttons The list of buttons to display (object with a label and a payload)
29
- * @param {function} onButtonClicked Called when the button is clicked with the label and the payload
30
- * @param {function} onFileUpload This is called when a file is uploaded
31
- */
32
- class Button extends react_1.Component {
33
- constructor(props) {
34
- super(props);
35
- this.handleButtonClick = (e) => {
36
- var _a, _b;
37
- if (this.props.preventDoubleClick) {
38
- e.target.disabled = true;
39
- }
40
- (_b = (_a = this.props).onButtonClick) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.label, this.props.payload);
41
- };
42
- this.handleFileUpload = (event) => {
43
- var _a, _b;
44
- if (!event.target.files) {
45
- return;
46
- }
47
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
48
- (_b = (_a = this.props).onFileUpload) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.label, this.props.payload, event.target.files[0]);
49
- };
50
- }
51
- renderFileUpload(accept) {
52
- return (react_1.default.createElement("button", { className: 'bpw-button' },
53
- react_1.default.createElement("span", null, this.props.label),
54
- react_1.default.createElement(FileInput_1.FileInput, { name: 'uploadField', accept: accept, className: 'bpw-file-message', placeholder: this.props.label, onFileChanged: this.handleFileUpload })));
55
- }
56
- render() {
57
- if (this.props.payload === 'BOTPRESS.IMAGE_UPLOAD') {
58
- return this.renderFileUpload('image/*');
59
- }
60
- if (this.props.payload === 'BOTPRESS.FILE_UPLOAD') {
61
- return this.renderFileUpload('*/*');
62
- }
63
- return (react_1.default.createElement("button", { className: 'bpw-button', onClick: this.handleButtonClick }, this.props.label));
64
- }
65
- }
66
- exports.Button = Button;