@opencx/widget 2.4.4-rn.2 → 2.4.4-rn.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-B-VyJuQ9.js → index-B09TSjhG.js} +2 -2
- package/dist/{index-B-VyJuQ9.js.map → index-B09TSjhG.js.map} +1 -1
- package/dist/{index-D2PGs8oF.cjs → index-DXhwJWO6.cjs} +2 -2
- package/dist/{index-D2PGs8oF.cjs.map → index-DXhwJWO6.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -53
- 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/package.json +1 -1
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
|
);
|
|
@@ -417,16 +417,16 @@ function oe(t) {
|
|
|
417
417
|
let c = o.getState();
|
|
418
418
|
if (!(c != null && c.id) && (e == null || e.debug("No active session, creating new session"), c = await n.createSession(), !c))
|
|
419
419
|
return !1;
|
|
420
|
-
c.assignee.kind === "ai" && (c = await n.refetchSession()
|
|
420
|
+
c.assignee.kind === "ai" && (c = await n.refetchSession() ?? c);
|
|
421
421
|
try {
|
|
422
422
|
e == null || e.debug("Sending message", { sessionId: c.id }), c.assignee.kind === "ai" ? s.setStatePartial({
|
|
423
|
-
loading: { isLoading: !0, reason: "
|
|
423
|
+
loading: { isLoading: !0, reason: "sending_message_to_bot" },
|
|
424
424
|
error: { hasError: !1 }
|
|
425
425
|
}) : s.setStatePartial({
|
|
426
|
-
loading: { isLoading: !0, reason: "
|
|
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
|
});
|
|
@@ -435,11 +435,12 @@ function oe(t) {
|
|
|
435
435
|
headers: g.headers,
|
|
436
436
|
query_params: g.queryParams,
|
|
437
437
|
session_id: c.id,
|
|
438
|
+
user: g.user,
|
|
438
439
|
...l
|
|
439
440
|
});
|
|
440
441
|
if (p.success) {
|
|
441
442
|
e == null || e.debug("Message sent successfully");
|
|
442
|
-
const I =
|
|
443
|
+
const I = m.addBotMessage(p);
|
|
443
444
|
if (I) {
|
|
444
445
|
const T = s.getState().messages;
|
|
445
446
|
s.setStatePartial({
|
|
@@ -448,7 +449,7 @@ function oe(t) {
|
|
|
448
449
|
}
|
|
449
450
|
} else {
|
|
450
451
|
e == null || e.warn("Message send failed", p.error);
|
|
451
|
-
const I =
|
|
452
|
+
const I = m.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"), T = s.getState().messages;
|
|
452
453
|
s.setStatePartial({
|
|
453
454
|
messages: [...T, I]
|
|
454
455
|
});
|
|
@@ -474,14 +475,14 @@ function oe(t) {
|
|
|
474
475
|
sendMessage: a,
|
|
475
476
|
createSession: n.createSession,
|
|
476
477
|
clearSession: n.clearSession,
|
|
477
|
-
cleanup: n.cleanup
|
|
478
|
+
cleanup: (l = !1) => n.cleanup(l)
|
|
478
479
|
};
|
|
479
480
|
}
|
|
480
481
|
function ie(t) {
|
|
481
482
|
const e = t.config.getConfig();
|
|
482
483
|
t.config.getConfig;
|
|
483
484
|
const s = `${e.token}:contact:${e.user.external_id}`, o = L(t.platform.storage) ? t.platform.storage : void 0;
|
|
484
|
-
let
|
|
485
|
+
let m = null;
|
|
485
486
|
o && A(
|
|
486
487
|
async () => {
|
|
487
488
|
const r = await o.getItem(s);
|
|
@@ -489,10 +490,10 @@ function ie(t) {
|
|
|
489
490
|
},
|
|
490
491
|
"Error loading contact from storage"
|
|
491
492
|
).then((r) => {
|
|
492
|
-
r.success && (
|
|
493
|
+
r.success && (m = r.result);
|
|
493
494
|
});
|
|
494
495
|
const n = new C({
|
|
495
|
-
contact:
|
|
496
|
+
contact: m,
|
|
496
497
|
loading: { isLoading: !1 },
|
|
497
498
|
error: { hasError: !1 }
|
|
498
499
|
});
|
|
@@ -642,7 +643,7 @@ const V = {
|
|
|
642
643
|
triggerOffset: "20px"
|
|
643
644
|
}, K = 1e3 * 3;
|
|
644
645
|
function ce(t) {
|
|
645
|
-
var s, o,
|
|
646
|
+
var s, o, m, n, a, i, l, c, r;
|
|
646
647
|
if (!t.token)
|
|
647
648
|
throw new Error("Token is required");
|
|
648
649
|
if (t.pollingInterval && t.pollingInterval < K)
|
|
@@ -658,7 +659,7 @@ function ce(t) {
|
|
|
658
659
|
bot: {
|
|
659
660
|
name: ((s = t.bot) == null ? void 0 : s.name) ?? "Bot",
|
|
660
661
|
avatarUrl: (o = t.bot) == null ? void 0 : o.avatarUrl,
|
|
661
|
-
id: ((
|
|
662
|
+
id: ((m = t.bot) == null ? void 0 : m.id) ?? null,
|
|
662
663
|
is_ai: ((n = t.bot) == null ? void 0 : n.is_ai) ?? !0
|
|
663
664
|
},
|
|
664
665
|
contactToken: t.contactToken,
|
|
@@ -696,7 +697,7 @@ function ce(t) {
|
|
|
696
697
|
};
|
|
697
698
|
}
|
|
698
699
|
function Y(t = {}) {
|
|
699
|
-
const e = [], s = [], o = [],
|
|
700
|
+
const e = [], s = [], o = [], m = async (n, a = {}) => {
|
|
700
701
|
let i = {
|
|
701
702
|
...t,
|
|
702
703
|
...a,
|
|
@@ -720,7 +721,7 @@ function Y(t = {}) {
|
|
|
720
721
|
throw c;
|
|
721
722
|
}
|
|
722
723
|
};
|
|
723
|
-
return
|
|
724
|
+
return m.interceptors = {
|
|
724
725
|
request: {
|
|
725
726
|
use: (n) => (e.push(n), e.length - 1),
|
|
726
727
|
eject: (n) => {
|
|
@@ -733,7 +734,7 @@ function Y(t = {}) {
|
|
|
733
734
|
s.splice(n, 1), o.splice(n, 1);
|
|
734
735
|
}
|
|
735
736
|
}
|
|
736
|
-
},
|
|
737
|
+
}, m;
|
|
737
738
|
}
|
|
738
739
|
var b;
|
|
739
740
|
class le {
|
|
@@ -745,15 +746,15 @@ class le {
|
|
|
745
746
|
value: ""
|
|
746
747
|
};
|
|
747
748
|
s != null && s.email ? (o.claim = "email", o.value = s.email) : s != null && s.phone && (o.claim = "phone", o.value = s.phone);
|
|
748
|
-
const
|
|
749
|
+
const m = {
|
|
749
750
|
"X-Bot-Token": this.options.config.token,
|
|
750
751
|
"X-Consumer-Id": `${o.claim}:${o.value}`,
|
|
751
752
|
"Content-Type": "application/json",
|
|
752
753
|
Accept: "application/json"
|
|
753
754
|
};
|
|
754
|
-
this.options.config.contactToken && (
|
|
755
|
+
this.options.config.contactToken && (m.Authorization = `Bearer ${this.options.config.contactToken}`), _(this, b, Y({
|
|
755
756
|
baseURL: `${this.options.config.apiUrl}/widget/v2`,
|
|
756
|
-
headers:
|
|
757
|
+
headers: m
|
|
757
758
|
}));
|
|
758
759
|
}
|
|
759
760
|
async me() {
|
|
@@ -771,8 +772,8 @@ class le {
|
|
|
771
772
|
async getSessionHistory(e, s) {
|
|
772
773
|
const o = new URLSearchParams({
|
|
773
774
|
lastMessageTimestamp: s || ""
|
|
774
|
-
}),
|
|
775
|
-
return (await h(this, b).call(this,
|
|
775
|
+
}), m = `/session/history/${e}?${o.toString()}`;
|
|
776
|
+
return (await h(this, b).call(this, m, {
|
|
776
777
|
method: "GET"
|
|
777
778
|
})).json();
|
|
778
779
|
}
|
|
@@ -794,7 +795,7 @@ function ue(t = {}) {
|
|
|
794
795
|
prefix: s = "[openCx]",
|
|
795
796
|
enabled: o = !0
|
|
796
797
|
} = t;
|
|
797
|
-
let
|
|
798
|
+
let m = e;
|
|
798
799
|
const n = {
|
|
799
800
|
debug: 0,
|
|
800
801
|
info: 1,
|
|
@@ -802,7 +803,7 @@ function ue(t = {}) {
|
|
|
802
803
|
error: 3
|
|
803
804
|
};
|
|
804
805
|
function a(c) {
|
|
805
|
-
return o && n[c] >= n[
|
|
806
|
+
return o && n[c] >= n[m];
|
|
806
807
|
}
|
|
807
808
|
function i(c) {
|
|
808
809
|
return `${s} ${c}`;
|
|
@@ -838,7 +839,7 @@ function ue(t = {}) {
|
|
|
838
839
|
a("error") && console.error(i(c), ...l(r));
|
|
839
840
|
},
|
|
840
841
|
setLevel(c) {
|
|
841
|
-
|
|
842
|
+
m = c;
|
|
842
843
|
}
|
|
843
844
|
};
|
|
844
845
|
}
|