@botpress/webchat 0.2.5 → 0.3.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.
- package/README.md +31 -0
- package/dist/components/Composer.d.ts +4 -5
- package/dist/components/Composer.js +1 -21
- package/dist/components/Container.js +1 -4
- package/dist/components/ConversationList.d.ts +1 -1
- package/dist/components/ConversationList.js +5 -46
- package/dist/components/Header.d.ts +1 -3
- package/dist/components/Header.js +7 -37
- package/dist/components/common/BotInfo/index.d.ts +1 -1
- package/dist/components/common/BotInfo/index.js +4 -14
- package/dist/components/messages/InlineFeedback.d.ts +2 -1
- package/dist/components/messages/Message.js +1 -5
- package/dist/components/messages/MessageGroup.d.ts +1 -5
- package/dist/components/messages/MessageGroup.js +4 -7
- package/dist/components/messages/MessageList.d.ts +1 -1
- package/dist/components/messages/MessageList.js +7 -29
- package/dist/core/api.d.ts +2 -6
- package/dist/core/api.js +4 -32
- package/dist/core/constants.d.ts +4 -32
- package/dist/core/constants.js +18 -32
- package/dist/core/socket.d.ts +1 -7
- package/dist/core/socket.js +7 -30
- package/dist/index.d.ts +2 -8
- package/dist/index.js +6 -27
- package/dist/main.d.ts +2 -2
- package/dist/main.js +84 -135
- package/dist/store/index.d.ts +4 -8
- package/dist/store/index.js +25 -62
- package/dist/store/view.d.ts +3 -4
- package/dist/store/view.js +6 -13
- package/dist/translations/index.d.ts +2 -1
- package/dist/translations/index.js +36 -1
- package/dist/typings.d.ts +117 -55
- package/dist/utils/analytics.d.ts +5 -0
- package/dist/utils/analytics.js +37 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +27 -0
- package/package.json +2 -3
- package/dist/components/ContextMenu.d.ts +0 -2
- package/dist/components/ContextMenu.js +0 -24
- package/dist/components/OverridableComponent.d.ts +0 -24
- package/dist/components/OverridableComponent.js +0 -50
- package/dist/components/Stylesheet.d.ts +0 -5
- package/dist/components/Stylesheet.js +0 -7
- package/dist/components/common/MoreOptions/index.d.ts +0 -21
- package/dist/components/common/MoreOptions/index.js +0 -60
- package/dist/components/common/Overlay/index.d.ts +0 -7
- package/dist/components/common/Overlay/index.js +0 -36
- package/dist/icons/CloseChat.d.ts +0 -6
- package/dist/icons/CloseChat.js +0 -9
- package/dist/icons/Send.d.ts +0 -6
- package/dist/icons/Send.js +0 -8
- package/dist/utils.d.ts +0 -8
- package/dist/utils.js +0 -111
package/dist/core/api.js
CHANGED
|
@@ -8,32 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const axios_1 = __importDefault(require("axios"));
|
|
16
12
|
const uuid_1 = require("uuid");
|
|
17
13
|
class WebchatApi {
|
|
18
14
|
constructor(socket) {
|
|
19
15
|
this.socket = socket;
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
listCurrentConversationMessages(limit) {
|
|
22
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
19
|
try {
|
|
24
|
-
|
|
25
|
-
return data;
|
|
20
|
+
return this.socket.socket.listMessages(limit);
|
|
26
21
|
}
|
|
27
22
|
catch (err) {
|
|
28
|
-
console.error('
|
|
23
|
+
console.error('An error occurred while listing the messages of the current conversation', err);
|
|
29
24
|
}
|
|
30
25
|
});
|
|
31
26
|
}
|
|
32
|
-
listCurrentConversationMessages(limit) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return this.socket.socket.listMessages(limit);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
27
|
fetchConversations() {
|
|
38
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
29
|
try {
|
|
@@ -43,7 +33,7 @@ class WebchatApi {
|
|
|
43
33
|
const limit = 1;
|
|
44
34
|
yield this.socket.socket.switchConversation(conversation.id);
|
|
45
35
|
const lastMessages = yield this.listCurrentConversationMessages(limit);
|
|
46
|
-
if (lastMessages.length >= limit) {
|
|
36
|
+
if (lastMessages && lastMessages.length >= limit) {
|
|
47
37
|
conversation.lastMessage = lastMessages[0];
|
|
48
38
|
}
|
|
49
39
|
}
|
|
@@ -68,16 +58,6 @@ class WebchatApi {
|
|
|
68
58
|
}
|
|
69
59
|
});
|
|
70
60
|
}
|
|
71
|
-
// TODO: Fis this
|
|
72
|
-
resetSession(conversationId) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
try {
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
console.error('Error while resetting conversation', err);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
61
|
createConversation() {
|
|
82
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
63
|
try {
|
|
@@ -124,14 +104,6 @@ class WebchatApi {
|
|
|
124
104
|
return this.socket.socket.sendFeedback(messageId, feedback);
|
|
125
105
|
});
|
|
126
106
|
}
|
|
127
|
-
uploadFile(file, payload, conversationId) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
const data = new FormData();
|
|
130
|
-
data.append('file', file);
|
|
131
|
-
data.append('conversationId', conversationId);
|
|
132
|
-
data.append('payload', payload);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
107
|
// TODO: Fix this
|
|
136
108
|
sendVoiceMessage(voice, ext, conversationId) {
|
|
137
109
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -1,42 +1,14 @@
|
|
|
1
|
+
import { Config } from '../typings';
|
|
1
2
|
declare const _default: {
|
|
2
|
-
/** These types are sent using the /message/ endpoint */
|
|
3
|
-
MESSAGE_TYPES: string[];
|
|
4
3
|
/** The duration of the hide / show chat */
|
|
5
|
-
|
|
4
|
+
ANIMATION_DURATION: number;
|
|
6
5
|
MIN_TIME_BETWEEN_SOUNDS: number;
|
|
7
|
-
|
|
8
|
-
HISTORY_MAX_MESSAGES: number;
|
|
6
|
+
SENT_HISTORY_SIZE: number;
|
|
9
7
|
/** The number of minutes before a new timestamp is displayed */
|
|
10
8
|
TIME_BETWEEN_DATES: number;
|
|
11
9
|
DEFAULT_LAYOUT_WIDTH: number;
|
|
12
10
|
DEFAULT_CONTAINER_WIDTH: number;
|
|
13
|
-
SENT_HISTORY_SIZE: number;
|
|
14
11
|
/** The default configuration when starting the chat */
|
|
15
|
-
DEFAULT_CONFIG:
|
|
16
|
-
userId: undefined;
|
|
17
|
-
extraStylesheet: string;
|
|
18
|
-
botName: undefined;
|
|
19
|
-
botConvoDescription: undefined;
|
|
20
|
-
overrides: undefined;
|
|
21
|
-
enableReset: boolean;
|
|
22
|
-
enableTranscriptDownload: boolean;
|
|
23
|
-
enableArrowNavigation: boolean;
|
|
24
|
-
showConversationsButton: boolean;
|
|
25
|
-
useSessionStorage: boolean;
|
|
26
|
-
showUserName: boolean;
|
|
27
|
-
showUserAvatar: boolean;
|
|
28
|
-
showTimestamp: boolean;
|
|
29
|
-
disableAnimations: boolean;
|
|
30
|
-
hideWidget: boolean;
|
|
31
|
-
externalAuthToken: undefined;
|
|
32
|
-
showPoweredBy: boolean;
|
|
33
|
-
enablePersistHistory: boolean;
|
|
34
|
-
enableResetSessionShortcut: boolean;
|
|
35
|
-
enableVoiceComposer: boolean;
|
|
36
|
-
enableConversationDeletion: boolean;
|
|
37
|
-
closeOnEscape: boolean;
|
|
38
|
-
recentConversationLifetime: string;
|
|
39
|
-
startNewConvoOnTimeout: boolean;
|
|
40
|
-
};
|
|
12
|
+
DEFAULT_CONFIG: Partial<Config>;
|
|
41
13
|
};
|
|
42
14
|
export default _default;
|
package/dist/core/constants.js
CHANGED
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const DEFAULT_CONFIG = {
|
|
4
|
+
botName: undefined,
|
|
5
|
+
botConversationDescription: undefined,
|
|
6
|
+
enableTranscriptDownload: true,
|
|
7
|
+
showConversationsButton: true,
|
|
8
|
+
useSessionStorage: false,
|
|
9
|
+
showTimestamp: false,
|
|
10
|
+
disableAnimations: false,
|
|
11
|
+
hideWidget: false,
|
|
12
|
+
showPoweredBy: false,
|
|
13
|
+
enablePersistHistory: true,
|
|
14
|
+
enableVoiceComposer: false,
|
|
15
|
+
enableConversationDeletion: false,
|
|
16
|
+
closeOnEscape: true
|
|
17
|
+
};
|
|
3
18
|
exports.default = {
|
|
4
|
-
/** These types are sent using the /message/ endpoint */
|
|
5
|
-
MESSAGE_TYPES: ['text', 'quick_reply', 'form', 'login_prompt', 'visit', 'postback'],
|
|
6
19
|
/** The duration of the hide / show chat */
|
|
7
|
-
|
|
20
|
+
ANIMATION_DURATION: 300,
|
|
8
21
|
MIN_TIME_BETWEEN_SOUNDS: 1000,
|
|
9
|
-
|
|
10
|
-
HISTORY_MAX_MESSAGES: 10,
|
|
22
|
+
SENT_HISTORY_SIZE: 20,
|
|
11
23
|
/** The number of minutes before a new timestamp is displayed */
|
|
12
24
|
TIME_BETWEEN_DATES: 10,
|
|
13
25
|
DEFAULT_LAYOUT_WIDTH: 360,
|
|
14
26
|
DEFAULT_CONTAINER_WIDTH: 360,
|
|
15
|
-
SENT_HISTORY_SIZE: 20,
|
|
16
27
|
/** The default configuration when starting the chat */
|
|
17
|
-
DEFAULT_CONFIG
|
|
18
|
-
userId: undefined,
|
|
19
|
-
extraStylesheet: '',
|
|
20
|
-
botName: undefined,
|
|
21
|
-
botConvoDescription: undefined,
|
|
22
|
-
overrides: undefined,
|
|
23
|
-
enableReset: true,
|
|
24
|
-
enableTranscriptDownload: true,
|
|
25
|
-
enableArrowNavigation: false,
|
|
26
|
-
showConversationsButton: true,
|
|
27
|
-
useSessionStorage: false,
|
|
28
|
-
showUserName: false,
|
|
29
|
-
showUserAvatar: false,
|
|
30
|
-
showTimestamp: false,
|
|
31
|
-
disableAnimations: false,
|
|
32
|
-
hideWidget: false,
|
|
33
|
-
externalAuthToken: undefined,
|
|
34
|
-
showPoweredBy: window.SHOW_POWERED_BY,
|
|
35
|
-
enablePersistHistory: true,
|
|
36
|
-
enableResetSessionShortcut: false,
|
|
37
|
-
enableVoiceComposer: false,
|
|
38
|
-
enableConversationDeletion: false,
|
|
39
|
-
closeOnEscape: true,
|
|
40
|
-
recentConversationLifetime: '5h',
|
|
41
|
-
startNewConvoOnTimeout: false
|
|
42
|
-
}
|
|
28
|
+
DEFAULT_CONFIG
|
|
43
29
|
};
|
package/dist/core/socket.d.ts
CHANGED
|
@@ -3,16 +3,10 @@ import { Config } from '../typings';
|
|
|
3
3
|
export default class BpSocket {
|
|
4
4
|
socket: MessagingSocket;
|
|
5
5
|
private chatId;
|
|
6
|
-
private waitingForUser?;
|
|
7
|
-
onClear: (event: any) => void;
|
|
8
6
|
onMessage: (event: any) => void;
|
|
9
|
-
onTyping: (event: any) => void;
|
|
10
|
-
onData: (event: any) => void;
|
|
11
|
-
onUserIdChanged: (userId: string) => void;
|
|
12
7
|
constructor(config: Config);
|
|
13
8
|
setup(): void;
|
|
14
9
|
sendPayload(payload: any): Promise<Message>;
|
|
15
10
|
postToParent: (_type: string, payload: any) => void;
|
|
16
|
-
|
|
17
|
-
waitForUserId(): Promise<void>;
|
|
11
|
+
connect(): Promise<void>;
|
|
18
12
|
}
|
package/dist/core/socket.js
CHANGED
|
@@ -14,7 +14,6 @@ class BpSocket {
|
|
|
14
14
|
constructor(config) {
|
|
15
15
|
this.postToParent = (_type, payload) => {
|
|
16
16
|
var _a;
|
|
17
|
-
// we could filter on event type if necessary
|
|
18
17
|
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage(Object.assign(Object.assign({}, payload), { chatId: this.chatId }), '*');
|
|
19
18
|
};
|
|
20
19
|
this.chatId = config.chatId;
|
|
@@ -22,15 +21,6 @@ class BpSocket {
|
|
|
22
21
|
}
|
|
23
22
|
setup() {
|
|
24
23
|
this.socket.on('message', this.onMessage);
|
|
25
|
-
/*
|
|
26
|
-
this.events.on('guest.webchat.clear', this.onClear)
|
|
27
|
-
this.events.on('guest.webchat.message', this.onMessage)
|
|
28
|
-
this.events.on('guest.webchat.typing', this.onTyping)
|
|
29
|
-
this.events.on('guest.webchat.data', this.onData)
|
|
30
|
-
*/
|
|
31
|
-
// firehose events to parent page
|
|
32
|
-
// TODO: why do we need this
|
|
33
|
-
// this.events.onAny(this.postToParent)
|
|
34
24
|
}
|
|
35
25
|
sendPayload(payload) {
|
|
36
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -39,28 +29,15 @@ class BpSocket {
|
|
|
39
29
|
return message;
|
|
40
30
|
});
|
|
41
31
|
}
|
|
42
|
-
|
|
43
|
-
waitForUserId() {
|
|
32
|
+
connect() {
|
|
44
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
const creds = window.BP_STORAGE.get('creds');
|
|
35
|
+
yield this.socket.connect(creds);
|
|
36
|
+
if (this.socket.userId) {
|
|
37
|
+
const userId = this.socket.userId;
|
|
38
|
+
window.BP_STORAGE.set('creds', this.socket.creds);
|
|
39
|
+
this.postToParent('', { userId });
|
|
47
40
|
}
|
|
48
|
-
this.waitingForUser = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const creds = window.BP_STORAGE.get('creds');
|
|
50
|
-
yield this.socket.connect(creds);
|
|
51
|
-
if (this.socket.userId) {
|
|
52
|
-
const userId = this.socket.userId;
|
|
53
|
-
window.BP_STORAGE.set('creds', this.socket.creds);
|
|
54
|
-
this.onUserIdChanged(userId);
|
|
55
|
-
this.postToParent('', { userId });
|
|
56
|
-
resolve();
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
this.waitingForUser = undefined;
|
|
60
|
-
reject();
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
return this.waitingForUser;
|
|
64
41
|
});
|
|
65
42
|
}
|
|
66
43
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { RootStore } from './store';
|
|
3
3
|
import { Config } from './typings';
|
|
4
|
-
export declare const Embedded: (props: any) => ExposedWebChat;
|
|
5
|
-
export declare const Fullscreen: (props: any) => ExposedWebChat;
|
|
6
4
|
interface State {
|
|
7
5
|
store: RootStore;
|
|
8
6
|
}
|
|
@@ -14,10 +12,6 @@ export declare class ExposedWebChat extends React.Component<Props, State> {
|
|
|
14
12
|
constructor(props: Props);
|
|
15
13
|
render(): JSX.Element;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* https://botpress.com/docs/developers/migrate/
|
|
20
|
-
*/
|
|
21
|
-
export { Embedded as embedded } from '.';
|
|
22
|
-
export { Fullscreen as fullscreen } from '.';
|
|
15
|
+
export declare const Embedded: (props: Props) => ExposedWebChat;
|
|
16
|
+
export declare const Fullscreen: (props: Props) => ExposedWebChat;
|
|
23
17
|
export * from './typings';
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.Fullscreen = exports.Embedded = exports.ExposedWebChat = void 0;
|
|
17
17
|
const mobx_1 = require("mobx");
|
|
18
18
|
const mobx_react_1 = require("mobx-react");
|
|
19
19
|
const react_1 = __importDefault(require("react"));
|
|
@@ -23,10 +23,6 @@ const store_1 = require("./store");
|
|
|
23
23
|
const translations_1 = require("./translations");
|
|
24
24
|
const storage_1 = __importDefault(require("./utils/storage"));
|
|
25
25
|
(0, mobx_1.configure)({ enforceActions: 'observed' });
|
|
26
|
-
const Embedded = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: false }));
|
|
27
|
-
exports.Embedded = Embedded;
|
|
28
|
-
const Fullscreen = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: true }));
|
|
29
|
-
exports.Fullscreen = Fullscreen;
|
|
30
26
|
class ExposedWebChat extends react_1.default.Component {
|
|
31
27
|
constructor(props) {
|
|
32
28
|
super(props);
|
|
@@ -40,30 +36,13 @@ class ExposedWebChat extends react_1.default.Component {
|
|
|
40
36
|
const { botUILanguage: locale } = store;
|
|
41
37
|
return (react_1.default.createElement(mobx_react_1.Provider, { store: store },
|
|
42
38
|
react_1.default.createElement(react_intl_1.IntlProvider, { locale: locale, messages: translations_1.translations[locale || translations_1.defaultLocale], defaultLocale: translations_1.defaultLocale },
|
|
43
|
-
react_1.default.createElement(main_1.default, Object.assign({
|
|
39
|
+
react_1.default.createElement(main_1.default, Object.assign({}, this.props)))));
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
42
|
exports.ExposedWebChat = ExposedWebChat;
|
|
47
|
-
// TODO: what does this observer do?
|
|
48
43
|
const Wrapper = (0, mobx_react_1.observer)(ExposedWebChat);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var _1 = require(".");
|
|
54
|
-
Object.defineProperty(exports, "embedded", { enumerable: true, get: function () { return _1.Embedded; } });
|
|
55
|
-
var _2 = require(".");
|
|
56
|
-
Object.defineProperty(exports, "fullscreen", { enumerable: true, get: function () { return _2.Fullscreen; } });
|
|
44
|
+
const Embedded = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: false }));
|
|
45
|
+
exports.Embedded = Embedded;
|
|
46
|
+
const Fullscreen = (props) => new Wrapper(Object.assign(Object.assign({}, props), { fullscreen: true }));
|
|
47
|
+
exports.Fullscreen = Fullscreen;
|
|
57
48
|
__exportStar(require("./typings"), exports);
|
|
58
|
-
// TODO: export this
|
|
59
|
-
/*
|
|
60
|
-
export {
|
|
61
|
-
Carousel,
|
|
62
|
-
QuickReplies,
|
|
63
|
-
LoginPrompt,
|
|
64
|
-
Text,
|
|
65
|
-
FileMessage,
|
|
66
|
-
FileInput,
|
|
67
|
-
Button
|
|
68
|
-
} from './components/messages/renderer'
|
|
69
|
-
*/
|
package/dist/main.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omi
|
|
|
9
9
|
} & import("mobx-react").IWrappedComponent<unknown>;
|
|
10
10
|
export default _default;
|
|
11
11
|
declare type MainProps = {
|
|
12
|
-
store
|
|
13
|
-
} & WrappedComponentProps & Pick<StoreDef, 'config' | 'initializeChat' | 'botInfo' | 'fetchBotInfo' | 'sendMessage' | '
|
|
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'>;
|