@subiz/widget-v4 4.1.201 → 4.1.203
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/api.md +1284 -0
- package/compiled_src/bot.js +1 -7
- package/compiled_src/chatbox/ChatButton.js +19 -16
- package/compiled_src/chatbox/MessageInput.js +1 -0
- package/compiled_src/chatbox/Widget.js +1 -0
- package/compiled_src/chatbox/main.js +28 -3
- package/compiled_src/lib.js +16 -1
- package/compiled_src/store/api.js +36 -4
- package/compiled_src/store/store.js +14 -1
- package/compiled_src/util/common.js +18 -18
- package/dist/{19d6b530a9c.app.js → 19df158c2ea.app.js} +1 -1
- package/dist/{19d6b530a9c.chat.html → 19df158c2ea.chat.html} +1 -1
- package/dist/{19d6b530a9c.chat.js → 19df158c2ea.chat.js} +1 -1
- package/dist/{19d6b530a9c.form.html → 19df158c2ea.form.html} +1 -1
- package/dist/19df158c2ea.form.js +1 -0
- package/dist/{19d6b530a9c.index.html → 19df158c2ea.index.html} +1 -1
- package/dist/{19d6b530a9c.library.html → 19df158c2ea.library.html} +1 -1
- package/dist/{19d6b530a9c.library.js → 19df158c2ea.library.js} +1 -1
- package/dist/{19d6b530a9c.preview.html → 19df158c2ea.preview.html} +1 -1
- package/dist/{19d6b530a9c.preview.js → 19df158c2ea.preview.js} +1 -1
- package/dist/{19d6b530a9c.webview.js → 19df158c2ea.webview.js} +1 -1
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +88 -39
- package/package.json +8 -8
- package/src/bot.js +1 -7
- package/src/chatbox/ChatButton.js +20 -15
- package/src/chatbox/MessageInput.js +1 -0
- package/src/chatbox/Widget.js +1 -1
- package/src/chatbox/main.js +24 -4
- package/src/lib.js +16 -1
- package/src/store/api.js +41 -3
- package/src/store/store.js +17 -2
- package/src/util/common.js +22 -21
- package/dist/19d6b530a9c.form.js +0 -1
- package/examples/track.js +0 -41
- /package/dist/{19d6b530a9c.127.js → 19df158c2ea.127.js} +0 -0
- /package/dist/{19d6b530a9c.132.js → 19df158c2ea.132.js} +0 -0
- /package/dist/{19d6b530a9c.185.js → 19df158c2ea.185.js} +0 -0
- /package/dist/{19d6b530a9c.27.js → 19df158c2ea.27.js} +0 -0
- /package/dist/{19d6b530a9c.278.js → 19df158c2ea.278.js} +0 -0
- /package/dist/{19d6b530a9c.339.js → 19df158c2ea.339.js} +0 -0
- /package/dist/{19d6b530a9c.459.js → 19df158c2ea.459.js} +0 -0
- /package/dist/{19d6b530a9c.490.js → 19df158c2ea.490.js} +0 -0
- /package/dist/{19d6b530a9c.74.js → 19df158c2ea.74.js} +0 -0
- /package/dist/{19d6b530a9c.997.js → 19df158c2ea.997.js} +0 -0
package/compiled_src/bot.js
CHANGED
|
@@ -19,13 +19,7 @@ function _default(store) {
|
|
|
19
19
|
if (!match) return;
|
|
20
20
|
let welcomMessages = bot.welcome_messages;
|
|
21
21
|
welcomMessages = _index.default.filter(welcomMessages, msg => {
|
|
22
|
-
if (
|
|
23
|
-
if (msg.block || msg.format === 'block') {
|
|
24
|
-
if (_index.default.isBlockEmpty(msg.block)) return false;
|
|
25
|
-
} else {
|
|
26
|
-
if (!(msg.text || '').trim()) return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
22
|
+
if (_index.default.isEmptyMessage(msg)) return false;
|
|
29
23
|
return true;
|
|
30
24
|
});
|
|
31
25
|
if (_index.default.size(welcomMessages)) {
|
|
@@ -28,21 +28,8 @@ class ChatButton extends _common.Com {
|
|
|
28
28
|
if (_index.default.get(ev, 'type') !== 'message_sent') return;
|
|
29
29
|
let bytype = _index.default.get(ev, 'by.type');
|
|
30
30
|
if (bytype !== 'system' && bytype !== 'agent' && bytype !== 'bot') return;
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
if (!att) return;
|
|
34
|
-
if (att.type === 'quick_replies') {
|
|
35
|
-
isquickreplies = true;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
let format = _index.default.get(ev, 'data.message.format');
|
|
39
|
-
let block = _index.default.get(ev, 'data.message.block');
|
|
40
|
-
if (block || format == 'block') {
|
|
41
|
-
if (_index.default.isBlockEmpty(block) && isquickreplies) return;
|
|
42
|
-
} else {
|
|
43
|
-
let message = _index.default.get(ev, 'data.message.text') || '';
|
|
44
|
-
if (!message && isquickreplies) return;
|
|
45
|
-
}
|
|
31
|
+
let message = _index.default.get(ev, 'data.message') || {};
|
|
32
|
+
if (_index.default.isEmptyMessage(message)) return;
|
|
46
33
|
let screen = _index.default.get(this.props.store.matchLastview(), 'screen');
|
|
47
34
|
let minimized = _index.default.get(this.props.store.matchLastview(), 'minimized');
|
|
48
35
|
if (screen === 'widget') return;
|
|
@@ -401,6 +388,9 @@ class ChatButton extends _common.Com {
|
|
|
401
388
|
imgurl = this.props.store.replaceFileUrl(imgurl);
|
|
402
389
|
imgsrc = this.props.store.replaceFileUrl(imgsrc);
|
|
403
390
|
maskurl = this.props.store.replaceFileUrl(maskurl);
|
|
391
|
+
imgurl = addVersionParam(imgurl);
|
|
392
|
+
imgsrc = addVersionParam(imgsrc);
|
|
393
|
+
maskurl = addVersionParam(maskurl);
|
|
404
394
|
if (!imgurl && !maskurl) {
|
|
405
395
|
whitebgcls += ' chat-button--white-bg--mask-only';
|
|
406
396
|
imgcontainerstyle = `
|
|
@@ -532,4 +522,17 @@ function randomAgent(agentM) {
|
|
|
532
522
|
}
|
|
533
523
|
const Ms30Mins = 30 * 60 * 1000;
|
|
534
524
|
const DEF_BG_URL = 'https://vcdn.subiz-cdn.com/file/bubble_11.svg?v=5';
|
|
535
|
-
const DEF_BG = 'linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)';
|
|
525
|
+
const DEF_BG = 'linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)';
|
|
526
|
+
function addVersionParam(url, version = 8) {
|
|
527
|
+
if (!url) return url;
|
|
528
|
+
try {
|
|
529
|
+
const u = new URL(url);
|
|
530
|
+
u.searchParams.set('v', version);
|
|
531
|
+
return u.toString();
|
|
532
|
+
} catch (e) {
|
|
533
|
+
const [base, hash] = url.split('#');
|
|
534
|
+
const hasQuery = base.includes('?');
|
|
535
|
+
const newUrl = base + (hasQuery ? '&' : '?') + `v=${version}`;
|
|
536
|
+
return hash ? newUrl + '#' + hash : newUrl;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
@@ -33,6 +33,7 @@ class MessageInput extends _common.Com {
|
|
|
33
33
|
}, 500);
|
|
34
34
|
this.resizeInput = _index.default.throttle(function () {
|
|
35
35
|
const input = this.refMessageInput.current;
|
|
36
|
+
if (!input) return;
|
|
36
37
|
input.style.setProperty('height', '1em', 'important');
|
|
37
38
|
const height = Math.min(200, input.scrollHeight);
|
|
38
39
|
input.style.setProperty('height', `${height}px`, 'important');
|
|
@@ -798,6 +798,7 @@ class Widget extends _common.Com {
|
|
|
798
798
|
agentids = agentids || _index.default.agentsOfConvo(convo)[0];
|
|
799
799
|
return (0, _preact.h)("div", {
|
|
800
800
|
class: "convo-list--item",
|
|
801
|
+
"data-cid": convo.id,
|
|
801
802
|
onClick: () => this.goToConvo(convo.id),
|
|
802
803
|
key: convo.id
|
|
803
804
|
}, (0, _preact.h)(_AgentsAvatar.default, {
|
|
@@ -11,9 +11,16 @@ var _common = require("../common.js");
|
|
|
11
11
|
var _preact = require("preact");
|
|
12
12
|
var _css = _interopRequireDefault(require("./css.js"));
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
17
|
class Main extends _common.Com {
|
|
15
18
|
constructor(props) {
|
|
16
19
|
super(props);
|
|
20
|
+
_defineProperty(this, "state", {
|
|
21
|
+
cssReady: false,
|
|
22
|
+
changing: false
|
|
23
|
+
});
|
|
17
24
|
this.refButton = (0, _preact.createRef)();
|
|
18
25
|
this.refWidget = (0, _preact.createRef)();
|
|
19
26
|
}
|
|
@@ -41,9 +48,6 @@ class Main extends _common.Com {
|
|
|
41
48
|
this.$cssStyleDiv.type = 'text/css';
|
|
42
49
|
this.$cssStyleDiv.id = 'subiz-style-for-' + this.props.plugin.id;
|
|
43
50
|
}
|
|
44
|
-
this.setState({
|
|
45
|
-
cssReady: false
|
|
46
|
-
});
|
|
47
51
|
this.checkExpand();
|
|
48
52
|
this.props.store.onResetCSS(this, () => this.refreshCSS());
|
|
49
53
|
this.props.store.onConvoEvent(this, ev => this.onConvoEvent(ev));
|
|
@@ -55,11 +59,32 @@ class Main extends _common.Com {
|
|
|
55
59
|
});
|
|
56
60
|
});
|
|
57
61
|
this.refreshCSS();
|
|
62
|
+
let lastview = this.props.store.matchLastview() || {};
|
|
63
|
+
let cid = _index.default.get(lastview, 'opts.cid');
|
|
64
|
+
if (cid) {
|
|
65
|
+
this._last_cid = cid;
|
|
66
|
+
this.setState({
|
|
67
|
+
changing: true
|
|
68
|
+
}, () => {
|
|
69
|
+
this.props.store.fetchConvo(cid).then(() => {
|
|
70
|
+
let convo = this.props.store.matchConvo(cid);
|
|
71
|
+
if (cid != this._last_cid) return;
|
|
72
|
+
this.setState({
|
|
73
|
+
changing: false
|
|
74
|
+
});
|
|
75
|
+
if (!convo) return this.showWidget({});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
58
79
|
this.setState({
|
|
59
80
|
cssReady: true
|
|
60
81
|
});
|
|
61
82
|
}
|
|
62
83
|
render() {
|
|
84
|
+
if (this.state.changing) {
|
|
85
|
+
if (typeof sbz_info != 'undefined') sbz_info.render_chatbox_changing_ready = _index.default.Date.now();
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
63
88
|
if (!this.state.cssReady) {
|
|
64
89
|
if (typeof sbz_info != 'undefined') sbz_info.render_chatbox_css_not_ready = _index.default.Date.now();
|
|
65
90
|
return null;
|
package/compiled_src/lib.js
CHANGED
|
@@ -20,7 +20,22 @@ class Widget {
|
|
|
20
20
|
_defineProperty(this, "getUser", () => _index.default.parseJSON(_index.default.stringify(this.store.matchUser())));
|
|
21
21
|
_defineProperty(this, "setViewingProduct", p => this.store.linkProduct(p));
|
|
22
22
|
_defineProperty(this, "getViewingProduct", () => this.store.getLinkedProduct());
|
|
23
|
-
_defineProperty(this, "track",
|
|
23
|
+
_defineProperty(this, "track", v => this.store.track(v));
|
|
24
|
+
_defineProperty(this, "event", async v => {
|
|
25
|
+
await this.store.readyGate.entry();
|
|
26
|
+
return this.store.api.sendEvent(v);
|
|
27
|
+
});
|
|
28
|
+
_defineProperty(this, "pageview", v => {
|
|
29
|
+
v = v || {};
|
|
30
|
+
return this.event({
|
|
31
|
+
type: 'content_viewed',
|
|
32
|
+
payload: {
|
|
33
|
+
url: v.url || location.href,
|
|
34
|
+
title: v.title || document.title,
|
|
35
|
+
referrer: v.referrer || document.referrer
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
24
39
|
this.impressionTokens = {};
|
|
25
40
|
this.domGate = new _index.default.Gate();
|
|
26
41
|
this.store = new _store.default(ApiURL, FileURL, RealtimeURL, inmem, fake);
|
|
@@ -170,12 +170,31 @@ class _default {
|
|
|
170
170
|
_defineProperty(this, "time", _ => ajax.setBaseUrl(this.ApiURL).withCredentials(true).setParser('json').get('/time'));
|
|
171
171
|
_defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
|
|
172
172
|
_defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
|
|
173
|
-
_defineProperty(this, "getAccountSetting", p => {
|
|
173
|
+
_defineProperty(this, "getAccountSetting", async p => {
|
|
174
174
|
let href = _index.default.get(document, 'location.href');
|
|
175
|
+
let res = {};
|
|
175
176
|
if (p && p.bot_id) {
|
|
176
|
-
|
|
177
|
+
res = await this.apireq.addQuery('url', href).addQuery('bot_id', p.bot_id).get(`/accounts/${this.accid}/settings`);
|
|
178
|
+
} else {
|
|
179
|
+
res = await this.apireq.addQuery('url', href).get(`/accounts/${this.accid}/settings`);
|
|
177
180
|
}
|
|
178
|
-
|
|
181
|
+
if (res.error) return res;
|
|
182
|
+
let plugins = _index.default.get(res, 'body.plugins') || [];
|
|
183
|
+
_index.default.map(plugins, plugin => {
|
|
184
|
+
if (plugin.type === 'popup') {
|
|
185
|
+
let pages = _index.default.get(plugin, 'popup.pages') || [];
|
|
186
|
+
_index.default.map(pages, page => {
|
|
187
|
+
_index.default.map(page.components, com => {
|
|
188
|
+
if (com.type === 'image') {
|
|
189
|
+
let url = _index.default.get(com, 'image.url');
|
|
190
|
+
_index.default.set(com, 'image.url', fallbackGCSUrl(url));
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
_index.default.set(res, 'body.plugins', plugins);
|
|
197
|
+
return res;
|
|
179
198
|
});
|
|
180
199
|
_defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
|
|
181
200
|
_defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
|
|
@@ -361,4 +380,17 @@ class _default {
|
|
|
361
380
|
});
|
|
362
381
|
}
|
|
363
382
|
}
|
|
364
|
-
exports.default = _default;
|
|
383
|
+
exports.default = _default;
|
|
384
|
+
function fallbackGCSUrl(url) {
|
|
385
|
+
try {
|
|
386
|
+
const u = new URL(url);
|
|
387
|
+
const isGCS = u.hostname === 'storage.googleapis.com';
|
|
388
|
+
const isSubizBucket = u.pathname.startsWith('/public-gcs.subiz-cdn.com/');
|
|
389
|
+
if (isGCS && isSubizBucket) {
|
|
390
|
+
return `https://${u.pathname.slice(1)}`;
|
|
391
|
+
}
|
|
392
|
+
return url;
|
|
393
|
+
} catch (e) {
|
|
394
|
+
return url;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
@@ -571,7 +571,17 @@ class Store {
|
|
|
571
571
|
}
|
|
572
572
|
this.readyGate.close();
|
|
573
573
|
accid = (accid || '').trim();
|
|
574
|
-
|
|
574
|
+
let lightConvos = this.kv.match('light_convos') || {};
|
|
575
|
+
this.lightConvos = {};
|
|
576
|
+
_index.default.map(lightConvos, convo => {
|
|
577
|
+
let in7Day = convo.created > _index.default.Date.now() - 7 * 24 * 3_600_000;
|
|
578
|
+
let events = _index.default.filter(convo.events, ev => ev.type === 'message_sent');
|
|
579
|
+
let messages = _index.default.map(events, ev => _index.default.get(ev, 'data.message') || {});
|
|
580
|
+
messages = _index.default.filter(messages, msg => !_index.default.isEmptyMessage(msg));
|
|
581
|
+
if (in7Day && _index.default.size(messages)) {
|
|
582
|
+
this.lightConvos[convo.id] = convo;
|
|
583
|
+
}
|
|
584
|
+
});
|
|
575
585
|
this.cache = new _kv.default(new _lsdb.default('sbz2023', true), 'kv');
|
|
576
586
|
if (this.realtime) this.realtime.stop();
|
|
577
587
|
if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL, realtimep, xhrsend, accid);
|
|
@@ -795,6 +805,9 @@ class Store {
|
|
|
795
805
|
if (traffic_source) this.kv.put('traffic_source', traffic_source);
|
|
796
806
|
return;
|
|
797
807
|
}
|
|
808
|
+
if (typeof e === 'object') {
|
|
809
|
+
if (!e.data) e.data = {};
|
|
810
|
+
}
|
|
798
811
|
return this.api.sendEvent(e);
|
|
799
812
|
}
|
|
800
813
|
async onWs(ev) {
|
|
@@ -354,12 +354,6 @@ function filter(collection, predicate) {
|
|
|
354
354
|
if (!collection) return [];
|
|
355
355
|
if (!predicate) return collection;
|
|
356
356
|
var out = [];
|
|
357
|
-
if (Array.isArray(collection)) {
|
|
358
|
-
for (let i = 0; i < collection.length; i++) {
|
|
359
|
-
if (predicate(collection[i], i)) out.push(collection[i]);
|
|
360
|
-
}
|
|
361
|
-
return out;
|
|
362
|
-
}
|
|
363
357
|
if (typeof collection === 'object') {
|
|
364
358
|
var keys = Object.keys(collection);
|
|
365
359
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -368,6 +362,12 @@ function filter(collection, predicate) {
|
|
|
368
362
|
}
|
|
369
363
|
return out;
|
|
370
364
|
}
|
|
365
|
+
if (Array.isArray(collection)) {
|
|
366
|
+
for (let i = 0; i < collection.length; i++) {
|
|
367
|
+
if (predicate(collection[i], i)) out.push(collection[i]);
|
|
368
|
+
}
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
371
|
return out;
|
|
372
372
|
}
|
|
373
373
|
function includes(collection, value) {
|
|
@@ -380,12 +380,6 @@ function map(collection, predicate) {
|
|
|
380
380
|
if (!collection) return [];
|
|
381
381
|
if (!predicate) predicate = i => i;
|
|
382
382
|
var out = [];
|
|
383
|
-
if (Array.isArray(collection)) {
|
|
384
|
-
for (let i = 0; i < collection.length; i++) {
|
|
385
|
-
out.push(predicate(collection[i], i));
|
|
386
|
-
}
|
|
387
|
-
return out;
|
|
388
|
-
}
|
|
389
383
|
if (typeof collection === 'object') {
|
|
390
384
|
var keys = Object.keys(collection);
|
|
391
385
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -394,6 +388,12 @@ function map(collection, predicate) {
|
|
|
394
388
|
}
|
|
395
389
|
return out;
|
|
396
390
|
}
|
|
391
|
+
if (Array.isArray(collection)) {
|
|
392
|
+
for (let i = 0; i < collection.length; i++) {
|
|
393
|
+
out.push(predicate(collection[i], i));
|
|
394
|
+
}
|
|
395
|
+
return out;
|
|
396
|
+
}
|
|
397
397
|
return out;
|
|
398
398
|
}
|
|
399
399
|
function each(collection, predicate) {
|
|
@@ -476,12 +476,6 @@ function find(collection, f) {
|
|
|
476
476
|
function findIndex(collection, f) {
|
|
477
477
|
if (!collection) return -1;
|
|
478
478
|
if (!f) return -1;
|
|
479
|
-
if (Array.isArray(collection)) {
|
|
480
|
-
for (let i = 0; i < collection.length; i++) {
|
|
481
|
-
if (f(collection[i], i)) return i;
|
|
482
|
-
}
|
|
483
|
-
return -1;
|
|
484
|
-
}
|
|
485
479
|
if (typeof collection === 'object') {
|
|
486
480
|
var keys = Object.keys(collection);
|
|
487
481
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -489,6 +483,12 @@ function findIndex(collection, f) {
|
|
|
489
483
|
if (f(collection[k], k)) return k;
|
|
490
484
|
}
|
|
491
485
|
}
|
|
486
|
+
if (Array.isArray(collection)) {
|
|
487
|
+
for (let i = 0; i < collection.length; i++) {
|
|
488
|
+
if (f(collection[i], i)) return i;
|
|
489
|
+
}
|
|
490
|
+
return -1;
|
|
491
|
+
}
|
|
492
492
|
return -1;
|
|
493
493
|
}
|
|
494
494
|
function orderBy(a, k, d) {
|