@opencx/widget-core 4.0.37 → 4.0.38
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/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +162 -128
- package/dist/index.js.map +1 -1
- package/dist/src/translation/el.d.ts +3 -0
- package/dist/src/translation/el.d.ts.map +1 -0
- package/dist/src/translation/index.d.ts +2 -0
- package/dist/src/translation/index.d.ts.map +1 -1
- package/dist/src/translation/ru.d.ts +3 -0
- package/dist/src/translation/ru.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,40 +4,40 @@ import { v4 as z } from "uuid";
|
|
|
4
4
|
const F = (h) => {
|
|
5
5
|
console.log(h.error);
|
|
6
6
|
}, B = (h) => {
|
|
7
|
-
const
|
|
7
|
+
const n = L({
|
|
8
8
|
baseUrl: h.baseUrl
|
|
9
9
|
}), a = {
|
|
10
10
|
onRequest: h.onRequest,
|
|
11
11
|
onResponse: h.onResponse,
|
|
12
12
|
onError: h.onError || F
|
|
13
13
|
};
|
|
14
|
-
return
|
|
14
|
+
return n.use(a), n;
|
|
15
15
|
};
|
|
16
16
|
class M {
|
|
17
|
-
constructor({ config:
|
|
17
|
+
constructor({ config: n }) {
|
|
18
18
|
var d, s;
|
|
19
19
|
this.userToken = null, this.constructClientOptions = (e) => {
|
|
20
|
-
const t = this.config.apiUrl || "https://api.open.cx",
|
|
20
|
+
const t = this.config.apiUrl || "https://api.open.cx", i = {
|
|
21
21
|
"X-Bot-Token": this.config.token,
|
|
22
22
|
"Content-Type": "application/json",
|
|
23
23
|
Accept: "application/json",
|
|
24
24
|
Authorization: e ? `Bearer ${e}` : void 0
|
|
25
25
|
};
|
|
26
|
-
return { baseUrl: t, headers:
|
|
26
|
+
return { baseUrl: t, headers: i };
|
|
27
27
|
}, this.createOpenAPIClient = ({
|
|
28
28
|
baseUrl: e,
|
|
29
29
|
headers: t
|
|
30
30
|
}) => B({
|
|
31
31
|
baseUrl: e,
|
|
32
|
-
onRequest: ({ request:
|
|
32
|
+
onRequest: ({ request: i }) => {
|
|
33
33
|
Object.entries(t).forEach(([o, l]) => {
|
|
34
|
-
l &&
|
|
34
|
+
l && i.headers.set(o, l);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}), this.setAuthToken = (e) => {
|
|
38
38
|
this.userToken = e;
|
|
39
|
-
const { baseUrl: t, headers:
|
|
40
|
-
this.client = this.createOpenAPIClient({ baseUrl: t, headers:
|
|
39
|
+
const { baseUrl: t, headers: i } = this.constructClientOptions(e);
|
|
40
|
+
this.client = this.createOpenAPIClient({ baseUrl: t, headers: i });
|
|
41
41
|
}, this.getExternalWidgetConfig = async () => await this.client.GET("/backend/widget/v2/config", {
|
|
42
42
|
params: { header: { "X-Bot-Token": this.config.token } }
|
|
43
43
|
}), this.sendMessage = async (e, t) => await this.client.POST("/backend/widget/v2/chat/send", {
|
|
@@ -54,24 +54,24 @@ class M {
|
|
|
54
54
|
}), this.pollSessionAndHistory = async ({
|
|
55
55
|
sessionId: e,
|
|
56
56
|
lastMessageTimestamp: t,
|
|
57
|
-
abortSignal:
|
|
57
|
+
abortSignal: i
|
|
58
58
|
}) => {
|
|
59
59
|
const o = t ? { lastMessageTimestamp: t } : void 0;
|
|
60
60
|
return await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
|
|
61
61
|
params: { path: { sessionId: e }, query: o },
|
|
62
|
-
signal:
|
|
62
|
+
signal: i
|
|
63
63
|
});
|
|
64
64
|
}, this.getSessions = async ({
|
|
65
65
|
cursor: e,
|
|
66
66
|
filters: t,
|
|
67
|
-
abortSignal:
|
|
67
|
+
abortSignal: i
|
|
68
68
|
}) => await this.client.GET("/backend/widget/v2/sessions", {
|
|
69
69
|
params: { query: { cursor: e, filters: JSON.stringify(t) } },
|
|
70
|
-
signal:
|
|
70
|
+
signal: i
|
|
71
71
|
}), this.uploadFile = async ({
|
|
72
72
|
file: e,
|
|
73
73
|
abortSignal: t,
|
|
74
|
-
onProgress:
|
|
74
|
+
onProgress: i
|
|
75
75
|
}) => new Promise((o, l) => {
|
|
76
76
|
var S;
|
|
77
77
|
const c = new FormData();
|
|
@@ -84,9 +84,9 @@ class M {
|
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
u.upload.addEventListener("progress", (f) => {
|
|
87
|
-
if (f.lengthComputable &&
|
|
87
|
+
if (f.lengthComputable && i) {
|
|
88
88
|
const v = Math.round(f.loaded / f.total * 100);
|
|
89
|
-
|
|
89
|
+
i(v);
|
|
90
90
|
}
|
|
91
91
|
}), u.addEventListener("load", () => {
|
|
92
92
|
if (u.status >= 200 && u.status < 300)
|
|
@@ -103,25 +103,25 @@ class M {
|
|
|
103
103
|
}), u.addEventListener("timeout", () => {
|
|
104
104
|
l(new Error("Upload timed out"));
|
|
105
105
|
});
|
|
106
|
-
const { baseUrl: p } = this.constructClientOptions(this.userToken),
|
|
107
|
-
u.open("POST",
|
|
106
|
+
const { baseUrl: p } = this.constructClientOptions(this.userToken), _ = `${p}/backend/widget/v2/upload`;
|
|
107
|
+
u.open("POST", _), u.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((S = this.config.user) == null ? void 0 : S.token) ? u.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), u.send(c);
|
|
108
108
|
}), this.vote = async (e) => await this.client.POST("/backend/widget/v2/chat/vote", { body: e }), this.resolveSession = async (e, t) => await this.client.POST("/backend/widget/v2/session/resolve", {
|
|
109
109
|
body: e,
|
|
110
110
|
signal: t
|
|
111
111
|
}), this.createStateCheckpoint = async (e) => await this.client.POST("/backend/widget/v2/checkpoint", {
|
|
112
112
|
body: e
|
|
113
|
-
}), this.submitCsat = async (e) => await this.client.POST("/backend/widget/v2/submit-csat", { body: e }), this.config =
|
|
113
|
+
}), this.submitCsat = async (e) => await this.client.POST("/backend/widget/v2/submit-csat", { body: e }), this.config = n, this.userToken = ((d = n.user) == null ? void 0 : d.token) || null;
|
|
114
114
|
const { baseUrl: a, headers: r } = this.constructClientOptions(
|
|
115
|
-
(s =
|
|
115
|
+
(s = n.user) == null ? void 0 : s.token
|
|
116
116
|
);
|
|
117
117
|
this.client = this.createOpenAPIClient({ baseUrl: a, headers: r });
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
function H(h,
|
|
121
|
-
console.error(`Missing case for ${h} in ${
|
|
120
|
+
function H(h, n) {
|
|
121
|
+
console.error(`Missing case for ${h} in ${n}`);
|
|
122
122
|
}
|
|
123
123
|
class y {
|
|
124
|
-
constructor(
|
|
124
|
+
constructor(n) {
|
|
125
125
|
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (a) => {
|
|
126
126
|
N(this.state, a) || (this.state = a, this.notifySubscribers(a));
|
|
127
127
|
}, this.setPartial = (a) => {
|
|
@@ -140,7 +140,7 @@ class y {
|
|
|
140
140
|
});
|
|
141
141
|
}, this.subscribe = (a) => (this.subscribers.add(a), () => {
|
|
142
142
|
this.subscribers.delete(a);
|
|
143
|
-
}), this.state =
|
|
143
|
+
}), this.state = n, this.initialState = n;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
class O {
|
|
@@ -149,14 +149,14 @@ class O {
|
|
|
149
149
|
isPolling: !1,
|
|
150
150
|
isError: !1
|
|
151
151
|
}), this.abortController = new AbortController(), this.reset = () => {
|
|
152
|
-
var
|
|
153
|
-
this.abortController.abort("Resetting poller"), (
|
|
154
|
-
}, this.stopPolling = null, this.startPolling = (
|
|
152
|
+
var n;
|
|
153
|
+
this.abortController.abort("Resetting poller"), (n = this.stopPolling) == null || n.call(this), this.stopPolling = null;
|
|
154
|
+
}, this.stopPolling = null, this.startPolling = (n, a) => {
|
|
155
155
|
if (this.stopPolling) return;
|
|
156
156
|
const r = [], d = async () => {
|
|
157
157
|
this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
|
|
158
158
|
try {
|
|
159
|
-
await
|
|
159
|
+
await n(this.abortController.signal);
|
|
160
160
|
} catch (s) {
|
|
161
161
|
if (this.abortController.signal.aborted)
|
|
162
162
|
return;
|
|
@@ -174,15 +174,15 @@ class O {
|
|
|
174
174
|
}
|
|
175
175
|
function R(h) {
|
|
176
176
|
try {
|
|
177
|
-
const
|
|
178
|
-
return
|
|
179
|
-
} catch (
|
|
180
|
-
return { error:
|
|
177
|
+
const n = h();
|
|
178
|
+
return n instanceof Promise ? n.then((a) => ({ data: a })).catch((a) => ({ error: a })) : { data: n };
|
|
179
|
+
} catch (n) {
|
|
180
|
+
return { error: n };
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
class q {
|
|
184
184
|
constructor({
|
|
185
|
-
api:
|
|
185
|
+
api: n,
|
|
186
186
|
config: a,
|
|
187
187
|
sessionCtx: r,
|
|
188
188
|
messageCtx: d,
|
|
@@ -210,18 +210,18 @@ class q {
|
|
|
210
210
|
}, this.fetchSessionAndHistory = async ({
|
|
211
211
|
sessionId: e,
|
|
212
212
|
abortSignal: t,
|
|
213
|
-
fetchFullHistory:
|
|
213
|
+
fetchFullHistory: i = !1
|
|
214
214
|
}) => {
|
|
215
215
|
var u;
|
|
216
216
|
this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
|
|
217
217
|
const o = this.messageCtx.state.get().messages, l = o.length > 0 ? ((u = o[o.length - 1]) == null ? void 0 : u.timestamp) ?? void 0 : void 0, { data: c } = await this.api.pollSessionAndHistory({
|
|
218
218
|
sessionId: e,
|
|
219
219
|
abortSignal: t,
|
|
220
|
-
lastMessageTimestamp:
|
|
220
|
+
lastMessageTimestamp: i ? void 0 : l
|
|
221
221
|
});
|
|
222
222
|
if (c != null && c.session && (this.sessionCtx.sessionState.setPartial({ session: c.session }), this.sessionCtx.setSessions([c.session])), c != null && c.history && c.history.length > 0) {
|
|
223
|
-
const p = this.messageCtx.state.get().messages, w = c.history.map(this.mapHistoryToMessage).filter((
|
|
224
|
-
(
|
|
223
|
+
const p = this.messageCtx.state.get().messages, w = c.history.map(this.mapHistoryToMessage).filter((_) => _ !== null).filter(
|
|
224
|
+
(_) => !p.some((C) => C.id === _.id)
|
|
225
225
|
);
|
|
226
226
|
this.messageCtx.state.setPartial({
|
|
227
227
|
messages: [...p, ...w]
|
|
@@ -229,7 +229,7 @@ class q {
|
|
|
229
229
|
}
|
|
230
230
|
this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
|
|
231
231
|
}, this.mapHistoryToMessage = (e) => {
|
|
232
|
-
var
|
|
232
|
+
var i;
|
|
233
233
|
const t = {
|
|
234
234
|
id: e.publicId,
|
|
235
235
|
timestamp: e.sentAt || "",
|
|
@@ -268,7 +268,7 @@ class q {
|
|
|
268
268
|
component: "bot_message",
|
|
269
269
|
agent: {
|
|
270
270
|
id: null,
|
|
271
|
-
name: ((
|
|
271
|
+
name: ((i = this.config.bot) == null ? void 0 : i.name) || "",
|
|
272
272
|
isAi: !0,
|
|
273
273
|
// Do not set avatarUrl from config here... let it be taken from the config at render time
|
|
274
274
|
avatarUrl: null,
|
|
@@ -335,16 +335,16 @@ class q {
|
|
|
335
335
|
const t = e.result;
|
|
336
336
|
if (t === null || typeof t != "object") return t;
|
|
337
337
|
if ("responseBodyText" in t && typeof t.responseBodyText == "string") {
|
|
338
|
-
const
|
|
338
|
+
const i = t.responseBodyText, o = R(() => JSON.parse(i)).data;
|
|
339
339
|
if (o) return o;
|
|
340
340
|
}
|
|
341
341
|
return e.result;
|
|
342
|
-
}, this.api =
|
|
342
|
+
}, this.api = n, this.config = a, this.sessionCtx = r, this.messageCtx = d, this.sessionPollingIntervalSeconds = s, this.registerPolling();
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
class V {
|
|
346
346
|
constructor({
|
|
347
|
-
config:
|
|
347
|
+
config: n,
|
|
348
348
|
api: a,
|
|
349
349
|
storageCtx: r
|
|
350
350
|
}) {
|
|
@@ -353,10 +353,10 @@ class V {
|
|
|
353
353
|
var s;
|
|
354
354
|
return !!(!((s = this.state.get().contact) != null && s.token) && this.config.collectUserData);
|
|
355
355
|
}, this.autoCreateUnverifiedUserIfNotExists = async () => {
|
|
356
|
-
var s, e, t,
|
|
356
|
+
var s, e, t, i, o, l, c, u, p, w, _, C, S, f;
|
|
357
357
|
if (!((s = this.config.user) != null && s.token)) {
|
|
358
358
|
if (this.config.collectUserData && !((t = (e = this.config.user) == null ? void 0 : e.data) != null && t.email)) {
|
|
359
|
-
if ((
|
|
359
|
+
if ((i = this.config.extraDataCollectionFields) != null && i.length)
|
|
360
360
|
return;
|
|
361
361
|
const v = await ((o = this.storageCtx) == null ? void 0 : o.getContactToken());
|
|
362
362
|
v && await this.setUnverifiedContact(v);
|
|
@@ -371,7 +371,7 @@ class V {
|
|
|
371
371
|
}
|
|
372
372
|
await this.createUnverifiedContact({
|
|
373
373
|
email: (w = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : w.email,
|
|
374
|
-
non_verified_name: (C = (
|
|
374
|
+
non_verified_name: (C = (_ = this.config.user) == null ? void 0 : _.data) == null ? void 0 : C.name,
|
|
375
375
|
non_verified_custom_data: (f = (S = this.config.user) == null ? void 0 : S.data) == null ? void 0 : f.customData
|
|
376
376
|
});
|
|
377
377
|
}
|
|
@@ -388,14 +388,14 @@ class V {
|
|
|
388
388
|
this.state.setPartial({ isCreatingUnverifiedContact: !1 });
|
|
389
389
|
}
|
|
390
390
|
}, this.setUnverifiedContact = async (s) => {
|
|
391
|
-
var
|
|
392
|
-
const e = await ((
|
|
391
|
+
var i, o, l, c;
|
|
392
|
+
const e = await ((i = this.storageCtx) == null ? void 0 : i.getExternalContactId()), t = ((o = this.config.user) == null ? void 0 : o.externalId) || e || z();
|
|
393
393
|
this.api.setAuthToken(s), await ((l = this.storageCtx) == null ? void 0 : l.setContactToken(s)), await ((c = this.storageCtx) == null ? void 0 : c.setExternalContactId(t)), this.state.setPartial({ contact: { token: s, externalId: t } });
|
|
394
|
-
}, this.config =
|
|
395
|
-
contact: (d =
|
|
396
|
-
token:
|
|
394
|
+
}, this.config = n, this.storageCtx = r, this.api = a, this.state = new y({
|
|
395
|
+
contact: (d = n.user) != null && d.token ? {
|
|
396
|
+
token: n.user.token,
|
|
397
397
|
// Set optional externalId from config... not local storage
|
|
398
|
-
externalId:
|
|
398
|
+
externalId: n.user.externalId
|
|
399
399
|
} : null,
|
|
400
400
|
extraCollectedData: void 0,
|
|
401
401
|
isCreatingUnverifiedContact: !1,
|
|
@@ -408,7 +408,7 @@ function k() {
|
|
|
408
408
|
}
|
|
409
409
|
class Y {
|
|
410
410
|
constructor({
|
|
411
|
-
config:
|
|
411
|
+
config: n,
|
|
412
412
|
api: a,
|
|
413
413
|
sessionCtx: r,
|
|
414
414
|
messageCtx: d
|
|
@@ -436,18 +436,18 @@ class Y {
|
|
|
436
436
|
}
|
|
437
437
|
]
|
|
438
438
|
});
|
|
439
|
-
const { data:
|
|
439
|
+
const { data: i, error: o } = await this.api.submitCsat({
|
|
440
440
|
...s,
|
|
441
441
|
system_message_uuid: t,
|
|
442
442
|
session_id: e
|
|
443
443
|
});
|
|
444
|
-
return { data:
|
|
445
|
-
}, this.config =
|
|
444
|
+
return { data: i, error: o };
|
|
445
|
+
}, this.config = n, this.api = a, this.sessionCtx = r, this.messageCtx = d;
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
448
|
class $ {
|
|
449
449
|
constructor({
|
|
450
|
-
config:
|
|
450
|
+
config: n,
|
|
451
451
|
api: a,
|
|
452
452
|
contactCtx: r,
|
|
453
453
|
sessionsPollingIntervalSeconds: d
|
|
@@ -490,10 +490,10 @@ class $ {
|
|
|
490
490
|
const s = (o = this.contactCtx.state.get().contact) == null ? void 0 : o.externalId, e = {
|
|
491
491
|
...this.getParsedCustomData(),
|
|
492
492
|
...s ? { external_id: s } : {}
|
|
493
|
-
}, { data: t, error:
|
|
493
|
+
}, { data: t, error: i } = await this.api.createSession({
|
|
494
494
|
customData: Object.keys(e).length > 0 ? e : void 0
|
|
495
495
|
});
|
|
496
|
-
return t ? (this.sessionState.setPartial({ session: t, isCreatingSession: !1 }), t) : (this.sessionState.setPartial({ isCreatingSession: !1 }), console.error("Failed to create session:",
|
|
496
|
+
return t ? (this.sessionState.setPartial({ session: t, isCreatingSession: !1 }), t) : (this.sessionState.setPartial({ isCreatingSession: !1 }), console.error("Failed to create session:", i), null);
|
|
497
497
|
}, this.loadMoreSessions = async () => {
|
|
498
498
|
if (this.sessionsState.get().isLastPage) return;
|
|
499
499
|
const { data: s } = await this.getSessions({
|
|
@@ -501,7 +501,7 @@ class $ {
|
|
|
501
501
|
});
|
|
502
502
|
if (s) {
|
|
503
503
|
const t = [...this.sessionsState.get().data, ...s.items].filter(
|
|
504
|
-
(
|
|
504
|
+
(i, o, l) => o === l.findIndex((c) => i.id === c.id)
|
|
505
505
|
);
|
|
506
506
|
this.sessionsState.setPartial({
|
|
507
507
|
data: t,
|
|
@@ -510,9 +510,9 @@ class $ {
|
|
|
510
510
|
});
|
|
511
511
|
}
|
|
512
512
|
}, this.getSessions = async ({ cursor: s }) => {
|
|
513
|
-
var t,
|
|
513
|
+
var t, i;
|
|
514
514
|
if (!((t = this.contactCtx.state.get().contact) != null && t.token)) return { data: null };
|
|
515
|
-
const e = (
|
|
515
|
+
const e = (i = this.contactCtx.state.get().contact) == null ? void 0 : i.externalId;
|
|
516
516
|
return await this.api.getSessions({
|
|
517
517
|
cursor: s,
|
|
518
518
|
filters: e ? {
|
|
@@ -521,7 +521,7 @@ class $ {
|
|
|
521
521
|
});
|
|
522
522
|
}, this.setSessions = (s) => {
|
|
523
523
|
const e = [...s, ...this.sessionsState.get().data].filter(
|
|
524
|
-
(t,
|
|
524
|
+
(t, i, o) => i === o.findIndex((l) => t.id === l.id)
|
|
525
525
|
);
|
|
526
526
|
this.sessionsState.setPartial({ data: e });
|
|
527
527
|
}, this.refreshSessions = async () => {
|
|
@@ -540,17 +540,17 @@ class $ {
|
|
|
540
540
|
var o;
|
|
541
541
|
const e = (o = this.sessionState.get().session) == null ? void 0 : o.id;
|
|
542
542
|
if (!e) return;
|
|
543
|
-
const { data: t, error:
|
|
543
|
+
const { data: t, error: i } = await this.api.createStateCheckpoint({
|
|
544
544
|
session_id: e,
|
|
545
545
|
payload: s
|
|
546
546
|
});
|
|
547
547
|
return t != null && t.success ? { success: !0 } : { success: !1 };
|
|
548
|
-
}, this.config =
|
|
548
|
+
}, this.config = n, this.api = a, this.contactCtx = r, this.sessionsPollingIntervalSeconds = d, this.registerSessionsRefresherWrapper();
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
class K {
|
|
552
552
|
constructor({
|
|
553
|
-
config:
|
|
553
|
+
config: n,
|
|
554
554
|
api: a,
|
|
555
555
|
sessionCtx: r,
|
|
556
556
|
contactCtx: d
|
|
@@ -564,7 +564,7 @@ class K {
|
|
|
564
564
|
}), this.sendMessageAbortController = new AbortController(), this.reset = () => {
|
|
565
565
|
this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
|
|
566
566
|
}, this.sendMessage = async (s) => {
|
|
567
|
-
var e, t,
|
|
567
|
+
var e, t, i, o, l, c, u, p, w;
|
|
568
568
|
try {
|
|
569
569
|
if (!s.content.trim() && (!s.attachments || s.attachments.length === 0)) {
|
|
570
570
|
console.warn(
|
|
@@ -572,7 +572,7 @@ class K {
|
|
|
572
572
|
);
|
|
573
573
|
return;
|
|
574
574
|
}
|
|
575
|
-
const
|
|
575
|
+
const _ = this.sessionCtx.sessionState.get().session, S = (_ == null ? void 0 : _.assignee.kind) === "ai", f = this.state.get().isSendingMessageToAI, v = this.state.get().messages.at(-1);
|
|
576
576
|
if (f || // If last message is from user, then bot response did not arrive yet
|
|
577
577
|
S && (v == null ? void 0 : v.type) === "USER") {
|
|
578
578
|
console.warn("Cannot send messages while awaiting AI response");
|
|
@@ -581,16 +581,16 @@ class K {
|
|
|
581
581
|
this.sendMessageAbortController = new AbortController(), this.state.setPartial({
|
|
582
582
|
lastAIResMightSolveUserIssue: !1,
|
|
583
583
|
isSendingMessage: !0,
|
|
584
|
-
isSendingMessageToAI: !!S || !
|
|
584
|
+
isSendingMessageToAI: !!S || !_
|
|
585
585
|
});
|
|
586
|
-
const P = this.state.get().messages, A = !((e = this.sessionCtx.sessionState.get().session) != null && e.id) && P.length === 0 && ((t = this.config.advancedInitialMessages) == null ? void 0 : t.some((
|
|
587
|
-
(
|
|
586
|
+
const P = this.state.get().messages, A = !((e = this.sessionCtx.sessionState.get().session) != null && e.id) && P.length === 0 && ((t = this.config.advancedInitialMessages) == null ? void 0 : t.some((g) => g.persistent)), T = A ? (this.config.advancedInitialMessages || []).filter((g) => g.persistent).map(
|
|
587
|
+
(g) => ({
|
|
588
588
|
id: k(),
|
|
589
589
|
component: "bot_message",
|
|
590
590
|
type: "AI",
|
|
591
591
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
592
592
|
data: {
|
|
593
|
-
message:
|
|
593
|
+
message: g.message
|
|
594
594
|
},
|
|
595
595
|
agent: this.config.bot ? { ...this.config.bot, isAi: !0, id: null } : void 0
|
|
596
596
|
})
|
|
@@ -604,7 +604,7 @@ class K {
|
|
|
604
604
|
...P,
|
|
605
605
|
I
|
|
606
606
|
]
|
|
607
|
-
}), !((
|
|
607
|
+
}), !((i = this.sessionCtx.sessionState.get().session) != null && i.id)) {
|
|
608
608
|
if (!await this.sessionCtx.createSession()) {
|
|
609
609
|
console.error("Failed to create session");
|
|
610
610
|
return;
|
|
@@ -630,19 +630,19 @@ class K {
|
|
|
630
630
|
},
|
|
631
631
|
language: this.config.language,
|
|
632
632
|
exit_mode_prompt: s.exitModePrompt,
|
|
633
|
-
initial_messages: A ? T.map((
|
|
634
|
-
uuid:
|
|
635
|
-
content:
|
|
633
|
+
initial_messages: A ? T.map((g) => ({
|
|
634
|
+
uuid: g.id,
|
|
635
|
+
content: g.data.message
|
|
636
636
|
})) : void 0
|
|
637
637
|
},
|
|
638
638
|
this.sendMessageAbortController.signal
|
|
639
639
|
);
|
|
640
640
|
if (m != null && m.success) {
|
|
641
|
-
const
|
|
642
|
-
if (
|
|
641
|
+
const g = this.toBotMessage(m);
|
|
642
|
+
if (g) {
|
|
643
643
|
const x = this.state.get().messages;
|
|
644
644
|
if (!!x.some(
|
|
645
|
-
(j) => j.id ===
|
|
645
|
+
(j) => j.id === g.id
|
|
646
646
|
)) {
|
|
647
647
|
this.state.setPartial({
|
|
648
648
|
lastAIResMightSolveUserIssue: ((l = m.autopilotResponse) == null ? void 0 : l.mightSolveUserIssue) || ((c = m.uiResponse) == null ? void 0 : c.mightSolveUserIssue)
|
|
@@ -650,21 +650,21 @@ class K {
|
|
|
650
650
|
return;
|
|
651
651
|
}
|
|
652
652
|
this.state.setPartial({
|
|
653
|
-
messages: [...x,
|
|
653
|
+
messages: [...x, g],
|
|
654
654
|
lastAIResMightSolveUserIssue: ((u = m.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((p = m.uiResponse) == null ? void 0 : p.mightSolveUserIssue)
|
|
655
655
|
});
|
|
656
656
|
}
|
|
657
657
|
m.session && this.sessionCtx.sessionState.setPartial({ session: m.session });
|
|
658
658
|
} else {
|
|
659
|
-
const
|
|
659
|
+
const g = this.toBotErrorMessage(
|
|
660
660
|
((w = m == null ? void 0 : m.error) == null ? void 0 : w.message) || "Something went wrong. Please refresh the page or try again."
|
|
661
661
|
), x = this.state.get().messages;
|
|
662
662
|
this.state.setPartial({
|
|
663
|
-
messages: [...x,
|
|
663
|
+
messages: [...x, g]
|
|
664
664
|
});
|
|
665
665
|
}
|
|
666
|
-
} catch (
|
|
667
|
-
this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:",
|
|
666
|
+
} catch (_) {
|
|
667
|
+
this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:", _);
|
|
668
668
|
} finally {
|
|
669
669
|
this.state.setPartial({
|
|
670
670
|
isSendingMessage: !1,
|
|
@@ -673,8 +673,8 @@ class K {
|
|
|
673
673
|
}
|
|
674
674
|
}, this.toUserMessage = (s, e) => {
|
|
675
675
|
const t = (() => {
|
|
676
|
-
const
|
|
677
|
-
return this.state.get().messages.length === 0 &&
|
|
676
|
+
const i = this.contactCtx.state.get().extraCollectedData;
|
|
677
|
+
return this.state.get().messages.length === 0 && i && Object.keys(i).length > 0 ? `${Object.entries(i).filter(([l, c]) => !!c).map(([l, c]) => `${l}: ${c}`).join(`
|
|
678
678
|
`)}
|
|
679
679
|
|
|
680
680
|
${s}` : s;
|
|
@@ -720,12 +720,12 @@ ${s}` : s;
|
|
|
720
720
|
variant: "error",
|
|
721
721
|
action: void 0
|
|
722
722
|
}
|
|
723
|
-
}), this.config =
|
|
723
|
+
}), this.config = n, this.api = a, this.sessionCtx = r, this.contactCtx = d;
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
726
|
class G {
|
|
727
727
|
constructor({
|
|
728
|
-
config:
|
|
728
|
+
config: n,
|
|
729
729
|
contactCtx: a,
|
|
730
730
|
sessionCtx: r,
|
|
731
731
|
resetChat: d
|
|
@@ -739,8 +739,8 @@ class G {
|
|
|
739
739
|
});
|
|
740
740
|
}), this.sessionCtx.sessionsState.subscribe(
|
|
741
741
|
({ isInitialFetchLoading: e, data: t }) => {
|
|
742
|
-
var
|
|
743
|
-
if ((
|
|
742
|
+
var i, o, l, c;
|
|
743
|
+
if ((i = this.config.router) != null && i.chatScreenOnly && // Do not route to a chat if we are currently inside one already
|
|
744
744
|
// This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
|
|
745
745
|
!((o = this.sessionCtx.sessionState.get().session) != null && o.id)) {
|
|
746
746
|
const u = (l = t.find((p) => p.isOpened)) == null ? void 0 : l.id;
|
|
@@ -753,19 +753,19 @@ class G {
|
|
|
753
753
|
this.resetChat(), this.state.setPartial({ screen: "sessions" });
|
|
754
754
|
}, this.toChatScreen = (e) => {
|
|
755
755
|
if (this.resetChat(), e) {
|
|
756
|
-
const t = this.sessionCtx.sessionsState.get().data.find((
|
|
756
|
+
const t = this.sessionCtx.sessionsState.get().data.find((i) => i.id === e);
|
|
757
757
|
if (!t) return;
|
|
758
758
|
this.sessionCtx.sessionState.setPartial({ session: t });
|
|
759
759
|
}
|
|
760
760
|
this.state.setPartial({ screen: "chat" });
|
|
761
|
-
}, this.config =
|
|
761
|
+
}, this.config = n, this.contactCtx = a, this.sessionCtx = r, this.resetChat = d, this.state = new y({
|
|
762
762
|
screen: this.contactCtx.shouldCollectData() ? "welcome" : (s = this.config.router) != null && s.chatScreenOnly ? "chat" : "sessions"
|
|
763
763
|
}), this.registerRoutingListener();
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
766
|
class J {
|
|
767
767
|
constructor({
|
|
768
|
-
storage:
|
|
768
|
+
storage: n,
|
|
769
769
|
config: a
|
|
770
770
|
}) {
|
|
771
771
|
this.KEYS = {
|
|
@@ -775,12 +775,12 @@ class J {
|
|
|
775
775
|
await this.storage.set(this.KEYS.contactToken(this.config.token), r);
|
|
776
776
|
}, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken(this.config.token)), this.setExternalContactId = async (r) => {
|
|
777
777
|
await this.storage.set(this.KEYS.externalContactId(this.config.token), r);
|
|
778
|
-
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage =
|
|
778
|
+
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage = n, this.config = a;
|
|
779
779
|
}
|
|
780
780
|
}
|
|
781
781
|
const b = class b {
|
|
782
782
|
constructor({
|
|
783
|
-
config:
|
|
783
|
+
config: n,
|
|
784
784
|
storage: a,
|
|
785
785
|
modes: r,
|
|
786
786
|
org: d
|
|
@@ -791,7 +791,7 @@ const b = class b {
|
|
|
791
791
|
throw Error(
|
|
792
792
|
"Widget polling values are not defined, did you call WidgetCtx.initialize()"
|
|
793
793
|
);
|
|
794
|
-
this.config =
|
|
794
|
+
this.config = n, this.org = d, this.api = new M({ config: n }), this.storageCtx = a ? new J({ storage: a, config: n }) : void 0, this.modes = r, this.contactCtx = new V({
|
|
795
795
|
api: this.api,
|
|
796
796
|
config: this.config,
|
|
797
797
|
storageCtx: this.storageCtx
|
|
@@ -825,12 +825,12 @@ const b = class b {
|
|
|
825
825
|
}
|
|
826
826
|
};
|
|
827
827
|
b.pollingIntervalsSeconds = null, b.initialize = async ({
|
|
828
|
-
config:
|
|
828
|
+
config: n,
|
|
829
829
|
storage: a
|
|
830
830
|
}) => {
|
|
831
831
|
var d, s, e;
|
|
832
832
|
const r = await new M({
|
|
833
|
-
config:
|
|
833
|
+
config: n
|
|
834
834
|
}).getExternalWidgetConfig();
|
|
835
835
|
if (!r.data)
|
|
836
836
|
throw new Error("Failed to fetch widget config");
|
|
@@ -838,7 +838,7 @@ b.pollingIntervalsSeconds = null, b.initialize = async ({
|
|
|
838
838
|
session: ((d = r.data) == null ? void 0 : d.sessionPollingIntervalSeconds) || 10,
|
|
839
839
|
sessions: ((s = r.data) == null ? void 0 : s.sessionsPollingIntervalSeconds) || 60
|
|
840
840
|
}, new b({
|
|
841
|
-
config:
|
|
841
|
+
config: n,
|
|
842
842
|
storage: a,
|
|
843
843
|
modes: ((e = r.data) == null ? void 0 : e.modes) || [],
|
|
844
844
|
org: {
|
|
@@ -881,6 +881,22 @@ const W = {
|
|
|
881
881
|
back_to_conversations: "Tilbage til samtaler",
|
|
882
882
|
closed_conversations: "Lukkede samtaler"
|
|
883
883
|
}, Z = {
|
|
884
|
+
write_a_message_placeholder: "Γράψτε ένα μήνυμα...",
|
|
885
|
+
your_issue_has_been_resolved: "Το πρόβλημά σας επιλύθηκε!",
|
|
886
|
+
new_conversation: "Νέα συνομιλία",
|
|
887
|
+
welcome_screen_title: "Καλώς ήρθατε στη συνομιλία υποστήριξης",
|
|
888
|
+
welcome_screen_description: "Είμαστε εδώ για να βοηθήσουμε! Ξεκινήστε μια συνομιλία και θα σας απαντήσουμε το συντομότερο δυνατό.",
|
|
889
|
+
your_name_placeholder: "Το όνομά σας",
|
|
890
|
+
your_email_placeholder: "Η διεύθυνση email σας",
|
|
891
|
+
start_chat_button: "Επικοινωνία με την υποστήριξη",
|
|
892
|
+
start_chat_button_loading: "Σύνδεση...",
|
|
893
|
+
i_need_more_help: "Χρειάζομαι περισσότερη βοήθεια",
|
|
894
|
+
this_was_helpful: "Αυτό ήταν χρήσιμο",
|
|
895
|
+
optional: "Προαιρετικό",
|
|
896
|
+
no_conversations_yet: "Δεν υπάρχουν συνομιλίες ακόμα",
|
|
897
|
+
back_to_conversations: "Πίσω στις συνομιλίες",
|
|
898
|
+
closed_conversations: "Κλειστές συνομιλίες"
|
|
899
|
+
}, Q = {
|
|
884
900
|
write_a_message_placeholder: "Nachricht schreiben...",
|
|
885
901
|
your_issue_has_been_resolved: "Ihr Problem wurde gelöst!",
|
|
886
902
|
new_conversation: "Neue Konversation",
|
|
@@ -896,7 +912,7 @@ const W = {
|
|
|
896
912
|
no_conversations_yet: "noch keine Gespräche",
|
|
897
913
|
back_to_conversations: "Zurück zur Konversationen",
|
|
898
914
|
closed_conversations: "Geschlossene Konversationen"
|
|
899
|
-
},
|
|
915
|
+
}, ee = {
|
|
900
916
|
write_a_message_placeholder: "Write a message...",
|
|
901
917
|
your_issue_has_been_resolved: "Your issue has been resolved!",
|
|
902
918
|
new_conversation: "New conversation",
|
|
@@ -912,7 +928,7 @@ const W = {
|
|
|
912
928
|
no_conversations_yet: "No conversations yet",
|
|
913
929
|
back_to_conversations: "Back to conversations",
|
|
914
930
|
closed_conversations: "Closed conversations"
|
|
915
|
-
},
|
|
931
|
+
}, te = {
|
|
916
932
|
write_a_message_placeholder: "Escribe un mensaje...",
|
|
917
933
|
your_issue_has_been_resolved: "¡Tu problema fue resuelto!",
|
|
918
934
|
new_conversation: "Nueva conversación",
|
|
@@ -928,7 +944,7 @@ const W = {
|
|
|
928
944
|
no_conversations_yet: "Sin conversaciones aún",
|
|
929
945
|
back_to_conversations: "Volver a conversaciones",
|
|
930
946
|
closed_conversations: "Conversaciones cerradas"
|
|
931
|
-
},
|
|
947
|
+
}, se = {
|
|
932
948
|
write_a_message_placeholder: "Kirjoita viesti...",
|
|
933
949
|
your_issue_has_been_resolved: "Ongelmasi on ratkaistu!",
|
|
934
950
|
new_conversation: "Uusi keskustelu",
|
|
@@ -944,7 +960,7 @@ const W = {
|
|
|
944
960
|
no_conversations_yet: "Ei vielä keskusteluja",
|
|
945
961
|
back_to_conversations: "Takaisin keskusteluihin",
|
|
946
962
|
closed_conversations: "Suljetut keskustelut"
|
|
947
|
-
},
|
|
963
|
+
}, ne = {
|
|
948
964
|
write_a_message_placeholder: "Écrivez un message...",
|
|
949
965
|
your_issue_has_been_resolved: "Votre problème a été résolu !",
|
|
950
966
|
new_conversation: "Nouvelle conversation",
|
|
@@ -976,7 +992,7 @@ const W = {
|
|
|
976
992
|
no_conversations_yet: "Nessuna conversazione ancora",
|
|
977
993
|
back_to_conversations: "Torna alle conversazioni",
|
|
978
994
|
closed_conversations: "Conversazioni chiuse"
|
|
979
|
-
},
|
|
995
|
+
}, ae = {
|
|
980
996
|
write_a_message_placeholder: "Schrijf een bericht...",
|
|
981
997
|
your_issue_has_been_resolved: "Uw probleem is opgelost!",
|
|
982
998
|
new_conversation: "Nieuw gesprek",
|
|
@@ -992,7 +1008,7 @@ const W = {
|
|
|
992
1008
|
no_conversations_yet: "Nog geen gesprekken",
|
|
993
1009
|
back_to_conversations: "Terug naar gesprekken",
|
|
994
1010
|
closed_conversations: "Afgesloten gesprekken"
|
|
995
|
-
},
|
|
1011
|
+
}, oe = {
|
|
996
1012
|
write_a_message_placeholder: "Skriv en melding...",
|
|
997
1013
|
your_issue_has_been_resolved: "Problemet ditt er løst!",
|
|
998
1014
|
new_conversation: "Ny samtale",
|
|
@@ -1008,7 +1024,7 @@ const W = {
|
|
|
1008
1024
|
no_conversations_yet: "Ingen samtaler ennå",
|
|
1009
1025
|
back_to_conversations: "Tilbake til samtaler",
|
|
1010
1026
|
closed_conversations: "Lukkede samtaler"
|
|
1011
|
-
},
|
|
1027
|
+
}, re = {
|
|
1012
1028
|
write_a_message_placeholder: "Napisz wiadomość...",
|
|
1013
1029
|
your_issue_has_been_resolved: "Twój problem został rozwiązany!",
|
|
1014
1030
|
new_conversation: "Nowa rozmowa",
|
|
@@ -1024,7 +1040,7 @@ const W = {
|
|
|
1024
1040
|
no_conversations_yet: "Jeszcze brak rozmów",
|
|
1025
1041
|
back_to_conversations: "Powrót do rozmów",
|
|
1026
1042
|
closed_conversations: "Zamknięte rozmowy"
|
|
1027
|
-
},
|
|
1043
|
+
}, le = {
|
|
1028
1044
|
write_a_message_placeholder: "Escreva uma mensagem...",
|
|
1029
1045
|
your_issue_has_been_resolved: "Seu problema foi resolvido!",
|
|
1030
1046
|
new_conversation: "Nova conversa",
|
|
@@ -1040,7 +1056,7 @@ const W = {
|
|
|
1040
1056
|
no_conversations_yet: "Nenhuma conversa ainda",
|
|
1041
1057
|
back_to_conversations: "Voltar para conversas",
|
|
1042
1058
|
closed_conversations: "Conversas fechadas"
|
|
1043
|
-
},
|
|
1059
|
+
}, ce = {
|
|
1044
1060
|
write_a_message_placeholder: "Scrie un mesaj...",
|
|
1045
1061
|
your_issue_has_been_resolved: "Problema ta a fost rezolvată!",
|
|
1046
1062
|
new_conversation: "Conversație nouă",
|
|
@@ -1056,7 +1072,7 @@ const W = {
|
|
|
1056
1072
|
no_conversations_yet: "Încă nu există conversații",
|
|
1057
1073
|
back_to_conversations: "Înapoi la conversații",
|
|
1058
1074
|
closed_conversations: "Conversații închise"
|
|
1059
|
-
},
|
|
1075
|
+
}, he = {
|
|
1060
1076
|
write_a_message_placeholder: "Skriv ett meddelande...",
|
|
1061
1077
|
your_issue_has_been_resolved: "Ditt problem har lösts!",
|
|
1062
1078
|
new_conversation: "Ny konversation",
|
|
@@ -1072,7 +1088,23 @@ const W = {
|
|
|
1072
1088
|
no_conversations_yet: "Inga konversationer ännu",
|
|
1073
1089
|
back_to_conversations: "Tillbaka till konversationer",
|
|
1074
1090
|
closed_conversations: "Stängda konversationer"
|
|
1075
|
-
},
|
|
1091
|
+
}, de = {
|
|
1092
|
+
write_a_message_placeholder: "Напишите сообщение...",
|
|
1093
|
+
your_issue_has_been_resolved: "Ваша проблема решена!",
|
|
1094
|
+
new_conversation: "Новый разговор",
|
|
1095
|
+
welcome_screen_title: "Добро пожаловать в чат поддержки",
|
|
1096
|
+
welcome_screen_description: "Мы здесь, чтобы помочь! Начните разговор, и мы ответим вам как можно скорее.",
|
|
1097
|
+
your_name_placeholder: "Ваше имя",
|
|
1098
|
+
your_email_placeholder: "Ваш адрес электронной почты",
|
|
1099
|
+
start_chat_button: "Связаться с поддержкой",
|
|
1100
|
+
start_chat_button_loading: "Подключение...",
|
|
1101
|
+
i_need_more_help: "Мне нужна дополнительная помощь",
|
|
1102
|
+
this_was_helpful: "Это было полезно",
|
|
1103
|
+
optional: "Необязательно",
|
|
1104
|
+
no_conversations_yet: "Пока нет разговоров",
|
|
1105
|
+
back_to_conversations: "Назад к разговорам",
|
|
1106
|
+
closed_conversations: "Закрытые разговоры"
|
|
1107
|
+
}, ue = {
|
|
1076
1108
|
write_a_message_placeholder: "Bir mesaj yazın...",
|
|
1077
1109
|
your_issue_has_been_resolved: "Sorununuz çözüldü!",
|
|
1078
1110
|
new_conversation: "Yeni konuşma",
|
|
@@ -1091,32 +1123,34 @@ const W = {
|
|
|
1091
1123
|
}, D = {
|
|
1092
1124
|
ar: W,
|
|
1093
1125
|
da: X,
|
|
1094
|
-
de:
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1126
|
+
de: Q,
|
|
1127
|
+
el: Z,
|
|
1128
|
+
en: ee,
|
|
1129
|
+
es: te,
|
|
1130
|
+
fi: se,
|
|
1131
|
+
fr: ne,
|
|
1099
1132
|
it: ie,
|
|
1100
|
-
nl:
|
|
1101
|
-
no:
|
|
1102
|
-
pl:
|
|
1103
|
-
pt:
|
|
1104
|
-
ro:
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1133
|
+
nl: ae,
|
|
1134
|
+
no: oe,
|
|
1135
|
+
pl: re,
|
|
1136
|
+
pt: le,
|
|
1137
|
+
ro: ce,
|
|
1138
|
+
ru: de,
|
|
1139
|
+
sv: he,
|
|
1140
|
+
tr: ue
|
|
1141
|
+
}, _e = Object.keys(D);
|
|
1142
|
+
function ve(h) {
|
|
1143
|
+
return _e.includes(h);
|
|
1110
1144
|
}
|
|
1111
|
-
function
|
|
1145
|
+
function be(h, n, a) {
|
|
1112
1146
|
var r;
|
|
1113
|
-
return ((r = a == null ? void 0 : a[
|
|
1147
|
+
return ((r = a == null ? void 0 : a[n]) == null ? void 0 : r[h]) || D[n][h] || "";
|
|
1114
1148
|
}
|
|
1115
1149
|
export {
|
|
1116
1150
|
y as PrimitiveState,
|
|
1117
1151
|
U as WidgetCtx,
|
|
1118
|
-
|
|
1152
|
+
be as getTranslation,
|
|
1119
1153
|
H as isExhaustive,
|
|
1120
|
-
|
|
1154
|
+
ve as isSupportedLanguage
|
|
1121
1155
|
};
|
|
1122
1156
|
//# sourceMappingURL=index.js.map
|