@botpress/webchat 0.2.3 → 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 +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 +4 -13
- package/dist/core/api.js +29 -130
- package/dist/core/socket.d.ts +0 -5
- package/dist/core/socket.js +2 -45
- 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 +1 -1
- package/dist/main.js +20 -37
- package/dist/store/composer.js +3 -6
- package/dist/store/index.d.ts +6 -12
- package/dist/store/index.js +74 -89
- 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 +6 -18
- package/dist/utils/storage.d.ts +17 -0
- package/dist/utils/storage.js +117 -0
- package/dist/utils.js +1 -1
- package/package.json +4 -2
- package/dist/components/common/BotInfo.js +0 -110
|
@@ -0,0 +1,163 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
26
|
+
const uniqueId_1 = __importDefault(require("lodash/uniqueId"));
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
29
|
+
const style = __importStar(require("./style.module.scss"));
|
|
30
|
+
const utils_1 = require("./utils");
|
|
31
|
+
const ToolTip = ({ childId, children, content, position = 'top', hoverOpenDelay }) => {
|
|
32
|
+
if (!content) {
|
|
33
|
+
return children;
|
|
34
|
+
}
|
|
35
|
+
const id = (0, react_1.useRef)(`botpress-tooltip-${(0, uniqueId_1.default)()}`);
|
|
36
|
+
const timeout = (0, react_1.useRef)(undefined);
|
|
37
|
+
const tooltipRef = (0, react_1.useRef)(null);
|
|
38
|
+
const tipRef = (0, react_1.useRef)(null);
|
|
39
|
+
const pastShow = (el) => {
|
|
40
|
+
var _a;
|
|
41
|
+
const elementRect = el.getBoundingClientRect();
|
|
42
|
+
const tooltipRect = (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
43
|
+
if (!tooltipRect) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const docWidth = document.documentElement.clientWidth, docHeight = document.documentElement.clientHeight;
|
|
47
|
+
const rx = elementRect.x + elementRect.width; // most right x
|
|
48
|
+
const lx = elementRect.x; // most left x
|
|
49
|
+
const ty = elementRect.y; // most top y
|
|
50
|
+
const by = elementRect.y + elementRect.height; // most bottom y
|
|
51
|
+
const overflowYMiddle = (tooltipRect.height - elementRect.height) / 2;
|
|
52
|
+
let overflowXMiddle = (tooltipRect.width - elementRect.width) / 2;
|
|
53
|
+
overflowXMiddle = overflowXMiddle < 0 ? 0 : overflowXMiddle;
|
|
54
|
+
const canBeXMiddle = rx + overflowXMiddle <= docWidth && lx - overflowXMiddle >= 0;
|
|
55
|
+
const canBeRight = rx + tooltipRect.width <= docWidth;
|
|
56
|
+
const canBeLeft = lx - tooltipRect.width >= 0;
|
|
57
|
+
const canBeYMiddle = ty - overflowYMiddle >= 0 && by + overflowYMiddle <= docHeight;
|
|
58
|
+
const canBeAbove = ty - tooltipRect.height >= 0;
|
|
59
|
+
const canBeBellow = by + tooltipRect.height <= docHeight;
|
|
60
|
+
let xClass = '';
|
|
61
|
+
let yClass = '';
|
|
62
|
+
switch (position) {
|
|
63
|
+
case 'top':
|
|
64
|
+
yClass = 'top';
|
|
65
|
+
if (!canBeAbove) {
|
|
66
|
+
yClass = 'bottom';
|
|
67
|
+
}
|
|
68
|
+
xClass = (0, utils_1.checkXPosition)(canBeXMiddle, canBeLeft);
|
|
69
|
+
break;
|
|
70
|
+
case 'bottom':
|
|
71
|
+
yClass = 'bottom';
|
|
72
|
+
if (!canBeBellow) {
|
|
73
|
+
yClass = 'top';
|
|
74
|
+
}
|
|
75
|
+
xClass = (0, utils_1.checkXPosition)(canBeXMiddle, canBeLeft);
|
|
76
|
+
break;
|
|
77
|
+
case 'left':
|
|
78
|
+
xClass = 'left';
|
|
79
|
+
if (!canBeLeft) {
|
|
80
|
+
xClass = 'right';
|
|
81
|
+
}
|
|
82
|
+
yClass = (0, utils_1.checkYPosition)(canBeYMiddle, canBeAbove);
|
|
83
|
+
break;
|
|
84
|
+
case 'right':
|
|
85
|
+
xClass = 'right';
|
|
86
|
+
if (!canBeRight) {
|
|
87
|
+
xClass = 'left';
|
|
88
|
+
}
|
|
89
|
+
yClass = (0, utils_1.checkYPosition)(canBeYMiddle, canBeAbove);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
const { left, top } = (0, utils_1.getPositions)({ xClass, yClass }, el, tooltipRef.current);
|
|
93
|
+
const tipPos = (0, utils_1.tipPosition)({ xClass, yClass }, el);
|
|
94
|
+
const inlineStyle = {
|
|
95
|
+
left: `${left}px`,
|
|
96
|
+
top: `${top}px`
|
|
97
|
+
};
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
var _a, _b, _c;
|
|
100
|
+
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.classList.add(style.visible);
|
|
101
|
+
if (xClass) {
|
|
102
|
+
(_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.classList.add(xClass);
|
|
103
|
+
}
|
|
104
|
+
if (yClass) {
|
|
105
|
+
(_c = tooltipRef.current) === null || _c === void 0 ? void 0 : _c.classList.add(yClass);
|
|
106
|
+
}
|
|
107
|
+
if (tooltipRef.current) {
|
|
108
|
+
tooltipRef.current.style.left = inlineStyle.left;
|
|
109
|
+
tooltipRef.current.style.top = inlineStyle.top;
|
|
110
|
+
}
|
|
111
|
+
if (tipRef.current) {
|
|
112
|
+
tipRef.current.style.left = tipPos.left;
|
|
113
|
+
tipRef.current.style.right = tipPos.right;
|
|
114
|
+
}
|
|
115
|
+
}, hoverOpenDelay || 0);
|
|
116
|
+
};
|
|
117
|
+
const show = (event) => {
|
|
118
|
+
document.addEventListener('mousemove', mouseMove);
|
|
119
|
+
clearTimeout(timeout.current);
|
|
120
|
+
handleHtmlRendering();
|
|
121
|
+
pastShow(event.currentTarget);
|
|
122
|
+
};
|
|
123
|
+
const mouseMove = (event) => {
|
|
124
|
+
var _a;
|
|
125
|
+
if (!((_a = event.target) === null || _a === void 0 ? void 0 : _a.closest(`#${childId || `${id.current}-trigger`}`))) {
|
|
126
|
+
hide();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const handleHtmlRendering = (classNames = '', inlineStyle = {}, tipPos = {}) => {
|
|
130
|
+
const body = document.getElementsByTagName('body')[0];
|
|
131
|
+
const toolTip = document.getElementById(id.current);
|
|
132
|
+
const div = document.createElement('div');
|
|
133
|
+
div.setAttribute('id', id.current);
|
|
134
|
+
if (toolTip) {
|
|
135
|
+
body.replaceChild(div, toolTip);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
body.appendChild(div);
|
|
139
|
+
}
|
|
140
|
+
react_dom_1.default.render(react_1.default.createElement("div", { ref: tooltipRef, className: (0, classnames_1.default)(style.tooltip, classNames), style: inlineStyle },
|
|
141
|
+
react_1.default.createElement("div", { ref: tipRef, className: "tooltipArrow", style: tipPos }),
|
|
142
|
+
react_1.default.createElement("div", { className: "tooltipInner" }, content)), div);
|
|
143
|
+
};
|
|
144
|
+
const hide = (_event) => {
|
|
145
|
+
var _a;
|
|
146
|
+
document.removeEventListener('mousemove', mouseMove);
|
|
147
|
+
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.classList.remove(style.visible);
|
|
148
|
+
const body = document.getElementsByTagName('body')[0];
|
|
149
|
+
clearTimeout(timeout.current);
|
|
150
|
+
timeout.current = window.setTimeout(() => {
|
|
151
|
+
const div = document.getElementById(id.current);
|
|
152
|
+
if (div) {
|
|
153
|
+
body.removeChild(div);
|
|
154
|
+
}
|
|
155
|
+
}, 300);
|
|
156
|
+
};
|
|
157
|
+
return react_1.default.cloneElement(react_1.default.Children.only(children), {
|
|
158
|
+
id: childId || `${id.current}-trigger`,
|
|
159
|
+
onMouseEnter: show,
|
|
160
|
+
onMouseLeave: hide
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
exports.default = ToolTip;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface PositionClasses {
|
|
2
|
+
xClass: string;
|
|
3
|
+
yClass: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const getPositions: (positionClasses: PositionClasses, el: EventTarget & Element, tooltip: HTMLDivElement | null) => {
|
|
6
|
+
left: number;
|
|
7
|
+
top: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const tipPosition: (positionClasses: PositionClasses, el: Element & EventTarget) => {
|
|
10
|
+
left: string;
|
|
11
|
+
right: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const checkXPosition: (canBeXMiddle: boolean, canBeLeft: boolean) => "left" | "right" | "";
|
|
14
|
+
export declare const checkYPosition: (canBeYMiddle: boolean, canBeAbove: boolean) => "bottom" | "top" | "";
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkYPosition = exports.checkXPosition = exports.tipPosition = exports.getPositions = void 0;
|
|
4
|
+
const getPositions = (positionClasses, el, tooltip) => {
|
|
5
|
+
const { xClass, yClass } = positionClasses;
|
|
6
|
+
const elementRect = el.getBoundingClientRect();
|
|
7
|
+
const tooltipRect = tooltip === null || tooltip === void 0 ? void 0 : tooltip.getBoundingClientRect();
|
|
8
|
+
const elLeft = elementRect.left;
|
|
9
|
+
const elWidth = elementRect.width;
|
|
10
|
+
const elTop = elementRect.top;
|
|
11
|
+
const elHeight = elementRect.height;
|
|
12
|
+
const tooltipWidth = (tooltipRect === null || tooltipRect === void 0 ? void 0 : tooltipRect.width) || 0;
|
|
13
|
+
const tooltipHeight = (tooltipRect === null || tooltipRect === void 0 ? void 0 : tooltipRect.height) || 0;
|
|
14
|
+
let left = elLeft + elWidth / 2 - tooltipWidth / 2;
|
|
15
|
+
if (xClass === 'left') {
|
|
16
|
+
left = elLeft - tooltipWidth;
|
|
17
|
+
if (yClass === 'top' || yClass === 'bottom') {
|
|
18
|
+
left = left + elWidth;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (xClass === 'right') {
|
|
22
|
+
left = elLeft;
|
|
23
|
+
if (yClass !== 'top' && yClass !== 'bottom') {
|
|
24
|
+
left = elLeft + elWidth;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let top = elTop + elHeight / 2 - tooltipHeight / 2;
|
|
28
|
+
if (yClass === 'top') {
|
|
29
|
+
top = elTop - tooltipHeight;
|
|
30
|
+
}
|
|
31
|
+
else if (yClass === 'bottom') {
|
|
32
|
+
top = elTop + elHeight;
|
|
33
|
+
}
|
|
34
|
+
return { left, top };
|
|
35
|
+
};
|
|
36
|
+
exports.getPositions = getPositions;
|
|
37
|
+
const tipPosition = (positionClasses, el) => {
|
|
38
|
+
const { xClass, yClass } = positionClasses;
|
|
39
|
+
const elementRect = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
|
|
40
|
+
const elWidth = (elementRect === null || elementRect === void 0 ? void 0 : elementRect.width) || 0;
|
|
41
|
+
let left = 'auto';
|
|
42
|
+
let right = 'auto';
|
|
43
|
+
if (xClass === 'left' && (yClass === 'top' || yClass === 'bottom')) {
|
|
44
|
+
right = `${elWidth / 2 - 5}px`;
|
|
45
|
+
}
|
|
46
|
+
else if (xClass === 'right' && (yClass === 'top' || yClass === 'bottom')) {
|
|
47
|
+
left = `${elWidth / 2 - 5}px`;
|
|
48
|
+
}
|
|
49
|
+
else if (!xClass) {
|
|
50
|
+
left = '50%';
|
|
51
|
+
}
|
|
52
|
+
return { left, right };
|
|
53
|
+
};
|
|
54
|
+
exports.tipPosition = tipPosition;
|
|
55
|
+
const checkXPosition = (canBeXMiddle, canBeLeft) => {
|
|
56
|
+
if (!canBeXMiddle) {
|
|
57
|
+
if (canBeLeft) {
|
|
58
|
+
return 'left';
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return 'right';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return '';
|
|
65
|
+
};
|
|
66
|
+
exports.checkXPosition = checkXPosition;
|
|
67
|
+
const checkYPosition = (canBeYMiddle, canBeAbove) => {
|
|
68
|
+
if (!canBeYMiddle) {
|
|
69
|
+
if (canBeAbove) {
|
|
70
|
+
return 'top';
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return 'bottom';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return '';
|
|
77
|
+
};
|
|
78
|
+
exports.checkYPosition = checkYPosition;
|
|
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
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
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
23
|
};
|
|
@@ -54,11 +45,6 @@ class Message extends react_1.Component {
|
|
|
54
45
|
renderTimestamp() {
|
|
55
46
|
return (react_1.default.createElement("span", { className: "bpw-message-timestamp" }, this.props.store.intl.formatTime(new Date(this.props.sentOn), { hour: 'numeric', minute: 'numeric' })));
|
|
56
47
|
}
|
|
57
|
-
onMessageClicked() {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
yield this.props.store.loadEventInDebugger(this.props.messageId, true);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
48
|
render() {
|
|
63
49
|
var _a, _b;
|
|
64
50
|
if (this.state.hasError) {
|
|
@@ -67,7 +53,6 @@ class Message extends react_1.Component {
|
|
|
67
53
|
const type = this.props.type || (this.props.payload && this.props.payload.type);
|
|
68
54
|
const wrappedType = this.props.payload && this.props.payload.wrapped && this.props.payload.wrapped.type;
|
|
69
55
|
const wrappedClass = `bpw-bubble-${wrappedType}`;
|
|
70
|
-
const isEmulator = this.props.store.config.isEmulator;
|
|
71
56
|
const rendered = (react_1.default.createElement(messaging_components_1.default, { key: this.props.messageId, content: this.props.payload, config: {
|
|
72
57
|
messageId: this.props.messageId,
|
|
73
58
|
noMessageBubble: this.props.noBubble,
|
|
@@ -82,7 +67,6 @@ class Message extends react_1.Component {
|
|
|
82
67
|
shouldPlay: this.props.shouldPlay,
|
|
83
68
|
intl: this.props.store.intl,
|
|
84
69
|
escapeHTML: true,
|
|
85
|
-
isInEmulator: this.props.store.config.isEmulator,
|
|
86
70
|
showTimestamp: this.props.store.config.showTimestamp
|
|
87
71
|
} }));
|
|
88
72
|
if (rendered === null) {
|
|
@@ -92,10 +76,7 @@ class Message extends react_1.Component {
|
|
|
92
76
|
if (this.props.noBubble || ((_b = (_a = this.props.payload) === null || _a === void 0 ? void 0 : _a.wrapped) === null || _b === void 0 ? void 0 : _b.noBubble)) {
|
|
93
77
|
return (react_1.default.createElement("div", { className: (0, classnames_1.default)(this.props.className, wrappedClass), style: additionalStyle }, rendered));
|
|
94
78
|
}
|
|
95
|
-
return (react_1.default.createElement("div", { className: (0, classnames_1.default)(this.props.className, wrappedClass, 'bpw-chat-bubble', `bpw-bubble-${type}
|
|
96
|
-
'bpw-bubble-highlight': this.props.isHighlighted,
|
|
97
|
-
'bpw-msg-hovering': isEmulator
|
|
98
|
-
}), "data-from": this.props.fromLabel, onClick: () => this.onMessageClicked(), tabIndex: -1, style: additionalStyle },
|
|
79
|
+
return (react_1.default.createElement("div", { className: (0, classnames_1.default)(this.props.className, wrappedClass, 'bpw-chat-bubble', `bpw-bubble-${type}`), "data-from": this.props.fromLabel, tabIndex: -1, style: additionalStyle },
|
|
99
80
|
react_1.default.createElement("div", { tabIndex: -1, className: "bpw-chat-bubble-content", onContextMenu: type !== 'session_reset' ? this.handleContextMenu : () => { } },
|
|
100
81
|
react_1.default.createElement("span", { className: "sr-only" }, this.props.store.intl.formatMessage({
|
|
101
82
|
id: this.props.isBotMessage ? 'message.botSaid' : 'message.iSaid',
|
|
@@ -9,13 +9,6 @@ declare class MessageGroup extends React.Component<Props> {
|
|
|
9
9
|
static getDerivedStateFromError(_error: Error): {
|
|
10
10
|
hasError: boolean;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated 12.0
|
|
14
|
-
* Here, we convert old format to the new format Botpress uses internally.
|
|
15
|
-
* - payload: all the data (raw, whatever) that is necessary to display the element
|
|
16
|
-
* - type: extracted from payload for easy sorting
|
|
17
|
-
*/
|
|
18
|
-
convertPayloadFromOldFormat: (data: any) => any;
|
|
19
12
|
onAudioEnded: () => void;
|
|
20
13
|
render(): JSX.Element | "* Cannot display message *";
|
|
21
14
|
}
|
|
@@ -31,5 +24,4 @@ declare type Props = {
|
|
|
31
24
|
onSendData?: any;
|
|
32
25
|
onFeedback?: any;
|
|
33
26
|
store?: RootStore;
|
|
34
|
-
|
|
35
|
-
} & Pick<StoreDef, 'showUserName' | 'messageWrapper'>;
|
|
27
|
+
} & Pick<StoreDef, 'showUserName'>;
|
|
@@ -16,35 +16,6 @@ class MessageGroup extends react_1.default.Component {
|
|
|
16
16
|
hasError: false,
|
|
17
17
|
audioPlayingIndex: 0
|
|
18
18
|
};
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated 12.0
|
|
21
|
-
* Here, we convert old format to the new format Botpress uses internally.
|
|
22
|
-
* - payload: all the data (raw, whatever) that is necessary to display the element
|
|
23
|
-
* - type: extracted from payload for easy sorting
|
|
24
|
-
*/
|
|
25
|
-
this.convertPayloadFromOldFormat = (data) => {
|
|
26
|
-
var _a, _b, _c;
|
|
27
|
-
let payload = data.payload || data.message_data || data.message_raw || { text: data.message_text };
|
|
28
|
-
if (!payload.type) {
|
|
29
|
-
payload.type = data.message_type || ((_a = data.message_data) === null || _a === void 0 ? void 0 : _a.type) || 'text';
|
|
30
|
-
}
|
|
31
|
-
// Keeping compatibility with old schema for the quick reply
|
|
32
|
-
if (data.message_type === 'quick_reply' && !payload.text) {
|
|
33
|
-
payload.text = data.message_text;
|
|
34
|
-
}
|
|
35
|
-
if (data.message_type === 'file' && !payload.url) {
|
|
36
|
-
payload.url = ((_b = data.message_data) === null || _b === void 0 ? void 0 : _b.url) || ((_c = data.message_raw) === null || _c === void 0 ? void 0 : _c.url);
|
|
37
|
-
}
|
|
38
|
-
if (this.props.messageWrapper && payload.type !== 'session_reset') {
|
|
39
|
-
payload = {
|
|
40
|
-
type: 'custom',
|
|
41
|
-
module: this.props.messageWrapper.module,
|
|
42
|
-
component: this.props.messageWrapper.component,
|
|
43
|
-
wrapped: payload
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return payload;
|
|
47
|
-
};
|
|
48
19
|
this.onAudioEnded = () => {
|
|
49
20
|
if (this.state.audioPlayingIndex >= this.props.messages.length - 1) {
|
|
50
21
|
this.state.audioPlayingIndex = -1;
|
|
@@ -77,9 +48,9 @@ class MessageGroup extends react_1.default.Component {
|
|
|
77
48
|
react_1.default.createElement("span", { "data-from": fromLabel, className: "from hidden", "aria-hidden": "true" }, fromLabel),
|
|
78
49
|
(0, sortBy_1.default)(messages, ['sent_on', 'eventId']).map((message, i, messages) => {
|
|
79
50
|
const isLastMsg = i === messages.length - 1;
|
|
80
|
-
const payload =
|
|
81
|
-
const showInlineFeedback = isBot && isLastMsg &&
|
|
82
|
-
return (react_1.default.createElement(Message_1.default, { key: `${message.id}-${message.payload.type}`,
|
|
51
|
+
const payload = message.payload;
|
|
52
|
+
const showInlineFeedback = isBot && isLastMsg && payload.collectFeedback;
|
|
53
|
+
return (react_1.default.createElement(Message_1.default, { key: `${message.id}-${message.payload.type}`, inlineFeedback: showInlineFeedback && (react_1.default.createElement(InlineFeedback_1.InlineFeedback, { intl: this.props.store.intl, messageId: message.id, onFeedback: this.props.onFeedback, messageFeedbacks: this.props.store.messageFeedbacks })), messageId: message.id, noBubble: !!payload.noBubble, fromLabel: fromLabel, isLastOfGroup: i >= this.props.messages.length - 1, isLastGroup: this.props.isLastGroup, isBotMessage: !message.authorId, payload: payload, sentOn: message.sentOn, onSendData: this.props.onSendData, onFileUpload: this.props.onFileUpload, store: this.props.store, onAudioEnded: this.onAudioEnded, shouldPlay: this.state.audioPlayingIndex === i }));
|
|
83
54
|
})))));
|
|
84
55
|
}
|
|
85
56
|
}
|
|
@@ -88,7 +59,5 @@ exports.default = (0, mobx_react_1.inject)(({ store }) => ({
|
|
|
88
59
|
onFeedback: store.sendFeedback,
|
|
89
60
|
onSendData: store.sendData,
|
|
90
61
|
onFileUpload: store.uploadFile,
|
|
91
|
-
|
|
92
|
-
showUserName: store.config.showUserName,
|
|
93
|
-
highlightedMessages: store.view.highlightedMessages
|
|
62
|
+
showUserName: store.config.showUserName
|
|
94
63
|
}))(MessageGroup);
|
|
@@ -7,4 +7,4 @@ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omi
|
|
|
7
7
|
WrappedComponent: React.ComponentType<MessageListProps>;
|
|
8
8
|
} & import("mobx-react").IWrappedComponent<unknown>;
|
|
9
9
|
export default _default;
|
|
10
|
-
declare type MessageListProps = WrappedComponentProps & Pick<StoreDef, 'intl' | 'isBotTyping' | 'focusedArea' | 'focusPrevious' | 'focusNext' | 'botAvatarUrl' | '
|
|
10
|
+
declare type MessageListProps = WrappedComponentProps & Pick<StoreDef, 'intl' | 'isBotTyping' | 'focusedArea' | 'focusPrevious' | 'focusNext' | 'botAvatarUrl' | 'botName' | 'enableArrowNavigation' | 'showUserAvatar' | 'currentMessages' | 'preferredLanguage'>;
|
|
@@ -96,7 +96,7 @@ class MessageList extends react_1.default.Component {
|
|
|
96
96
|
react_1.default.createElement("div", { className: 'bpw-small-line' })));
|
|
97
97
|
}
|
|
98
98
|
renderAvatar(name, url) {
|
|
99
|
-
const avatarSize =
|
|
99
|
+
const avatarSize = 40;
|
|
100
100
|
return react_1.default.createElement(Avatar_1.default, { name: name, avatarUrl: url, height: avatarSize, width: avatarSize });
|
|
101
101
|
}
|
|
102
102
|
renderMessageGroups() {
|
|
@@ -163,7 +163,6 @@ class MessageList extends react_1.default.Component {
|
|
|
163
163
|
}
|
|
164
164
|
exports.default = (0, mobx_react_1.inject)(({ store }) => ({
|
|
165
165
|
intl: store.intl,
|
|
166
|
-
isEmulator: store.isEmulator,
|
|
167
166
|
botName: store.botName,
|
|
168
167
|
isBotTyping: store.isBotTyping,
|
|
169
168
|
botAvatarUrl: store.botAvatarUrl,
|
package/dist/core/api.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Message } from '@botpress/messaging-socket';
|
|
3
3
|
import { RecentConversation } from '..';
|
|
4
|
-
import {
|
|
4
|
+
import { BotInfo, uuid } from '../typings';
|
|
5
5
|
import BpSocket from './socket';
|
|
6
6
|
export default class WebchatApi {
|
|
7
7
|
private socket;
|
|
8
8
|
private axios;
|
|
9
9
|
private axiosConfig;
|
|
10
|
-
private userId;
|
|
11
10
|
constructor(socket: BpSocket);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
fetchPreferences(): Promise<any>;
|
|
15
|
-
updateUserPreferredLanguage(language: string): Promise<void>;
|
|
16
|
-
fetchConversations(): Promise<RecentConversation[] | undefined>;
|
|
11
|
+
fetchBotInfo(mediaFileServiceUrl: string): Promise<BotInfo | undefined>;
|
|
12
|
+
fetchConversations(): Promise<RecentConversation[]>;
|
|
17
13
|
fetchConversation(conversationId: uuid): Promise<{
|
|
18
14
|
messages: Message[];
|
|
19
15
|
id?: string | undefined;
|
|
@@ -24,14 +20,9 @@ export default class WebchatApi {
|
|
|
24
20
|
resetSession(conversationId: uuid): Promise<void>;
|
|
25
21
|
createConversation(): Promise<uuid | undefined>;
|
|
26
22
|
startConversation(): Promise<void>;
|
|
27
|
-
downloadConversation(conversationId: uuid): Promise<any>;
|
|
28
23
|
sendMessage(payload: any, conversationId: uuid): Promise<Message | undefined>;
|
|
29
|
-
|
|
24
|
+
deleteConversation(conversationId: uuid): Promise<void>;
|
|
30
25
|
sendFeedback(feedback: number, messageId: uuid): Promise<void>;
|
|
31
|
-
getMessageIdsFeedbackInfo(messageIds: uuid[]): Promise<EventFeedback[] | undefined>;
|
|
32
26
|
uploadFile(file: File, payload: string, conversationId: uuid): Promise<void>;
|
|
33
27
|
sendVoiceMessage(voice: Buffer, ext: string, conversationId: uuid): Promise<void>;
|
|
34
|
-
setReference(reference: string, conversationId: uuid): Promise<void>;
|
|
35
|
-
listByIncomingEvent(messageId: uuid): Promise<any>;
|
|
36
|
-
handleApiError: (error: any) => Promise<void>;
|
|
37
28
|
}
|