@opencx/widget 2.4.4-rn.3 → 2.4.4
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/dist/basic.cjs +1 -1
- package/dist/basic.js +1 -1
- package/dist/core/client/chat.d.ts +1 -1
- package/dist/{index-BWogWLb5.js → index-B6Q20SQP.js} +2 -2
- package/dist/{index-BWogWLb5.js.map → index-B6Q20SQP.js.map} +1 -1
- package/dist/index-DAb3AX4O.cjs +18 -0
- package/dist/{index-D-1u4USy.cjs.map → index-DAb3AX4O.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -50
- package/dist/index.js.map +1 -1
- package/dist/package.json.d.ts +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist-embed/script.js +1 -1
- package/dist-embed/script.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-D-1u4USy.cjs +0 -18
package/dist/index.js
CHANGED
|
@@ -19,12 +19,12 @@ class C {
|
|
|
19
19
|
S(this, "emitLifecycle", (e, s) => {
|
|
20
20
|
const o = this.lifecycleListeners.get(e);
|
|
21
21
|
if (o) {
|
|
22
|
-
const
|
|
22
|
+
const m = {
|
|
23
23
|
type: e,
|
|
24
24
|
timestamp: Date.now(),
|
|
25
25
|
data: s
|
|
26
26
|
};
|
|
27
|
-
o.forEach((n) => n(
|
|
27
|
+
o.forEach((n) => n(m));
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
/**
|
|
@@ -202,7 +202,7 @@ function X(t, e, s) {
|
|
|
202
202
|
}));
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function m(i, l) {
|
|
206
206
|
return {
|
|
207
207
|
id: O(),
|
|
208
208
|
type: "FROM_USER",
|
|
@@ -249,24 +249,24 @@ function X(t, e, s) {
|
|
|
249
249
|
}
|
|
250
250
|
return {
|
|
251
251
|
fetchHistoryMessages: o,
|
|
252
|
-
addUserMessage:
|
|
252
|
+
addUserMessage: m,
|
|
253
253
|
addBotMessage: n,
|
|
254
254
|
addErrorMessage: a
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
function z(t, e, s, o,
|
|
257
|
+
function z(t, e, s, o, m, n) {
|
|
258
258
|
var U, N;
|
|
259
259
|
const a = (U = n.platform) == null ? void 0 : U.logger;
|
|
260
260
|
let i = null;
|
|
261
|
-
const l = (N = n.platform) == null ? void 0 : N.storage, c = `${
|
|
261
|
+
const l = (N = n.platform) == null ? void 0 : N.storage, c = `${m.getConfig().user.external_id}:${m.getConfig().token}:session`, r = n.config.getSettings().persistSession;
|
|
262
262
|
async function u() {
|
|
263
263
|
if (l)
|
|
264
264
|
try {
|
|
265
265
|
a == null || a.debug("Attempting to restore session from storage");
|
|
266
266
|
const d = await l.getItem(c);
|
|
267
267
|
if (d) {
|
|
268
|
-
const
|
|
269
|
-
a == null || a.info("Session restored from storage", { sessionId:
|
|
268
|
+
const f = JSON.parse(d);
|
|
269
|
+
a == null || a.info("Session restored from storage", { sessionId: f.id }), e.setState(f), await o.fetchHistoryMessages(f), g();
|
|
270
270
|
}
|
|
271
271
|
} catch (d) {
|
|
272
272
|
a == null || a.error("Error restoring session from storage:", d);
|
|
@@ -276,11 +276,11 @@ function z(t, e, s, o, f, n) {
|
|
|
276
276
|
l && (a == null || a.debug("Setting up session persistence"), e.subscribe(async (d) => {
|
|
277
277
|
try {
|
|
278
278
|
d ? (await l.setItem(c, JSON.stringify(d)), a == null || a.debug("Session persisted to storage", { sessionId: d.id })) : (await l.removeItem(c), a == null || a.debug("Session removed from storage"));
|
|
279
|
-
} catch (
|
|
280
|
-
a == null || a.error("Error persisting session:",
|
|
279
|
+
} catch (f) {
|
|
280
|
+
a == null || a.error("Error persisting session:", f), s.setStatePartial({
|
|
281
281
|
error: {
|
|
282
282
|
hasError: !0,
|
|
283
|
-
message:
|
|
283
|
+
message: f instanceof Error ? f.message : "Failed to persist session",
|
|
284
284
|
code: "SESSION_PERSISTENCE_FAILED"
|
|
285
285
|
}
|
|
286
286
|
});
|
|
@@ -293,10 +293,10 @@ function z(t, e, s, o, f, n) {
|
|
|
293
293
|
const d = [];
|
|
294
294
|
d.push(
|
|
295
295
|
setInterval(async () => {
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
296
|
+
const f = e.getState();
|
|
297
|
+
if (f != null && f.id)
|
|
298
298
|
try {
|
|
299
|
-
const w = await t.getSession(
|
|
299
|
+
const w = await t.getSession(f.id);
|
|
300
300
|
w && e.setState(w);
|
|
301
301
|
} catch (w) {
|
|
302
302
|
a == null || a.error("Error polling session:", w);
|
|
@@ -304,10 +304,10 @@ function z(t, e, s, o, f, n) {
|
|
|
304
304
|
}, k.SESSION)
|
|
305
305
|
), d.push(
|
|
306
306
|
setInterval(async () => {
|
|
307
|
-
const
|
|
308
|
-
if (
|
|
307
|
+
const f = e.getState();
|
|
308
|
+
if (f != null && f.id)
|
|
309
309
|
try {
|
|
310
|
-
await o.fetchHistoryMessages(
|
|
310
|
+
await o.fetchHistoryMessages(f);
|
|
311
311
|
} catch (w) {
|
|
312
312
|
a == null || a.error("Error polling messages:", w);
|
|
313
313
|
}
|
|
@@ -326,12 +326,12 @@ function z(t, e, s, o, f, n) {
|
|
|
326
326
|
return a == null || a.info("Session created successfully", { sessionId: d.id }), e.setState(d), g(), d;
|
|
327
327
|
} catch (d) {
|
|
328
328
|
a == null || a.error("Failed to create session:", d);
|
|
329
|
-
const
|
|
329
|
+
const f = {
|
|
330
330
|
hasError: !0,
|
|
331
331
|
message: d instanceof Error ? d.message : "Failed to create session",
|
|
332
332
|
code: "SESSION_CREATION_FAILED"
|
|
333
333
|
};
|
|
334
|
-
return s.setStatePartial({ error:
|
|
334
|
+
return s.setStatePartial({ error: f }), null;
|
|
335
335
|
} finally {
|
|
336
336
|
s.setStatePartial({
|
|
337
337
|
loading: { isLoading: !1, reason: null }
|
|
@@ -339,7 +339,7 @@ function z(t, e, s, o, f, n) {
|
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
async function I() {
|
|
342
|
-
var
|
|
342
|
+
var f;
|
|
343
343
|
const d = e.getState();
|
|
344
344
|
if (d != null && d.id)
|
|
345
345
|
try {
|
|
@@ -348,7 +348,7 @@ function z(t, e, s, o, f, n) {
|
|
|
348
348
|
keyboard: null,
|
|
349
349
|
loading: { isLoading: !1 },
|
|
350
350
|
error: { hasError: !1 }
|
|
351
|
-
}), (
|
|
351
|
+
}), (f = n.onSessionDestroy) == null || f.call(n);
|
|
352
352
|
} catch (w) {
|
|
353
353
|
console.error("Error clearing session:", w), s.setStatePartial({
|
|
354
354
|
error: {
|
|
@@ -359,19 +359,19 @@ function z(t, e, s, o, f, n) {
|
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
|
-
function T() {
|
|
362
|
+
function T(d = !1) {
|
|
363
363
|
try {
|
|
364
|
-
i && (i(), i = null), r && l && L(l) && l.removeItem(c), s.setState({
|
|
364
|
+
i && (i(), i = null), d && r && l && L(l) && l.removeItem(c), s.setState({
|
|
365
365
|
messages: [],
|
|
366
366
|
keyboard: null,
|
|
367
367
|
loading: { isLoading: !1 },
|
|
368
368
|
error: { hasError: !1 }
|
|
369
369
|
}), e.setState(null), s.clear(), e.clear();
|
|
370
|
-
} catch (
|
|
371
|
-
console.error("Error in cleanup:",
|
|
370
|
+
} catch (f) {
|
|
371
|
+
console.error("Error in cleanup:", f), s.setStatePartial({
|
|
372
372
|
error: {
|
|
373
373
|
hasError: !0,
|
|
374
|
-
message:
|
|
374
|
+
message: f instanceof Error ? f.message : "Failed to cleanup",
|
|
375
375
|
code: "SESSION_CLEAR_FAILED"
|
|
376
376
|
}
|
|
377
377
|
});
|
|
@@ -383,8 +383,8 @@ function z(t, e, s, o, f, n) {
|
|
|
383
383
|
async function q() {
|
|
384
384
|
const d = e.getState();
|
|
385
385
|
if (!(d != null && d.id)) return;
|
|
386
|
-
const
|
|
387
|
-
return
|
|
386
|
+
const f = await F(d.id);
|
|
387
|
+
return f && e.setState(f), f;
|
|
388
388
|
}
|
|
389
389
|
return r && L(l) && (u(), E()), {
|
|
390
390
|
createSession: p,
|
|
@@ -404,11 +404,11 @@ function oe(t) {
|
|
|
404
404
|
keyboard: null,
|
|
405
405
|
loading: { isLoading: !1 },
|
|
406
406
|
error: { hasError: !1 }
|
|
407
|
-
}), o = new C(null),
|
|
407
|
+
}), o = new C(null), m = X(t.api, s, e), n = z(
|
|
408
408
|
t.api,
|
|
409
409
|
o,
|
|
410
410
|
s,
|
|
411
|
-
|
|
411
|
+
m,
|
|
412
412
|
t.config,
|
|
413
413
|
t
|
|
414
414
|
);
|
|
@@ -426,7 +426,7 @@ function oe(t) {
|
|
|
426
426
|
loading: { isLoading: !0, reason: "sending_message_to_agent" },
|
|
427
427
|
error: { hasError: !1 }
|
|
428
428
|
});
|
|
429
|
-
const u =
|
|
429
|
+
const u = m.addUserMessage(l.content, l.attachments || void 0), E = s.getState().messages;
|
|
430
430
|
s.setStatePartial({
|
|
431
431
|
messages: [...E, u]
|
|
432
432
|
});
|
|
@@ -440,7 +440,7 @@ function oe(t) {
|
|
|
440
440
|
});
|
|
441
441
|
if (p.success) {
|
|
442
442
|
e == null || e.debug("Message sent successfully");
|
|
443
|
-
const I =
|
|
443
|
+
const I = m.addBotMessage(p);
|
|
444
444
|
if (I) {
|
|
445
445
|
const T = s.getState().messages;
|
|
446
446
|
s.setStatePartial({
|
|
@@ -449,7 +449,7 @@ function oe(t) {
|
|
|
449
449
|
}
|
|
450
450
|
} else {
|
|
451
451
|
e == null || e.warn("Message send failed", p.error);
|
|
452
|
-
const I =
|
|
452
|
+
const I = m.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"), T = s.getState().messages;
|
|
453
453
|
s.setStatePartial({
|
|
454
454
|
messages: [...T, I]
|
|
455
455
|
});
|
|
@@ -475,14 +475,14 @@ function oe(t) {
|
|
|
475
475
|
sendMessage: a,
|
|
476
476
|
createSession: n.createSession,
|
|
477
477
|
clearSession: n.clearSession,
|
|
478
|
-
cleanup: n.cleanup
|
|
478
|
+
cleanup: (l = !1) => n.cleanup(l)
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
481
|
function ie(t) {
|
|
482
482
|
const e = t.config.getConfig();
|
|
483
483
|
t.config.getConfig;
|
|
484
484
|
const s = `${e.token}:contact:${e.user.external_id}`, o = L(t.platform.storage) ? t.platform.storage : void 0;
|
|
485
|
-
let
|
|
485
|
+
let m = null;
|
|
486
486
|
o && A(
|
|
487
487
|
async () => {
|
|
488
488
|
const r = await o.getItem(s);
|
|
@@ -490,10 +490,10 @@ function ie(t) {
|
|
|
490
490
|
},
|
|
491
491
|
"Error loading contact from storage"
|
|
492
492
|
).then((r) => {
|
|
493
|
-
r.success && (
|
|
493
|
+
r.success && (m = r.result);
|
|
494
494
|
});
|
|
495
495
|
const n = new C({
|
|
496
|
-
contact:
|
|
496
|
+
contact: m,
|
|
497
497
|
loading: { isLoading: !1 },
|
|
498
498
|
error: { hasError: !1 }
|
|
499
499
|
});
|
|
@@ -643,7 +643,7 @@ const V = {
|
|
|
643
643
|
triggerOffset: "20px"
|
|
644
644
|
}, K = 1e3 * 3;
|
|
645
645
|
function ce(t) {
|
|
646
|
-
var s, o,
|
|
646
|
+
var s, o, m, n, a, i, l, c, r;
|
|
647
647
|
if (!t.token)
|
|
648
648
|
throw new Error("Token is required");
|
|
649
649
|
if (t.pollingInterval && t.pollingInterval < K)
|
|
@@ -659,7 +659,7 @@ function ce(t) {
|
|
|
659
659
|
bot: {
|
|
660
660
|
name: ((s = t.bot) == null ? void 0 : s.name) ?? "Bot",
|
|
661
661
|
avatarUrl: (o = t.bot) == null ? void 0 : o.avatarUrl,
|
|
662
|
-
id: ((
|
|
662
|
+
id: ((m = t.bot) == null ? void 0 : m.id) ?? null,
|
|
663
663
|
is_ai: ((n = t.bot) == null ? void 0 : n.is_ai) ?? !0
|
|
664
664
|
},
|
|
665
665
|
contactToken: t.contactToken,
|
|
@@ -697,7 +697,7 @@ function ce(t) {
|
|
|
697
697
|
};
|
|
698
698
|
}
|
|
699
699
|
function Y(t = {}) {
|
|
700
|
-
const e = [], s = [], o = [],
|
|
700
|
+
const e = [], s = [], o = [], m = async (n, a = {}) => {
|
|
701
701
|
let i = {
|
|
702
702
|
...t,
|
|
703
703
|
...a,
|
|
@@ -721,7 +721,7 @@ function Y(t = {}) {
|
|
|
721
721
|
throw c;
|
|
722
722
|
}
|
|
723
723
|
};
|
|
724
|
-
return
|
|
724
|
+
return m.interceptors = {
|
|
725
725
|
request: {
|
|
726
726
|
use: (n) => (e.push(n), e.length - 1),
|
|
727
727
|
eject: (n) => {
|
|
@@ -734,7 +734,7 @@ function Y(t = {}) {
|
|
|
734
734
|
s.splice(n, 1), o.splice(n, 1);
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
|
-
},
|
|
737
|
+
}, m;
|
|
738
738
|
}
|
|
739
739
|
var b;
|
|
740
740
|
class le {
|
|
@@ -746,15 +746,15 @@ class le {
|
|
|
746
746
|
value: ""
|
|
747
747
|
};
|
|
748
748
|
s != null && s.email ? (o.claim = "email", o.value = s.email) : s != null && s.phone && (o.claim = "phone", o.value = s.phone);
|
|
749
|
-
const
|
|
749
|
+
const m = {
|
|
750
750
|
"X-Bot-Token": this.options.config.token,
|
|
751
751
|
"X-Consumer-Id": `${o.claim}:${o.value}`,
|
|
752
752
|
"Content-Type": "application/json",
|
|
753
753
|
Accept: "application/json"
|
|
754
754
|
};
|
|
755
|
-
this.options.config.contactToken && (
|
|
755
|
+
this.options.config.contactToken && (m.Authorization = `Bearer ${this.options.config.contactToken}`), _(this, b, Y({
|
|
756
756
|
baseURL: `${this.options.config.apiUrl}/widget/v2`,
|
|
757
|
-
headers:
|
|
757
|
+
headers: m
|
|
758
758
|
}));
|
|
759
759
|
}
|
|
760
760
|
async me() {
|
|
@@ -772,8 +772,8 @@ class le {
|
|
|
772
772
|
async getSessionHistory(e, s) {
|
|
773
773
|
const o = new URLSearchParams({
|
|
774
774
|
lastMessageTimestamp: s || ""
|
|
775
|
-
}),
|
|
776
|
-
return (await h(this, b).call(this,
|
|
775
|
+
}), m = `/session/history/${e}?${o.toString()}`;
|
|
776
|
+
return (await h(this, b).call(this, m, {
|
|
777
777
|
method: "GET"
|
|
778
778
|
})).json();
|
|
779
779
|
}
|
|
@@ -795,7 +795,7 @@ function ue(t = {}) {
|
|
|
795
795
|
prefix: s = "[openCx]",
|
|
796
796
|
enabled: o = !0
|
|
797
797
|
} = t;
|
|
798
|
-
let
|
|
798
|
+
let m = e;
|
|
799
799
|
const n = {
|
|
800
800
|
debug: 0,
|
|
801
801
|
info: 1,
|
|
@@ -803,7 +803,7 @@ function ue(t = {}) {
|
|
|
803
803
|
error: 3
|
|
804
804
|
};
|
|
805
805
|
function a(c) {
|
|
806
|
-
return o && n[c] >= n[
|
|
806
|
+
return o && n[c] >= n[m];
|
|
807
807
|
}
|
|
808
808
|
function i(c) {
|
|
809
809
|
return `${s} ${c}`;
|
|
@@ -839,7 +839,7 @@ function ue(t = {}) {
|
|
|
839
839
|
a("error") && console.error(i(c), ...l(r));
|
|
840
840
|
},
|
|
841
841
|
setLevel(c) {
|
|
842
|
-
|
|
842
|
+
m = c;
|
|
843
843
|
}
|
|
844
844
|
};
|
|
845
845
|
}
|