@opencx/widget-core 4.0.9 → 4.0.10
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/__tests__/test-utils.d.ts +5 -0
- package/dist/api/api-caller.d.ts +5 -0
- package/dist/api/schema.d.ts +163 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +117 -99
- package/dist/index.js.map +1 -1
- package/dist/types/widget-config.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { v4 as
|
|
4
|
-
const
|
|
1
|
+
import _ from "openapi-fetch";
|
|
2
|
+
import B from "lodash.isequal";
|
|
3
|
+
import { v4 as O } from "uuid";
|
|
4
|
+
const L = (d) => {
|
|
5
5
|
console.log(d.error);
|
|
6
|
-
},
|
|
7
|
-
const n =
|
|
6
|
+
}, $ = (d) => {
|
|
7
|
+
const n = _({
|
|
8
8
|
baseUrl: d.baseUrl
|
|
9
9
|
}), o = {
|
|
10
10
|
onRequest: d.onRequest,
|
|
11
11
|
onResponse: d.onResponse,
|
|
12
|
-
onError: d.onError ||
|
|
12
|
+
onError: d.onError || L
|
|
13
13
|
};
|
|
14
14
|
return n.use(o), n;
|
|
15
15
|
};
|
|
16
|
-
class
|
|
16
|
+
class M {
|
|
17
17
|
constructor({ config: n }) {
|
|
18
18
|
var g, e;
|
|
19
19
|
this.userToken = null, this.constructClientOptions = (t) => {
|
|
@@ -27,7 +27,7 @@ class T {
|
|
|
27
27
|
}, this.createOpenAPIClient = ({
|
|
28
28
|
baseUrl: t,
|
|
29
29
|
headers: s
|
|
30
|
-
}) =>
|
|
30
|
+
}) => $({
|
|
31
31
|
baseUrl: t,
|
|
32
32
|
onRequest: ({ request: i }) => {
|
|
33
33
|
Object.entries(s).forEach(([r, a]) => {
|
|
@@ -75,7 +75,7 @@ class T {
|
|
|
75
75
|
abortSignal: s,
|
|
76
76
|
onProgress: i
|
|
77
77
|
}) => new Promise((r, a) => {
|
|
78
|
-
var
|
|
78
|
+
var b;
|
|
79
79
|
const h = new FormData();
|
|
80
80
|
h.append("file", t);
|
|
81
81
|
const l = new XMLHttpRequest();
|
|
@@ -85,18 +85,18 @@ class T {
|
|
|
85
85
|
a(new DOMException("Aborted", "AbortError"));
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
l.upload.addEventListener("progress", (
|
|
89
|
-
if (
|
|
90
|
-
const
|
|
91
|
-
i(
|
|
88
|
+
l.upload.addEventListener("progress", (f) => {
|
|
89
|
+
if (f.lengthComputable && i) {
|
|
90
|
+
const S = Math.round(f.loaded / f.total * 100);
|
|
91
|
+
i(S);
|
|
92
92
|
}
|
|
93
93
|
}), l.addEventListener("load", () => {
|
|
94
94
|
if (l.status >= 200 && l.status < 300)
|
|
95
95
|
try {
|
|
96
|
-
const
|
|
97
|
-
r(
|
|
98
|
-
} catch (
|
|
99
|
-
a(new Error(`Failed to parse response: ${
|
|
96
|
+
const f = JSON.parse(l.responseText);
|
|
97
|
+
r(f);
|
|
98
|
+
} catch (f) {
|
|
99
|
+
a(new Error(`Failed to parse response: ${f}`));
|
|
100
100
|
}
|
|
101
101
|
else
|
|
102
102
|
a(new Error(`Upload failed with status: ${l.status}`));
|
|
@@ -105,8 +105,8 @@ class T {
|
|
|
105
105
|
}), l.addEventListener("timeout", () => {
|
|
106
106
|
a(new Error("Upload timed out"));
|
|
107
107
|
});
|
|
108
|
-
const { baseUrl:
|
|
109
|
-
l.open("POST",
|
|
108
|
+
const { baseUrl: p } = this.constructClientOptions(this.userToken), m = `${p}/backend/widget/v2/upload`;
|
|
109
|
+
l.open("POST", m), l.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((b = this.config.user) == null ? void 0 : b.token) ? l.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), l.send(h);
|
|
110
110
|
}), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.resolveSession = async (t, s) => await this.client.POST("/backend/widget/v2/session/resolve", {
|
|
111
111
|
body: t,
|
|
112
112
|
signal: s
|
|
@@ -122,7 +122,7 @@ class T {
|
|
|
122
122
|
class P {
|
|
123
123
|
constructor(n) {
|
|
124
124
|
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (o) => {
|
|
125
|
-
|
|
125
|
+
B(this.state, o) || (this.state = o, this.notifySubscribers(o));
|
|
126
126
|
}, this.setPartial = (o) => {
|
|
127
127
|
if (o == null) return;
|
|
128
128
|
const c = { ...this.state, ...o };
|
|
@@ -142,7 +142,7 @@ class P {
|
|
|
142
142
|
}), this.state = n, this.initialState = n;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
class
|
|
145
|
+
class F {
|
|
146
146
|
constructor() {
|
|
147
147
|
this.state = new P({
|
|
148
148
|
isPolling: !1,
|
|
@@ -171,7 +171,7 @@ class R {
|
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function q(d) {
|
|
175
175
|
try {
|
|
176
176
|
const n = d();
|
|
177
177
|
return n instanceof Promise ? n.then((o) => ({ data: o })).catch((o) => ({ error: o })) : { data: n };
|
|
@@ -179,7 +179,7 @@ function _(d) {
|
|
|
179
179
|
return { error: n };
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
class
|
|
182
|
+
class N {
|
|
183
183
|
constructor({
|
|
184
184
|
api: n,
|
|
185
185
|
config: o,
|
|
@@ -187,7 +187,7 @@ class L {
|
|
|
187
187
|
messageCtx: g,
|
|
188
188
|
sessionPollingIntervalSeconds: e
|
|
189
189
|
}) {
|
|
190
|
-
this.poller = new
|
|
190
|
+
this.poller = new F(), this.registerPolling = () => {
|
|
191
191
|
this.sessionCtx.sessionState.subscribe(({ session: t }) => {
|
|
192
192
|
t != null && t.id ? this.poller.startPolling(async (s) => {
|
|
193
193
|
this.hackAndSlash(t.id, s);
|
|
@@ -202,11 +202,11 @@ class L {
|
|
|
202
202
|
lastMessageTimestamp: r
|
|
203
203
|
});
|
|
204
204
|
if (a != null && a.session && (this.sessionCtx.sessionState.setPartial({ session: a.session }), this.sessionCtx.setSessions([a.session])), a != null && a.history && a.history.length > 0) {
|
|
205
|
-
const l = this.messageCtx.state.get().messages,
|
|
206
|
-
(
|
|
205
|
+
const l = this.messageCtx.state.get().messages, p = a.history.map(this.mapHistoryToMessage).filter(
|
|
206
|
+
(v) => !l.some((m) => m.id === v.id)
|
|
207
207
|
);
|
|
208
208
|
this.messageCtx.state.setPartial({
|
|
209
|
-
messages: [...l, ...
|
|
209
|
+
messages: [...l, ...p]
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
|
|
@@ -262,14 +262,14 @@ class L {
|
|
|
262
262
|
const s = t.result;
|
|
263
263
|
if (s === null || typeof s != "object") return s;
|
|
264
264
|
if ("responseBodyText" in s && typeof s.responseBodyText == "string") {
|
|
265
|
-
const i = s.responseBodyText, r =
|
|
265
|
+
const i = s.responseBodyText, r = q(() => JSON.parse(i)).data;
|
|
266
266
|
if (r) return r;
|
|
267
267
|
}
|
|
268
268
|
return t.result;
|
|
269
269
|
}, this.api = n, this.config = o, this.sessionCtx = c, this.messageCtx = g, this.sessionPollingIntervalSeconds = e, this.registerPolling();
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
class
|
|
272
|
+
class H {
|
|
273
273
|
constructor({
|
|
274
274
|
config: n,
|
|
275
275
|
api: o,
|
|
@@ -280,26 +280,26 @@ class B {
|
|
|
280
280
|
var e;
|
|
281
281
|
return !!(!((e = this.state.get().contact) != null && e.token) && this.config.collectUserData);
|
|
282
282
|
}, this.autoCreateUnverifiedUserIfNotExists = async () => {
|
|
283
|
-
var e, t, s, i, r, a, h, l,
|
|
283
|
+
var e, t, s, i, r, a, h, l, p, v, m, w, b, f;
|
|
284
284
|
if (!((e = this.config.user) != null && e.token)) {
|
|
285
285
|
if (this.config.collectUserData && !((s = (t = this.config.user) == null ? void 0 : t.data) != null && s.email)) {
|
|
286
286
|
if ((i = this.config.extraDataCollectionFields) != null && i.length)
|
|
287
287
|
return;
|
|
288
|
-
const
|
|
289
|
-
|
|
288
|
+
const S = await ((r = this.storageCtx) == null ? void 0 : r.getContactToken());
|
|
289
|
+
S && await this.setUnverifiedContact(S);
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
292
|
if (!((h = (a = this.config.user) == null ? void 0 : a.data) != null && h.email)) {
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
295
|
-
await this.setUnverifiedContact(
|
|
293
|
+
const S = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
|
|
294
|
+
if (S) {
|
|
295
|
+
await this.setUnverifiedContact(S);
|
|
296
296
|
return;
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
await this.createUnverifiedContact({
|
|
300
|
-
email: (
|
|
301
|
-
non_verified_name: ((
|
|
302
|
-
non_verified_custom_data: (
|
|
300
|
+
email: (v = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : v.email,
|
|
301
|
+
non_verified_name: ((w = (m = this.config.user) == null ? void 0 : m.data) == null ? void 0 : w.name) || "Anonymous",
|
|
302
|
+
non_verified_custom_data: (f = (b = this.config.user) == null ? void 0 : b.data) == null ? void 0 : f.customData
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
}, this.createUnverifiedContact = async (e, t) => {
|
|
@@ -316,7 +316,7 @@ class B {
|
|
|
316
316
|
}
|
|
317
317
|
}, this.setUnverifiedContact = async (e) => {
|
|
318
318
|
var i, r, a, h;
|
|
319
|
-
const t = await ((i = this.storageCtx) == null ? void 0 : i.getExternalContactId()), s = ((r = this.config.user) == null ? void 0 : r.externalId) || t ||
|
|
319
|
+
const t = await ((i = this.storageCtx) == null ? void 0 : i.getExternalContactId()), s = ((r = this.config.user) == null ? void 0 : r.externalId) || t || O();
|
|
320
320
|
this.api.setAuthToken(e), await ((a = this.storageCtx) == null ? void 0 : a.setContactToken(e)), await ((h = this.storageCtx) == null ? void 0 : h.setExternalContactId(s)), this.state.setPartial({ contact: { token: e, externalId: s } });
|
|
321
321
|
}, this.config = n, this.storageCtx = c, this.api = o, this.state = new P({
|
|
322
322
|
contact: (g = n.user) != null && g.token ? {
|
|
@@ -330,17 +330,17 @@ class B {
|
|
|
330
330
|
}), this.autoCreateUnverifiedUserIfNotExists();
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
function
|
|
334
|
-
return
|
|
333
|
+
function k() {
|
|
334
|
+
return O();
|
|
335
335
|
}
|
|
336
|
-
class
|
|
336
|
+
class X {
|
|
337
337
|
constructor({
|
|
338
338
|
config: n,
|
|
339
339
|
api: o,
|
|
340
340
|
contactCtx: c,
|
|
341
341
|
sessionsPollingIntervalSeconds: g
|
|
342
342
|
}) {
|
|
343
|
-
this.sessionsRefresher = new
|
|
343
|
+
this.sessionsRefresher = new F(), this.sessionState = new P({
|
|
344
344
|
session: null,
|
|
345
345
|
isCreatingSession: !1,
|
|
346
346
|
isResolvingSession: !1
|
|
@@ -429,7 +429,7 @@ class $ {
|
|
|
429
429
|
}, this.config = n, this.api = o, this.contactCtx = c, this.sessionsPollingIntervalSeconds = g, this.registerSessionsRefresherWrapper();
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
class
|
|
432
|
+
class G {
|
|
433
433
|
constructor({
|
|
434
434
|
config: n,
|
|
435
435
|
api: o,
|
|
@@ -444,7 +444,7 @@ class q {
|
|
|
444
444
|
}), this.sendMessageAbortController = new AbortController(), this.reset = () => {
|
|
445
445
|
this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
|
|
446
446
|
}, this.sendMessage = async (e) => {
|
|
447
|
-
var t, s, i, r, a, h, l,
|
|
447
|
+
var t, s, i, r, a, h, l, p, v, m;
|
|
448
448
|
try {
|
|
449
449
|
if (!e.content.trim() && (!e.attachments || e.attachments.length === 0)) {
|
|
450
450
|
console.warn(
|
|
@@ -452,37 +452,51 @@ class q {
|
|
|
452
452
|
);
|
|
453
453
|
return;
|
|
454
454
|
}
|
|
455
|
-
const
|
|
456
|
-
if (
|
|
457
|
-
|
|
455
|
+
const w = this.state.get().isSendingMessage, b = ((t = this.sessionCtx.sessionState.get().session) == null ? void 0 : t.assignee.kind) === "ai", f = this.state.get().messages, S = f.length > 0 ? f[f.length - 1] : void 0;
|
|
456
|
+
if (b && w || // If last message is from user, then bot response did not arrive yet
|
|
457
|
+
b && (S == null ? void 0 : S.type) === "FROM_USER") {
|
|
458
458
|
console.warn("Cannot send messages while awaiting AI response");
|
|
459
459
|
return;
|
|
460
460
|
}
|
|
461
461
|
this.sendMessageAbortController = new AbortController(), this.state.setPartial({ lastAIResMightSolveUserIssue: !1 }), this.state.setPartial({ isSendingMessage: !0 });
|
|
462
|
-
const u = this.
|
|
462
|
+
const T = this.state.get().messages, E = !((s = this.sessionCtx.sessionState.get().session) != null && s.id) && T.length === 0 && ((i = this.config.advancedInitialMessages) == null ? void 0 : i.some((u) => u.persistent)), R = E ? (this.config.advancedInitialMessages || []).filter((u) => u.persistent).map(
|
|
463
|
+
(u) => ({
|
|
464
|
+
id: k(),
|
|
465
|
+
component: "bot_message",
|
|
466
|
+
type: "FROM_BOT",
|
|
467
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
468
|
+
data: {
|
|
469
|
+
message: u.message
|
|
470
|
+
}
|
|
471
|
+
})
|
|
472
|
+
) : [], y = this.toUserMessage(
|
|
463
473
|
e.content.trim(),
|
|
464
474
|
e.attachments || void 0
|
|
465
|
-
)
|
|
475
|
+
);
|
|
466
476
|
if (this.state.setPartial({
|
|
467
|
-
messages: [
|
|
468
|
-
|
|
477
|
+
messages: [
|
|
478
|
+
...R,
|
|
479
|
+
...T,
|
|
480
|
+
y
|
|
481
|
+
]
|
|
482
|
+
}), !((r = this.sessionCtx.sessionState.get().session) != null && r.id)) {
|
|
469
483
|
if (!await this.sessionCtx.createSession()) {
|
|
470
484
|
console.error("Failed to create session");
|
|
471
485
|
return;
|
|
472
486
|
}
|
|
473
487
|
this.sessionCtx.refreshSessions();
|
|
474
488
|
}
|
|
475
|
-
const
|
|
476
|
-
if (!
|
|
477
|
-
const { data:
|
|
489
|
+
const U = (a = this.sessionCtx.sessionState.get().session) == null ? void 0 : a.id;
|
|
490
|
+
if (!U) return;
|
|
491
|
+
const { data: C } = await this.api.sendMessage(
|
|
478
492
|
{
|
|
479
|
-
uuid:
|
|
493
|
+
uuid: y.id,
|
|
480
494
|
bot_token: this.config.token,
|
|
481
495
|
headers: this.config.headers,
|
|
482
496
|
query_params: this.config.queryParams,
|
|
483
497
|
body_properties: this.config.bodyProperties,
|
|
484
|
-
session_id:
|
|
485
|
-
content:
|
|
498
|
+
session_id: U,
|
|
499
|
+
content: y.content,
|
|
486
500
|
attachments: e.attachments,
|
|
487
501
|
clientContext: this.config.context,
|
|
488
502
|
custom_data: {
|
|
@@ -490,38 +504,42 @@ class q {
|
|
|
490
504
|
...e.customData || {}
|
|
491
505
|
},
|
|
492
506
|
language: this.config.language,
|
|
493
|
-
exit_mode_prompt: e.exitModePrompt
|
|
507
|
+
exit_mode_prompt: e.exitModePrompt,
|
|
508
|
+
initial_messages: E ? R.map((u) => ({
|
|
509
|
+
uuid: u.id,
|
|
510
|
+
content: u.data.message
|
|
511
|
+
})) : void 0
|
|
494
512
|
},
|
|
495
513
|
this.sendMessageAbortController.signal
|
|
496
514
|
);
|
|
497
|
-
if (
|
|
498
|
-
const
|
|
499
|
-
if (
|
|
500
|
-
const
|
|
501
|
-
if (!!
|
|
502
|
-
(
|
|
515
|
+
if (C != null && C.success) {
|
|
516
|
+
const u = this.toBotMessage(C);
|
|
517
|
+
if (u) {
|
|
518
|
+
const I = this.state.get().messages;
|
|
519
|
+
if (!!I.some(
|
|
520
|
+
(D) => D.id === u.id
|
|
503
521
|
)) {
|
|
504
522
|
this.state.setPartial({
|
|
505
|
-
lastAIResMightSolveUserIssue: ((
|
|
523
|
+
lastAIResMightSolveUserIssue: ((h = C.autopilotResponse) == null ? void 0 : h.mightSolveUserIssue) || ((l = C.uiResponse) == null ? void 0 : l.mightSolveUserIssue)
|
|
506
524
|
});
|
|
507
525
|
return;
|
|
508
526
|
}
|
|
509
527
|
this.state.setPartial({
|
|
510
|
-
messages: [...
|
|
511
|
-
lastAIResMightSolveUserIssue: ((
|
|
528
|
+
messages: [...I, u],
|
|
529
|
+
lastAIResMightSolveUserIssue: ((p = C.autopilotResponse) == null ? void 0 : p.mightSolveUserIssue) || ((v = C.uiResponse) == null ? void 0 : v.mightSolveUserIssue)
|
|
512
530
|
});
|
|
513
531
|
}
|
|
514
|
-
|
|
532
|
+
C.session && this.sessionCtx.sessionState.setPartial({ session: C.session });
|
|
515
533
|
} else {
|
|
516
|
-
const
|
|
517
|
-
((
|
|
518
|
-
),
|
|
534
|
+
const u = this.toBotErrorMessage(
|
|
535
|
+
((m = C == null ? void 0 : C.error) == null ? void 0 : m.message) || "Unknown error occurred"
|
|
536
|
+
), I = this.state.get().messages;
|
|
519
537
|
this.state.setPartial({
|
|
520
|
-
messages: [...
|
|
538
|
+
messages: [...I, u]
|
|
521
539
|
});
|
|
522
540
|
}
|
|
523
|
-
} catch (
|
|
524
|
-
this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:",
|
|
541
|
+
} catch (w) {
|
|
542
|
+
this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:", w);
|
|
525
543
|
} finally {
|
|
526
544
|
this.state.setPartial({ isSendingMessage: !1 });
|
|
527
545
|
}
|
|
@@ -534,7 +552,7 @@ class q {
|
|
|
534
552
|
${e}` : e;
|
|
535
553
|
})();
|
|
536
554
|
return {
|
|
537
|
-
id:
|
|
555
|
+
id: k(),
|
|
538
556
|
type: "FROM_USER",
|
|
539
557
|
content: s,
|
|
540
558
|
deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -545,7 +563,7 @@ ${e}` : e;
|
|
|
545
563
|
var t;
|
|
546
564
|
return e.success && e.autopilotResponse ? {
|
|
547
565
|
type: "FROM_BOT",
|
|
548
|
-
id: e.autopilotResponse.id ||
|
|
566
|
+
id: e.autopilotResponse.id || k(),
|
|
549
567
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
550
568
|
component: "bot_message",
|
|
551
569
|
agent: this.config.bot ? {
|
|
@@ -564,7 +582,7 @@ ${e}` : e;
|
|
|
564
582
|
} : null;
|
|
565
583
|
}, this.toBotErrorMessage = (e) => ({
|
|
566
584
|
type: "FROM_BOT",
|
|
567
|
-
id:
|
|
585
|
+
id: k(),
|
|
568
586
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
569
587
|
component: "TEXT",
|
|
570
588
|
data: {
|
|
@@ -575,7 +593,7 @@ ${e}` : e;
|
|
|
575
593
|
}), this.config = n, this.api = o, this.sessionCtx = c, this.contactCtx = g;
|
|
576
594
|
}
|
|
577
595
|
}
|
|
578
|
-
class
|
|
596
|
+
class K {
|
|
579
597
|
constructor({
|
|
580
598
|
config: n,
|
|
581
599
|
contactCtx: o,
|
|
@@ -595,7 +613,7 @@ class N {
|
|
|
595
613
|
if ((i = this.config.router) != null && i.chatScreenOnly && // Do not route to a chat if we are currently inside one already
|
|
596
614
|
// This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
|
|
597
615
|
!((r = this.sessionCtx.sessionState.get().session) != null && r.id)) {
|
|
598
|
-
const l = (a = s.find((
|
|
616
|
+
const l = (a = s.find((p) => p.isOpened)) == null ? void 0 : a.id;
|
|
599
617
|
return l ? this.toChatScreen(l) : void 0;
|
|
600
618
|
}
|
|
601
619
|
s.length || ((h = this.config.router) == null ? void 0 : h.goToChatIfNoSessions) !== !1 && !t && this.state.get().screen !== "chat" && this.toChatScreen();
|
|
@@ -615,7 +633,7 @@ class N {
|
|
|
615
633
|
}), this.registerRoutingListener();
|
|
616
634
|
}
|
|
617
635
|
}
|
|
618
|
-
class
|
|
636
|
+
class Y {
|
|
619
637
|
constructor({
|
|
620
638
|
storage: n,
|
|
621
639
|
config: o
|
|
@@ -630,7 +648,7 @@ class H {
|
|
|
630
648
|
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage = n, this.config = o;
|
|
631
649
|
}
|
|
632
650
|
}
|
|
633
|
-
const
|
|
651
|
+
const x = class x {
|
|
634
652
|
constructor({
|
|
635
653
|
config: n,
|
|
636
654
|
storage: o,
|
|
@@ -638,31 +656,31 @@ const v = class v {
|
|
|
638
656
|
}) {
|
|
639
657
|
if (this.modes = [], this.resetChat = () => {
|
|
640
658
|
this.sessionCtx.reset(), this.messageCtx.reset();
|
|
641
|
-
}, !
|
|
659
|
+
}, !x.pollingIntervalsSeconds)
|
|
642
660
|
throw Error(
|
|
643
661
|
"Widget polling values are not defined, did you call WidgetCtx.initialize()"
|
|
644
662
|
);
|
|
645
|
-
this.config = n, this.api = new
|
|
663
|
+
this.config = n, this.api = new M({ config: n }), this.storageCtx = o ? new Y({ storage: o, config: n }) : void 0, this.modes = c, this.contactCtx = new H({
|
|
646
664
|
api: this.api,
|
|
647
665
|
config: this.config,
|
|
648
666
|
storageCtx: this.storageCtx
|
|
649
|
-
}), this.sessionCtx = new
|
|
667
|
+
}), this.sessionCtx = new X({
|
|
650
668
|
config: this.config,
|
|
651
669
|
api: this.api,
|
|
652
670
|
contactCtx: this.contactCtx,
|
|
653
|
-
sessionsPollingIntervalSeconds:
|
|
654
|
-
}), this.messageCtx = new
|
|
671
|
+
sessionsPollingIntervalSeconds: x.pollingIntervalsSeconds.sessions
|
|
672
|
+
}), this.messageCtx = new G({
|
|
655
673
|
config: this.config,
|
|
656
674
|
api: this.api,
|
|
657
675
|
sessionCtx: this.sessionCtx,
|
|
658
676
|
contactCtx: this.contactCtx
|
|
659
|
-
}), this.activeSessionPollingCtx = new
|
|
677
|
+
}), this.activeSessionPollingCtx = new N({
|
|
660
678
|
api: this.api,
|
|
661
679
|
config: this.config,
|
|
662
680
|
sessionCtx: this.sessionCtx,
|
|
663
681
|
messageCtx: this.messageCtx,
|
|
664
|
-
sessionPollingIntervalSeconds:
|
|
665
|
-
}), this.routerCtx = new
|
|
682
|
+
sessionPollingIntervalSeconds: x.pollingIntervalsSeconds.session
|
|
683
|
+
}), this.routerCtx = new K({
|
|
666
684
|
config: this.config,
|
|
667
685
|
contactCtx: this.contactCtx,
|
|
668
686
|
sessionCtx: this.sessionCtx,
|
|
@@ -670,30 +688,30 @@ const v = class v {
|
|
|
670
688
|
});
|
|
671
689
|
}
|
|
672
690
|
};
|
|
673
|
-
|
|
691
|
+
x.pollingIntervalsSeconds = null, x.initialize = async ({
|
|
674
692
|
config: n,
|
|
675
693
|
storage: o
|
|
676
694
|
}) => {
|
|
677
695
|
var g, e, t;
|
|
678
|
-
const c = await new
|
|
696
|
+
const c = await new M({
|
|
679
697
|
config: n
|
|
680
698
|
}).getExternalWidgetConfig();
|
|
681
|
-
return
|
|
699
|
+
return x.pollingIntervalsSeconds = {
|
|
682
700
|
session: ((g = c.data) == null ? void 0 : g.sessionPollingIntervalSeconds) || 10,
|
|
683
701
|
sessions: ((e = c.data) == null ? void 0 : e.sessionsPollingIntervalSeconds) || 60
|
|
684
|
-
}, new
|
|
702
|
+
}, new x({
|
|
685
703
|
config: n,
|
|
686
704
|
storage: o,
|
|
687
705
|
modes: ((t = c.data) == null ? void 0 : t.modes) || []
|
|
688
706
|
});
|
|
689
707
|
};
|
|
690
|
-
let
|
|
691
|
-
function
|
|
708
|
+
let A = x;
|
|
709
|
+
function Q(d, n) {
|
|
692
710
|
console.error(`Missing case for ${d} in ${n}`);
|
|
693
711
|
}
|
|
694
712
|
export {
|
|
695
713
|
P as PrimitiveState,
|
|
696
|
-
|
|
697
|
-
|
|
714
|
+
A as WidgetCtx,
|
|
715
|
+
Q as isExhaustive
|
|
698
716
|
};
|
|
699
717
|
//# sourceMappingURL=index.js.map
|