@botpress/webchat 0.2.1 → 0.2.5
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.
- package/dist/components/Composer.d.ts +1 -1
- package/dist/components/Composer.js +12 -2
- package/dist/components/Container.d.ts +1 -1
- package/dist/components/Container.js +0 -2
- package/dist/components/ContextMenu.js +0 -9
- package/dist/components/Header.d.ts +1 -1
- package/dist/components/Header.js +10 -27
- package/dist/components/VoiceRecorder.js +6 -2
- package/dist/components/common/{Avatar.d.ts → Avatar/index.d.ts} +0 -0
- package/dist/components/common/Avatar/index.js +13 -0
- package/dist/components/common/{BotInfo.d.ts → BotInfo/index.d.ts} +2 -2
- package/dist/components/common/BotInfo/index.js +112 -0
- package/dist/components/common/ConfirmDialog/index.d.ts +11 -0
- package/dist/components/common/ConfirmDialog/index.js +78 -0
- package/dist/components/common/Dialog/index.d.ts +17 -0
- package/dist/components/common/Dialog/index.js +57 -0
- package/dist/components/common/MoreOptions/index.d.ts +21 -0
- package/dist/components/common/MoreOptions/index.js +60 -0
- package/dist/components/common/Overlay/index.d.ts +7 -0
- package/dist/components/common/{Avatar.js → Overlay/index.js} +15 -8
- package/dist/components/common/ToolTip/index.d.ts +10 -0
- package/dist/components/common/ToolTip/index.js +163 -0
- package/dist/components/common/ToolTip/utils.d.ts +15 -0
- package/dist/components/common/ToolTip/utils.js +78 -0
- package/dist/components/messages/Message.js +1 -20
- package/dist/components/messages/MessageGroup.d.ts +1 -9
- package/dist/components/messages/MessageGroup.js +4 -35
- package/dist/components/messages/MessageList.d.ts +1 -1
- package/dist/components/messages/MessageList.js +1 -2
- package/dist/core/api.d.ts +5 -15
- package/dist/core/api.js +31 -128
- package/dist/core/socket.d.ts +0 -3
- package/dist/core/socket.js +2 -21
- package/dist/icons/Cancel.d.ts +5 -0
- package/dist/icons/Cancel.js +10 -0
- package/dist/icons/Microphone.d.ts +5 -0
- package/dist/icons/Microphone.js +12 -0
- package/dist/index.js +4 -3
- package/dist/main.d.ts +1 -1
- package/dist/main.js +20 -37
- package/dist/store/composer.js +3 -6
- package/dist/store/index.d.ts +5 -11
- package/dist/store/index.js +84 -85
- package/dist/store/view.d.ts +0 -2
- package/dist/store/view.js +0 -10
- package/dist/translations/index.d.ts +2 -1
- package/dist/translations/index.js +9 -4
- package/dist/typings.d.ts +8 -18
- package/dist/utils/storage.d.ts +16 -0
- package/dist/utils/storage.js +129 -0
- package/dist/utils.js +1 -1
- package/package.json +6 -2
- package/dist/components/common/BotInfo.js +0 -110
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
exports.BPStorage = void 0;
|
|
7
|
+
const aes_1 = __importDefault(require("crypto-js/aes"));
|
|
8
|
+
const enc_utf8_1 = __importDefault(require("crypto-js/enc-utf8"));
|
|
9
|
+
const sha256_1 = __importDefault(require("crypto-js/sha256"));
|
|
10
|
+
const js_cookie_1 = __importDefault(require("js-cookie"));
|
|
11
|
+
class BPStorage {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.serialize = (value) => {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
if (value === null || value === undefined) {
|
|
16
|
+
throw new Error('[Storage] Cannot store null or undefined values');
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
let str = '';
|
|
20
|
+
if (typeof value === 'string') {
|
|
21
|
+
str = value;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
str = JSON.stringify(value);
|
|
25
|
+
}
|
|
26
|
+
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.encryptionKey) === null || _b === void 0 ? void 0 : _b.length) {
|
|
27
|
+
str = aes_1.default.encrypt(str, this.config.encryptionKey).toString();
|
|
28
|
+
}
|
|
29
|
+
return str;
|
|
30
|
+
}
|
|
31
|
+
catch (_c) {
|
|
32
|
+
console.error('[Storage] Error parsing value', value);
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.deserialize = (strValue) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
if (strValue === null || strValue === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.encryptionKey) === null || _b === void 0 ? void 0 : _b.length) {
|
|
43
|
+
strValue = aes_1.default.decrypt(strValue, this.config.encryptionKey).toString(enc_utf8_1.default);
|
|
44
|
+
}
|
|
45
|
+
return JSON.parse(strValue);
|
|
46
|
+
}
|
|
47
|
+
catch (_c) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
this.getStorageKey = (key) => {
|
|
52
|
+
var _a, _b, _c;
|
|
53
|
+
const rawKey = `bp-chat-${key}`;
|
|
54
|
+
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.encryptionKey) === null || _b === void 0 ? void 0 : _b.length) {
|
|
55
|
+
return `${rawKey}-${(0, sha256_1.default)(`${this.config.clientId}-${this.config.encryptionKey}`).toString()}`;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return `${rawKey}-${(_c = this.config) === null || _c === void 0 ? void 0 : _c.clientId}`;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
this.getDriver = () => {
|
|
62
|
+
var _a;
|
|
63
|
+
if (this._storage) {
|
|
64
|
+
return this._storage;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const storage = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.useSessionStorage) === true && typeof sessionStorage !== 'undefined' ? sessionStorage : localStorage;
|
|
68
|
+
const tempKey = '__storage_test__';
|
|
69
|
+
storage.setItem(tempKey, tempKey);
|
|
70
|
+
storage.removeItem(tempKey);
|
|
71
|
+
return (this._storage = storage);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
return (this._storage = 'cookie');
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (config) {
|
|
78
|
+
this._config = config;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
get config() {
|
|
82
|
+
return this._config;
|
|
83
|
+
}
|
|
84
|
+
set config(config) {
|
|
85
|
+
this._config = config;
|
|
86
|
+
}
|
|
87
|
+
set(key, value) {
|
|
88
|
+
if (!this.config) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const driver = this.getDriver();
|
|
93
|
+
driver !== 'cookie'
|
|
94
|
+
? driver.setItem(this.getStorageKey(key), this.serialize(value))
|
|
95
|
+
: js_cookie_1.default.set(this.getStorageKey(key), this.serialize(value));
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
console.error('Error while setting data into storage.', err.message);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
get(key) {
|
|
102
|
+
if (!this.config) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const driver = this.getDriver();
|
|
107
|
+
return driver !== 'cookie'
|
|
108
|
+
? this.deserialize(driver.getItem(this.getStorageKey(key)))
|
|
109
|
+
: this.deserialize(js_cookie_1.default.get(this.getStorageKey(key)));
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error('Error while getting data from storage.', err.message);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
del(key) {
|
|
116
|
+
if (!this.config) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const driver = this.getDriver();
|
|
121
|
+
driver !== 'cookie' ? driver.removeItem(this.getStorageKey(key)) : js_cookie_1.default.remove(this.getStorageKey(key));
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
console.error('Error while deleting data from storage.', err.message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.BPStorage = BPStorage;
|
|
129
|
+
exports.default = BPStorage;
|
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/webchat",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"source": "src/index.tsx",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@types/crypto-js": "^4.1.1",
|
|
18
|
+
"@types/js-cookie": "^3.0.1",
|
|
17
19
|
"@types/lodash": "^4.14.178",
|
|
18
20
|
"@types/mime": "^2.0.3",
|
|
19
21
|
"@types/node": "^16.11.13",
|
|
@@ -24,14 +26,16 @@
|
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|
|
26
28
|
"@blueprintjs/core": "^3.23.1",
|
|
27
|
-
"@botpress/messaging-components": "0.2.
|
|
29
|
+
"@botpress/messaging-components": "0.2.1",
|
|
28
30
|
"@botpress/messaging-socket": "1.1.0",
|
|
29
31
|
"@formatjs/intl-pluralrules": "^4.1.6",
|
|
30
32
|
"@formatjs/intl-utils": "^3.8.4",
|
|
31
33
|
"@juggle/resize-observer": "^3.0.2",
|
|
32
34
|
"axios": "^0.25.0",
|
|
33
35
|
"classnames": "^2.3.1",
|
|
36
|
+
"crypto-js": "^4.1.1",
|
|
34
37
|
"date-fns": "^1.30.1",
|
|
38
|
+
"js-cookie": "^3.0.1",
|
|
35
39
|
"lodash": "^4.17.21",
|
|
36
40
|
"mime": "^3.0.0",
|
|
37
41
|
"mobx": "5.15.7",
|
|
@@ -1,110 +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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
const classnames_1 = __importDefault(require("classnames"));
|
|
35
|
-
const mobx_react_1 = require("mobx-react");
|
|
36
|
-
const React = __importStar(require("react"));
|
|
37
|
-
const react_intl_1 = require("react-intl");
|
|
38
|
-
const Email_1 = __importDefault(require("../../icons/Email"));
|
|
39
|
-
const Phone_1 = __importDefault(require("../../icons/Phone"));
|
|
40
|
-
const Website_1 = __importDefault(require("../../icons/Website"));
|
|
41
|
-
const utils_1 = require("../../utils");
|
|
42
|
-
const Avatar_1 = __importDefault(require("./Avatar"));
|
|
43
|
-
const CoverPicture = ({ botInfo }) => (React.createElement("div", { className: 'bpw-botinfo-cover-picture-wrapper' },
|
|
44
|
-
React.createElement("img", { className: 'bpw-botinfo-cover-picture', src: (botInfo.details && botInfo.details.coverPictureUrl) ||
|
|
45
|
-
`https://via.placeholder.com/400x175?text=${botInfo.name}` })));
|
|
46
|
-
class BotInfoPage extends React.Component {
|
|
47
|
-
constructor() {
|
|
48
|
-
super(...arguments);
|
|
49
|
-
this.changeLanguage = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const lang = e.target.value;
|
|
51
|
-
yield this.props.updatePreferredLanguage(lang);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
componentDidMount() {
|
|
55
|
-
var _a;
|
|
56
|
-
(_a = this.btnEl) === null || _a === void 0 ? void 0 : _a.focus();
|
|
57
|
-
}
|
|
58
|
-
renderDescription(text) {
|
|
59
|
-
const html = (0, utils_1.renderUnsafeHTML)(text, this.props.escapeHTML);
|
|
60
|
-
return React.createElement("div", { className: 'bpw-botinfo-description', dangerouslySetInnerHTML: { __html: html } });
|
|
61
|
-
}
|
|
62
|
-
render() {
|
|
63
|
-
const { botInfo, botName, avatarUrl } = this.props;
|
|
64
|
-
const onDismiss = this.props.isConversationStarted ? this.props.toggleBotInfo : this.props.startConversation;
|
|
65
|
-
return (React.createElement("div", { className: (0, classnames_1.default)('bpw-botinfo-container', {
|
|
66
|
-
'bpw-rtl': this.props.rtl
|
|
67
|
-
}) },
|
|
68
|
-
React.createElement(CoverPicture, { botInfo: botInfo }),
|
|
69
|
-
React.createElement("div", { className: 'bpw-botinfo-summary' },
|
|
70
|
-
React.createElement(Avatar_1.default, { name: botName, avatarUrl: avatarUrl, height: 64, width: 64 }),
|
|
71
|
-
React.createElement("h3", null, botName),
|
|
72
|
-
this.renderDescription(botInfo.description)),
|
|
73
|
-
botInfo.details && (React.createElement(React.Fragment, null,
|
|
74
|
-
React.createElement("div", { className: 'bpw-botinfo-links' },
|
|
75
|
-
botInfo.details.phoneNumber && (React.createElement("div", { className: 'bpw-botinfo-link' },
|
|
76
|
-
React.createElement("i", null,
|
|
77
|
-
React.createElement(Phone_1.default, null)),
|
|
78
|
-
React.createElement("a", { target: '_blank', href: `tel:${botInfo.details.phoneNumber}` }, botInfo.details.phoneNumber))),
|
|
79
|
-
botInfo.details.website && (React.createElement("div", { className: 'bpw-botinfo-link' },
|
|
80
|
-
React.createElement("i", null,
|
|
81
|
-
React.createElement(Website_1.default, null)),
|
|
82
|
-
React.createElement("a", { target: '_blank', href: botInfo.details.website }, botInfo.details.website))),
|
|
83
|
-
botInfo.details.emailAddress && (React.createElement("div", { className: 'bpw-botinfo-link' },
|
|
84
|
-
React.createElement("i", null,
|
|
85
|
-
React.createElement(Email_1.default, null)),
|
|
86
|
-
React.createElement("a", { target: '_blank', href: `mailto:${botInfo.details.emailAddress}` }, botInfo.details.emailAddress)))),
|
|
87
|
-
botInfo.details.termsConditions && (React.createElement("div", { className: 'bpw-botinfo-terms' },
|
|
88
|
-
React.createElement("a", { target: '_blank', href: botInfo.details.termsConditions },
|
|
89
|
-
React.createElement(react_intl_1.FormattedMessage, { id: 'botInfo.termsAndConditions' })))),
|
|
90
|
-
botInfo.details.privacyPolicy && (React.createElement("div", { className: 'bpw-botinfo-terms' },
|
|
91
|
-
React.createElement("a", { target: '_blank', href: botInfo.details.privacyPolicy },
|
|
92
|
-
React.createElement(react_intl_1.FormattedMessage, { id: 'botInfo.privacyPolicy' })))))),
|
|
93
|
-
botInfo.languages.length > 1 && (React.createElement("div", { className: 'bpw-botinfo-preferred-language' },
|
|
94
|
-
React.createElement(react_intl_1.FormattedMessage, { id: 'botInfo.preferredLanguage' }),
|
|
95
|
-
React.createElement("select", { value: this.props.preferredLanguage, onChange: this.changeLanguage }, botInfo.languages.map((lang) => (React.createElement("option", { key: lang, value: lang }, lang.toUpperCase())))))),
|
|
96
|
-
React.createElement("button", { tabIndex: 1, ref: (el) => (this.btnEl = el), className: 'bpw-botinfo-start-button', onClick: onDismiss.bind(this, undefined) }, this.props.isConversationStarted ? (React.createElement(react_intl_1.FormattedMessage, { id: 'botInfo.backToConversation' })) : (React.createElement(react_intl_1.FormattedMessage, { id: 'botInfo.startConversation' })))));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.default = (0, mobx_react_1.inject)(({ store }) => ({
|
|
100
|
-
botName: store.botName,
|
|
101
|
-
botInfo: store.botInfo,
|
|
102
|
-
avatarUrl: store.botAvatarUrl,
|
|
103
|
-
startConversation: store.startConversation,
|
|
104
|
-
toggleBotInfo: store.view.toggleBotInfo,
|
|
105
|
-
isConversationStarted: store.isConversationStarted,
|
|
106
|
-
updatePreferredLanguage: store.updatePreferredLanguage,
|
|
107
|
-
preferredLanguage: store.preferredLanguage,
|
|
108
|
-
escapeHTML: store.escapeHTML,
|
|
109
|
-
rtl: store.rtl
|
|
110
|
-
}))((0, react_intl_1.injectIntl)((0, mobx_react_1.observer)(BotInfoPage)));
|