@subiz/widget-v4 4.1.215 → 4.1.216
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 +6 -0
- package/api.md +9 -5
- package/assets/img/bubble_default.svg +1 -0
- package/assets/less/widget.less +12 -0
- package/compiled_src/chatbox/ChatButton.js +19 -17
- package/compiled_src/store/store.js +4 -1
- package/dist/{1a12a5ed6a9.278.js → 1a12ecfb6db.278.js} +1 -1
- package/dist/1a12ecfb6db.app.js +1 -0
- package/dist/{1a12a5ed6a9.chat.html → 1a12ecfb6db.chat.html} +1 -1
- package/dist/1a12ecfb6db.chat.js +1 -0
- package/dist/{1a12a5ed6a9.form.html → 1a12ecfb6db.form.html} +1 -1
- package/dist/{1a12a5ed6a9.form.js → 1a12ecfb6db.form.js} +1 -1
- package/dist/{1a12a5ed6a9.index.html → 1a12ecfb6db.index.html} +1 -1
- package/dist/{1a12a5ed6a9.library.html → 1a12ecfb6db.library.html} +1 -1
- package/dist/1a12ecfb6db.library.js +1 -0
- package/dist/{1a12a5ed6a9.preview.html → 1a12ecfb6db.preview.html} +1 -1
- package/dist/1a12ecfb6db.preview.js +1 -0
- package/dist/1a12ecfb6db.webview.js +1 -0
- package/dist/HASH +1 -0
- package/dist/assets/img/{bubble_default.7d5e4ab.svg → bubble_default.6f6eec8.svg} +1 -0
- package/dist/screenshoot.js +25 -20
- package/package.json +1 -1
- package/src/chatbox/ChatButton.js +22 -20
- package/src/store/store.js +3 -2
- package/up +18 -0
- package/dist/.HASH +0 -1
- package/dist/1a12a5ed6a9.app.js +0 -1
- package/dist/1a12a5ed6a9.chat.js +0 -1
- package/dist/1a12a5ed6a9.library.js +0 -1
- package/dist/1a12a5ed6a9.preview.js +0 -1
- package/dist/1a12a5ed6a9.webview.js +0 -1
- /package/dist/{1a12a5ed6a9.127.js → 1a12ecfb6db.127.js} +0 -0
- /package/dist/{1a12a5ed6a9.132.js → 1a12ecfb6db.132.js} +0 -0
- /package/dist/{1a12a5ed6a9.185.js → 1a12ecfb6db.185.js} +0 -0
- /package/dist/{1a12a5ed6a9.27.js → 1a12ecfb6db.27.js} +0 -0
- /package/dist/{1a12a5ed6a9.339.js → 1a12ecfb6db.339.js} +0 -0
- /package/dist/{1a12a5ed6a9.459.js → 1a12ecfb6db.459.js} +0 -0
- /package/dist/{1a12a5ed6a9.490.js → 1a12ecfb6db.490.js} +0 -0
package/README.md
CHANGED
|
@@ -6,6 +6,12 @@ $ npm run dev
|
|
|
6
6
|
|
|
7
7
|
visit: http://localhost:8082/?account_id=acqcsmrppbftadjzxnvo
|
|
8
8
|
|
|
9
|
+
The fallback button keeps the configured width and height and has an opaque
|
|
10
|
+
white backing. Each dimension defaults to 70px only when it is not configured.
|
|
11
|
+
|
|
12
|
+
Masks use data URLs rather than blob URLs. If data URLs are blocked, the widget
|
|
13
|
+
tries the original image URL with CORS before using the fallback button.
|
|
14
|
+
|
|
9
15
|
### To test widget in injection mode
|
|
10
16
|
|
|
11
17
|
``` sh
|
package/api.md
CHANGED
|
@@ -1264,6 +1264,7 @@ nghiệp vụ của form do website thực hiện.
|
|
|
1264
1264
|
subiz('waitReady', async function () {
|
|
1265
1265
|
try {
|
|
1266
1266
|
const result = await subiz('getFormStatus', 'website_contact')
|
|
1267
|
+
// result.values: [{key: 'fullname', label: 'Họ tên', value: 'Nguyễn Văn An'}, ...]
|
|
1267
1268
|
if (result.submitted) document.getElementById('contact-form').hidden = true
|
|
1268
1269
|
} catch (error) {
|
|
1269
1270
|
// Không ẩn form khi kiểm tra thất bại.
|
|
@@ -1272,11 +1273,13 @@ subiz('waitReady', async function () {
|
|
|
1272
1273
|
```
|
|
1273
1274
|
|
|
1274
1275
|
`getFormStatus(formId)` đọc qua store KV/LSDB của widget, không gọi API trạng thái
|
|
1275
|
-
hay lấy hội thoại. Sau khi submit thành công, SDK lưu dấu đã gửi
|
|
1276
|
-
tách theo account, ID khách và ID form.
|
|
1277
|
-
|
|
1276
|
+
hay lấy hội thoại. Sau khi submit thành công, SDK lưu dấu đã gửi và nội dung form
|
|
1277
|
+
trong 7 ngày, tách theo account, ID khách và ID form. Bản ghi gồm mã hội thoại,
|
|
1278
|
+
thời điểm hết hạn và `values` của lần gửi thành công gần nhất, theo dạng
|
|
1279
|
+
`[{key, label, value}]` với giá trị đã chuẩn hóa thành chuỗi như khi gửi.
|
|
1280
|
+
Đọc trạng thái không gia hạn thời gian lưu. Lần gửi thất bại không ghi đè dữ liệu cũ.
|
|
1278
1281
|
|
|
1279
|
-
Kết quả: `{submitted: true, status: 'found', conversation_id}` nếu còn hạn;
|
|
1282
|
+
Kết quả: `{submitted: true, status: 'found', conversation_id, values}` nếu còn hạn;
|
|
1280
1283
|
`{submitted: false, status: 'not_found'}` nếu chưa lưu; `status: 'expired'` khi
|
|
1281
1284
|
hết hạn (đồng thời xóa bản ghi); `status: 'storage_unavailable'` khi trình duyệt
|
|
1282
1285
|
không cho truy cập localStorage. Lỗi lưu localStorage không biến một submit đã
|
|
@@ -1286,7 +1289,8 @@ SDK bỏ qua sự kiện realtime của hội thoại kênh form trước khi l
|
|
|
1286
1289
|
thoại; không mở hội thoại form trong chat widget. Luồng chat thông thường giữ
|
|
1287
1290
|
nguyên. Trạng thái chỉ có trên cùng website/trình duyệt và cùng ID khách, không
|
|
1288
1291
|
đồng bộ thiết bị khác, mất khi xóa localStorage. Các lần gửi trước khi bổ sung
|
|
1289
|
-
cơ chế lưu này không được tự khôi phục từ server.
|
|
1292
|
+
cơ chế lưu này không được tự khôi phục từ server. Bản ghi cũ chỉ lưu dấu đã gửi
|
|
1293
|
+
vẫn trả `submitted: true` nếu còn hạn, nhưng `values: []` vì chưa lưu nội dung.
|
|
1290
1294
|
|
|
1291
1295
|
SDK không truy cập localStorage trực tiếp: store dùng `kv.put/match/del` và
|
|
1292
1296
|
LSDB hiện có. Khi widget dùng chế độ in-memory hoặc trình duyệt chặn lưu trữ,
|
package/assets/less/widget.less
CHANGED
|
@@ -438,6 +438,18 @@
|
|
|
438
438
|
// min-height: @desktop-chat-button-height;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
.chat-button--fallback {
|
|
442
|
+
.chat-button--img-container {
|
|
443
|
+
background-size: 100% 100%;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.chat-button--img {
|
|
447
|
+
width: 100%;
|
|
448
|
+
min-width: 0;
|
|
449
|
+
height: 100%;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
441
453
|
.chat-button.chat-button--left {
|
|
442
454
|
float: left;
|
|
443
455
|
}
|
|
@@ -400,18 +400,10 @@ class ChatButton extends _common.Com {
|
|
|
400
400
|
this.readyGate.close();
|
|
401
401
|
const [loaded, mask] = await Promise.all([Promise.all(appearance.urls.filter(url => url !== appearance.maskAsset).map(url => preloadButtonImage(url))), appearance.maskAsset ? prepareButtonMask(appearance.maskAsset) : Promise.resolve(null)]);
|
|
402
402
|
const stale = () => !this._isMounted || this._buttonImageVersion !== version;
|
|
403
|
-
if (stale())
|
|
404
|
-
if (mask) URL.revokeObjectURL(mask);
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
403
|
+
if (stale()) return;
|
|
407
404
|
const fallback = loaded.some(success => !success) || !!appearance.maskAsset && !mask;
|
|
408
405
|
const ready = !fallback || (await preloadButtonImage(defaultBubble));
|
|
409
|
-
if (stale())
|
|
410
|
-
if (mask) URL.revokeObjectURL(mask);
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
if (this._buttonMaskUrl) URL.revokeObjectURL(this._buttonMaskUrl);
|
|
414
|
-
this._buttonMaskUrl = mask;
|
|
406
|
+
if (stale()) return;
|
|
415
407
|
if (this._buttonElement) window.getComputedStyle(this._buttonElement).transform;
|
|
416
408
|
this.setState({
|
|
417
409
|
ready,
|
|
@@ -422,7 +414,6 @@ class ChatButton extends _common.Com {
|
|
|
422
414
|
this.readyGate.open();
|
|
423
415
|
}
|
|
424
416
|
componentWillUnmount() {
|
|
425
|
-
if (this._buttonMaskUrl) URL.revokeObjectURL(this._buttonMaskUrl);
|
|
426
417
|
if (this._animateTimeout) clearTimeout(this._animateTimeout);
|
|
427
418
|
}
|
|
428
419
|
renderButton() {
|
|
@@ -437,11 +428,12 @@ class ChatButton extends _common.Com {
|
|
|
437
428
|
imgwidth,
|
|
438
429
|
imgheight
|
|
439
430
|
} = appearance;
|
|
431
|
+
const fallback = this.state.readyImageKey === appearance.key && this.state.fallbackButtonImage;
|
|
440
432
|
if (appearance.maskAsset) {
|
|
441
433
|
maskurl = this.state.readyImageKey === appearance.key ? this.state.buttonMaskUrl : '';
|
|
442
434
|
if (imgsrc === appearance.maskAsset) imgsrc = maskurl || '';
|
|
443
435
|
}
|
|
444
|
-
if (
|
|
436
|
+
if (fallback) {
|
|
445
437
|
imgsrc = imgurl = defaultBubble;
|
|
446
438
|
maskurl = '';
|
|
447
439
|
}
|
|
@@ -501,7 +493,11 @@ class ChatButton extends _common.Com {
|
|
|
501
493
|
mask-size: cover !important;
|
|
502
494
|
`;
|
|
503
495
|
}
|
|
496
|
+
if (fallback) {
|
|
497
|
+
imgcontainerstyle += `width: ${imgwidth}px !important; height: ${imgheight}px !important;`;
|
|
498
|
+
}
|
|
504
499
|
let cls = 'chat-button chat-button--' + position;
|
|
500
|
+
if (fallback) cls += ' chat-button--fallback';
|
|
505
501
|
let whiteBgStyle = `
|
|
506
502
|
width: ${imgwidth - 4}px !important;
|
|
507
503
|
height: ${imgheight - 4}px !important;
|
|
@@ -624,13 +620,19 @@ function preloadButtonImage(src, {
|
|
|
624
620
|
});
|
|
625
621
|
}
|
|
626
622
|
async function prepareButtonMask(src) {
|
|
627
|
-
let url;
|
|
628
623
|
try {
|
|
629
624
|
const response = await fetch(src);
|
|
630
625
|
if (!response.ok) return null;
|
|
631
|
-
|
|
632
|
-
|
|
626
|
+
const blob = await response.blob();
|
|
627
|
+
const url = await new Promise(resolve => {
|
|
628
|
+
const reader = new FileReader();
|
|
629
|
+
reader.onload = () => resolve(reader.result);
|
|
630
|
+
reader.onerror = reader.onabort = () => resolve('');
|
|
631
|
+
reader.readAsDataURL(blob);
|
|
632
|
+
});
|
|
633
|
+
if (url && (await preloadButtonImage(url))) return url;
|
|
633
634
|
} catch (_) {}
|
|
634
|
-
|
|
635
|
-
|
|
635
|
+
return (await preloadButtonImage(src, {
|
|
636
|
+
crossOrigin: true
|
|
637
|
+
})) ? src : null;
|
|
636
638
|
}
|
|
@@ -885,10 +885,12 @@ class Store {
|
|
|
885
885
|
await this.readyGate.entry();
|
|
886
886
|
const key = websiteFormStorageKey(this.api, formid);
|
|
887
887
|
const kv = this.kv;
|
|
888
|
+
const values = _index.default.cloneDeep(payload.values);
|
|
888
889
|
const result = formResult(await this.api.submitWebsiteForm(formid, payload));
|
|
889
890
|
try {
|
|
890
891
|
kv.put(key, {
|
|
891
892
|
conversation_id: result.conversation_id,
|
|
893
|
+
values,
|
|
892
894
|
expires_at: _index.default.Date.now() + 7 * 24 * 60 * 60 * 1000
|
|
893
895
|
});
|
|
894
896
|
} catch (_) {}
|
|
@@ -919,7 +921,8 @@ class Store {
|
|
|
919
921
|
return {
|
|
920
922
|
submitted: true,
|
|
921
923
|
status: 'found',
|
|
922
|
-
conversation_id: receipt.conversation_id
|
|
924
|
+
conversation_id: receipt.conversation_id,
|
|
925
|
+
values: Array.isArray(receipt.values) ? _index.default.cloneDeep(receipt.values) : []
|
|
923
926
|
};
|
|
924
927
|
} catch (_) {
|
|
925
928
|
return {
|