@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/compiled_src/bot.js
CHANGED
|
@@ -17,6 +17,15 @@ function _default(store) {
|
|
|
17
17
|
run = () => true;
|
|
18
18
|
let match = _index.default.checkRunConditions(bot.initiative_frequency, bot.conditions, store.matchLastBotRun(bot.id), store);
|
|
19
19
|
if (!match) return;
|
|
20
|
+
if (bot.id.startsWith('at')) {
|
|
21
|
+
if (!bot.welcome_message) return;
|
|
22
|
+
let {
|
|
23
|
+
error
|
|
24
|
+
} = await store.startLightConvo(bot.id, bot.welcome_message, common.getLocale(bot, _index.default.detectLang()));
|
|
25
|
+
if (error) return console.error(error);
|
|
26
|
+
store.logBotRun(bot.id);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
20
29
|
let {
|
|
21
30
|
error
|
|
22
31
|
} = await store.startConvo({
|
|
@@ -57,6 +57,7 @@ function AgentsAvatar(props) {
|
|
|
57
57
|
}
|
|
58
58
|
if (agents.length === 1) {
|
|
59
59
|
var agent = agents[0];
|
|
60
|
+
let avatarurl = agent.avatar_url || props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png');
|
|
60
61
|
var groupClass = mode === 'primary' ? 'group-avatar--agent-middle' : 'group-avatar--agent-left';
|
|
61
62
|
return (0, _preact.h)("div", {
|
|
62
63
|
class: `group-avatar group-avatar--${mode}`
|
|
@@ -69,7 +70,7 @@ function AgentsAvatar(props) {
|
|
|
69
70
|
height: 35,
|
|
70
71
|
class: `avatar ${groupClass}`,
|
|
71
72
|
alt: "agent avatar",
|
|
72
|
-
src:
|
|
73
|
+
src: avatarurl
|
|
73
74
|
})));
|
|
74
75
|
}
|
|
75
76
|
if (agents.length === 2) {
|
|
@@ -86,7 +87,7 @@ function AgentsAvatar(props) {
|
|
|
86
87
|
height: 35,
|
|
87
88
|
alt: "agent avatar left",
|
|
88
89
|
class: "avatar group-avatar--agent-left",
|
|
89
|
-
src: props.store.replaceFileUrl(leftAgent.avatar_url) || require('../../assets/img/
|
|
90
|
+
src: props.store.replaceFileUrl(leftAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
|
|
90
91
|
})), (0, _preact.h)("div", {
|
|
91
92
|
class: "d-inline-block pos-relative",
|
|
92
93
|
"data-tooltip": rightAgent.fullname || acc.name,
|
|
@@ -96,7 +97,7 @@ function AgentsAvatar(props) {
|
|
|
96
97
|
width: 35,
|
|
97
98
|
height: 35,
|
|
98
99
|
class: "avatar group-avatar--agent-right",
|
|
99
|
-
src: props.store.replaceFileUrl(rightAgent.avatar_url) || require('../../assets/img/
|
|
100
|
+
src: props.store.replaceFileUrl(rightAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
|
|
100
101
|
})));
|
|
101
102
|
}
|
|
102
103
|
let leftAgent = agents[0];
|
|
@@ -113,7 +114,7 @@ function AgentsAvatar(props) {
|
|
|
113
114
|
height: 35,
|
|
114
115
|
alt: "agent avatar left",
|
|
115
116
|
class: "avatar group-avatar--agent-left",
|
|
116
|
-
src: props.store.replaceFileUrl(leftAgent.avatar_url) || require('../../assets/img/
|
|
117
|
+
src: props.store.replaceFileUrl(leftAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
|
|
117
118
|
})), (0, _preact.h)("div", {
|
|
118
119
|
class: "d-inline-block pos-relative",
|
|
119
120
|
"data-tooltip": middleAgent.fullname || acc.name,
|
|
@@ -123,7 +124,7 @@ function AgentsAvatar(props) {
|
|
|
123
124
|
width: 35,
|
|
124
125
|
height: 35,
|
|
125
126
|
class: "avatar group-avatar--agent-middle",
|
|
126
|
-
src: props.store.replaceFileUrl(middleAgent.avatar_url) || require('../../assets/img/
|
|
127
|
+
src: props.store.replaceFileUrl(middleAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
|
|
127
128
|
})), (0, _preact.h)("div", {
|
|
128
129
|
class: "d-inline-block pos-relative",
|
|
129
130
|
"data-tooltip": rightAgent.fullname || acc.name,
|
|
@@ -133,6 +134,6 @@ function AgentsAvatar(props) {
|
|
|
133
134
|
height: 35,
|
|
134
135
|
alt: "agent avatar right",
|
|
135
136
|
class: "avatar group-avatar--agent-right",
|
|
136
|
-
src: props.store.replaceFileUrl(rightAgent.avatar_url) || require('../../assets/img/
|
|
137
|
+
src: props.store.replaceFileUrl(rightAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
|
|
137
138
|
})));
|
|
138
139
|
}
|
|
@@ -25,7 +25,7 @@ class ChatButton extends _common.Com {
|
|
|
25
25
|
this.props.store.onConvoEvent(this, ev => {
|
|
26
26
|
if (_index.default.get(ev, 'type') !== 'message_sent') return;
|
|
27
27
|
let bytype = _index.default.get(ev, 'by.type');
|
|
28
|
-
if (bytype !== 'system' && bytype !== 'agent') return;
|
|
28
|
+
if (bytype !== 'system' && bytype !== 'agent' && bytype !== 'bot') return;
|
|
29
29
|
let isquickreplies = false;
|
|
30
30
|
_index.default.map(_index.default.get(ev, 'data.message.attachments', []), att => {
|
|
31
31
|
if (!att) return;
|
|
@@ -94,18 +94,23 @@ class ChatButton extends _common.Com {
|
|
|
94
94
|
displayPreview: false
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
97
|
+
pickBestGreeting() {
|
|
98
|
+
let convoM = this.props.store.matchConvo('*');
|
|
99
|
+
let unseenConvo = _index.default.filter(convoM, convo => {
|
|
100
|
+
let seen = _index.default.isConvoSeen(convo, this.props.store.matchUser().id);
|
|
101
|
+
return !seen;
|
|
102
|
+
}).sort((a, b) => _index.default.get(b, 'last_message_sent.created', 0) - _index.default.get(a, 'last_message_sent.created', 0));
|
|
103
|
+
if (_index.default.size(unseenConvo) == 0) {
|
|
104
|
+
if (this.props.store.isMobile()) {
|
|
105
|
+
let accid = _index.default.get(this.props.plugin, 'chatbox.account_id', {});
|
|
106
|
+
if (accid === 'acqjeefqeaoiagyfprap') return;
|
|
107
|
+
}
|
|
108
|
+
let greeting = _index.default.get(this.props.plugin, 'chatbox.greeting', {});
|
|
109
|
+
let agentM = this.props.store.matchAgent('*');
|
|
110
|
+
let byid = greeting.agent_id;
|
|
111
|
+
if (!byid) byid = randomAgent(agentM).id;
|
|
112
|
+
let text = this.props.t.i18n(_index.default.get(greeting, 'greeting', {})) || greeting.message;
|
|
113
|
+
return {
|
|
109
114
|
by: {
|
|
110
115
|
id: byid,
|
|
111
116
|
type: 'agent'
|
|
@@ -116,7 +121,13 @@ class ChatButton extends _common.Com {
|
|
|
116
121
|
format: 'plaintext'
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
|
-
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return unseenConvo[0].last_message_sent;
|
|
127
|
+
}
|
|
128
|
+
ShowGreeting() {
|
|
129
|
+
this.setState({
|
|
130
|
+
previewEvent: this.pickBestGreeting(),
|
|
120
131
|
displayPreview: true
|
|
121
132
|
});
|
|
122
133
|
}
|
|
@@ -182,7 +193,7 @@ class ChatButton extends _common.Com {
|
|
|
182
193
|
if (!agent) agent = this.props.store.matchAgent('*')[byid] || {};
|
|
183
194
|
agent = _index.default.cloneDeep(agent);
|
|
184
195
|
agent.fullname = agent.fullname || _index.default.get(account, 'name') || this.props.t('agent');
|
|
185
|
-
agent.avatar_url = agent.avatar_url ||
|
|
196
|
+
agent.avatar_url = agent.avatar_url || account.logo_url || require('../../assets/img/image_default.png');
|
|
186
197
|
let position = _index.default.get(accountSetting, 'desktop_button.position') || 'right';
|
|
187
198
|
if (this.props.store.isMobile()) {
|
|
188
199
|
position = _index.default.get(accountSetting, 'mobile_button.position') || position;
|
|
@@ -56,6 +56,47 @@ class Widget extends _common.Com {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
let text = message.text;
|
|
59
|
+
if (this.props.cid && this.props.cid.startsWith('cslight')) {
|
|
60
|
+
let cid = this.props.cid;
|
|
61
|
+
this._creating = (this._creating || 0) + 1;
|
|
62
|
+
let _creating = this._creating;
|
|
63
|
+
this.setState({
|
|
64
|
+
creating: true
|
|
65
|
+
});
|
|
66
|
+
let botid = cid.split('_')[0].slice(7);
|
|
67
|
+
const {
|
|
68
|
+
convo,
|
|
69
|
+
error
|
|
70
|
+
} = await this.props.store.startConvo({
|
|
71
|
+
locale: this.props.t.locale(),
|
|
72
|
+
message: text,
|
|
73
|
+
members: [{
|
|
74
|
+
type: 'bot',
|
|
75
|
+
id: botid
|
|
76
|
+
}],
|
|
77
|
+
initial_by: this.props.store.matchUser().id
|
|
78
|
+
});
|
|
79
|
+
if (_creating != this._creating) return;
|
|
80
|
+
if (error) {
|
|
81
|
+
this.setState({
|
|
82
|
+
creating: false
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.props.store.deleteLightConvo(cid);
|
|
87
|
+
await this.props.store.sendConvoEvent(convo.id, 'message_sent', {
|
|
88
|
+
message
|
|
89
|
+
});
|
|
90
|
+
if (_creating != this._creating) return;
|
|
91
|
+
this.props.onGo({
|
|
92
|
+
view: 'chat',
|
|
93
|
+
cid: convo.id
|
|
94
|
+
});
|
|
95
|
+
this.setState({
|
|
96
|
+
creating: false
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
59
100
|
if (!this.props.cid) {
|
|
60
101
|
this._creating = (this._creating || 0) + 1;
|
|
61
102
|
let _creating = this._creating;
|
package/compiled_src/store/kv.js
CHANGED
|
@@ -27,7 +27,6 @@ class _default {
|
|
|
27
27
|
init() {
|
|
28
28
|
if (this.initialized) return;
|
|
29
29
|
let inmemItemM = {};
|
|
30
|
-
console.time('KV' + this.name);
|
|
31
30
|
let allitems = this.db.all('items');
|
|
32
31
|
allitems.forEach(function (item) {
|
|
33
32
|
inmemItemM[item.key] = item.value;
|
|
@@ -47,7 +46,6 @@ class _default {
|
|
|
47
46
|
this.db.removes('items', [removekeys]);
|
|
48
47
|
}
|
|
49
48
|
this.initialized = true;
|
|
50
|
-
console.timeEnd('KV' + this.name);
|
|
51
49
|
}
|
|
52
50
|
all() {
|
|
53
51
|
if (this.dead) return [];
|
|
@@ -61,12 +61,15 @@ class Store {
|
|
|
61
61
|
if (!id) return;
|
|
62
62
|
if (id === '*') {
|
|
63
63
|
this._touchAcc();
|
|
64
|
-
return _index.default.filter(this.cache.all(), (value, k) => k.startsWith('convo_'));
|
|
64
|
+
return _index.default.filter(this.cache.all(), (value, k) => k.startsWith('convo_')).concat(_index.default.map(this.lightConvos));
|
|
65
65
|
}
|
|
66
|
+
if (id.startsWith('cslight')) return this.lightConvos[id];
|
|
66
67
|
if (!this.isInsync(id)) this.fetchConvo(id);
|
|
67
68
|
return this.cache.match('convo_' + id);
|
|
68
69
|
});
|
|
69
70
|
_defineProperty(this, "fetchConvo", async cid => {
|
|
71
|
+
if (!cid) return;
|
|
72
|
+
if (cid.startsWith('cslight')) return;
|
|
70
73
|
if (this._die) return dieErr;
|
|
71
74
|
await this.readyGate.entry();
|
|
72
75
|
await this.reconnectGate.entry(undefined, true);
|
|
@@ -85,9 +88,12 @@ class Store {
|
|
|
85
88
|
_defineProperty(this, "outofmsgM", {});
|
|
86
89
|
_defineProperty(this, "listEvents", id => {
|
|
87
90
|
if (!id || id === '*' || typeof id !== 'string') return;
|
|
91
|
+
if (id.startsWith('cslight')) return _index.default.get(this.lightConvos, [id, 'events'], []);
|
|
88
92
|
return this.chain.listM(id);
|
|
89
93
|
});
|
|
90
94
|
_defineProperty(this, "fetchMoreEvents", async convoid => {
|
|
95
|
+
if (!convoid) return;
|
|
96
|
+
if (convoid.startsWith('cslight')) return [[], ''];
|
|
91
97
|
if (!this.isInsync('events' + convoid)) {
|
|
92
98
|
await this.readyGate.entry();
|
|
93
99
|
await this.reconnectGate.entry(undefined, true);
|
|
@@ -199,6 +205,7 @@ class Store {
|
|
|
199
205
|
this.FileURL = FileURL;
|
|
200
206
|
this._track_page_view = true;
|
|
201
207
|
this.device_type = 'desktop';
|
|
208
|
+
this.lightConvos = {};
|
|
202
209
|
if (this.fake) this.api = new _api_fake.default(ApiURL, FileURL);else this.api = new _api.default(ApiURL, FileURL);
|
|
203
210
|
if (!inmem) {
|
|
204
211
|
try {
|
|
@@ -219,9 +226,9 @@ class Store {
|
|
|
219
226
|
this.chain = new _chain.default(new _lsdb.default('cbz2023', true), 'ch');
|
|
220
227
|
this.getLocaleContent = this.api.getLocaleContent;
|
|
221
228
|
this.g_haveSentSeenM = {};
|
|
222
|
-
this.last_focused =
|
|
229
|
+
this.last_focused = this.now();
|
|
223
230
|
window.addEventListener('blur', () => {
|
|
224
|
-
this.last_focused =
|
|
231
|
+
this.last_focused = this.now();
|
|
225
232
|
this.sendPresence();
|
|
226
233
|
});
|
|
227
234
|
window.addEventListener('focus', () => {
|
|
@@ -243,7 +250,7 @@ class Store {
|
|
|
243
250
|
this._presenceInterval2 = _index.default.setInterval(() => {
|
|
244
251
|
if (this._die) return _index.default.clearInterval(this._presenceInterval2);
|
|
245
252
|
if (this.browserVisibility === 'visible' && document.hasFocus()) return;
|
|
246
|
-
if (this.last_focused &&
|
|
253
|
+
if (this.last_focused && this.now() - this.last_focused > 30 * 60000) {
|
|
247
254
|
return;
|
|
248
255
|
}
|
|
249
256
|
this.sendPresence();
|
|
@@ -470,6 +477,7 @@ class Store {
|
|
|
470
477
|
await this.reconnectWs(accid, user.id);
|
|
471
478
|
this.reconnect();
|
|
472
479
|
});
|
|
480
|
+
this.lightConvos = this.kv.match('light_convos') || {};
|
|
473
481
|
this.seenLoop();
|
|
474
482
|
await this.reconnect({
|
|
475
483
|
user: user
|
|
@@ -528,9 +536,8 @@ class Store {
|
|
|
528
536
|
if (!lastmsgsent) return;
|
|
529
537
|
if (this.g_haveSentSeenM[lastmsgsent.id]) return;
|
|
530
538
|
if (lastmsgsent.id === lastmsgsent.data.message.idempotency_key) return;
|
|
531
|
-
this.api.markAsSeen(id, lastmsgsent.id);
|
|
532
539
|
this.pubsub.publish('events', {
|
|
533
|
-
created:
|
|
540
|
+
created: this.now(),
|
|
534
541
|
type: 'message_pong',
|
|
535
542
|
by: {
|
|
536
543
|
type: 'user'
|
|
@@ -541,14 +548,25 @@ class Store {
|
|
|
541
548
|
id: '*',
|
|
542
549
|
pongs: [{
|
|
543
550
|
type: 'seen',
|
|
544
|
-
created:
|
|
551
|
+
created: this.now()
|
|
545
552
|
}]
|
|
546
553
|
}
|
|
547
554
|
}
|
|
548
555
|
});
|
|
556
|
+
if (id.startsWith('cslight')) {
|
|
557
|
+
let old = this.lightConvos[id];
|
|
558
|
+
let user = this.matchUser();
|
|
559
|
+
if (!old) return;
|
|
560
|
+
let mem = _index.default.find(old.members, mem => mem.type == 'user' && mem.id == user.id);
|
|
561
|
+
mem.seen_at = this.now();
|
|
562
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
563
|
+
this.g_haveSentSeenM[lastmsgsent.id] = true;
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
this.api.markAsSeen(id, lastmsgsent.id);
|
|
549
567
|
let convo = this.cache.match('convo_' + id) || {};
|
|
550
568
|
let mem = _index.default.find(convo.members, m => m.id === user.id);
|
|
551
|
-
if (mem) mem.seen_at =
|
|
569
|
+
if (mem) mem.seen_at = this.now();
|
|
552
570
|
this._setConvo(convo);
|
|
553
571
|
this.g_haveSentSeenM[lastmsgsent.id] = true;
|
|
554
572
|
});
|
|
@@ -704,7 +722,7 @@ class Store {
|
|
|
704
722
|
let cid = _index.default.convoOfEv(ev);
|
|
705
723
|
let convo;
|
|
706
724
|
let alreadyFetched = false;
|
|
707
|
-
if (cid) {
|
|
725
|
+
if (cid && !cid.startsWith('cslight')) {
|
|
708
726
|
convo = this.cache.match('convo_' + cid);
|
|
709
727
|
if (!convo || !convo.id) {
|
|
710
728
|
let {
|
|
@@ -717,6 +735,15 @@ class Store {
|
|
|
717
735
|
this._setConvo(convo);
|
|
718
736
|
}
|
|
719
737
|
}
|
|
738
|
+
if (cid.startsWith('cslight')) {
|
|
739
|
+
convo = this.lightConvos[cid];
|
|
740
|
+
if (!convo) return;
|
|
741
|
+
convo.events.push(ev);
|
|
742
|
+
convo.last_message_sent = ev;
|
|
743
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
744
|
+
this.pubsub.publish('events', ev);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
720
747
|
if (!convo) return;
|
|
721
748
|
this.pubsub.publish('events', ev);
|
|
722
749
|
if (ev.type === 'conversation_joined') {
|
|
@@ -813,8 +840,65 @@ class Store {
|
|
|
813
840
|
}
|
|
814
841
|
typing(cid) {
|
|
815
842
|
if (!cid) return;
|
|
843
|
+
if (cid.startsWith('cslight')) return;
|
|
816
844
|
this._typing(cid);
|
|
817
845
|
}
|
|
846
|
+
deleteLightConvo(id) {
|
|
847
|
+
delete this.lightConvos[id];
|
|
848
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
849
|
+
}
|
|
850
|
+
startLightConvo(botid, message, locale) {
|
|
851
|
+
let convoid = 'cslight' + botid + '_' + this.now();
|
|
852
|
+
let user = this.cache.match('user') || {};
|
|
853
|
+
let old = this.lightConvos[convoid];
|
|
854
|
+
if (old) return {
|
|
855
|
+
convo: old
|
|
856
|
+
};
|
|
857
|
+
let now = this.now();
|
|
858
|
+
let ev = {};
|
|
859
|
+
ev.created = now;
|
|
860
|
+
ev.event_time = now;
|
|
861
|
+
ev.id = 'evfake' + now;
|
|
862
|
+
ev.type = 'message_sent';
|
|
863
|
+
ev.by = {
|
|
864
|
+
id: botid,
|
|
865
|
+
type: 'bot'
|
|
866
|
+
};
|
|
867
|
+
ev.data = {
|
|
868
|
+
message: message
|
|
869
|
+
};
|
|
870
|
+
ev.data.message.conversation_id = convoid;
|
|
871
|
+
let newconvo = {
|
|
872
|
+
id: convoid,
|
|
873
|
+
locale: locale,
|
|
874
|
+
initial_by: botid,
|
|
875
|
+
created: now,
|
|
876
|
+
actived: now,
|
|
877
|
+
last_message_sent: ev,
|
|
878
|
+
members: [{
|
|
879
|
+
type: 'user',
|
|
880
|
+
id: user.id
|
|
881
|
+
}, {
|
|
882
|
+
type: 'bot',
|
|
883
|
+
id: botid,
|
|
884
|
+
membership: 'active'
|
|
885
|
+
}],
|
|
886
|
+
state: 'active',
|
|
887
|
+
touchpoint: {
|
|
888
|
+
id: convoid,
|
|
889
|
+
channel: 'subiz',
|
|
890
|
+
source: 'web'
|
|
891
|
+
},
|
|
892
|
+
traffic_source: 'direct',
|
|
893
|
+
events: [ev]
|
|
894
|
+
};
|
|
895
|
+
this.lightConvos[convoid] = newconvo;
|
|
896
|
+
this.kv.put('light_convos', this.lightConvos);
|
|
897
|
+
this.pubsub.publish('events', ev);
|
|
898
|
+
return {
|
|
899
|
+
convo: newconvo
|
|
900
|
+
};
|
|
901
|
+
}
|
|
818
902
|
async startConvo(req) {
|
|
819
903
|
if (!req) req = {};
|
|
820
904
|
await this.readyGate.entry();
|
|
@@ -840,9 +924,11 @@ class Store {
|
|
|
840
924
|
return this.api.lookupOrder(key);
|
|
841
925
|
}
|
|
842
926
|
createPostback(cid, postback) {
|
|
927
|
+
if (cid && cid.startsWith('cslight')) return;
|
|
843
928
|
return this.api.createPostback(cid, postback);
|
|
844
929
|
}
|
|
845
930
|
sendReaction(cid, ev) {
|
|
931
|
+
if (cid && cid.startsWith('cslight')) return;
|
|
846
932
|
return this.api.sendConvoEvent(cid, ev);
|
|
847
933
|
}
|
|
848
934
|
async sendConvoEvent(cid, type, data) {
|
|
@@ -896,6 +982,7 @@ class Store {
|
|
|
896
982
|
att.url = url;
|
|
897
983
|
});
|
|
898
984
|
if (event._error) return this.onWs(event);
|
|
985
|
+
if (cid && cid.startsWith('cslight')) return;
|
|
899
986
|
let {
|
|
900
987
|
body: ret,
|
|
901
988
|
error
|
|
@@ -917,7 +1004,7 @@ class Store {
|
|
|
917
1004
|
first_interaction: 1
|
|
918
1005
|
});
|
|
919
1006
|
}
|
|
920
|
-
this.kv.put('last_msg_sent',
|
|
1007
|
+
this.kv.put('last_msg_sent', this.now());
|
|
921
1008
|
return ret;
|
|
922
1009
|
}
|
|
923
1010
|
_setConvo(convo) {
|
|
@@ -1002,6 +1089,7 @@ class Store {
|
|
|
1002
1089
|
}
|
|
1003
1090
|
async listmessageapi(type, anchor, limit) {
|
|
1004
1091
|
let convoid = type;
|
|
1092
|
+
if (convoid && convoid.startsWith('cslight')) return [fakeevents, '', undefined, true];
|
|
1005
1093
|
let {
|
|
1006
1094
|
body: events,
|
|
1007
1095
|
code,
|
|
@@ -1035,16 +1123,16 @@ class Store {
|
|
|
1035
1123
|
}
|
|
1036
1124
|
async loopTime() {
|
|
1037
1125
|
if (this._die) return;
|
|
1038
|
-
let startms =
|
|
1126
|
+
let startms = this.now();
|
|
1039
1127
|
if (!_index.default.get(this.cache.match('user'), 'id')) return _index.default.setTimeout(() => this.loopTime(), 240000);
|
|
1040
1128
|
let {
|
|
1041
1129
|
body: t,
|
|
1042
1130
|
error
|
|
1043
1131
|
} = await this.api.time();
|
|
1044
1132
|
if (error) return _index.default.setTimeout(() => this.loopTime(), 30000);
|
|
1045
|
-
var latences = Math.abs(
|
|
1133
|
+
var latences = Math.abs(this.now() - startms) / 2;
|
|
1046
1134
|
var serverMs = new _index.default.Date(t).getTime() + latences;
|
|
1047
|
-
var localMs =
|
|
1135
|
+
var localMs = this.now();
|
|
1048
1136
|
this.timeDiff = Math.floor(serverMs - localMs);
|
|
1049
1137
|
_index.default.setTimeout(() => this.loopTime(), 240000);
|
|
1050
1138
|
}
|