@subiz/widget-v4 4.1.155 → 4.1.157
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/bot.js +9 -0
- package/compiled_src/chatbox/AgentsAvatar.js +7 -6
- package/compiled_src/chatbox/ChatButton.js +26 -15
- package/compiled_src/chatbox/Widget.js +41 -0
- package/compiled_src/store/kv.js +0 -2
- package/compiled_src/store/store.js +101 -13
- package/dist/19888eff7f5.app.js +1 -0
- package/dist/{19816b2e8ca.chat.html → 19888eff7f5.chat.html} +1 -1
- package/dist/19888eff7f5.chat.js +1 -0
- package/dist/{19816b2e8ca.form.html → 19888eff7f5.form.html} +1 -1
- package/dist/19888eff7f5.form.js +1 -0
- package/dist/{19816b2e8ca.index.html → 19888eff7f5.index.html} +1 -1
- package/dist/{19816b2e8ca.library.html → 19888eff7f5.library.html} +1 -1
- package/dist/19888eff7f5.library.js +1 -0
- package/dist/{19816b2e8ca.preview.html → 19888eff7f5.preview.html} +1 -1
- package/dist/19888eff7f5.preview.js +1 -0
- package/dist/19888eff7f5.webview.js +1 -0
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +226 -34
- package/package.json +3 -3
- package/src/bot.js +8 -1
- package/src/chatbox/AgentsAvatar.js +30 -12
- package/src/chatbox/ChatButton.js +31 -18
- package/src/chatbox/Widget.js +27 -0
- package/src/store/kv.js +11 -14
- package/src/store/store.js +92 -17
- package/dist/19816b2e8ca.app.js +0 -1
- package/dist/19816b2e8ca.chat.js +0 -1
- package/dist/19816b2e8ca.form.js +0 -1
- package/dist/19816b2e8ca.library.js +0 -1
- package/dist/19816b2e8ca.preview.js +0 -1
- package/dist/19816b2e8ca.webview.js +0 -1
- /package/dist/{19816b2e8ca.127.js → 19888eff7f5.127.js} +0 -0
- /package/dist/{19816b2e8ca.132.js → 19888eff7f5.132.js} +0 -0
- /package/dist/{19816b2e8ca.185.js → 19888eff7f5.185.js} +0 -0
- /package/dist/{19816b2e8ca.27.js → 19888eff7f5.27.js} +0 -0
- /package/dist/{19816b2e8ca.278.js → 19888eff7f5.278.js} +0 -0
- /package/dist/{19816b2e8ca.339.js → 19888eff7f5.339.js} +0 -0
- /package/dist/{19816b2e8ca.459.js → 19888eff7f5.459.js} +0 -0
- /package/dist/{19816b2e8ca.490.js → 19888eff7f5.490.js} +0 -0
- /package/dist/{19816b2e8ca.74.js → 19888eff7f5.74.js} +0 -0
- /package/dist/{19816b2e8ca.997.js → 19888eff7f5.997.js} +0 -0
package/dist/HASH
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
19888eff7f5
|
package/dist/screenshoot.js
CHANGED
|
@@ -3775,6 +3775,57 @@ function jsonifyTextPlain(param, done) {
|
|
|
3775
3775
|
_defineProperty(this, "sendTyping", cid => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`));
|
|
3776
3776
|
_defineProperty(this, "sendLostFocus", () => this.apireq.post(`/accounts/${this.accid}/focuses/${this.uid}/delete`));
|
|
3777
3777
|
_defineProperty(this, "uploadToS3", async file => {
|
|
3778
|
+
let name = file.name.replace(/\s+/g, '_');
|
|
3779
|
+
var {
|
|
3780
|
+
body,
|
|
3781
|
+
error
|
|
3782
|
+
} = await this.apireq.setBaseUrl('https://api5.subiz.com.vn/4.1').setQuery({
|
|
3783
|
+
'account-id': this.accid,
|
|
3784
|
+
description: 'upload\n user-client: web-widget',
|
|
3785
|
+
name: name,
|
|
3786
|
+
presign: true,
|
|
3787
|
+
size: file.size,
|
|
3788
|
+
type: file.type
|
|
3789
|
+
}).post('/files');
|
|
3790
|
+
if (error) return {
|
|
3791
|
+
body,
|
|
3792
|
+
error
|
|
3793
|
+
};
|
|
3794
|
+
let signedurl = body.signed_url;
|
|
3795
|
+
let fileid = body.id;
|
|
3796
|
+
let err = await new Promise(resolve => {
|
|
3797
|
+
const xhr = new util/* default */.A.XMLHttpRequest();
|
|
3798
|
+
xhr.open('PUT', signedurl, true);
|
|
3799
|
+
xhr.setRequestHeader('Content-Type', file.mimetype);
|
|
3800
|
+
xhr.onload = function () {
|
|
3801
|
+
if (xhr.status === 200) {
|
|
3802
|
+
resolve();
|
|
3803
|
+
} else {
|
|
3804
|
+
resolve(new Error(`Upload failed: ${xhr.statusText}`));
|
|
3805
|
+
}
|
|
3806
|
+
};
|
|
3807
|
+
xhr.onerror = function () {
|
|
3808
|
+
resolve(new Error('Network error during upload.'));
|
|
3809
|
+
};
|
|
3810
|
+
xhr.send(file);
|
|
3811
|
+
});
|
|
3812
|
+
if (err) return {
|
|
3813
|
+
error: err
|
|
3814
|
+
};
|
|
3815
|
+
var {
|
|
3816
|
+
body,
|
|
3817
|
+
error
|
|
3818
|
+
} = await this.apireq.setBaseUrl('https://api5.subiz.com.vn/4.1').setQuery({
|
|
3819
|
+
'account-id': this.accid
|
|
3820
|
+
}).post(`/files/${fileid}/uploaded`);
|
|
3821
|
+
if (error) return {
|
|
3822
|
+
error
|
|
3823
|
+
};
|
|
3824
|
+
return {
|
|
3825
|
+
url: util/* default */.A.get(body, 'file.url', '')
|
|
3826
|
+
};
|
|
3827
|
+
});
|
|
3828
|
+
_defineProperty(this, "uploadToS32", async file => {
|
|
3778
3829
|
var {
|
|
3779
3830
|
body,
|
|
3780
3831
|
error
|
|
@@ -3830,7 +3881,7 @@ function jsonifyTextPlain(param, done) {
|
|
|
3830
3881
|
this.refreshLock = new util/* default */.A.Mutex();
|
|
3831
3882
|
this.FileURL = FileURL;
|
|
3832
3883
|
this.ApiURL = ApiURL;
|
|
3833
|
-
this.api41 = ajax.setBaseUrl('https://
|
|
3884
|
+
this.api41 = ajax.setBaseUrl('https://api.sbz.vn/4.1').withCredentials(true).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json');
|
|
3834
3885
|
this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').beforeHook((param, done) => {
|
|
3835
3886
|
if (this.token_generator) {
|
|
3836
3887
|
let user_id = this.profile_id;
|
|
@@ -4803,12 +4854,15 @@ class Store {
|
|
|
4803
4854
|
if (!id) return;
|
|
4804
4855
|
if (id === '*') {
|
|
4805
4856
|
this._touchAcc();
|
|
4806
|
-
return util/* default */.A.filter(this.cache.all(), (value, k) => k.startsWith('convo_'));
|
|
4857
|
+
return util/* default */.A.filter(this.cache.all(), (value, k) => k.startsWith('convo_')).concat(util/* default */.A.map(this.lightConvos));
|
|
4807
4858
|
}
|
|
4859
|
+
if (id.startsWith('cslight')) return this.lightConvos[id];
|
|
4808
4860
|
if (!this.isInsync(id)) this.fetchConvo(id);
|
|
4809
4861
|
return this.cache.match('convo_' + id);
|
|
4810
4862
|
});
|
|
4811
4863
|
store_defineProperty(this, "fetchConvo", async cid => {
|
|
4864
|
+
if (!cid) return;
|
|
4865
|
+
if (cid.startsWith('cslight')) return;
|
|
4812
4866
|
if (this._die) return dieErr;
|
|
4813
4867
|
await this.readyGate.entry();
|
|
4814
4868
|
await this.reconnectGate.entry(undefined, true);
|
|
@@ -4827,9 +4881,12 @@ class Store {
|
|
|
4827
4881
|
store_defineProperty(this, "outofmsgM", {});
|
|
4828
4882
|
store_defineProperty(this, "listEvents", id => {
|
|
4829
4883
|
if (!id || id === '*' || typeof id !== 'string') return;
|
|
4884
|
+
if (id.startsWith('cslight')) return util/* default */.A.get(this.lightConvos, [id, 'events'], []);
|
|
4830
4885
|
return this.chain.listM(id);
|
|
4831
4886
|
});
|
|
4832
4887
|
store_defineProperty(this, "fetchMoreEvents", async convoid => {
|
|
4888
|
+
if (!convoid) return;
|
|
4889
|
+
if (convoid.startsWith('cslight')) return [[], ''];
|
|
4833
4890
|
if (!this.isInsync('events' + convoid)) {
|
|
4834
4891
|
await this.readyGate.entry();
|
|
4835
4892
|
await this.reconnectGate.entry(undefined, true);
|
|
@@ -4941,6 +4998,7 @@ class Store {
|
|
|
4941
4998
|
this.FileURL = FileURL;
|
|
4942
4999
|
this._track_page_view = true;
|
|
4943
5000
|
this.device_type = 'desktop';
|
|
5001
|
+
this.lightConvos = {};
|
|
4944
5002
|
if (this.fake) this.api = new api_fake(ApiURL, FileURL);else this.api = new api(ApiURL, FileURL);
|
|
4945
5003
|
if (!inmem) {
|
|
4946
5004
|
try {
|
|
@@ -4961,9 +5019,9 @@ class Store {
|
|
|
4961
5019
|
this.chain = new Chain(new lsdb('cbz2023', true), 'ch');
|
|
4962
5020
|
this.getLocaleContent = this.api.getLocaleContent;
|
|
4963
5021
|
this.g_haveSentSeenM = {};
|
|
4964
|
-
this.last_focused =
|
|
5022
|
+
this.last_focused = this.now();
|
|
4965
5023
|
window.addEventListener('blur', () => {
|
|
4966
|
-
this.last_focused =
|
|
5024
|
+
this.last_focused = this.now();
|
|
4967
5025
|
this.sendPresence();
|
|
4968
5026
|
});
|
|
4969
5027
|
window.addEventListener('focus', () => {
|
|
@@ -4985,7 +5043,7 @@ class Store {
|
|
|
4985
5043
|
this._presenceInterval2 = util/* default */.A.setInterval(() => {
|
|
4986
5044
|
if (this._die) return util/* default */.A.clearInterval(this._presenceInterval2);
|
|
4987
5045
|
if (this.browserVisibility === 'visible' && document.hasFocus()) return;
|
|
4988
|
-
if (this.last_focused &&
|
|
5046
|
+
if (this.last_focused && this.now() - this.last_focused > 30 * 60000) {
|
|
4989
5047
|
return;
|
|
4990
5048
|
}
|
|
4991
5049
|
this.sendPresence();
|
|
@@ -5212,6 +5270,7 @@ class Store {
|
|
|
5212
5270
|
await this.reconnectWs(accid, user.id);
|
|
5213
5271
|
this.reconnect();
|
|
5214
5272
|
});
|
|
5273
|
+
this.lightConvos = this.kv.match('light_convos') || {};
|
|
5215
5274
|
this.seenLoop();
|
|
5216
5275
|
await this.reconnect({
|
|
5217
5276
|
user: user
|
|
@@ -5270,9 +5329,8 @@ class Store {
|
|
|
5270
5329
|
if (!lastmsgsent) return;
|
|
5271
5330
|
if (this.g_haveSentSeenM[lastmsgsent.id]) return;
|
|
5272
5331
|
if (lastmsgsent.id === lastmsgsent.data.message.idempotency_key) return;
|
|
5273
|
-
this.api.markAsSeen(id, lastmsgsent.id);
|
|
5274
5332
|
this.pubsub.publish('events', {
|
|
5275
|
-
created:
|
|
5333
|
+
created: this.now(),
|
|
5276
5334
|
type: 'message_pong',
|
|
5277
5335
|
by: {
|
|
5278
5336
|
type: 'user'
|
|
@@ -5283,14 +5341,25 @@ class Store {
|
|
|
5283
5341
|
id: '*',
|
|
5284
5342
|
pongs: [{
|
|
5285
5343
|
type: 'seen',
|
|
5286
|
-
created:
|
|
5344
|
+
created: this.now()
|
|
5287
5345
|
}]
|
|
5288
5346
|
}
|
|
5289
5347
|
}
|
|
5290
5348
|
});
|
|
5349
|
+
if (id.startsWith('cslight')) {
|
|
5350
|
+
let old = this.lightConvos[id];
|
|
5351
|
+
let user = this.matchUser();
|
|
5352
|
+
if (!old) return;
|
|
5353
|
+
let mem = util/* default */.A.find(old.members, mem => mem.type == 'user' && mem.id == user.id);
|
|
5354
|
+
mem.seen_at = this.now();
|
|
5355
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
5356
|
+
this.g_haveSentSeenM[lastmsgsent.id] = true;
|
|
5357
|
+
return;
|
|
5358
|
+
}
|
|
5359
|
+
this.api.markAsSeen(id, lastmsgsent.id);
|
|
5291
5360
|
let convo = this.cache.match('convo_' + id) || {};
|
|
5292
5361
|
let mem = util/* default */.A.find(convo.members, m => m.id === user.id);
|
|
5293
|
-
if (mem) mem.seen_at =
|
|
5362
|
+
if (mem) mem.seen_at = this.now();
|
|
5294
5363
|
this._setConvo(convo);
|
|
5295
5364
|
this.g_haveSentSeenM[lastmsgsent.id] = true;
|
|
5296
5365
|
});
|
|
@@ -5451,7 +5520,7 @@ class Store {
|
|
|
5451
5520
|
let cid = util/* default */.A.convoOfEv(ev);
|
|
5452
5521
|
let convo;
|
|
5453
5522
|
let alreadyFetched = false;
|
|
5454
|
-
if (cid) {
|
|
5523
|
+
if (cid && !cid.startsWith('cslight')) {
|
|
5455
5524
|
convo = this.cache.match('convo_' + cid);
|
|
5456
5525
|
if (!convo || !convo.id) {
|
|
5457
5526
|
let {
|
|
@@ -5464,6 +5533,15 @@ class Store {
|
|
|
5464
5533
|
this._setConvo(convo);
|
|
5465
5534
|
}
|
|
5466
5535
|
}
|
|
5536
|
+
if (cid.startsWith('cslight')) {
|
|
5537
|
+
convo = this.lightConvos[cid];
|
|
5538
|
+
if (!convo) return;
|
|
5539
|
+
convo.events.push(ev);
|
|
5540
|
+
convo.last_message_sent = ev;
|
|
5541
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
5542
|
+
this.pubsub.publish('events', ev);
|
|
5543
|
+
return;
|
|
5544
|
+
}
|
|
5467
5545
|
if (!convo) return;
|
|
5468
5546
|
this.pubsub.publish('events', ev);
|
|
5469
5547
|
if (ev.type === 'conversation_joined') {
|
|
@@ -5560,8 +5638,65 @@ class Store {
|
|
|
5560
5638
|
}
|
|
5561
5639
|
typing(cid) {
|
|
5562
5640
|
if (!cid) return;
|
|
5641
|
+
if (cid.startsWith('cslight')) return;
|
|
5563
5642
|
this._typing(cid);
|
|
5564
5643
|
}
|
|
5644
|
+
deleteLightConvo(id) {
|
|
5645
|
+
delete this.lightConvos[id];
|
|
5646
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
5647
|
+
}
|
|
5648
|
+
startLightConvo(botid, message, locale) {
|
|
5649
|
+
let convoid = 'cslight' + botid + '_' + this.now();
|
|
5650
|
+
let user = this.cache.match('user') || {};
|
|
5651
|
+
let old = this.lightConvos[convoid];
|
|
5652
|
+
if (old) return {
|
|
5653
|
+
convo: old
|
|
5654
|
+
};
|
|
5655
|
+
let now = this.now();
|
|
5656
|
+
let ev = {};
|
|
5657
|
+
ev.created = now;
|
|
5658
|
+
ev.event_time = now;
|
|
5659
|
+
ev.id = 'evfake' + now;
|
|
5660
|
+
ev.type = 'message_sent';
|
|
5661
|
+
ev.by = {
|
|
5662
|
+
id: botid,
|
|
5663
|
+
type: 'bot'
|
|
5664
|
+
};
|
|
5665
|
+
ev.data = {
|
|
5666
|
+
message: message
|
|
5667
|
+
};
|
|
5668
|
+
ev.data.message.conversation_id = convoid;
|
|
5669
|
+
let newconvo = {
|
|
5670
|
+
id: convoid,
|
|
5671
|
+
locale: locale,
|
|
5672
|
+
initial_by: botid,
|
|
5673
|
+
created: now,
|
|
5674
|
+
actived: now,
|
|
5675
|
+
last_message_sent: ev,
|
|
5676
|
+
members: [{
|
|
5677
|
+
type: 'user',
|
|
5678
|
+
id: user.id
|
|
5679
|
+
}, {
|
|
5680
|
+
type: 'bot',
|
|
5681
|
+
id: botid,
|
|
5682
|
+
membership: 'active'
|
|
5683
|
+
}],
|
|
5684
|
+
state: 'active',
|
|
5685
|
+
touchpoint: {
|
|
5686
|
+
id: convoid,
|
|
5687
|
+
channel: 'subiz',
|
|
5688
|
+
source: 'web'
|
|
5689
|
+
},
|
|
5690
|
+
traffic_source: 'direct',
|
|
5691
|
+
events: [ev]
|
|
5692
|
+
};
|
|
5693
|
+
this.pubsub.publish('events', ev);
|
|
5694
|
+
this.lightConvos[convoid] = newconvo;
|
|
5695
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
5696
|
+
return {
|
|
5697
|
+
convo: newconvo
|
|
5698
|
+
};
|
|
5699
|
+
}
|
|
5565
5700
|
async startConvo(req) {
|
|
5566
5701
|
if (!req) req = {};
|
|
5567
5702
|
await this.readyGate.entry();
|
|
@@ -5587,9 +5722,11 @@ class Store {
|
|
|
5587
5722
|
return this.api.lookupOrder(key);
|
|
5588
5723
|
}
|
|
5589
5724
|
createPostback(cid, postback) {
|
|
5725
|
+
if (cid && cid.startsWith('cslight')) return;
|
|
5590
5726
|
return this.api.createPostback(cid, postback);
|
|
5591
5727
|
}
|
|
5592
5728
|
sendReaction(cid, ev) {
|
|
5729
|
+
if (cid && cid.startsWith('cslight')) return;
|
|
5593
5730
|
return this.api.sendConvoEvent(cid, ev);
|
|
5594
5731
|
}
|
|
5595
5732
|
async sendConvoEvent(cid, type, data) {
|
|
@@ -5643,6 +5780,7 @@ class Store {
|
|
|
5643
5780
|
att.url = url;
|
|
5644
5781
|
});
|
|
5645
5782
|
if (event._error) return this.onWs(event);
|
|
5783
|
+
if (cid && cid.startsWith('cslight')) return;
|
|
5646
5784
|
let {
|
|
5647
5785
|
body: ret,
|
|
5648
5786
|
error
|
|
@@ -5664,7 +5802,7 @@ class Store {
|
|
|
5664
5802
|
first_interaction: 1
|
|
5665
5803
|
});
|
|
5666
5804
|
}
|
|
5667
|
-
this.kv.put('last_msg_sent',
|
|
5805
|
+
this.kv.put('last_msg_sent', this.now());
|
|
5668
5806
|
return ret;
|
|
5669
5807
|
}
|
|
5670
5808
|
_setConvo(convo) {
|
|
@@ -5749,6 +5887,7 @@ class Store {
|
|
|
5749
5887
|
}
|
|
5750
5888
|
async listmessageapi(type, anchor, limit) {
|
|
5751
5889
|
let convoid = type;
|
|
5890
|
+
if (convoid && convoid.startsWith('cslight')) return [fakeevents, '', undefined, true];
|
|
5752
5891
|
let {
|
|
5753
5892
|
body: events,
|
|
5754
5893
|
code,
|
|
@@ -5782,16 +5921,16 @@ class Store {
|
|
|
5782
5921
|
}
|
|
5783
5922
|
async loopTime() {
|
|
5784
5923
|
if (this._die) return;
|
|
5785
|
-
let startms =
|
|
5924
|
+
let startms = this.now();
|
|
5786
5925
|
if (!util/* default */.A.get(this.cache.match('user'), 'id')) return util/* default */.A.setTimeout(() => this.loopTime(), 240000);
|
|
5787
5926
|
let {
|
|
5788
5927
|
body: t,
|
|
5789
5928
|
error
|
|
5790
5929
|
} = await this.api.time();
|
|
5791
5930
|
if (error) return util/* default */.A.setTimeout(() => this.loopTime(), 30000);
|
|
5792
|
-
var latences = Math.abs(
|
|
5931
|
+
var latences = Math.abs(this.now() - startms) / 2;
|
|
5793
5932
|
var serverMs = new util/* default */.A.Date(t).getTime() + latences;
|
|
5794
|
-
var localMs =
|
|
5933
|
+
var localMs = this.now();
|
|
5795
5934
|
this.timeDiff = Math.floor(serverMs - localMs);
|
|
5796
5935
|
util/* default */.A.setTimeout(() => this.loopTime(), 240000);
|
|
5797
5936
|
}
|
|
@@ -6037,7 +6176,7 @@ class ChatButton extends common/* Com */.Mw {
|
|
|
6037
6176
|
this.props.store.onConvoEvent(this, ev => {
|
|
6038
6177
|
if (util/* default */.A.get(ev, 'type') !== 'message_sent') return;
|
|
6039
6178
|
let bytype = util/* default */.A.get(ev, 'by.type');
|
|
6040
|
-
if (bytype !== 'system' && bytype !== 'agent') return;
|
|
6179
|
+
if (bytype !== 'system' && bytype !== 'agent' && bytype !== 'bot') return;
|
|
6041
6180
|
let isquickreplies = false;
|
|
6042
6181
|
util/* default */.A.map(util/* default */.A.get(ev, 'data.message.attachments', []), att => {
|
|
6043
6182
|
if (!att) return;
|
|
@@ -6106,18 +6245,23 @@ class ChatButton extends common/* Com */.Mw {
|
|
|
6106
6245
|
displayPreview: false
|
|
6107
6246
|
});
|
|
6108
6247
|
}
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6248
|
+
pickBestGreeting() {
|
|
6249
|
+
let convoM = this.props.store.matchConvo('*');
|
|
6250
|
+
let unseenConvo = util/* default */.A.filter(convoM, convo => {
|
|
6251
|
+
let seen = util/* default */.A.isConvoSeen(convo, this.props.store.matchUser().id);
|
|
6252
|
+
return !seen;
|
|
6253
|
+
}).sort((a, b) => util/* default */.A.get(b, 'last_message_sent.created', 0) - util/* default */.A.get(a, 'last_message_sent.created', 0));
|
|
6254
|
+
if (util/* default */.A.size(unseenConvo) == 0) {
|
|
6255
|
+
if (this.props.store.isMobile()) {
|
|
6256
|
+
let accid = util/* default */.A.get(this.props.plugin, 'chatbox.account_id', {});
|
|
6257
|
+
if (accid === 'acqjeefqeaoiagyfprap') return;
|
|
6258
|
+
}
|
|
6259
|
+
let greeting = util/* default */.A.get(this.props.plugin, 'chatbox.greeting', {});
|
|
6260
|
+
let agentM = this.props.store.matchAgent('*');
|
|
6261
|
+
let byid = greeting.agent_id;
|
|
6262
|
+
if (!byid) byid = randomAgent(agentM).id;
|
|
6263
|
+
let text = this.props.t.i18n(util/* default */.A.get(greeting, 'greeting', {})) || greeting.message;
|
|
6264
|
+
return {
|
|
6121
6265
|
by: {
|
|
6122
6266
|
id: byid,
|
|
6123
6267
|
type: 'agent'
|
|
@@ -6128,7 +6272,13 @@ class ChatButton extends common/* Com */.Mw {
|
|
|
6128
6272
|
format: 'plaintext'
|
|
6129
6273
|
}
|
|
6130
6274
|
}
|
|
6131
|
-
}
|
|
6275
|
+
};
|
|
6276
|
+
}
|
|
6277
|
+
return unseenConvo[0].last_message_sent;
|
|
6278
|
+
}
|
|
6279
|
+
ShowGreeting() {
|
|
6280
|
+
this.setState({
|
|
6281
|
+
previewEvent: this.pickBestGreeting(),
|
|
6132
6282
|
displayPreview: true
|
|
6133
6283
|
});
|
|
6134
6284
|
}
|
|
@@ -6488,6 +6638,7 @@ function AgentsAvatar(props) {
|
|
|
6488
6638
|
}
|
|
6489
6639
|
if (agents.length === 1) {
|
|
6490
6640
|
var agent = agents[0];
|
|
6641
|
+
let avatarurl = agent.avatar_url || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582);
|
|
6491
6642
|
var groupClass = mode === 'primary' ? 'group-avatar--agent-middle' : 'group-avatar--agent-left';
|
|
6492
6643
|
return (0,preact_module.h)("div", {
|
|
6493
6644
|
class: `group-avatar group-avatar--${mode}`
|
|
@@ -6500,7 +6651,7 @@ function AgentsAvatar(props) {
|
|
|
6500
6651
|
height: 35,
|
|
6501
6652
|
class: `avatar ${groupClass}`,
|
|
6502
6653
|
alt: "agent avatar",
|
|
6503
|
-
src:
|
|
6654
|
+
src: avatarurl
|
|
6504
6655
|
})));
|
|
6505
6656
|
}
|
|
6506
6657
|
if (agents.length === 2) {
|
|
@@ -6517,7 +6668,7 @@ function AgentsAvatar(props) {
|
|
|
6517
6668
|
height: 35,
|
|
6518
6669
|
alt: "agent avatar left",
|
|
6519
6670
|
class: "avatar group-avatar--agent-left",
|
|
6520
|
-
src: props.store.replaceFileUrl(leftAgent.avatar_url) || __webpack_require__(
|
|
6671
|
+
src: props.store.replaceFileUrl(leftAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
|
|
6521
6672
|
})), (0,preact_module.h)("div", {
|
|
6522
6673
|
class: "d-inline-block pos-relative",
|
|
6523
6674
|
"data-tooltip": rightAgent.fullname || acc.name,
|
|
@@ -6527,7 +6678,7 @@ function AgentsAvatar(props) {
|
|
|
6527
6678
|
width: 35,
|
|
6528
6679
|
height: 35,
|
|
6529
6680
|
class: "avatar group-avatar--agent-right",
|
|
6530
|
-
src: props.store.replaceFileUrl(rightAgent.avatar_url) || __webpack_require__(
|
|
6681
|
+
src: props.store.replaceFileUrl(rightAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
|
|
6531
6682
|
})));
|
|
6532
6683
|
}
|
|
6533
6684
|
let leftAgent = agents[0];
|
|
@@ -6544,7 +6695,7 @@ function AgentsAvatar(props) {
|
|
|
6544
6695
|
height: 35,
|
|
6545
6696
|
alt: "agent avatar left",
|
|
6546
6697
|
class: "avatar group-avatar--agent-left",
|
|
6547
|
-
src: props.store.replaceFileUrl(leftAgent.avatar_url) || __webpack_require__(
|
|
6698
|
+
src: props.store.replaceFileUrl(leftAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
|
|
6548
6699
|
})), (0,preact_module.h)("div", {
|
|
6549
6700
|
class: "d-inline-block pos-relative",
|
|
6550
6701
|
"data-tooltip": middleAgent.fullname || acc.name,
|
|
@@ -6554,7 +6705,7 @@ function AgentsAvatar(props) {
|
|
|
6554
6705
|
width: 35,
|
|
6555
6706
|
height: 35,
|
|
6556
6707
|
class: "avatar group-avatar--agent-middle",
|
|
6557
|
-
src: props.store.replaceFileUrl(middleAgent.avatar_url) || __webpack_require__(
|
|
6708
|
+
src: props.store.replaceFileUrl(middleAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
|
|
6558
6709
|
})), (0,preact_module.h)("div", {
|
|
6559
6710
|
class: "d-inline-block pos-relative",
|
|
6560
6711
|
"data-tooltip": rightAgent.fullname || acc.name,
|
|
@@ -6564,7 +6715,7 @@ function AgentsAvatar(props) {
|
|
|
6564
6715
|
height: 35,
|
|
6565
6716
|
alt: "agent avatar right",
|
|
6566
6717
|
class: "avatar group-avatar--agent-right",
|
|
6567
|
-
src: props.store.replaceFileUrl(rightAgent.avatar_url) || __webpack_require__(
|
|
6718
|
+
src: props.store.replaceFileUrl(rightAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
|
|
6568
6719
|
})));
|
|
6569
6720
|
}
|
|
6570
6721
|
;// ./src/chatbox/Header.js
|
|
@@ -9751,6 +9902,47 @@ class Widget extends common/* Com */.Mw {
|
|
|
9751
9902
|
return;
|
|
9752
9903
|
}
|
|
9753
9904
|
let text = message.text;
|
|
9905
|
+
if (this.props.cid && this.props.cid.startsWith('cslight')) {
|
|
9906
|
+
let cid = this.props.cid;
|
|
9907
|
+
this._creating = (this._creating || 0) + 1;
|
|
9908
|
+
let _creating = this._creating;
|
|
9909
|
+
this.setState({
|
|
9910
|
+
creating: true
|
|
9911
|
+
});
|
|
9912
|
+
let botid = cid.split('_')[0].slice(7);
|
|
9913
|
+
const {
|
|
9914
|
+
convo,
|
|
9915
|
+
error
|
|
9916
|
+
} = await this.props.store.startConvo({
|
|
9917
|
+
locale: this.props.t.locale(),
|
|
9918
|
+
message: text,
|
|
9919
|
+
members: [{
|
|
9920
|
+
type: 'bot',
|
|
9921
|
+
id: botid
|
|
9922
|
+
}],
|
|
9923
|
+
initial_by: this.props.store.matchUser().id
|
|
9924
|
+
});
|
|
9925
|
+
if (_creating != this._creating) return;
|
|
9926
|
+
if (error) {
|
|
9927
|
+
this.setState({
|
|
9928
|
+
creating: false
|
|
9929
|
+
});
|
|
9930
|
+
return;
|
|
9931
|
+
}
|
|
9932
|
+
this.props.store.deleteLightConvo(cid);
|
|
9933
|
+
await this.props.store.sendConvoEvent(convo.id, 'message_sent', {
|
|
9934
|
+
message
|
|
9935
|
+
});
|
|
9936
|
+
if (_creating != this._creating) return;
|
|
9937
|
+
this.props.onGo({
|
|
9938
|
+
view: 'chat',
|
|
9939
|
+
cid: convo.id
|
|
9940
|
+
});
|
|
9941
|
+
this.setState({
|
|
9942
|
+
creating: false
|
|
9943
|
+
});
|
|
9944
|
+
return;
|
|
9945
|
+
}
|
|
9754
9946
|
if (!this.props.cid) {
|
|
9755
9947
|
this._creating = (this._creating || 0) + 1;
|
|
9756
9948
|
let _creating = this._creating;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subiz/widget-v4",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.157",
|
|
4
4
|
"main": "./compiled_src/lib.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "npx webpack serve --config webpack.dev.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@subiz/flow": "^1.1.0",
|
|
14
14
|
"@subiz/wsclient": "^4.0.34",
|
|
15
15
|
"cookie_js": "1.4.2",
|
|
16
|
-
"core-js": "^3.
|
|
16
|
+
"core-js": "^3.45.0",
|
|
17
17
|
"css-loader": "5.2.7",
|
|
18
18
|
"file-loader": "^6.2.0",
|
|
19
19
|
"less": "^4.4.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"babel-loader": "^10.0.0",
|
|
30
30
|
"babel-plugin-syntax-jsx": "^6.18.0",
|
|
31
31
|
"html-webpack-plugin": "^5.6.3",
|
|
32
|
-
"puppeteer": "^24.
|
|
32
|
+
"puppeteer": "^24.16.0",
|
|
33
33
|
"webpack": "^5.101.0",
|
|
34
34
|
"webpack-bundle-analyzer": "^4.10.2",
|
|
35
35
|
"webpack-cli": "^6.0.1",
|
package/src/bot.js
CHANGED
|
@@ -11,7 +11,14 @@ export default function (store) {
|
|
|
11
11
|
run = () => true // dont run twice
|
|
12
12
|
let match = sb.checkRunConditions(bot.initiative_frequency, bot.conditions, store.matchLastBotRun(bot.id), store)
|
|
13
13
|
if (!match) return
|
|
14
|
-
|
|
14
|
+
if (bot.id.startsWith('at')) {
|
|
15
|
+
if (!bot.welcome_message) return
|
|
16
|
+
let {error} = await store.startLightConvo(bot.id, bot.welcome_message, common.getLocale(bot, sb.detectLang()))
|
|
17
|
+
if (error) return console.error(error)
|
|
18
|
+
store.logBotRun(bot.id)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
// old bot, should deprecated
|
|
15
22
|
let {error} = await store.startConvo({
|
|
16
23
|
initial_by: bot.id,
|
|
17
24
|
locale: common.getLocale(bot, sb.detectLang()),
|
|
@@ -59,6 +59,10 @@ export default function AgentsAvatar(props) {
|
|
|
59
59
|
// 1 agent
|
|
60
60
|
if (agents.length === 1) {
|
|
61
61
|
var agent = agents[0]
|
|
62
|
+
|
|
63
|
+
let avatarurl =
|
|
64
|
+
agent.avatar_url || props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
|
|
65
|
+
|
|
62
66
|
var groupClass = mode === 'primary' ? 'group-avatar--agent-middle' : 'group-avatar--agent-left'
|
|
63
67
|
return (
|
|
64
68
|
<div class={`group-avatar group-avatar--${mode}`}>
|
|
@@ -67,13 +71,7 @@ export default function AgentsAvatar(props) {
|
|
|
67
71
|
data-tooltip={agent.fullname || acc.name}
|
|
68
72
|
data-tooltip-position={tooltippos}
|
|
69
73
|
>
|
|
70
|
-
<img
|
|
71
|
-
width={35}
|
|
72
|
-
height={35}
|
|
73
|
-
class={`avatar ${groupClass}`}
|
|
74
|
-
alt='agent avatar'
|
|
75
|
-
src={props.store.replaceFileUrl(agent.avatar_url) || require('../../assets/img/default_avatar.png')}
|
|
76
|
-
/>
|
|
74
|
+
<img width={35} height={35} class={`avatar ${groupClass}`} alt='agent avatar' src={avatarurl} />
|
|
77
75
|
</div>
|
|
78
76
|
</div>
|
|
79
77
|
)
|
|
@@ -95,7 +93,11 @@ export default function AgentsAvatar(props) {
|
|
|
95
93
|
height={35}
|
|
96
94
|
alt='agent avatar left'
|
|
97
95
|
class='avatar group-avatar--agent-left'
|
|
98
|
-
src={
|
|
96
|
+
src={
|
|
97
|
+
props.store.replaceFileUrl(leftAgent.avatar_url) ||
|
|
98
|
+
props.store.replaceFileUrl(acc.logo_url) ||
|
|
99
|
+
require('../../assets/img/image_default.png')
|
|
100
|
+
}
|
|
99
101
|
/>
|
|
100
102
|
</div>
|
|
101
103
|
<div
|
|
@@ -108,7 +110,11 @@ export default function AgentsAvatar(props) {
|
|
|
108
110
|
width={35}
|
|
109
111
|
height={35}
|
|
110
112
|
class='avatar group-avatar--agent-right'
|
|
111
|
-
src={
|
|
113
|
+
src={
|
|
114
|
+
props.store.replaceFileUrl(rightAgent.avatar_url) ||
|
|
115
|
+
props.store.replaceFileUrl(acc.logo_url) ||
|
|
116
|
+
require('../../assets/img/image_default.png')
|
|
117
|
+
}
|
|
112
118
|
/>
|
|
113
119
|
</div>
|
|
114
120
|
</div>
|
|
@@ -132,7 +138,11 @@ export default function AgentsAvatar(props) {
|
|
|
132
138
|
height={35}
|
|
133
139
|
alt='agent avatar left'
|
|
134
140
|
class='avatar group-avatar--agent-left'
|
|
135
|
-
src={
|
|
141
|
+
src={
|
|
142
|
+
props.store.replaceFileUrl(leftAgent.avatar_url) ||
|
|
143
|
+
props.store.replaceFileUrl(acc.logo_url) ||
|
|
144
|
+
require('../../assets/img/image_default.png')
|
|
145
|
+
}
|
|
136
146
|
/>
|
|
137
147
|
</div>
|
|
138
148
|
<div
|
|
@@ -145,7 +155,11 @@ export default function AgentsAvatar(props) {
|
|
|
145
155
|
width={35}
|
|
146
156
|
height={35}
|
|
147
157
|
class='avatar group-avatar--agent-middle'
|
|
148
|
-
src={
|
|
158
|
+
src={
|
|
159
|
+
props.store.replaceFileUrl(middleAgent.avatar_url) ||
|
|
160
|
+
props.store.replaceFileUrl(acc.logo_url) ||
|
|
161
|
+
require('../../assets/img/image_default.png')
|
|
162
|
+
}
|
|
149
163
|
/>
|
|
150
164
|
</div>
|
|
151
165
|
<div
|
|
@@ -158,7 +172,11 @@ export default function AgentsAvatar(props) {
|
|
|
158
172
|
height={35}
|
|
159
173
|
alt='agent avatar right'
|
|
160
174
|
class='avatar group-avatar--agent-right'
|
|
161
|
-
src={
|
|
175
|
+
src={
|
|
176
|
+
props.store.replaceFileUrl(rightAgent.avatar_url) ||
|
|
177
|
+
props.store.replaceFileUrl(acc.logo_url) ||
|
|
178
|
+
require('../../assets/img/image_default.png')
|
|
179
|
+
}
|
|
162
180
|
/>
|
|
163
181
|
</div>
|
|
164
182
|
</div>
|