@subiz/widget-v4 4.1.116 → 4.1.119
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/assets/less/base.less +1 -0
- package/assets/less/chatbox.less +2 -0
- package/assets/less/message.less +42 -22
- package/assets/less/message_input.less +2 -0
- package/assets/less/order.less +1 -1
- package/assets/less/widget.less +33 -16
- package/assets/less/widget_header.less +35 -36
- package/compiled_src/chatbox/AgentsAvatar.js +1 -1
- package/compiled_src/chatbox/Event.js +70 -15
- package/compiled_src/chatbox/Events.js +108 -19
- package/compiled_src/chatbox/Header.js +5 -4
- package/compiled_src/chatbox/InfoMessage.js +2 -13
- package/compiled_src/chatbox/MessageInput.js +25 -9
- package/compiled_src/chatbox/TextMessage.js +11 -2
- package/compiled_src/chatbox/Widget.js +29 -22
- package/compiled_src/chatbox/main.js +3 -0
- package/compiled_src/chatbox/time.js +1 -0
- package/compiled_src/lib.js +4 -0
- package/compiled_src/plugin.js +4 -0
- package/compiled_src/util/common.js +89 -0
- package/dist/185.js +19 -19
- package/dist/19641cfa41e.278.js +1 -0
- package/dist/19641cfa41e.app.js +1 -0
- package/dist/{195ec5442e3.index.html → 19641cfa41e.index.html} +1 -1
- package/dist/{195ec5442e3.library.html → 19641cfa41e.library.html} +1 -1
- package/dist/19641cfa41e.library.js +1 -0
- package/dist/{195ec5442e3.preview.html → 19641cfa41e.preview.html} +1 -1
- package/dist/19641cfa41e.preview.js +1 -0
- package/dist/19641cfa41e.webview.js +1 -0
- package/dist/278.js +1 -1
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +562 -185
- package/package.json +4 -4
- package/src/chatbox/AgentsAvatar.js +1 -1
- package/src/chatbox/Event.js +76 -15
- package/src/chatbox/Events.js +95 -14
- package/src/chatbox/Header.js +3 -2
- package/src/chatbox/InfoMessage.js +0 -14
- package/src/chatbox/MessageInput.js +23 -7
- package/src/chatbox/TextMessage.js +13 -0
- package/src/chatbox/Widget.js +22 -19
- package/src/chatbox/main.js +4 -0
- package/src/chatbox/time.js +12 -8
- package/src/lib.js +5 -0
- package/src/plugin.js +5 -0
- package/src/util/common.js +121 -0
- package/up +33 -21
- package/compiled_src/chatbox/Typing.js +0 -77
- package/dist/195ec5442e3.278.js +0 -1
- package/dist/195ec5442e3.app.js +0 -1
- package/dist/195ec5442e3.library.js +0 -1
- package/dist/195ec5442e3.preview.js +0 -1
- package/dist/195ec5442e3.webview.js +0 -1
- package/src/chatbox/Typing.js +0 -72
- /package/dist/{195ec5442e3.127.js → 19641cfa41e.127.js} +0 -0
- /package/dist/{195ec5442e3.132.js → 19641cfa41e.132.js} +0 -0
- /package/dist/{195ec5442e3.185.js → 19641cfa41e.185.js} +0 -0
- /package/dist/{195ec5442e3.27.js → 19641cfa41e.27.js} +0 -0
- /package/dist/{195ec5442e3.459.js → 19641cfa41e.459.js} +0 -0
- /package/dist/{195ec5442e3.490.js → 19641cfa41e.490.js} +0 -0
- /package/dist/{195ec5442e3.74.js → 19641cfa41e.74.js} +0 -0
- /package/dist/{195ec5442e3.997.js → 19641cfa41e.997.js} +0 -0
|
@@ -26,9 +26,64 @@ class Events extends _common.Com {
|
|
|
26
26
|
}, 500);
|
|
27
27
|
this.checkAndSeen();
|
|
28
28
|
}
|
|
29
|
+
componentDidMount() {
|
|
30
|
+
this.setState({
|
|
31
|
+
isShowTyping: false,
|
|
32
|
+
typing_event: {}
|
|
33
|
+
});
|
|
34
|
+
this.props.store.onConvoEvent(this, ev => {
|
|
35
|
+
if (_index.default.convoOfEv(ev) !== this.props.cid) return;
|
|
36
|
+
if (_index.default.get(ev, 'by.type') === 'user') return;
|
|
37
|
+
let oldby = _index.default.get(this.state.typing_event, 'by.id');
|
|
38
|
+
if (oldby && _index.default.get(ev, 'by.id') !== oldby) return;
|
|
39
|
+
if (_index.default.get(ev, 'type') === 'message_sent') {
|
|
40
|
+
if (this.timer) _index.default.clearTimeout(this.timer);
|
|
41
|
+
this.timer = null;
|
|
42
|
+
this.setState({
|
|
43
|
+
isShowTyping: false
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (_index.default.get(ev, 'type') !== 'conversation_typing') return;
|
|
48
|
+
let ag = this.props.store.matchAgent(_index.default.get(ev, 'by.id')) || {};
|
|
49
|
+
if (ag.type == 'agent' && !_index.default.get(this.props.plugin, 'chatbox.show_agent_typing')) return;
|
|
50
|
+
this.setState({
|
|
51
|
+
typing_event: ev,
|
|
52
|
+
isShowTyping: true
|
|
53
|
+
});
|
|
54
|
+
if (this.timer) _index.default.clearTimeout(this.timer);
|
|
55
|
+
this.timer = _index.default.setTimeout(() => {
|
|
56
|
+
if (_index.default.convoOfEv(ev) !== this.props.cid) return;
|
|
57
|
+
this.timer = null;
|
|
58
|
+
this.setState({
|
|
59
|
+
isShowTyping: false
|
|
60
|
+
});
|
|
61
|
+
}, 5000);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
29
64
|
componentDidUpdate(prevProps) {
|
|
30
65
|
if (prevProps.cid !== this.props.cid) this.loadConvo();
|
|
31
66
|
}
|
|
67
|
+
ShowTyping() {
|
|
68
|
+
this.setState({
|
|
69
|
+
isShowTyping: true,
|
|
70
|
+
typing_event: {
|
|
71
|
+
id: 'evzz' + _index.default.Date.now(),
|
|
72
|
+
created: _index.default.Date.now(),
|
|
73
|
+
by: {
|
|
74
|
+
type: 'agent'
|
|
75
|
+
},
|
|
76
|
+
type: 'conversation_typing'
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (this.timer) _index.default.clearTimeout(this.timer);
|
|
80
|
+
this.timer = _index.default.setTimeout(() => {
|
|
81
|
+
this.timer = null;
|
|
82
|
+
this.setState({
|
|
83
|
+
isShowTyping: false
|
|
84
|
+
});
|
|
85
|
+
}, 5000);
|
|
86
|
+
}
|
|
32
87
|
render() {
|
|
33
88
|
if (this.state.error) return this.renderError();
|
|
34
89
|
let events = _index.default.map(this.props.store.listEvents(this.props.cid));
|
|
@@ -51,18 +106,36 @@ class Events extends _common.Com {
|
|
|
51
106
|
events = _index.default.map(events, ev => ({
|
|
52
107
|
ev: ev
|
|
53
108
|
}));
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
109
|
+
if (this.state.isShowTyping) {
|
|
110
|
+
let ev = this.state.typing_event || {
|
|
111
|
+
id: 'evzz' + _index.default.Date.now(),
|
|
112
|
+
created: _index.default.Date.now(),
|
|
113
|
+
by: {
|
|
114
|
+
type: 'agent'
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
let fakeev = {
|
|
118
|
+
is_typing: true,
|
|
119
|
+
id: ev.id,
|
|
120
|
+
ev: {
|
|
121
|
+
id: ev.id,
|
|
122
|
+
created: ev.created,
|
|
123
|
+
by: ev.by,
|
|
124
|
+
type: 'message_sent',
|
|
125
|
+
data: {
|
|
126
|
+
message: {
|
|
127
|
+
text: '...',
|
|
128
|
+
conversation_id: this.props.cid
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
console.log('FA', fakeev);
|
|
134
|
+
events.push(fakeev);
|
|
63
135
|
}
|
|
136
|
+
processEvents(convo, events);
|
|
64
137
|
let $events = _index.default.map(events, ev => {
|
|
65
|
-
let isLast = ev.ev.id ===
|
|
138
|
+
let isLast = ev.ev.id === _index.default.get(convo, 'last_message_sent.id');
|
|
66
139
|
return (0, _preact.h)(_Event.default, {
|
|
67
140
|
isLast: isLast,
|
|
68
141
|
chatbox: this.props.chatbox,
|
|
@@ -78,7 +151,7 @@ class Events extends _common.Com {
|
|
|
78
151
|
});
|
|
79
152
|
let $loading = null;
|
|
80
153
|
let style = 'opacity: 1 !important';
|
|
81
|
-
if (this.
|
|
154
|
+
if (this.props.creating) {
|
|
82
155
|
$loading = (0, _preact.h)(_spinner.default, {
|
|
83
156
|
static: true,
|
|
84
157
|
mode: _index.default.get(this.props.chatbox, 'primary_color', 'dark'),
|
|
@@ -87,6 +160,17 @@ class Events extends _common.Com {
|
|
|
87
160
|
});
|
|
88
161
|
style = 'opacity: 0 !important';
|
|
89
162
|
}
|
|
163
|
+
if (this.state.loading) {
|
|
164
|
+
if (_index.default.Date.now() - this.state.loading > 500) {
|
|
165
|
+
$loading = (0, _preact.h)(_spinner.default, {
|
|
166
|
+
static: true,
|
|
167
|
+
mode: _index.default.get(this.props.chatbox, 'primary_color', 'dark'),
|
|
168
|
+
size: "120",
|
|
169
|
+
center: true
|
|
170
|
+
});
|
|
171
|
+
style = 'opacity: 0 !important';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
90
174
|
return (0, _preact.h)(_preact.Fragment, null, $loading, (0, _preact.h)("div", {
|
|
91
175
|
style: style,
|
|
92
176
|
ref: ref => this.refBody = ref,
|
|
@@ -154,10 +238,16 @@ class Events extends _common.Com {
|
|
|
154
238
|
if (!this.props.cid) return;
|
|
155
239
|
this.lastContentOffsetY = 0;
|
|
156
240
|
this.setState({
|
|
157
|
-
loading:
|
|
241
|
+
loading: false
|
|
158
242
|
});
|
|
159
243
|
let events = this.props.store.listEvents(this.props.cid);
|
|
160
244
|
if (_index.default.size(events) === 0) {
|
|
245
|
+
this.setState({
|
|
246
|
+
loading: _index.default.Date.now()
|
|
247
|
+
});
|
|
248
|
+
_index.default.setTimeout(() => {
|
|
249
|
+
this.forceUpdate();
|
|
250
|
+
}, 800);
|
|
161
251
|
let cid = this.props.cid;
|
|
162
252
|
let {
|
|
163
253
|
error
|
|
@@ -173,17 +263,11 @@ class Events extends _common.Com {
|
|
|
173
263
|
return;
|
|
174
264
|
}
|
|
175
265
|
}
|
|
176
|
-
this.setState({
|
|
177
|
-
loading: true
|
|
178
|
-
});
|
|
179
266
|
this.props.store.fetchMoreEvents(this.props.cid);
|
|
180
267
|
this.setState({
|
|
181
268
|
error: false
|
|
182
269
|
});
|
|
183
270
|
this.scrollToBottom();
|
|
184
|
-
_index.default.setTimeout(() => this.setState({
|
|
185
|
-
loading: false
|
|
186
|
-
}), 50);
|
|
187
271
|
}
|
|
188
272
|
isBottom() {
|
|
189
273
|
let $container = this.refBody;
|
|
@@ -198,7 +282,7 @@ class Events extends _common.Com {
|
|
|
198
282
|
_index.default.setTimeout(() => {
|
|
199
283
|
const $div = this.refBody;
|
|
200
284
|
if ($div) $div.scrollTop = $div.scrollHeight;
|
|
201
|
-
},
|
|
285
|
+
}, 100);
|
|
202
286
|
if (this.props.isShow) {
|
|
203
287
|
if (this.props.store.browserVisibility === 'visible' && document.hasFocus()) {
|
|
204
288
|
this.props.store.seenConvo(this.props.cid);
|
|
@@ -210,14 +294,19 @@ exports.default = Events;
|
|
|
210
294
|
function processEvents(convo, events) {
|
|
211
295
|
events = events.filter(event => visibleEvent(event.ev));
|
|
212
296
|
if (events.length < 1) return;
|
|
297
|
+
var lastAgentEvent;
|
|
213
298
|
for (var i = 1; i < events.length; i++) {
|
|
214
299
|
let curEvent = events[i];
|
|
215
300
|
let lastEvent = events[i - 1];
|
|
301
|
+
if (_index.default.get(curEvent, 'ev.by.type') != 'user' && !curEvent.is_typing) {
|
|
302
|
+
lastAgentEvent = curEvent;
|
|
303
|
+
}
|
|
216
304
|
if (visibleEvent(curEvent.ev)) {
|
|
217
305
|
let elapsedSec = _index.default.unixSec(curEvent.ev.created) - _index.default.unixSec(lastEvent.ev.created);
|
|
218
306
|
if (elapsedSec > 120) curEvent.show_time = true;
|
|
219
307
|
}
|
|
220
308
|
}
|
|
309
|
+
if (lastAgentEvent) lastAgentEvent.show_time = true;
|
|
221
310
|
for (var i = 0; i < events.length; i++) {
|
|
222
311
|
let curEvent = events[i];
|
|
223
312
|
if (_index.default.get(curEvent, 'ev.type') === 'message_sent') {
|
|
@@ -49,11 +49,12 @@ class Header extends _common.Com {
|
|
|
49
49
|
return (0, _preact.h)("div", {
|
|
50
50
|
class: cls,
|
|
51
51
|
style: style
|
|
52
|
-
}, $back, (0, _preact.h)(
|
|
52
|
+
}, $back, (0, _preact.h)("div", {
|
|
53
|
+
class: "mr-2"
|
|
54
|
+
}), (0, _preact.h)(_AgentsAvatar.default, {
|
|
53
55
|
plugin: this.props.plugin,
|
|
54
56
|
store: this.props.store,
|
|
55
|
-
mode: "secondary"
|
|
56
|
-
agent_ids: agentIdsJoined
|
|
57
|
+
mode: "secondary"
|
|
57
58
|
}), (0, _preact.h)("div", {
|
|
58
59
|
class: "widget-header--title-container"
|
|
59
60
|
}, (0, _preact.h)("div", {
|
|
@@ -188,7 +189,7 @@ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi
|
|
|
188
189
|
let accSetting = this.props.plugin.chatbox || {};
|
|
189
190
|
if (accSetting.hide_close_button) return null;
|
|
190
191
|
return (0, _preact.h)("div", {
|
|
191
|
-
class: "widget-header--button
|
|
192
|
+
class: "widget-header--button-close",
|
|
192
193
|
"data-tooltip": this.props.t('close'),
|
|
193
194
|
"data-tooltip-position": "bottom",
|
|
194
195
|
onClick: e => this.onCloseClick(e)
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _index = _interopRequireDefault(require("../util/index.js"));
|
|
8
|
-
var _time = _interopRequireDefault(require("./time.js"));
|
|
9
8
|
var _common = require("../common.js");
|
|
10
9
|
var _preact = require("preact");
|
|
11
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -18,16 +17,6 @@ function getRateLang(rating) {
|
|
|
18
17
|
class InfoMessage extends _common.Com {
|
|
19
18
|
render() {
|
|
20
19
|
let ev = this.props.ev.ev;
|
|
21
|
-
var $time = null;
|
|
22
|
-
if (this.props.ev.show_time) {
|
|
23
|
-
$time = (0, _preact.h)("div", {
|
|
24
|
-
class: "convo-event-time"
|
|
25
|
-
}, (0, _preact.h)(_time.default, {
|
|
26
|
-
time: ev.created,
|
|
27
|
-
t: this.props.t
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
if (this.props.store.isAIDevMode()) $time = null;
|
|
31
20
|
if (ev.type === 'conversation_rated') {
|
|
32
21
|
var rating = _index.default.get(ev, 'data.conversation.ratings.0', {
|
|
33
22
|
no_rating: true,
|
|
@@ -36,14 +25,14 @@ class InfoMessage extends _common.Com {
|
|
|
36
25
|
if (rating.no_rating) return null;
|
|
37
26
|
return (0, _preact.h)("div", {
|
|
38
27
|
class: "convo-event"
|
|
39
|
-
},
|
|
28
|
+
}, (0, _preact.h)("div", {
|
|
40
29
|
class: "info-message"
|
|
41
30
|
}, this.props.t('rated_as') + ' ' + this.props.t(getRateLang(rating.rating)).toLowerCase()));
|
|
42
31
|
}
|
|
43
32
|
if (ev.type === 'conversation_state_updated' && _index.default.get(ev, 'data.conversation.state') === 'ended') {
|
|
44
33
|
return (0, _preact.h)("div", {
|
|
45
34
|
class: "convo-event"
|
|
46
|
-
},
|
|
35
|
+
}, (0, _preact.h)("div", {
|
|
47
36
|
class: "info-message"
|
|
48
37
|
}, this.props.t('conversation_ended')));
|
|
49
38
|
}
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _index = _interopRequireDefault(require("../util/index.js"));
|
|
8
8
|
var _common = require("../common.js");
|
|
9
9
|
var _preact = require("preact");
|
|
10
|
+
var _spinner = _interopRequireDefault(require("./spinner.js"));
|
|
10
11
|
var _Emoji = _interopRequireDefault(require("./Emoji.js"));
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -43,7 +44,7 @@ class MessageInput extends _common.Com {
|
|
|
43
44
|
$input.blur();
|
|
44
45
|
}
|
|
45
46
|
render() {
|
|
46
|
-
var buttons = (0, _preact.h)("div", {
|
|
47
|
+
var $buttons = (0, _preact.h)("div", {
|
|
47
48
|
class: "d-flex flex-row align-self-end"
|
|
48
49
|
}, this.renderEmoji(), (0, _preact.h)("div", {
|
|
49
50
|
"data-tooltip-poasition": "top-left",
|
|
@@ -52,7 +53,7 @@ class MessageInput extends _common.Com {
|
|
|
52
53
|
}));
|
|
53
54
|
var msg = _index.default.trim(this.state.msgValue);
|
|
54
55
|
if (msg.length > 0) {
|
|
55
|
-
buttons = (0, _preact.h)("div", {
|
|
56
|
+
$buttons = (0, _preact.h)("div", {
|
|
56
57
|
class: "d-flex flex-row align-self-end"
|
|
57
58
|
}, this.renderEmoji(), (0, _preact.h)("div", {
|
|
58
59
|
"data-tooltip-position": "top-left",
|
|
@@ -60,9 +61,16 @@ class MessageInput extends _common.Com {
|
|
|
60
61
|
onClick: () => this.submitMessage()
|
|
61
62
|
}));
|
|
62
63
|
}
|
|
64
|
+
if (this.props.is_loading) {
|
|
65
|
+
$buttons = (0, _preact.h)("div", {
|
|
66
|
+
class: "d-flex flex-row align-self-end"
|
|
67
|
+
}, (0, _preact.h)(_spinner.default, {
|
|
68
|
+
size: "32"
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
63
71
|
var containercls = '';
|
|
64
72
|
var disabled = this.hasUnfinishRequiredFormOrLock() || this.props.disabled;
|
|
65
|
-
if (disabled) containercls = 'message-input--disabled';
|
|
73
|
+
if (disabled || this.props.is_loading) containercls = 'message-input--disabled';
|
|
66
74
|
return (0, _preact.h)("div", {
|
|
67
75
|
class: `message-input ${containercls}`,
|
|
68
76
|
onClick: e => {
|
|
@@ -78,7 +86,7 @@ class MessageInput extends _common.Com {
|
|
|
78
86
|
disabled: disabled,
|
|
79
87
|
class: "message-input--input",
|
|
80
88
|
maxlength: "1024",
|
|
81
|
-
placeholder: this.props.t('message_input_help'),
|
|
89
|
+
placeholder: this.props.t('message_input_help').substr(0, 25),
|
|
82
90
|
ref: this.refMessageInput,
|
|
83
91
|
rows: "1",
|
|
84
92
|
value: this.state.msgValue,
|
|
@@ -86,7 +94,7 @@ class MessageInput extends _common.Com {
|
|
|
86
94
|
onPaste: e => this.pasteImage(e),
|
|
87
95
|
"data-emojiable": "true",
|
|
88
96
|
onKeydown: e => this.onKeydown(e)
|
|
89
|
-
}), buttons);
|
|
97
|
+
}), $buttons);
|
|
90
98
|
}
|
|
91
99
|
hasUnfinishRequiredFormOrLock() {
|
|
92
100
|
let convo = this.props.store.matchConvo(this.props.cid);
|
|
@@ -214,6 +222,12 @@ class MessageInput extends _common.Com {
|
|
|
214
222
|
class: "emoji-picker--item emoji--wink"
|
|
215
223
|
})));
|
|
216
224
|
}
|
|
225
|
+
applyMessage(text) {
|
|
226
|
+
this.setState({
|
|
227
|
+
msgValue: text
|
|
228
|
+
});
|
|
229
|
+
this.resizeInput();
|
|
230
|
+
}
|
|
217
231
|
focus() {
|
|
218
232
|
if (this.props.disabled) return;
|
|
219
233
|
this.refMessageInput.current && this.refMessageInput.current.focus();
|
|
@@ -292,15 +306,17 @@ class MessageInput extends _common.Com {
|
|
|
292
306
|
msg = msg || _index.default.trim(this.state.msgValue) || '';
|
|
293
307
|
if (!msg) return;
|
|
294
308
|
if (this.props.disabled) return;
|
|
309
|
+
if (this.props.onSend) {
|
|
310
|
+
await this.props.onSend({
|
|
311
|
+
text: msg,
|
|
312
|
+
format: 'plaintext'
|
|
313
|
+
});
|
|
314
|
+
}
|
|
295
315
|
this.setState({
|
|
296
316
|
openEmoji: false,
|
|
297
317
|
msgValue: ''
|
|
298
318
|
});
|
|
299
319
|
this.resizeInput();
|
|
300
|
-
this.props.onSend && this.props.onSend({
|
|
301
|
-
text: msg,
|
|
302
|
-
format: 'plaintext'
|
|
303
|
-
});
|
|
304
320
|
}
|
|
305
321
|
sendTyping() {
|
|
306
322
|
if (!this.props.cid) return;
|
|
@@ -9,8 +9,17 @@ var _block = _interopRequireDefault(require("./block.js"));
|
|
|
9
9
|
var _common = require("../common.js");
|
|
10
10
|
var _preact = require("preact");
|
|
11
11
|
var _Emoji = _interopRequireDefault(require("./Emoji.js"));
|
|
12
|
+
var _time = _interopRequireDefault(require("./time.js"));
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
class TextMessage extends _common.Com {
|
|
15
|
+
renderTime() {
|
|
16
|
+
if (!this.props.showTime && !this.props.isLast && !this.props.isFirst) return null;
|
|
17
|
+
return (0, _preact.h)("div", null, (0, _preact.h)(_time.default, {
|
|
18
|
+
class: "inline-time",
|
|
19
|
+
time: _index.default.get(this.props.ev, 'created', _index.default.Date.now()),
|
|
20
|
+
t: this.props.t
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
14
23
|
render() {
|
|
15
24
|
var format = _index.default.get(this.props.ev, 'data.message.format', 'plaintext');
|
|
16
25
|
let block = _index.default.get(this.props.ev, 'data.message.block');
|
|
@@ -52,7 +61,7 @@ class TextMessage extends _common.Com {
|
|
|
52
61
|
if (byType === 'agent') return (0, _preact.h)("div", {
|
|
53
62
|
class: "message-agent message-text--agent",
|
|
54
63
|
title: t
|
|
55
|
-
}, tags);
|
|
64
|
+
}, tags, this.renderTime());
|
|
56
65
|
return (0, _preact.h)("div", {
|
|
57
66
|
class: "message-user message-text--user",
|
|
58
67
|
title: t
|
|
@@ -70,7 +79,7 @@ class TextMessage extends _common.Com {
|
|
|
70
79
|
}, (0, _preact.h)(_block.default, {
|
|
71
80
|
block: block,
|
|
72
81
|
onLink: this.props.onLink
|
|
73
|
-
}));
|
|
82
|
+
}), this.renderTime());
|
|
74
83
|
}
|
|
75
84
|
return (0, _preact.h)("div", {
|
|
76
85
|
class: "message-user message-text--user",
|
|
@@ -11,10 +11,8 @@ var _AgentsAvatar = _interopRequireDefault(require("./AgentsAvatar.js"));
|
|
|
11
11
|
var _Header = _interopRequireDefault(require("./Header.js"));
|
|
12
12
|
var _MessageInput = _interopRequireDefault(require("./MessageInput.js"));
|
|
13
13
|
var _Events = _interopRequireDefault(require("./Events.js"));
|
|
14
|
-
var _Typing = _interopRequireDefault(require("./Typing.js"));
|
|
15
14
|
var _Rating = _interopRequireDefault(require("./Rating.js"));
|
|
16
15
|
var _ListField = _interopRequireDefault(require("./ListField.js"));
|
|
17
|
-
var _spinner = _interopRequireDefault(require("./spinner.js"));
|
|
18
16
|
var _time = _interopRequireDefault(require("./time.js"));
|
|
19
17
|
var _common = require("../common.js");
|
|
20
18
|
var _preact = require("preact");
|
|
@@ -73,26 +71,33 @@ class Widget extends _common.Com {
|
|
|
73
71
|
initial_by: this.props.store.matchUser().id
|
|
74
72
|
});
|
|
75
73
|
if (_creating != this._creating) return;
|
|
76
|
-
if (error) {
|
|
74
|
+
if (error) {
|
|
75
|
+
this.setState({
|
|
76
|
+
creating: false
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
77
80
|
await this.props.store.sendConvoEvent(convo.id, 'message_sent', {
|
|
78
81
|
message
|
|
79
82
|
});
|
|
80
83
|
if (_creating != this._creating) return;
|
|
81
|
-
this.setState({
|
|
82
|
-
creating: false
|
|
83
|
-
});
|
|
84
84
|
this.props.onGo({
|
|
85
85
|
view: 'chat',
|
|
86
86
|
cid: convo.id
|
|
87
87
|
});
|
|
88
|
+
this.setState({
|
|
89
|
+
creating: false
|
|
90
|
+
});
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
_index.default.setTimeout(async () => {
|
|
94
|
+
await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
|
|
95
|
+
message
|
|
96
|
+
});
|
|
97
|
+
this.setState({
|
|
98
|
+
creating: false
|
|
99
|
+
});
|
|
100
|
+
}, 1);
|
|
96
101
|
});
|
|
97
102
|
_defineProperty(this, "onLink", (e, url) => {
|
|
98
103
|
if (!url) return e.preventDefault();
|
|
@@ -135,6 +140,9 @@ class Widget extends _common.Com {
|
|
|
135
140
|
if (!this.props.store.isMobile()) this.focusInput();
|
|
136
141
|
this.updateFormDataFields();
|
|
137
142
|
}
|
|
143
|
+
applyMessage(text) {
|
|
144
|
+
this.focusInput(text);
|
|
145
|
+
}
|
|
138
146
|
componentDidUpdate(prevProp) {
|
|
139
147
|
if (prevProp.isShow !== this.props.isShow) {
|
|
140
148
|
if (this.props.isShow && !this.props.store.isMobile()) this.focusInput();
|
|
@@ -148,14 +156,14 @@ class Widget extends _common.Com {
|
|
|
148
156
|
quickReplyMessage: {}
|
|
149
157
|
});
|
|
150
158
|
_index.default.setTimeout(() => {
|
|
151
|
-
this
|
|
159
|
+
this.$events && this.$events.focus();
|
|
152
160
|
if (!this.props.store.isMobile()) this.focusInput();
|
|
153
161
|
}, 100);
|
|
154
162
|
this.updateFormDataFields();
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
ShowTyping() {
|
|
158
|
-
this
|
|
166
|
+
this.$events && this.$events.ShowTyping();
|
|
159
167
|
}
|
|
160
168
|
shouldShowForm() {
|
|
161
169
|
let form;
|
|
@@ -727,7 +735,7 @@ class Widget extends _common.Com {
|
|
|
727
735
|
_index.default.setTimeout(() => $input && $input.blur());
|
|
728
736
|
_index.default.setTimeout(() => $input && $input.blur(), 300);
|
|
729
737
|
}
|
|
730
|
-
focusInput() {
|
|
738
|
+
focusInput(text) {
|
|
731
739
|
if (this.props.store.isPreview) return;
|
|
732
740
|
if (this.shouldShowForm()) {
|
|
733
741
|
let firstemptykey = '';
|
|
@@ -745,6 +753,9 @@ class Widget extends _common.Com {
|
|
|
745
753
|
}
|
|
746
754
|
var $input = this.msgInput.current;
|
|
747
755
|
if (!$input) return;
|
|
756
|
+
if (text != undefined && typeof text === 'string') {
|
|
757
|
+
$input.applyMessage(text);
|
|
758
|
+
}
|
|
748
759
|
_index.default.setTimeout(() => $input.focus());
|
|
749
760
|
_index.default.setTimeout(() => $input.focus(), 300);
|
|
750
761
|
}
|
|
@@ -777,6 +788,7 @@ class Widget extends _common.Com {
|
|
|
777
788
|
ref: this.msgInput,
|
|
778
789
|
cid: this.props.cid,
|
|
779
790
|
onChange: this.onChangeMessageInput,
|
|
791
|
+
is_loading: this.state.creating,
|
|
780
792
|
onSend: this.sendMessage,
|
|
781
793
|
t: this.props.t
|
|
782
794
|
});
|
|
@@ -800,18 +812,13 @@ class Widget extends _common.Com {
|
|
|
800
812
|
store: this.props.store,
|
|
801
813
|
chatbox: this.props.plugin.chatbox || {},
|
|
802
814
|
onFormSubmit: e => this.onEventFormSubmit(e),
|
|
803
|
-
ref: ref => this
|
|
815
|
+
ref: ref => this.$events = ref,
|
|
804
816
|
cid: this.props.cid,
|
|
805
817
|
creating: this.creating,
|
|
806
818
|
onSend: e => this.sendMessage(e),
|
|
807
819
|
onPostback: e => this.createPostback(e),
|
|
808
|
-
t: this.props.t
|
|
809
|
-
}), (0, _preact.h)(_Typing.default, {
|
|
810
|
-
store: this.props.store,
|
|
811
|
-
cid: this.props.cid,
|
|
812
820
|
t: this.props.t,
|
|
813
|
-
plugin: this.props.plugin
|
|
814
|
-
ref: this.refTyping
|
|
821
|
+
plugin: this.props.plugin
|
|
815
822
|
})), (0, _preact.h)(_Rating.default, {
|
|
816
823
|
forceView: this.props.view,
|
|
817
824
|
plugin: this.props.plugin,
|
|
@@ -155,6 +155,9 @@ class Main extends _common.Com {
|
|
|
155
155
|
cid: p.cid
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
+
applyMessage(text) {
|
|
159
|
+
this.refWidget.current && this.refWidget.current.applyMessage(text);
|
|
160
|
+
}
|
|
158
161
|
showGreeting() {
|
|
159
162
|
this.refButton.current && this.refButton.current.ShowGreeting();
|
|
160
163
|
}
|
package/compiled_src/lib.js
CHANGED
|
@@ -260,6 +260,10 @@ class Widget {
|
|
|
260
260
|
if (this.pluginMgr) this.pluginMgr.destroy();
|
|
261
261
|
this.store.destroy();
|
|
262
262
|
}
|
|
263
|
+
async applyMessage(msg) {
|
|
264
|
+
await this.domGate.entry();
|
|
265
|
+
this.pluginMgr.applyTextToCurrentChatbox(msg);
|
|
266
|
+
}
|
|
263
267
|
_overridePlugin(plugins) {
|
|
264
268
|
this.store.overridePlugin(plugins);
|
|
265
269
|
}
|
package/compiled_src/plugin.js
CHANGED
|
@@ -264,6 +264,10 @@ class PluginMgr {
|
|
|
264
264
|
let chatbox = this.findChatbox();
|
|
265
265
|
if (chatbox) return chatbox.call('showGreeting');
|
|
266
266
|
}
|
|
267
|
+
applyTextToCurrentChatbox(text) {
|
|
268
|
+
let chatbox = this.findChatbox();
|
|
269
|
+
if (chatbox) return chatbox.call('applyMessage', text);
|
|
270
|
+
}
|
|
267
271
|
hideCurrentGreeting() {
|
|
268
272
|
let chatbox = this.findChatbox();
|
|
269
273
|
if (chatbox) return chatbox.call('hideGreeting');
|