@opencx/widget 3.0.96 → 3.0.98
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/designs.cjs +2 -2
- package/dist/designs.cjs.map +1 -1
- package/dist/designs.js +9 -9
- package/dist/designs.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +2 -2
- package/dist/src/headless/core/api/schema.d.ts +2 -2
- package/dist/src/headless/core/context/storage.ctx.d.ts +4 -1
- package/dist/src/headless/core/types/widget-config.d.ts +8 -0
- package/dist/{useModes-Dm1CBDor.js → useModes-CAWYsYJp.js} +3 -3
- package/dist/{useModes-Dm1CBDor.js.map → useModes-CAWYsYJp.js.map} +1 -1
- package/dist/{useModes-BJqYvlSG.cjs → useModes-CJkq9L6f.cjs} +2 -2
- package/dist/{useModes-BJqYvlSG.cjs.map → useModes-CJkq9L6f.cjs.map} +1 -1
- package/dist/{widget.ctx-CfUvw50X.js → widget.ctx-B-jCTG4Y.js} +115 -112
- package/dist/{widget.ctx-CfUvw50X.js.map → widget.ctx-B-jCTG4Y.js.map} +1 -1
- package/dist/{widget.ctx-B-9oCDpY.cjs → widget.ctx-XvIjOOOZ.cjs} +3 -3
- package/dist/{widget.ctx-B-9oCDpY.cjs.map → widget.ctx-XvIjOOOZ.cjs.map} +1 -1
- package/dist-embed/script.js +3 -3
- package/dist-embed/script.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,18 +3,18 @@ import O from "lodash.isequal";
|
|
|
3
3
|
import { v4 as E } from "uuid";
|
|
4
4
|
const F = (d) => {
|
|
5
5
|
console.log(d.error);
|
|
6
|
-
},
|
|
7
|
-
const
|
|
6
|
+
}, D = (d) => {
|
|
7
|
+
const n = M({
|
|
8
8
|
baseUrl: d.baseUrl
|
|
9
9
|
}), o = {
|
|
10
10
|
onRequest: d.onRequest,
|
|
11
11
|
onResponse: d.onResponse,
|
|
12
12
|
onError: d.onError || F
|
|
13
13
|
};
|
|
14
|
-
return
|
|
14
|
+
return n.use(o), n;
|
|
15
15
|
};
|
|
16
16
|
class T {
|
|
17
|
-
constructor({ config:
|
|
17
|
+
constructor({ config: n }) {
|
|
18
18
|
var g, e;
|
|
19
19
|
this.userToken = null, this.constructClientOptions = (t) => {
|
|
20
20
|
const s = this.config.apiUrl || "https://api.open.cx", i = {
|
|
@@ -27,11 +27,11 @@ class T {
|
|
|
27
27
|
}, this.createOpenAPIClient = ({
|
|
28
28
|
baseUrl: t,
|
|
29
29
|
headers: s
|
|
30
|
-
}) =>
|
|
30
|
+
}) => D({
|
|
31
31
|
baseUrl: t,
|
|
32
32
|
onRequest: ({ request: i }) => {
|
|
33
|
-
Object.entries(s).forEach(([r,
|
|
34
|
-
|
|
33
|
+
Object.entries(s).forEach(([r, a]) => {
|
|
34
|
+
a && i.headers.set(r, a);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}), this.setAuthToken = (t) => {
|
|
@@ -74,59 +74,59 @@ class T {
|
|
|
74
74
|
file: t,
|
|
75
75
|
abortSignal: s,
|
|
76
76
|
onProgress: i
|
|
77
|
-
}) => new Promise((r,
|
|
77
|
+
}) => new Promise((r, a) => {
|
|
78
78
|
var v;
|
|
79
79
|
const h = new FormData();
|
|
80
80
|
h.append("file", t);
|
|
81
|
-
const
|
|
81
|
+
const l = new XMLHttpRequest();
|
|
82
82
|
if (s && (s.addEventListener("abort", () => {
|
|
83
|
-
|
|
83
|
+
l.abort(), a(new DOMException("Aborted", "AbortError"));
|
|
84
84
|
}), s.aborted)) {
|
|
85
|
-
|
|
85
|
+
a(new DOMException("Aborted", "AbortError"));
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
l.upload.addEventListener("progress", (u) => {
|
|
89
89
|
if (u.lengthComputable && i) {
|
|
90
90
|
const S = Math.round(u.loaded / u.total * 100);
|
|
91
91
|
i(S);
|
|
92
92
|
}
|
|
93
|
-
}),
|
|
94
|
-
if (
|
|
93
|
+
}), l.addEventListener("load", () => {
|
|
94
|
+
if (l.status >= 200 && l.status < 300)
|
|
95
95
|
try {
|
|
96
|
-
const u = JSON.parse(
|
|
96
|
+
const u = JSON.parse(l.responseText);
|
|
97
97
|
r(u);
|
|
98
98
|
} catch (u) {
|
|
99
|
-
|
|
99
|
+
a(new Error(`Failed to parse response: ${u}`));
|
|
100
100
|
}
|
|
101
101
|
else
|
|
102
|
-
|
|
103
|
-
}),
|
|
104
|
-
|
|
105
|
-
}),
|
|
106
|
-
|
|
102
|
+
a(new Error(`Upload failed with status: ${l.status}`));
|
|
103
|
+
}), l.addEventListener("error", () => {
|
|
104
|
+
a(new Error("Network error occurred"));
|
|
105
|
+
}), l.addEventListener("timeout", () => {
|
|
106
|
+
a(new Error("Upload timed out"));
|
|
107
107
|
});
|
|
108
108
|
const { baseUrl: C } = this.constructClientOptions(this.userToken), p = `${C}/backend/widget/v2/upload`;
|
|
109
|
-
|
|
109
|
+
l.open("POST", p), l.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((v = this.config.user) == null ? void 0 : v.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
|
|
113
113
|
}), this.createStateCheckpoint = async (t) => await this.client.POST("/backend/widget/v2/checkpoint", {
|
|
114
114
|
body: t
|
|
115
|
-
}), this.config =
|
|
116
|
-
const { baseUrl: o, headers:
|
|
117
|
-
(e =
|
|
115
|
+
}), this.config = n, this.userToken = ((g = n.user) == null ? void 0 : g.token) || null;
|
|
116
|
+
const { baseUrl: o, headers: c } = this.constructClientOptions(
|
|
117
|
+
(e = n.user) == null ? void 0 : e.token
|
|
118
118
|
);
|
|
119
|
-
this.client = this.createOpenAPIClient({ baseUrl: o, headers:
|
|
119
|
+
this.client = this.createOpenAPIClient({ baseUrl: o, headers: c });
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
class P {
|
|
123
|
-
constructor(
|
|
123
|
+
constructor(n) {
|
|
124
124
|
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (o) => {
|
|
125
125
|
O(this.state, o) || (this.state = o, this.notifySubscribers(o));
|
|
126
126
|
}, this.setPartial = (o) => {
|
|
127
127
|
if (o == null) return;
|
|
128
|
-
const
|
|
129
|
-
this.set(
|
|
128
|
+
const c = { ...this.state, ...o };
|
|
129
|
+
this.set(c);
|
|
130
130
|
}, this.reset = () => {
|
|
131
131
|
this.set(this.initialState);
|
|
132
132
|
}, this.notifySubscribers = (o) => {
|
|
@@ -139,7 +139,7 @@ class P {
|
|
|
139
139
|
});
|
|
140
140
|
}, this.subscribe = (o) => (this.subscribers.add(o), () => {
|
|
141
141
|
this.subscribers.delete(o);
|
|
142
|
-
}), this.state =
|
|
142
|
+
}), this.state = n, this.initialState = n;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
class R {
|
|
@@ -148,14 +148,14 @@ class R {
|
|
|
148
148
|
isPolling: !1,
|
|
149
149
|
isError: !1
|
|
150
150
|
}), this.abortController = new AbortController(), this.reset = () => {
|
|
151
|
-
var
|
|
152
|
-
this.abortController.abort("Resetting poller"), (
|
|
153
|
-
}, this.stopPolling = null, this.startPolling = (
|
|
151
|
+
var n;
|
|
152
|
+
this.abortController.abort("Resetting poller"), (n = this.stopPolling) == null || n.call(this), this.stopPolling = null;
|
|
153
|
+
}, this.stopPolling = null, this.startPolling = (n, o) => {
|
|
154
154
|
if (this.stopPolling) return;
|
|
155
|
-
const
|
|
155
|
+
const c = [], g = async () => {
|
|
156
156
|
this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
|
|
157
157
|
try {
|
|
158
|
-
await
|
|
158
|
+
await n(this.abortController.signal);
|
|
159
159
|
} catch (e) {
|
|
160
160
|
if (this.abortController.signal.aborted)
|
|
161
161
|
return;
|
|
@@ -163,10 +163,10 @@ class R {
|
|
|
163
163
|
} finally {
|
|
164
164
|
this.state.setPartial({ isPolling: !1 });
|
|
165
165
|
}
|
|
166
|
-
this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") :
|
|
166
|
+
this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : c.push(setTimeout(g, o));
|
|
167
167
|
};
|
|
168
168
|
g(), this.stopPolling = () => {
|
|
169
|
-
|
|
169
|
+
c.forEach(clearTimeout), this.state.reset();
|
|
170
170
|
};
|
|
171
171
|
};
|
|
172
172
|
}
|
|
@@ -174,19 +174,19 @@ class R {
|
|
|
174
174
|
function z(d) {
|
|
175
175
|
return d();
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function _(d) {
|
|
178
178
|
try {
|
|
179
|
-
const
|
|
180
|
-
return
|
|
181
|
-
} catch (
|
|
182
|
-
return { error:
|
|
179
|
+
const n = d();
|
|
180
|
+
return n instanceof Promise ? n.then((o) => ({ data: o })).catch((o) => ({ error: o })) : { data: n };
|
|
181
|
+
} catch (n) {
|
|
182
|
+
return { error: n };
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
class L {
|
|
186
186
|
constructor({
|
|
187
|
-
api:
|
|
187
|
+
api: n,
|
|
188
188
|
config: o,
|
|
189
|
-
sessionCtx:
|
|
189
|
+
sessionCtx: c,
|
|
190
190
|
messageCtx: g,
|
|
191
191
|
sessionPollingIntervalSeconds: e
|
|
192
192
|
}) {
|
|
@@ -199,22 +199,22 @@ class L {
|
|
|
199
199
|
}, this.hackAndSlash = async (t, s) => {
|
|
200
200
|
var h;
|
|
201
201
|
this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
|
|
202
|
-
const i = this.messageCtx.state.get().messages, r = i.length > 0 ? (h = i[i.length - 1]) == null ? void 0 : h.timestamp : void 0, { data:
|
|
202
|
+
const i = this.messageCtx.state.get().messages, r = i.length > 0 ? (h = i[i.length - 1]) == null ? void 0 : h.timestamp : void 0, { data: a } = await this.api.pollSessionAndHistory({
|
|
203
203
|
sessionId: t,
|
|
204
204
|
abortSignal: s,
|
|
205
205
|
lastMessageTimestamp: r
|
|
206
206
|
});
|
|
207
|
-
if (
|
|
208
|
-
const
|
|
209
|
-
(x) => !
|
|
207
|
+
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) {
|
|
208
|
+
const l = this.messageCtx.state.get().messages, C = a.history.map(this.mapHistoryToMessage).filter(
|
|
209
|
+
(x) => !l.some((p) => p.id === x.id)
|
|
210
210
|
);
|
|
211
211
|
this.messageCtx.state.setPartial({
|
|
212
|
-
messages: [...
|
|
212
|
+
messages: [...l, ...C]
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
|
|
216
216
|
}, this.mapHistoryToMessage = (t) => {
|
|
217
|
-
var r,
|
|
217
|
+
var r, a;
|
|
218
218
|
const s = {
|
|
219
219
|
id: t.publicId,
|
|
220
220
|
timestamp: t.sentAt || "",
|
|
@@ -251,7 +251,7 @@ class L {
|
|
|
251
251
|
id: null,
|
|
252
252
|
name: ((r = this.config.bot) == null ? void 0 : r.name) || "",
|
|
253
253
|
isAi: !0,
|
|
254
|
-
avatar: ((
|
|
254
|
+
avatar: ((a = this.config.bot) == null ? void 0 : a.avatar) || ""
|
|
255
255
|
},
|
|
256
256
|
data: {
|
|
257
257
|
message: t.content.text || "",
|
|
@@ -265,25 +265,25 @@ class L {
|
|
|
265
265
|
const s = t.result;
|
|
266
266
|
if (s === null || typeof s != "object") return s;
|
|
267
267
|
if ("responseBodyText" in s && typeof s.responseBodyText == "string") {
|
|
268
|
-
const i = s.responseBodyText, r =
|
|
268
|
+
const i = s.responseBodyText, r = _(() => JSON.parse(i)).data;
|
|
269
269
|
if (r) return r;
|
|
270
270
|
}
|
|
271
271
|
return t.result;
|
|
272
|
-
}, this.api =
|
|
272
|
+
}, this.api = n, this.config = o, this.sessionCtx = c, this.messageCtx = g, this.sessionPollingIntervalSeconds = e, this.registerPolling();
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
class B {
|
|
276
276
|
constructor({
|
|
277
|
-
config:
|
|
277
|
+
config: n,
|
|
278
278
|
api: o,
|
|
279
|
-
storageCtx:
|
|
279
|
+
storageCtx: c
|
|
280
280
|
}) {
|
|
281
281
|
var g;
|
|
282
282
|
this.shouldCollectData = () => {
|
|
283
283
|
var e;
|
|
284
284
|
return !!(!((e = this.state.get().contact) != null && e.token) && this.config.collectUserData);
|
|
285
285
|
}, this.autoCreateUnverifiedUserIfNotExists = async () => {
|
|
286
|
-
var e, t, s, i, r,
|
|
286
|
+
var e, t, s, i, r, a, h, l, C, x, p, b, v, u;
|
|
287
287
|
if (!((e = this.config.user) != null && e.token)) {
|
|
288
288
|
if (this.config.collectUserData && !((s = (t = this.config.user) == null ? void 0 : t.data) != null && s.email)) {
|
|
289
289
|
if ((i = this.config.extraDataCollectionFields) != null && i.length)
|
|
@@ -292,8 +292,8 @@ class B {
|
|
|
292
292
|
S && await this.setUnverifiedContact(S);
|
|
293
293
|
return;
|
|
294
294
|
}
|
|
295
|
-
if (!((h = (
|
|
296
|
-
const S = await ((
|
|
295
|
+
if (!((h = (a = this.config.user) == null ? void 0 : a.data) != null && h.email)) {
|
|
296
|
+
const S = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
|
|
297
297
|
if (S) {
|
|
298
298
|
await this.setUnverifiedContact(S);
|
|
299
299
|
return;
|
|
@@ -318,14 +318,14 @@ class B {
|
|
|
318
318
|
this.state.setPartial({ isCreatingUnverifiedContact: !1 });
|
|
319
319
|
}
|
|
320
320
|
}, this.setUnverifiedContact = async (e) => {
|
|
321
|
-
var i, r,
|
|
321
|
+
var i, r, a, h;
|
|
322
322
|
const t = await ((i = this.storageCtx) == null ? void 0 : i.getExternalContactId()), s = ((r = this.config.user) == null ? void 0 : r.externalId) || t || E();
|
|
323
|
-
this.api.setAuthToken(e), await ((
|
|
324
|
-
}, this.config =
|
|
325
|
-
contact: (g =
|
|
326
|
-
token:
|
|
323
|
+
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 } });
|
|
324
|
+
}, this.config = n, this.storageCtx = c, this.api = o, this.state = new P({
|
|
325
|
+
contact: (g = n.user) != null && g.token ? {
|
|
326
|
+
token: n.user.token,
|
|
327
327
|
// Set optional externalId from config... not local storage
|
|
328
|
-
externalId:
|
|
328
|
+
externalId: n.user.externalId
|
|
329
329
|
} : null,
|
|
330
330
|
extraCollectedData: void 0,
|
|
331
331
|
isCreatingUnverifiedContact: !1,
|
|
@@ -333,14 +333,14 @@ class B {
|
|
|
333
333
|
}), this.autoCreateUnverifiedUserIfNotExists();
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
|
-
function
|
|
336
|
+
function I() {
|
|
337
337
|
return E();
|
|
338
338
|
}
|
|
339
339
|
class q {
|
|
340
340
|
constructor({
|
|
341
|
-
config:
|
|
341
|
+
config: n,
|
|
342
342
|
api: o,
|
|
343
|
-
contactCtx:
|
|
343
|
+
contactCtx: c,
|
|
344
344
|
sessionsPollingIntervalSeconds: g
|
|
345
345
|
}) {
|
|
346
346
|
this.sessionsRefresher = new R(), this.sessionState = new P({
|
|
@@ -385,7 +385,7 @@ class q {
|
|
|
385
385
|
});
|
|
386
386
|
if (e) {
|
|
387
387
|
const s = [...this.sessionsState.get().data, ...e.items].filter(
|
|
388
|
-
(i, r,
|
|
388
|
+
(i, r, a) => r === a.findIndex((h) => i.id === h.id)
|
|
389
389
|
);
|
|
390
390
|
this.sessionsState.setPartial({
|
|
391
391
|
data: s,
|
|
@@ -405,7 +405,7 @@ class q {
|
|
|
405
405
|
});
|
|
406
406
|
}, this.setSessions = (e) => {
|
|
407
407
|
const t = [...e, ...this.sessionsState.get().data].filter(
|
|
408
|
-
(s, i, r) => i === r.findIndex((
|
|
408
|
+
(s, i, r) => i === r.findIndex((a) => s.id === a.id)
|
|
409
409
|
);
|
|
410
410
|
this.sessionsState.setPartial({ data: t });
|
|
411
411
|
}, this.refreshSessions = async () => {
|
|
@@ -429,14 +429,14 @@ class q {
|
|
|
429
429
|
payload: e
|
|
430
430
|
});
|
|
431
431
|
return s ? { data: s } : { success: !1, error: i };
|
|
432
|
-
}, this.config =
|
|
432
|
+
}, this.config = n, this.api = o, this.contactCtx = c, this.sessionsPollingIntervalSeconds = g, this.registerSessionsRefresherWrapper();
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
class $ {
|
|
436
436
|
constructor({
|
|
437
|
-
config:
|
|
437
|
+
config: n,
|
|
438
438
|
api: o,
|
|
439
|
-
sessionCtx:
|
|
439
|
+
sessionCtx: c,
|
|
440
440
|
contactCtx: g
|
|
441
441
|
}) {
|
|
442
442
|
this.state = new P({
|
|
@@ -447,12 +447,12 @@ class $ {
|
|
|
447
447
|
}), this.sendMessageAbortController = new AbortController(), this.reset = () => {
|
|
448
448
|
this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
|
|
449
449
|
}, this.sendMessage = async (e) => {
|
|
450
|
-
var
|
|
450
|
+
var a, h, l, C, x, p, b, v;
|
|
451
451
|
if (!e.content.trim() && (!e.attachments || e.attachments.length === 0)) {
|
|
452
452
|
console.warn("Cannot send an empty message of no content or attachments");
|
|
453
453
|
return;
|
|
454
454
|
}
|
|
455
|
-
const t = this.state.get().isSendingMessage, s = ((
|
|
455
|
+
const t = this.state.get().isSendingMessage, s = ((a = this.sessionCtx.sessionState.get().session) == null ? void 0 : a.assignee.kind) === "ai", i = this.state.get().messages, r = i.length > 0 ? i[i.length - 1] : void 0;
|
|
456
456
|
if (s && t || // If last message is from user, then bot response did not arrive yet
|
|
457
457
|
s && (r == null ? void 0 : r.type) === "FROM_USER") {
|
|
458
458
|
console.warn("Cannot send messages while awaiting AI response");
|
|
@@ -474,8 +474,8 @@ class $ {
|
|
|
474
474
|
}
|
|
475
475
|
this.sessionCtx.refreshSessions();
|
|
476
476
|
}
|
|
477
|
-
const
|
|
478
|
-
if (!
|
|
477
|
+
const y = (l = this.sessionCtx.sessionState.get().session) == null ? void 0 : l.id;
|
|
478
|
+
if (!y) return;
|
|
479
479
|
const { data: f } = await this.api.sendMessage(
|
|
480
480
|
{
|
|
481
481
|
uuid: u.id,
|
|
@@ -483,7 +483,7 @@ class $ {
|
|
|
483
483
|
headers: this.config.headers,
|
|
484
484
|
query_params: this.config.queryParams,
|
|
485
485
|
body_properties: this.config.bodyProperties,
|
|
486
|
-
session_id:
|
|
486
|
+
session_id: y,
|
|
487
487
|
content: u.content,
|
|
488
488
|
attachments: e.attachments,
|
|
489
489
|
clientContext: this.config.context,
|
|
@@ -499,8 +499,8 @@ class $ {
|
|
|
499
499
|
if (f != null && f.success) {
|
|
500
500
|
const w = this.toBotMessage(f);
|
|
501
501
|
if (w) {
|
|
502
|
-
const
|
|
503
|
-
if (!!
|
|
502
|
+
const k = this.state.get().messages;
|
|
503
|
+
if (!!k.some(
|
|
504
504
|
(A) => A.id === w.id
|
|
505
505
|
)) {
|
|
506
506
|
this.state.setPartial({
|
|
@@ -509,7 +509,7 @@ class $ {
|
|
|
509
509
|
return;
|
|
510
510
|
}
|
|
511
511
|
this.state.setPartial({
|
|
512
|
-
messages: [...
|
|
512
|
+
messages: [...k, w],
|
|
513
513
|
lastAIResMightSolveUserIssue: ((p = f.autopilotResponse) == null ? void 0 : p.mightSolveUserIssue) || ((b = f.uiResponse) == null ? void 0 : b.mightSolveUserIssue)
|
|
514
514
|
});
|
|
515
515
|
}
|
|
@@ -517,9 +517,9 @@ class $ {
|
|
|
517
517
|
} else {
|
|
518
518
|
const w = this.toBotErrorMessage(
|
|
519
519
|
((v = f == null ? void 0 : f.error) == null ? void 0 : v.message) || "Unknown error occurred"
|
|
520
|
-
),
|
|
520
|
+
), k = this.state.get().messages;
|
|
521
521
|
this.state.setPartial({
|
|
522
|
-
messages: [...
|
|
522
|
+
messages: [...k, w]
|
|
523
523
|
});
|
|
524
524
|
}
|
|
525
525
|
} catch (u) {
|
|
@@ -530,13 +530,13 @@ class $ {
|
|
|
530
530
|
}, this.toUserMessage = (e, t) => {
|
|
531
531
|
const s = (() => {
|
|
532
532
|
const i = this.contactCtx.state.get().extraCollectedData;
|
|
533
|
-
return this.state.get().messages.length === 0 && i && Object.keys(i).length > 0 ? `${Object.entries(i).filter(([
|
|
533
|
+
return this.state.get().messages.length === 0 && i && Object.keys(i).length > 0 ? `${Object.entries(i).filter(([a, h]) => !!h).map(([a, h]) => `${a}: ${h}`).join(`
|
|
534
534
|
`)}
|
|
535
535
|
|
|
536
536
|
${e}` : e;
|
|
537
537
|
})();
|
|
538
538
|
return {
|
|
539
|
-
id:
|
|
539
|
+
id: I(),
|
|
540
540
|
type: "FROM_USER",
|
|
541
541
|
content: s,
|
|
542
542
|
deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -547,7 +547,7 @@ ${e}` : e;
|
|
|
547
547
|
var t;
|
|
548
548
|
return e.success && e.autopilotResponse ? {
|
|
549
549
|
type: "FROM_BOT",
|
|
550
|
-
id: e.autopilotResponse.id ||
|
|
550
|
+
id: e.autopilotResponse.id || I(),
|
|
551
551
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
552
552
|
component: "bot_message",
|
|
553
553
|
agent: this.config.bot ? {
|
|
@@ -566,7 +566,7 @@ ${e}` : e;
|
|
|
566
566
|
} : null;
|
|
567
567
|
}, this.toBotErrorMessage = (e) => ({
|
|
568
568
|
type: "FROM_BOT",
|
|
569
|
-
id:
|
|
569
|
+
id: I(),
|
|
570
570
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
571
571
|
component: "TEXT",
|
|
572
572
|
data: {
|
|
@@ -574,14 +574,14 @@ ${e}` : e;
|
|
|
574
574
|
variant: "error",
|
|
575
575
|
action: void 0
|
|
576
576
|
}
|
|
577
|
-
}), this.config =
|
|
577
|
+
}), this.config = n, this.api = o, this.sessionCtx = c, this.contactCtx = g;
|
|
578
578
|
}
|
|
579
579
|
}
|
|
580
580
|
class N {
|
|
581
581
|
constructor({
|
|
582
|
-
config:
|
|
582
|
+
config: n,
|
|
583
583
|
contactCtx: o,
|
|
584
|
-
sessionCtx:
|
|
584
|
+
sessionCtx: c,
|
|
585
585
|
resetChat: g
|
|
586
586
|
}) {
|
|
587
587
|
var e;
|
|
@@ -593,12 +593,12 @@ class N {
|
|
|
593
593
|
});
|
|
594
594
|
}), this.sessionCtx.sessionsState.subscribe(
|
|
595
595
|
({ isInitialFetchLoading: t, data: s }) => {
|
|
596
|
-
var i, r,
|
|
596
|
+
var i, r, a, h;
|
|
597
597
|
if ((i = this.config.router) != null && i.chatScreenOnly && // Do not route to a chat if we are currently inside one already
|
|
598
598
|
// This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
|
|
599
599
|
!((r = this.sessionCtx.sessionState.get().session) != null && r.id)) {
|
|
600
|
-
const
|
|
601
|
-
return
|
|
600
|
+
const l = (a = s.find((C) => C.isOpened)) == null ? void 0 : a.id;
|
|
601
|
+
return l ? this.toChatScreen(l) : void 0;
|
|
602
602
|
}
|
|
603
603
|
s.length || ((h = this.config.router) == null ? void 0 : h.goToChatIfNoSessions) !== !1 && !t && this.state.get().screen !== "chat" && this.toChatScreen();
|
|
604
604
|
}
|
|
@@ -612,28 +612,31 @@ class N {
|
|
|
612
612
|
this.sessionCtx.sessionState.setPartial({ session: s });
|
|
613
613
|
}
|
|
614
614
|
this.state.setPartial({ screen: "chat" });
|
|
615
|
-
}, this.config =
|
|
615
|
+
}, this.config = n, this.contactCtx = o, this.sessionCtx = c, this.resetChat = g, this.state = new P({
|
|
616
616
|
screen: this.contactCtx.shouldCollectData() ? "welcome" : (e = this.config.router) != null && e.chatScreenOnly ? "chat" : "sessions"
|
|
617
617
|
}), this.registerRoutingListener();
|
|
618
618
|
}
|
|
619
619
|
}
|
|
620
620
|
class H {
|
|
621
|
-
constructor({
|
|
621
|
+
constructor({
|
|
622
|
+
storage: n,
|
|
623
|
+
config: o
|
|
624
|
+
}) {
|
|
622
625
|
this.KEYS = {
|
|
623
|
-
contactToken:
|
|
624
|
-
externalContactId:
|
|
625
|
-
}, this.setContactToken = async (
|
|
626
|
-
await this.storage.set(this.KEYS.contactToken,
|
|
627
|
-
}, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken), this.setExternalContactId = async (
|
|
628
|
-
await this.storage.set(this.KEYS.externalContactId,
|
|
629
|
-
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId), this.storage =
|
|
626
|
+
contactToken: (c) => `opencx-widget:org-token-${c}:contact-token`,
|
|
627
|
+
externalContactId: (c) => `opencx-widget:org-token-${c}:external-contact-id`
|
|
628
|
+
}, this.setContactToken = async (c) => {
|
|
629
|
+
await this.storage.set(this.KEYS.contactToken(this.config.token), c);
|
|
630
|
+
}, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken(this.config.token)), this.setExternalContactId = async (c) => {
|
|
631
|
+
await this.storage.set(this.KEYS.externalContactId(this.config.token), c);
|
|
632
|
+
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage = n, this.config = o;
|
|
630
633
|
}
|
|
631
634
|
}
|
|
632
635
|
const m = class m {
|
|
633
636
|
constructor({
|
|
634
|
-
config:
|
|
637
|
+
config: n,
|
|
635
638
|
storage: o,
|
|
636
|
-
modes:
|
|
639
|
+
modes: c
|
|
637
640
|
}) {
|
|
638
641
|
if (this.modes = [], this.resetChat = () => {
|
|
639
642
|
this.sessionCtx.reset(), this.messageCtx.reset();
|
|
@@ -641,7 +644,7 @@ const m = class m {
|
|
|
641
644
|
throw Error(
|
|
642
645
|
"Widget polling values are not defined, did you call WidgetCtx.initialize()"
|
|
643
646
|
);
|
|
644
|
-
this.config =
|
|
647
|
+
this.config = n, this.api = new T({ config: n }), this.storageCtx = o ? new H({ storage: o, config: n }) : void 0, this.modes = c, this.contactCtx = new B({
|
|
645
648
|
api: this.api,
|
|
646
649
|
config: this.config,
|
|
647
650
|
storageCtx: this.storageCtx
|
|
@@ -670,20 +673,20 @@ const m = class m {
|
|
|
670
673
|
}
|
|
671
674
|
};
|
|
672
675
|
m.pollingIntervalsSeconds = null, m.initialize = async ({
|
|
673
|
-
config:
|
|
676
|
+
config: n,
|
|
674
677
|
storage: o
|
|
675
678
|
}) => {
|
|
676
679
|
var g, e, t;
|
|
677
|
-
const
|
|
678
|
-
config:
|
|
680
|
+
const c = await new T({
|
|
681
|
+
config: n
|
|
679
682
|
}).getExternalWidgetConfig();
|
|
680
683
|
return m.pollingIntervalsSeconds = {
|
|
681
|
-
session: ((g =
|
|
682
|
-
sessions: ((e =
|
|
684
|
+
session: ((g = c.data) == null ? void 0 : g.sessionPollingIntervalSeconds) || 10,
|
|
685
|
+
sessions: ((e = c.data) == null ? void 0 : e.sessionsPollingIntervalSeconds) || 60
|
|
683
686
|
}, new m({
|
|
684
|
-
config:
|
|
687
|
+
config: n,
|
|
685
688
|
storage: o,
|
|
686
|
-
modes: ((t =
|
|
689
|
+
modes: ((t = c.data) == null ? void 0 : t.modes) || []
|
|
687
690
|
});
|
|
688
691
|
};
|
|
689
692
|
let U = m;
|
|
@@ -692,4 +695,4 @@ export {
|
|
|
692
695
|
U as W,
|
|
693
696
|
z as r
|
|
694
697
|
};
|
|
695
|
-
//# sourceMappingURL=widget.ctx-
|
|
698
|
+
//# sourceMappingURL=widget.ctx-B-jCTG4Y.js.map
|