@subiz/widget-v4 4.1.161 → 4.1.163
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/compiled_src/chatbox/Event.js +1 -1
- package/compiled_src/chatbox/MessageInput.js +7 -0
- package/compiled_src/chatbox/TextMessage.js +2 -7
- package/compiled_src/lib.js +0 -1
- package/compiled_src/util/common.js +11 -0
- package/dist/{1989dde475e.app.js → 198a2dde018.app.js} +1 -1
- package/dist/{1989dde475e.chat.html → 198a2dde018.chat.html} +1 -1
- package/dist/{1989dde475e.chat.js → 198a2dde018.chat.js} +1 -1
- package/dist/{1989dde475e.form.html → 198a2dde018.form.html} +1 -1
- package/dist/{1989dde475e.form.js → 198a2dde018.form.js} +1 -1
- package/dist/{1989dde475e.index.html → 198a2dde018.index.html} +1 -1
- package/dist/{1989dde475e.library.html → 198a2dde018.library.html} +1 -1
- package/dist/{1989dde475e.library.js → 198a2dde018.library.js} +1 -1
- package/dist/{1989dde475e.preview.html → 198a2dde018.preview.html} +1 -1
- package/dist/198a2dde018.preview.js +1 -0
- package/dist/{1989dde475e.webview.js → 198a2dde018.webview.js} +1 -1
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +31 -2
- package/package.json +1 -1
- package/src/chatbox/Event.js +2 -1
- package/src/chatbox/MessageInput.js +10 -0
- package/src/chatbox/TextMessage.js +1 -13
- package/src/lib.js +1 -1
- package/src/store/store.js +0 -2
- package/src/util/common.js +21 -4
- package/tracking.js +44 -0
- package/dist/1989dde475e.preview.js +0 -1
- /package/dist/{1989dde475e.127.js → 198a2dde018.127.js} +0 -0
- /package/dist/{1989dde475e.132.js → 198a2dde018.132.js} +0 -0
- /package/dist/{1989dde475e.185.js → 198a2dde018.185.js} +0 -0
- /package/dist/{1989dde475e.27.js → 198a2dde018.27.js} +0 -0
- /package/dist/{1989dde475e.278.js → 198a2dde018.278.js} +0 -0
- /package/dist/{1989dde475e.339.js → 198a2dde018.339.js} +0 -0
- /package/dist/{1989dde475e.459.js → 198a2dde018.459.js} +0 -0
- /package/dist/{1989dde475e.490.js → 198a2dde018.490.js} +0 -0
- /package/dist/{1989dde475e.74.js → 198a2dde018.74.js} +0 -0
- /package/dist/{1989dde475e.997.js → 198a2dde018.997.js} +0 -0
package/dist/HASH
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
198a2dde018
|
package/dist/screenshoot.js
CHANGED
|
@@ -7202,6 +7202,13 @@ class MessageInput extends common/* Com */.Mw {
|
|
|
7202
7202
|
}
|
|
7203
7203
|
focus() {
|
|
7204
7204
|
if (this.props.disabled) return;
|
|
7205
|
+
const activeElement = document.activeElement;
|
|
7206
|
+
let focused = false;
|
|
7207
|
+
if (activeElement) {
|
|
7208
|
+
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') focused = true;
|
|
7209
|
+
if (activeElement.hasAttribute('contenteditable') && activeElement.getAttribute('contenteditable') === 'true') focused = true;
|
|
7210
|
+
}
|
|
7211
|
+
if (focused) return;
|
|
7205
7212
|
this.refMessageInput.current && this.refMessageInput.current.focus();
|
|
7206
7213
|
util/* default */.A.setTimeout(() => {
|
|
7207
7214
|
this.refMessageInput.current && this.refMessageInput.current.focus();
|
|
@@ -8848,7 +8855,7 @@ class Event extends common/* Com */.Mw {
|
|
|
8848
8855
|
let ev = this.props.event.ev;
|
|
8849
8856
|
let attachments = util/* default */.A.get(ev, 'data.message.attachments');
|
|
8850
8857
|
let hasForm = util/* default */.A.find(attachments, att => att.type === 'form');
|
|
8851
|
-
if (ev
|
|
8858
|
+
if (isEmptyMessage(util/* default */.A.get(ev, 'data.message'))) return null;
|
|
8852
8859
|
this.tryLoadOrder(ev);
|
|
8853
8860
|
let t = new util/* default */.A.Date(ev.created).toLocaleString();
|
|
8854
8861
|
if (util/* default */.A.get(ev, 'by.type') !== 'user') {
|
|
@@ -9117,6 +9124,10 @@ class Event extends common/* Com */.Mw {
|
|
|
9117
9124
|
return acc.name;
|
|
9118
9125
|
}
|
|
9119
9126
|
}
|
|
9127
|
+
function isEmptyMessage(msg) {
|
|
9128
|
+
if (!msg) return true;
|
|
9129
|
+
if (!msg.text && !msg.block && !util/* default */.A.size(msg.attachments)) return true;
|
|
9130
|
+
}
|
|
9120
9131
|
;// ./src/chatbox/Events.js
|
|
9121
9132
|
|
|
9122
9133
|
|
|
@@ -11737,7 +11748,25 @@ class lib_Widget {
|
|
|
11737
11748
|
return this.store.sendConversion(formid, values, impressiontoken);
|
|
11738
11749
|
}
|
|
11739
11750
|
startConvo(req) {
|
|
11740
|
-
|
|
11751
|
+
req = util/* default */.A.cloneDeep(req) || {};
|
|
11752
|
+
if (req.welcome_message) {
|
|
11753
|
+
return this.store.startLightConvo(req.bot_id, req.welcome_message, req.locale, req.is_testing, req.bot_version);
|
|
11754
|
+
}
|
|
11755
|
+
let members = req.members || [];
|
|
11756
|
+
if (req.bot_id) {
|
|
11757
|
+
let botid = req.bot_id;
|
|
11758
|
+
delete req.bot_id;
|
|
11759
|
+
if (!util/* default */.A.find(members, m => b.id == botid)) {
|
|
11760
|
+
members.push({
|
|
11761
|
+
type: 'bot',
|
|
11762
|
+
id: botid,
|
|
11763
|
+
bot_version: req.bot_version
|
|
11764
|
+
});
|
|
11765
|
+
}
|
|
11766
|
+
}
|
|
11767
|
+
req.members = members;
|
|
11768
|
+
req.initial_by = this.store.matchUser().id;
|
|
11769
|
+
return this.store.startConvo(req);
|
|
11741
11770
|
}
|
|
11742
11771
|
async showGreeting() {
|
|
11743
11772
|
await this.domGate.entry();
|
package/package.json
CHANGED
package/src/chatbox/Event.js
CHANGED
|
@@ -234,7 +234,8 @@ export default class Event extends Com {
|
|
|
234
234
|
let ev = this.props.event.ev
|
|
235
235
|
let attachments = sb.get(ev, 'data.message.attachments')
|
|
236
236
|
let hasForm = sb.find(attachments, (att) => att.type === 'form')
|
|
237
|
-
if (ev
|
|
237
|
+
if (sb.isEmptyMessage(sb.get(ev, 'data.message'))) return null
|
|
238
|
+
|
|
238
239
|
this.tryLoadOrder(ev)
|
|
239
240
|
let t = new sb.Date(ev.created).toLocaleString()
|
|
240
241
|
// message of agent
|
|
@@ -242,6 +242,16 @@ export default class MessageInput extends Com {
|
|
|
242
242
|
|
|
243
243
|
focus() {
|
|
244
244
|
if (this.props.disabled) return
|
|
245
|
+
// check document has current input focused, so we dont interupt the compose procedure
|
|
246
|
+
const activeElement = document.activeElement
|
|
247
|
+
let focused = false
|
|
248
|
+
if (activeElement) {
|
|
249
|
+
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') focused = true
|
|
250
|
+
if (activeElement.hasAttribute('contenteditable') && activeElement.getAttribute('contenteditable') === 'true')
|
|
251
|
+
focused = true
|
|
252
|
+
}
|
|
253
|
+
if (focused) return
|
|
254
|
+
|
|
245
255
|
this.refMessageInput.current && this.refMessageInput.current.focus()
|
|
246
256
|
sb.setTimeout(() => {
|
|
247
257
|
this.refMessageInput.current && this.refMessageInput.current.focus()
|
|
@@ -73,7 +73,7 @@ export default class TextMessage extends Com {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
renderBlock(block) {
|
|
76
|
-
if (isEmptyBlock(block)) return null
|
|
76
|
+
if (sb.isEmptyBlock(block)) return null
|
|
77
77
|
let t = new sb.Date(sb.get(this.props.ev, 'created')).toLocaleString()
|
|
78
78
|
let byType = sb.get(this.props.ev, 'by.type')
|
|
79
79
|
if (byType !== 'user') byType = 'agent'
|
|
@@ -94,15 +94,3 @@ export default class TextMessage extends Com {
|
|
|
94
94
|
)
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
function isEmptyBlock(block) {
|
|
99
|
-
if (!block || !block.type) return true
|
|
100
|
-
let hasContent =
|
|
101
|
-
sb.size(
|
|
102
|
-
sb.filter(
|
|
103
|
-
sb.map(block.content, (block) => isEmptyBlock(block)),
|
|
104
|
-
(isEmpty) => !isEmpty,
|
|
105
|
-
),
|
|
106
|
-
) > 0
|
|
107
|
-
return !sb.trim(block.text) && !hasContent
|
|
108
|
-
}
|
package/src/lib.js
CHANGED
|
@@ -218,12 +218,12 @@ class Widget {
|
|
|
218
218
|
return this.store.sendConversion(formid, values, impressiontoken)
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
// req.bot_id != "" -> start conversation with bot id
|
|
221
222
|
startConvo(req) {
|
|
222
223
|
req = sb.cloneDeep(req) || {}
|
|
223
224
|
if (req.welcome_message) {
|
|
224
225
|
return this.store.startLightConvo(req.bot_id, req.welcome_message, req.locale, req.is_testing, req.bot_version)
|
|
225
226
|
}
|
|
226
|
-
console.log(req)
|
|
227
227
|
let members = req.members || []
|
|
228
228
|
if (req.bot_id) {
|
|
229
229
|
let botid = req.bot_id
|
package/src/store/store.js
CHANGED
package/src/util/common.js
CHANGED
|
@@ -12,7 +12,7 @@ var op = require('./op.js')
|
|
|
12
12
|
* @return Array The HSL representation
|
|
13
13
|
*/
|
|
14
14
|
export function rgbToHsl(r, g, b) {
|
|
15
|
-
;(r /= 255), (g /= 255), (b /= 255)
|
|
15
|
+
;((r /= 255), (g /= 255), (b /= 255))
|
|
16
16
|
|
|
17
17
|
var max = Math.max(r, g, b),
|
|
18
18
|
min = Math.min(r, g, b)
|
|
@@ -721,9 +721,9 @@ export function replaceCssVariable(css, setting) {
|
|
|
721
721
|
'desktop_button.height',
|
|
722
722
|
'desktop_button.margin_x',
|
|
723
723
|
'desktop_button.margin_y',
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
724
|
+
'form_header_font_size',
|
|
725
|
+
'form_desc_font_size',
|
|
726
|
+
'form_input_label_font_size',
|
|
727
727
|
'width',
|
|
728
728
|
'height',
|
|
729
729
|
].includes(path)
|
|
@@ -1548,3 +1548,20 @@ function absLink(url) {
|
|
|
1548
1548
|
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url
|
|
1549
1549
|
return url
|
|
1550
1550
|
}
|
|
1551
|
+
|
|
1552
|
+
export function isEmptyBlock(block) {
|
|
1553
|
+
if (!block || !block.type) return true
|
|
1554
|
+
let hasContent =
|
|
1555
|
+
size(
|
|
1556
|
+
filter(
|
|
1557
|
+
map(block.content, (block) => isEmptyBlock(block)),
|
|
1558
|
+
(isEmpty) => !isEmpty,
|
|
1559
|
+
),
|
|
1560
|
+
) > 0
|
|
1561
|
+
return !trim(block.text) && !hasContent
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
export function isEmptyMessage(msg) {
|
|
1565
|
+
if (!msg) return true
|
|
1566
|
+
if (!msg.text && isEmptyBlock(msg.block) && !size(msg.attachments)) return true
|
|
1567
|
+
}
|
package/tracking.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// send signal to server when the chatbox is not visible
|
|
2
|
+
|
|
3
|
+
setTimeout(() => {
|
|
4
|
+
var $button = document.querySelector('div.chat-button')
|
|
5
|
+
|
|
6
|
+
let status = ''
|
|
7
|
+
if ($button) {
|
|
8
|
+
var rect = $button.getBoundingClientRect()
|
|
9
|
+
var visible = rect.width > 0 && rect.height > 0
|
|
10
|
+
if (visible) {
|
|
11
|
+
// the chatbox is visible
|
|
12
|
+
return
|
|
13
|
+
} else {
|
|
14
|
+
// the chatbox is not visible
|
|
15
|
+
status = 'hidden'
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
// the chatbox is not found in DOM
|
|
19
|
+
status = 'not-found'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Collect device and browser info
|
|
23
|
+
var info = {
|
|
24
|
+
status: status,
|
|
25
|
+
userAgent: navigator.userAgent,
|
|
26
|
+
platform: navigator.platform,
|
|
27
|
+
language: navigator.language,
|
|
28
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Send via XHR
|
|
32
|
+
var xhr = new XMLHttpRequest()
|
|
33
|
+
xhr.open('POST', 'https://api.subiz.com.vn/4.1/chatbox-failed', true)
|
|
34
|
+
xhr.withCredentials = false
|
|
35
|
+
xhr.setRequestHeader('Content-Type', 'text/plain')
|
|
36
|
+
|
|
37
|
+
xhr.onreadystatechange = function () {
|
|
38
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
39
|
+
console.log('Server responded with:', xhr.status, xhr.responseText)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
xhr.send(JSON.stringify(info))
|
|
44
|
+
}, 10000)
|