@botpress/webchat 0.2.0 → 0.2.4
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 +2 -23
- package/dist/components/ContextMenu.js +0 -9
- package/dist/components/ConversationList.js +1 -1
- 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 -39
- package/dist/components/messages/MessageList.d.ts +1 -1
- package/dist/components/messages/MessageList.js +1 -2
- package/dist/core/api.d.ts +4 -13
- package/dist/core/api.js +35 -127
- package/dist/core/socket.d.ts +0 -3
- package/dist/core/socket.js +2 -21
- package/dist/fonts/roboto.d.ts +4 -0
- package/dist/fonts/roboto.js +9 -0
- 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.d.ts +1 -1
- package/dist/index.js +7 -0
- package/dist/main.d.ts +2 -1
- package/dist/main.js +50 -47
- package/dist/store/composer.js +3 -6
- package/dist/store/index.d.ts +7 -12
- package/dist/store/index.js +92 -97
- 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 +9 -19
- package/dist/utils/storage.d.ts +17 -0
- package/dist/utils/storage.js +117 -0
- package/dist/utils.js +1 -1
- package/package.json +6 -2
- package/dist/components/Keyboard.d.ts +0 -22
- package/dist/components/Keyboard.js +0 -86
- package/dist/components/common/BotInfo.js +0 -110
package/dist/typings.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { RootStore } from './store';
|
|
3
|
+
import { BPStorage } from './utils/storage';
|
|
3
4
|
declare global {
|
|
4
5
|
interface Window {
|
|
5
6
|
__BP_VISITOR_SOCKET_ID: string;
|
|
6
7
|
__BP_VISITOR_ID: string;
|
|
7
8
|
botpressWebChat: any;
|
|
8
9
|
store: RootStore;
|
|
9
|
-
BOT_API_PATH: string;
|
|
10
|
-
API_PATH: string;
|
|
11
|
-
BOTPRESS_VERSION: string;
|
|
12
|
-
BOT_NAME: string;
|
|
13
|
-
ROOT_PATH: string;
|
|
14
10
|
BOT_ID: string;
|
|
15
|
-
BP_BASE_PATH: string;
|
|
16
11
|
SEND_USAGE_STATS: boolean;
|
|
17
12
|
SHOW_POWERED_BY: boolean;
|
|
18
13
|
USE_SESSION_STORAGE: boolean;
|
|
19
|
-
BP_STORAGE:
|
|
14
|
+
BP_STORAGE: BPStorage;
|
|
20
15
|
botpress: {
|
|
21
16
|
[moduleName: string]: any;
|
|
22
17
|
};
|
|
@@ -35,7 +30,6 @@ export declare namespace Renderer {
|
|
|
35
30
|
noBubble?: boolean;
|
|
36
31
|
keyboard?: any;
|
|
37
32
|
eventId?: string;
|
|
38
|
-
isHighlighted?: boolean;
|
|
39
33
|
isLastGroup?: boolean;
|
|
40
34
|
isLastOfGroup?: boolean;
|
|
41
35
|
isBotMessage?: boolean;
|
|
@@ -145,6 +139,8 @@ export interface StudioConnector {
|
|
|
145
139
|
export interface Config {
|
|
146
140
|
/** Url of the messaging server */
|
|
147
141
|
messagingUrl: string;
|
|
142
|
+
/** Url of the Media File Service where we fetch the bot info */
|
|
143
|
+
mediaFileServiceUrl?: string;
|
|
148
144
|
/** Id of your messaging client */
|
|
149
145
|
clientId: string;
|
|
150
146
|
botId?: string;
|
|
@@ -155,7 +151,6 @@ export interface Config {
|
|
|
155
151
|
userIdScope?: string;
|
|
156
152
|
enableReset: boolean;
|
|
157
153
|
stylesheet?: string;
|
|
158
|
-
isEmulator?: boolean;
|
|
159
154
|
extraStylesheet?: string;
|
|
160
155
|
showConversationsButton: boolean;
|
|
161
156
|
showUserName: boolean;
|
|
@@ -196,8 +191,6 @@ export interface Config {
|
|
|
196
191
|
enablePersistHistory: boolean;
|
|
197
192
|
/** Experimental: expose the store to the parent frame for more control on the webchat's behavior */
|
|
198
193
|
exposeStore: boolean;
|
|
199
|
-
/** Reference ensures that a specific value and its signature are valid */
|
|
200
|
-
reference?: string;
|
|
201
194
|
/** If true, Websocket is created when the Webchat is opened. Bot cannot be proactive. */
|
|
202
195
|
lazySocket?: boolean;
|
|
203
196
|
/** If true, chat will no longer play the notification sound for new messages. */
|
|
@@ -206,6 +199,8 @@ export interface Config {
|
|
|
206
199
|
chatId?: string;
|
|
207
200
|
/** CSS class to be applied to iframe */
|
|
208
201
|
className?: string;
|
|
202
|
+
/** Key used to encrypt data in the localStorage */
|
|
203
|
+
encryptionKey?: string;
|
|
209
204
|
}
|
|
210
205
|
export declare type OverridableComponents = 'below_conversation' | 'before_container' | 'composer';
|
|
211
206
|
export interface Overrides {
|
|
@@ -234,6 +229,8 @@ export interface BotInfo {
|
|
|
234
229
|
escapeHTML: boolean;
|
|
235
230
|
};
|
|
236
231
|
lazySocket: boolean;
|
|
232
|
+
extraStylesheet?: string;
|
|
233
|
+
disableNotificationSound?: boolean;
|
|
237
234
|
}
|
|
238
235
|
export declare type uuid = string;
|
|
239
236
|
export interface Conversation {
|
|
@@ -260,7 +257,7 @@ export interface Message {
|
|
|
260
257
|
authorId: uuid | undefined;
|
|
261
258
|
sentOn: Date;
|
|
262
259
|
payload: any;
|
|
263
|
-
timeInMs
|
|
260
|
+
timeInMs?: number;
|
|
264
261
|
}
|
|
265
262
|
export interface QueuedMessage {
|
|
266
263
|
message: Message;
|
|
@@ -296,13 +293,6 @@ export interface CustomAction {
|
|
|
296
293
|
/** The event triggered when the action is clicked */
|
|
297
294
|
onClick: (actionId: string, messageProps: any, event: React.MouseEvent) => void;
|
|
298
295
|
}
|
|
299
|
-
/** When set, this will wrap every messages displayed in the webchat */
|
|
300
|
-
export interface MessageWrapper {
|
|
301
|
-
/** The name of the module hosting the component */
|
|
302
|
-
module: string;
|
|
303
|
-
/** Name of the component exposed by the module */
|
|
304
|
-
component: string;
|
|
305
|
-
}
|
|
306
296
|
export interface EventFeedback {
|
|
307
297
|
messageId: uuid;
|
|
308
298
|
feedback?: number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Config } from '../typings';
|
|
2
|
+
export declare type StorageConfig = Pick<Config, 'clientId' | 'encryptionKey' | 'useSessionStorage'>;
|
|
3
|
+
export declare class BPStorage {
|
|
4
|
+
private _config;
|
|
5
|
+
private _storage;
|
|
6
|
+
constructor(config: StorageConfig);
|
|
7
|
+
get config(): Partial<StorageConfig>;
|
|
8
|
+
set config(config: Partial<StorageConfig>);
|
|
9
|
+
private serialize;
|
|
10
|
+
private deserialize;
|
|
11
|
+
private getStorageKey;
|
|
12
|
+
private getDriver;
|
|
13
|
+
set<T>(key: string, value: T): void;
|
|
14
|
+
get<T = string>(key: string): T | undefined;
|
|
15
|
+
del(key: string): void;
|
|
16
|
+
}
|
|
17
|
+
export default BPStorage;
|
|
@@ -0,0 +1,117 @@
|
|
|
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;
|
|
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 ((_a = this.config.encryptionKey) === null || _a === void 0 ? void 0 : _a.length) {
|
|
27
|
+
str = aes_1.default.encrypt(str, this.config.encryptionKey).toString();
|
|
28
|
+
}
|
|
29
|
+
return str;
|
|
30
|
+
}
|
|
31
|
+
catch (_b) {
|
|
32
|
+
console.error('[Storage] Error parsing value', value);
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.deserialize = (strValue) => {
|
|
37
|
+
var _a;
|
|
38
|
+
if (strValue === null || strValue === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
if ((_a = this.config.encryptionKey) === null || _a === void 0 ? void 0 : _a.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 (_b) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
this.getStorageKey = (key) => {
|
|
52
|
+
var _a, _b;
|
|
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}-${this.config.clientId}`;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
this.getDriver = () => {
|
|
62
|
+
if (this._storage) {
|
|
63
|
+
return this._storage;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const storage = this.config.useSessionStorage === true && typeof sessionStorage !== 'undefined' ? sessionStorage : localStorage;
|
|
67
|
+
const tempKey = '__storage_test__';
|
|
68
|
+
storage.setItem(tempKey, tempKey);
|
|
69
|
+
storage.removeItem(tempKey);
|
|
70
|
+
return (this._storage = storage);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
return (this._storage = 'cookie');
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
this._config = config;
|
|
77
|
+
}
|
|
78
|
+
get config() {
|
|
79
|
+
return this._config;
|
|
80
|
+
}
|
|
81
|
+
set config(config) {
|
|
82
|
+
this._config = Object.assign(Object.assign({}, this._config), config);
|
|
83
|
+
}
|
|
84
|
+
set(key, value) {
|
|
85
|
+
try {
|
|
86
|
+
const driver = this.getDriver();
|
|
87
|
+
driver !== 'cookie'
|
|
88
|
+
? driver.setItem(this.getStorageKey(key), this.serialize(value))
|
|
89
|
+
: js_cookie_1.default.set(this.getStorageKey(key), this.serialize(value));
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
console.error('Error while setting data into storage.', err.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
get(key) {
|
|
96
|
+
try {
|
|
97
|
+
const driver = this.getDriver();
|
|
98
|
+
return driver !== 'cookie'
|
|
99
|
+
? this.deserialize(driver.getItem(this.getStorageKey(key)))
|
|
100
|
+
: this.deserialize(js_cookie_1.default.get(this.getStorageKey(key)));
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
console.error('Error while getting data from storage.', err.message);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
del(key) {
|
|
107
|
+
try {
|
|
108
|
+
const driver = this.getDriver();
|
|
109
|
+
driver !== 'cookie' ? driver.removeItem(this.getStorageKey(key)) : js_cookie_1.default.remove(this.getStorageKey(key));
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error('Error while deleting data from storage.', err.message);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.BPStorage = BPStorage;
|
|
117
|
+
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.4",
|
|
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,22 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export declare class Prepend extends React.Component<Partial<KeyboardElementsProps>> {
|
|
3
|
-
render(): JSX.Element;
|
|
4
|
-
}
|
|
5
|
-
export declare class Append extends React.Component<Partial<KeyboardElementsProps>> {
|
|
6
|
-
render(): JSX.Element;
|
|
7
|
-
}
|
|
8
|
-
export declare class Default extends React.Component<Partial<KeyboardElementsProps>> {
|
|
9
|
-
static prependRef: React.RefObject<HTMLDivElement>;
|
|
10
|
-
static appendRef: React.RefObject<HTMLDivElement>;
|
|
11
|
-
static isReady: () => boolean;
|
|
12
|
-
render(): JSX.Element;
|
|
13
|
-
}
|
|
14
|
-
interface KeyboardElementsProps {
|
|
15
|
-
/** When true, the keyboard is appended at the end. Otherwise, it is prepended */
|
|
16
|
-
append?: boolean;
|
|
17
|
-
index?: number;
|
|
18
|
-
visible?: boolean;
|
|
19
|
-
/** A keyboard can be any kind of element */
|
|
20
|
-
keyboard?: any;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,86 +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.Default = exports.Append = exports.Prepend = void 0;
|
|
23
|
-
const React = __importStar(require("react"));
|
|
24
|
-
const ReactDOM = __importStar(require("react-dom"));
|
|
25
|
-
class KeyboardElements extends React.Component {
|
|
26
|
-
constructor(props) {
|
|
27
|
-
super(props);
|
|
28
|
-
this.container = document.createElement('div');
|
|
29
|
-
}
|
|
30
|
-
insertChildAt(child, index = 0, parent) {
|
|
31
|
-
if (index >= parent.children.length) {
|
|
32
|
-
parent.appendChild(child);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
parent.insertBefore(child, parent.children[index]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
componentDidMount() {
|
|
39
|
-
if (this.props.append) {
|
|
40
|
-
this.insertChildAt(this.container, this.props.index, Default.appendRef.current);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.insertChildAt(this.container, this.props.index, Default.prependRef.current);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
componentWillUnmount() {
|
|
47
|
-
var _a, _b;
|
|
48
|
-
if (this.props.append) {
|
|
49
|
-
(_a = Default.appendRef.current) === null || _a === void 0 ? void 0 : _a.removeChild(this.container);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
(_b = Default.prependRef.current) === null || _b === void 0 ? void 0 : _b.removeChild(this.container);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
render() {
|
|
56
|
-
return ReactDOM.createPortal(this.props.children, this.container);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
class Prepend extends React.Component {
|
|
60
|
-
render() {
|
|
61
|
-
return (React.createElement("div", null,
|
|
62
|
-
this.props.visible && React.createElement(KeyboardElements, { index: this.props.index }, this.props.keyboard),
|
|
63
|
-
this.props.children));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.Prepend = Prepend;
|
|
67
|
-
class Append extends React.Component {
|
|
68
|
-
render() {
|
|
69
|
-
return (React.createElement("div", null,
|
|
70
|
-
this.props.visible && React.createElement(KeyboardElements, { append: true }, this.props.keyboard),
|
|
71
|
-
this.props.children));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.Append = Append;
|
|
75
|
-
class Default extends React.Component {
|
|
76
|
-
render() {
|
|
77
|
-
return (React.createElement("div", { className: 'bpw-keyboard' },
|
|
78
|
-
React.createElement("div", { ref: Default.prependRef }),
|
|
79
|
-
this.props.children,
|
|
80
|
-
React.createElement("div", { ref: Default.appendRef })));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.Default = Default;
|
|
84
|
-
Default.prependRef = React.createRef();
|
|
85
|
-
Default.appendRef = React.createRef();
|
|
86
|
-
Default.isReady = () => Default.appendRef.current !== null;
|
|
@@ -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)));
|