@botpress/webchat 0.3.2 → 0.4.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.
@@ -0,0 +1,88 @@
1
+ // TODO: This seems completely outdated. Does not match classes used by the component
2
+
3
+ @mixin bottomBorder() {
4
+ border-bottom: solid 1px rgba(0, 0, 0, 0.1);
5
+ }
6
+
7
+ $charcoal: #1e1e1e;
8
+
9
+ // Fix for IE which has trouble with the max-width property
10
+ @media only screen and (min-width: 800px) {
11
+ .bot-info-container {
12
+ width: 800px;
13
+ }
14
+ }
15
+
16
+ .bot-info-container {
17
+ margin: 0 auto;
18
+ max-width: 800px;
19
+ text-align: center;
20
+ color: $charcoal;
21
+ overflow-y: auto;
22
+ svg {
23
+ fill: $charcoal;
24
+ }
25
+ & > img {
26
+ width: 100%;
27
+ }
28
+ p,
29
+ a,
30
+ button {
31
+ font-size: 0.9em;
32
+ color: rgb(102, 102, 102);
33
+ text-decoration: none;
34
+ }
35
+ }
36
+
37
+ .summary {
38
+ margin-top: -32px;
39
+ @include bottomBorder();
40
+ box-shadow: 0px 4px 5px -5px #ccc;
41
+ h3 {
42
+ margin: 0;
43
+ }
44
+ p {
45
+ margin-top: 0.4em;
46
+ margin-block-end: 1em;
47
+ }
48
+ }
49
+
50
+ .links {
51
+ @include bottomBorder();
52
+ }
53
+
54
+ .icon-link {
55
+ padding-left: 25%;
56
+ display: flex;
57
+ margin: 20px 0;
58
+ i {
59
+ margin-right: 10px;
60
+ }
61
+ }
62
+
63
+ .terms {
64
+ padding: 0px 20px;
65
+ text-align: left;
66
+ a {
67
+ display: inline-block;
68
+ width: 100%;
69
+ line-height: 2.5;
70
+ @include bottomBorder();
71
+ }
72
+ }
73
+
74
+ .startBtn {
75
+ font: inherit;
76
+ color: inherit;
77
+ background-color: transparent;
78
+ cursor: pointer;
79
+ border-radius: 20px;
80
+ line-height: 24px;
81
+ padding: 5px 10px;
82
+ margin-top: 25px;
83
+ border: 1px solid rgb(100, 100, 100);
84
+ &:focus {
85
+ border: 1px solid black;
86
+ color: black;
87
+ }
88
+ }
@@ -0,0 +1,48 @@
1
+ @import '../variables.scss';
2
+
3
+ .ConfirmDialogContainer > div {
4
+ z-index: 9999;
5
+
6
+ :global {
7
+ .bp3-button-text {
8
+ font-size: 12px !important;
9
+ }
10
+
11
+ .bp3-dialog-body {
12
+ display: flex;
13
+ }
14
+
15
+ .bp3-button {
16
+ box-shadow: unset !important;
17
+ background-image: unset !important;
18
+ border-radius: 5px !important;
19
+ padding-top: 6px;
20
+ }
21
+
22
+ .bp3-button.bp3-intent-warning {
23
+ background-color: var(--lighthouse);
24
+
25
+ &:hover {
26
+ background-color: var(--hover-lighthouse);
27
+ }
28
+
29
+ &:focus {
30
+ background-color: var(--focus-lighthouse);
31
+ }
32
+ }
33
+
34
+ .bp3-button:not([class*='bp3-intent']) {
35
+ background-color: white;
36
+
37
+ &:hover,
38
+ &:focus {
39
+ background-color: var(--seashell);
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ .icon {
46
+ margin-right: 16px;
47
+ color: var(--lighthouse) !important;
48
+ }
@@ -0,0 +1,29 @@
1
+ :global(.bp3-dialog-container) {
2
+ height: 100%;
3
+ }
4
+
5
+ .dialog {
6
+ max-height: 90%;
7
+ background-color: white !important;
8
+ overflow-y: auto;
9
+
10
+ .form,
11
+ :global(.bp3-dialog-body) {
12
+ overflow: auto;
13
+ height: calc(100% - 34px);
14
+ }
15
+
16
+ :global {
17
+ .bp3-button {
18
+ transition: color 0.3s, background 0.3s;
19
+ }
20
+ }
21
+ }
22
+
23
+ .dialogBody {
24
+ position: relative;
25
+ margin: 0 !important;
26
+ padding: 20px !important;
27
+ padding-bottom: 6px !important;
28
+ overflow: auto;
29
+ }
@@ -0,0 +1,108 @@
1
+ @import '../variables.scss';
2
+
3
+ .tooltip {
4
+ position: fixed;
5
+ font-style: normal;
6
+ font-weight: 400;
7
+ letter-spacing: normal;
8
+ line-height: 1.25;
9
+ text-align: left;
10
+ text-shadow: none;
11
+ text-transform: none;
12
+ white-space: normal;
13
+ word-break: normal;
14
+ word-spacing: normal;
15
+ word-wrap: normal;
16
+ font-size: 12px;
17
+ opacity: 0;
18
+ visibility: hidden;
19
+ z-index: 99999999;
20
+ transition: opacity 0.3s, visibility 0.3s;
21
+
22
+ &.visible {
23
+ opacity: 1;
24
+ visibility: visible;
25
+ }
26
+
27
+ &.hidden {
28
+ opacity: 0;
29
+ visibility: hidden;
30
+ }
31
+
32
+ &:global {
33
+ &.right:not(.top):not(.bottom) {
34
+ margin-left: 5px;
35
+
36
+ .tooltipArrow {
37
+ top: 50%;
38
+ left: auto;
39
+ margin-left: -5px;
40
+ border-width: 5px 5px 5px 0;
41
+ border-right-color: var(--reef);
42
+ }
43
+ }
44
+
45
+ &.left:not(.top):not(.bottom) {
46
+ margin-left: -5px;
47
+
48
+ .tooltipArrow {
49
+ top: 50%;
50
+ margin-top: -5px;
51
+ border-width: 5px 0 5px 5px;
52
+ border-left-color: var(--reef);
53
+ right: -5px;
54
+ left: auto;
55
+ }
56
+ }
57
+
58
+ &.top {
59
+ margin-top: -5px;
60
+
61
+ .tooltipArrow {
62
+ top: auto;
63
+ bottom: -5px;
64
+ left: 50%;
65
+ margin-left: -5px;
66
+ border-width: 5px 5px 0;
67
+ border-top-color: var(--reef);
68
+ }
69
+ }
70
+
71
+ &.bottom {
72
+ margin-top: 5px;
73
+
74
+ .tooltipArrow {
75
+ top: 0;
76
+ left: 50%;
77
+ margin-left: -5px;
78
+ border-width: 0 5px 5px;
79
+ border-bottom-color: var(--reef);
80
+ }
81
+ }
82
+ }
83
+ :global {
84
+ .tooltipArrow {
85
+ top: 50%;
86
+ left: 0;
87
+ margin-top: -5px;
88
+ border-width: 5px 5px 5px 0;
89
+ border-right-color: var(--reef);
90
+ position: absolute;
91
+ width: 0;
92
+ height: 0;
93
+ border-color: transparent;
94
+ border-right-color: transparent;
95
+ border-style: solid;
96
+ }
97
+
98
+ .tooltipInner {
99
+ background: var(--reef);
100
+ border-radius: 3px;
101
+ color: #fff;
102
+ max-width: 400px;
103
+ padding: 5px 8px !important;
104
+ text-align: center;
105
+ white-space: nowrap;
106
+ }
107
+ }
108
+ }
@@ -0,0 +1,38 @@
1
+ :root {
2
+ --main-bg-color: #ffffff;
3
+ --main-bg-color-hover: rgba(255, 255, 255, 0.9);
4
+ --main-fg-color: #000000;
5
+ --main-fg-color-hover: rgba(0, 0, 0, 0.07);
6
+
7
+ --white: #ffffff;
8
+ --bg: #f5f6f8;
9
+ --seashell: #e2e2e2;
10
+ --gray: #bec5c9;
11
+ --reef: #5c7080;
12
+ --shark: #1a1e22;
13
+ --overlay: rgba(26, 30, 34, 0.8);
14
+ --success: #019d90;
15
+ --say: #a4ded0;
16
+ --trigger: #ffe5b4;
17
+ --execute: #b0c4de;
18
+ --listen: #ffe699;
19
+ --prompt: #e2c7e0;
20
+ --standard: #000000;
21
+ --skill-call: #0000ff;
22
+ --if-else: #febbad;
23
+ --lighthouse: #f66f48;
24
+ --focus-lighthouse: #e06542;
25
+ --hover-lighthouse: #f39c82;
26
+ --hover-lighthouse-30: #f9ddd5;
27
+ --ocean: #3276ea;
28
+ --hover-ocean: #cad7f5;
29
+
30
+ --spacing-x-small: 2px;
31
+ --spacing-small: 4px;
32
+ --spacing-medium: 8px;
33
+ --spacing-large: 12px;
34
+ --spacing-x-large: 16px;
35
+ --spacing-xx-large: 20px;
36
+ --spacing-xxx-large: 24px;
37
+ --spacing-xxxx-large: 28px;
38
+ }
@@ -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
  }
@@ -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 = window.BP_STORAGE.get('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;
@@ -0,0 +1 @@
1
+ declare module '*.scss';
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,7 @@
1
+ import { MessagingSocket } from '@botpress/messaging-socket';
2
+ declare global {
3
+ interface Window {
4
+ websocket: MessagingSocket;
5
+ }
6
+ }
7
+ declare module '*.scss';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
- return this.props.mergeConfig(data.payload);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/webchat",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "source": "src/index.tsx",
@@ -9,7 +9,8 @@
9
9
  "build": "yarn && yarn run -T tsc --build",
10
10
  "watch": "yarn && yarn run -T tsc --build --watch",
11
11
  "dev": "yarn run -T parcel test/index.html",
12
- "prepublish": "yarn run -T rimraf dist && yarn --immutable && yarn run -T tsc --build && yarn run -T rimraf dist/.tsbuildinfo"
12
+ "copy:scss": "yarn run -T copyfiles -u 1 ./src/**/*.scss dist",
13
+ "prepublish": "yarn run -T rimraf dist && yarn --immutable && yarn run -T tsc --build && yarn run -T rimraf dist/.tsbuildinfo && yarn copy:scss"
13
14
  },
14
15
  "files": [
15
16
  "dist",
@@ -28,8 +29,8 @@
28
29
  },
29
30
  "dependencies": {
30
31
  "@blueprintjs/core": "^3.23.1",
31
- "@botpress/messaging-components": "0.3.0",
32
- "@botpress/messaging-socket": "1.1.1",
32
+ "@botpress/messaging-components": "0.4.0",
33
+ "@botpress/messaging-socket": "1.2.0",
33
34
  "@formatjs/intl-pluralrules": "^4.1.6",
34
35
  "@formatjs/intl-utils": "^3.8.4",
35
36
  "@juggle/resize-observer": "^3.0.2",