@opencx/widget-core 4.0.51 → 4.0.52

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.js CHANGED
@@ -3,7 +3,7 @@ import V from "lodash.isequal";
3
3
  import { v4 as L } from "uuid";
4
4
  const F = (_) => {
5
5
  console.log(_.error);
6
- }, B = (_) => {
6
+ }, H = (_) => {
7
7
  const o = D({
8
8
  baseUrl: _.baseUrl
9
9
  }), i = {
@@ -27,7 +27,7 @@ class M {
27
27
  }, this.createOpenAPIClient = ({
28
28
  baseUrl: e,
29
29
  headers: t
30
- }) => B({
30
+ }) => H({
31
31
  baseUrl: e,
32
32
  onRequest: ({ request: a }) => {
33
33
  Object.entries(t).forEach(([n, r]) => {
@@ -74,37 +74,37 @@ class M {
74
74
  onProgress: a
75
75
  }) => new Promise((n, r) => {
76
76
  var k;
77
- const c = new FormData();
78
- c.append("file", e);
79
- const u = new XMLHttpRequest();
77
+ const u = new FormData();
78
+ u.append("file", e);
79
+ const c = new XMLHttpRequest();
80
80
  if (t && (t.addEventListener("abort", () => {
81
- u.abort(), r(new DOMException("Aborted", "AbortError"));
81
+ c.abort(), r(new DOMException("Aborted", "AbortError"));
82
82
  }), t.aborted)) {
83
83
  r(new DOMException("Aborted", "AbortError"));
84
84
  return;
85
85
  }
86
- u.upload.addEventListener("progress", (g) => {
87
- if (g.lengthComputable && a) {
88
- const f = Math.round(g.loaded / g.total * 100);
89
- a(f);
86
+ c.upload.addEventListener("progress", (m) => {
87
+ if (m.lengthComputable && a) {
88
+ const w = Math.round(m.loaded / m.total * 100);
89
+ a(w);
90
90
  }
91
- }), u.addEventListener("load", () => {
92
- if (u.status >= 200 && u.status < 300)
91
+ }), c.addEventListener("load", () => {
92
+ if (c.status >= 200 && c.status < 300)
93
93
  try {
94
- const g = JSON.parse(u.responseText);
95
- n(g);
96
- } catch (g) {
97
- r(new Error(`Failed to parse response: ${g}`));
94
+ const m = JSON.parse(c.responseText);
95
+ n(m);
96
+ } catch (m) {
97
+ r(new Error(`Failed to parse response: ${m}`));
98
98
  }
99
99
  else
100
- r(new Error(`Upload failed with status: ${u.status}`));
101
- }), u.addEventListener("error", () => {
100
+ r(new Error(`Upload failed with status: ${c.status}`));
101
+ }), c.addEventListener("error", () => {
102
102
  r(new Error("Network error occurred"));
103
- }), u.addEventListener("timeout", () => {
103
+ }), c.addEventListener("timeout", () => {
104
104
  r(new Error("Upload timed out"));
105
105
  });
106
- const { baseUrl: p } = this.constructClientOptions(this.userToken), b = `${p}/backend/widget/v2/upload`;
107
- u.open("POST", b), u.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((k = this.config.user) == null ? void 0 : k.token) ? u.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), u.send(c);
106
+ const { baseUrl: v } = this.constructClientOptions(this.userToken), b = `${v}/backend/widget/v2/upload`;
107
+ c.open("POST", b), c.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((k = this.config.user) == null ? void 0 : k.token) ? c.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), c.send(u);
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
@@ -117,7 +117,7 @@ class M {
117
117
  this.client = this.createOpenAPIClient({ baseUrl: i, headers: l });
118
118
  }
119
119
  }
120
- function K(_, o) {
120
+ function B(_, o) {
121
121
  console.error(`Missing case for ${_} in ${o}`);
122
122
  }
123
123
  class S {
@@ -143,7 +143,7 @@ class S {
143
143
  }), this.state = o, this.initialState = o;
144
144
  }
145
145
  }
146
- class U {
146
+ class O {
147
147
  constructor() {
148
148
  this.state = new S({
149
149
  isPolling: !1,
@@ -172,7 +172,7 @@ class U {
172
172
  };
173
173
  }
174
174
  }
175
- function N(_) {
175
+ function U(_) {
176
176
  try {
177
177
  const o = _();
178
178
  return o instanceof Promise ? o.then((i) => ({ data: i })).catch((i) => ({ error: i })) : { data: o };
@@ -180,7 +180,7 @@ function N(_) {
180
180
  return { error: o };
181
181
  }
182
182
  }
183
- class H {
183
+ class K {
184
184
  constructor({
185
185
  api: o,
186
186
  config: i,
@@ -188,7 +188,7 @@ class H {
188
188
  messageCtx: h,
189
189
  sessionPollingIntervalSeconds: s
190
190
  }) {
191
- this.poller = new U(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.registerPolling = () => {
191
+ this.poller = new O(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.registerPolling = () => {
192
192
  this.sessionCtx.sessionState.subscribe(({ session: e }) => {
193
193
  e != null && e.id ? this.poller.startPolling(async (t) => {
194
194
  this.fetchSessionAndHistory({ sessionId: e.id, abortSignal: t });
@@ -212,20 +212,27 @@ class H {
212
212
  abortSignal: t,
213
213
  fetchFullHistory: a = !1
214
214
  }) => {
215
- var u;
216
- this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
217
- const n = this.messageCtx.state.get().messages, r = n.length > 0 ? ((u = n[n.length - 1]) == null ? void 0 : u.timestamp) ?? void 0 : void 0, { data: c } = await this.api.pollSessionAndHistory({
215
+ var v;
216
+ const n = this.messageCtx.state.get().messages.length === 0;
217
+ n && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
218
+ const r = this.messageCtx.state.get().messages, u = r.length > 0 ? ((v = r[r.length - 1]) == null ? void 0 : v.timestamp) ?? void 0 : void 0, { data: c } = await this.api.pollSessionAndHistory({
218
219
  sessionId: e,
219
220
  abortSignal: t,
220
- lastMessageTimestamp: a ? void 0 : r
221
+ lastMessageTimestamp: a ? void 0 : u
221
222
  });
222
223
  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, y = c.history.map(this.mapHistoryToMessage).filter((b) => b !== null).filter(
224
- (b) => !p.some((v) => v.id === b.id)
224
+ const f = this.messageCtx.state.get().messages, b = c.history.map(this.mapHistoryToMessage).filter((d) => d !== null).filter(
225
+ (d) => !f.some((k) => k.id === d.id)
225
226
  );
226
- this.messageCtx.state.setPartial({
227
- messages: [...p, ...y]
228
- });
227
+ if (this.messageCtx.state.setPartial({
228
+ messages: [...f, ...b]
229
+ }), n)
230
+ this.messageCtx.markAsDispatchedToOnMessageReceivedHook(
231
+ b.map((d) => d.id)
232
+ );
233
+ else
234
+ for (const d of b)
235
+ this.messageCtx.dispatchToOnMessageReceivedHook(d);
229
236
  }
230
237
  this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
231
238
  }, this.mapHistoryToMessage = (e) => {
@@ -326,7 +333,7 @@ class H {
326
333
  case "none":
327
334
  return null;
328
335
  default:
329
- return K(
336
+ return B(
330
337
  e.systemMessagePayload,
331
338
  this.constructSystemMessage.name
332
339
  ), null;
@@ -335,7 +342,7 @@ class H {
335
342
  const t = e.result;
336
343
  if (t === null || typeof t != "object") return t;
337
344
  if ("responseBodyText" in t && typeof t.responseBodyText == "string") {
338
- const a = t.responseBodyText, n = N(() => JSON.parse(a)).data;
345
+ const a = t.responseBodyText, n = U(() => JSON.parse(a)).data;
339
346
  if (n) return n;
340
347
  }
341
348
  return e.result;
@@ -353,26 +360,26 @@ class J {
353
360
  var s;
354
361
  return !!(!((s = this.state.get().contact) != null && s.token) && this.config.collectUserData);
355
362
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
356
- var s, e, t, a, n, r, c, u, p, y, b, v, k, g;
363
+ var s, e, t, a, n, r, u, c, v, f, b, d, k, m;
357
364
  if (!((s = this.config.user) != null && s.token)) {
358
365
  if (this.config.collectUserData && !((t = (e = this.config.user) == null ? void 0 : e.data) != null && t.email)) {
359
366
  if ((a = this.config.extraDataCollectionFields) != null && a.length)
360
367
  return;
361
- const f = await ((n = this.storageCtx) == null ? void 0 : n.getContactToken());
362
- f && await this.setUnverifiedContact(f);
368
+ const w = await ((n = this.storageCtx) == null ? void 0 : n.getContactToken());
369
+ w && await this.setUnverifiedContact(w);
363
370
  return;
364
371
  }
365
- if (!((c = (r = this.config.user) == null ? void 0 : r.data) != null && c.email)) {
366
- const f = await ((u = this.storageCtx) == null ? void 0 : u.getContactToken());
367
- if (f) {
368
- await this.setUnverifiedContact(f);
372
+ if (!((u = (r = this.config.user) == null ? void 0 : r.data) != null && u.email)) {
373
+ const w = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
374
+ if (w) {
375
+ await this.setUnverifiedContact(w);
369
376
  return;
370
377
  }
371
378
  }
372
379
  await this.createUnverifiedContact({
373
- email: (y = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : y.email,
374
- non_verified_name: (v = (b = this.config.user) == null ? void 0 : b.data) == null ? void 0 : v.name,
375
- non_verified_custom_data: (g = (k = this.config.user) == null ? void 0 : k.data) == null ? void 0 : g.customData
380
+ email: (f = (v = this.config.user) == null ? void 0 : v.data) == null ? void 0 : f.email,
381
+ non_verified_name: (d = (b = this.config.user) == null ? void 0 : b.data) == null ? void 0 : d.name,
382
+ non_verified_custom_data: (m = (k = this.config.user) == null ? void 0 : k.data) == null ? void 0 : m.customData
376
383
  });
377
384
  }
378
385
  }, this.createUnverifiedContact = async (s, e) => {
@@ -388,9 +395,9 @@ class J {
388
395
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
389
396
  }
390
397
  }, this.setUnverifiedContact = async (s) => {
391
- var a, n, r, c;
398
+ var a, n, r, u;
392
399
  const e = await ((a = this.storageCtx) == null ? void 0 : a.getExternalContactId()), t = ((n = this.config.user) == null ? void 0 : n.externalId) || e || L();
393
- this.api.setAuthToken(s), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(s)), await ((c = this.storageCtx) == null ? void 0 : c.setExternalContactId(t)), this.state.setPartial({ contact: { token: s, externalId: t } });
400
+ this.api.setAuthToken(s), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(s)), await ((u = this.storageCtx) == null ? void 0 : u.setExternalContactId(t)), this.state.setPartial({ contact: { token: s, externalId: t } });
394
401
  }, this.config = o, this.storageCtx = l, this.api = i, this.state = new S({
395
402
  contact: (h = o.user) != null && h.token ? {
396
403
  token: o.user.token,
@@ -452,7 +459,7 @@ class W {
452
459
  contactCtx: l,
453
460
  sessionsPollingIntervalSeconds: h
454
461
  }) {
455
- this.sessionsRefresher = new U(), this.sessionState = new S({
462
+ this.sessionsRefresher = new O(), this.sessionState = new S({
456
463
  session: null,
457
464
  isCreatingSession: !1,
458
465
  isResolvingSession: !1
@@ -481,11 +488,11 @@ class W {
481
488
  Object.entries(this.config.sessionCustomData || {}).map(
482
489
  ([s, e]) => {
483
490
  var t;
484
- return typeof e == "string" ? [s, e] : typeof e == "boolean" ? [s, e] : typeof e == "number" ? [s, e] : [s, ((t = N(() => JSON.stringify(e))) == null ? void 0 : t.data) || ""];
491
+ return typeof e == "string" ? [s, e] : typeof e == "boolean" ? [s, e] : typeof e == "number" ? [s, e] : [s, ((t = U(() => JSON.stringify(e))) == null ? void 0 : t.data) || ""];
485
492
  }
486
493
  )
487
494
  ), this.createSession = async () => {
488
- var n, r, c;
495
+ var n, r, u;
489
496
  this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
490
497
  const s = (n = this.contactCtx.state.get().contact) == null ? void 0 : n.externalId, e = {
491
498
  ...this.getParsedCustomData(),
@@ -493,7 +500,7 @@ class W {
493
500
  }, { data: t, error: a } = await this.api.createSession({
494
501
  customData: Object.keys(e).length > 0 ? e : void 0
495
502
  });
496
- return t ? (this.sessionState.setPartial({ session: t, isCreatingSession: !1 }), (c = (r = this.config.hooks) == null ? void 0 : r.onSessionCreated) == null || c.call(r, { session: t }), t) : (this.sessionState.setPartial({ isCreatingSession: !1 }), console.error("Failed to create session:", a), null);
503
+ return t ? (this.sessionState.setPartial({ session: t, isCreatingSession: !1 }), (u = (r = this.config.hooks) == null ? void 0 : r.onSessionCreated) == null || u.call(r, { session: t }), t) : (this.sessionState.setPartial({ isCreatingSession: !1 }), console.error("Failed to create session:", a), null);
497
504
  }, this.loadMoreSessions = async () => {
498
505
  if (this.sessionsState.get().isLastPage) return;
499
506
  const { data: s } = await this.getSessions({
@@ -501,7 +508,7 @@ class W {
501
508
  });
502
509
  if (s) {
503
510
  const t = [...this.sessionsState.get().data, ...s.items].filter(
504
- (a, n, r) => n === r.findIndex((c) => a.id === c.id)
511
+ (a, n, r) => n === r.findIndex((u) => a.id === u.id)
505
512
  );
506
513
  this.sessionsState.setPartial({
507
514
  data: t,
@@ -561,10 +568,19 @@ class Y {
561
568
  isSendingMessageToAI: !1,
562
569
  lastAIResMightSolveUserIssue: !1,
563
570
  isInitialFetchLoading: !1
564
- }), this.sendMessageAbortController = new AbortController(), this.reset = () => {
565
- this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
571
+ }), this.sendMessageAbortController = new AbortController(), this.messageIdsDispatchedToOnMessageReceivedHook = /* @__PURE__ */ new Set(), this.reset = () => {
572
+ this.sendMessageAbortController.abort("Resetting chat"), this.state.reset(), this.messageIdsDispatchedToOnMessageReceivedHook.clear();
573
+ }, this.dispatchToOnMessageReceivedHook = (s) => {
574
+ var t, a;
575
+ if (s.type === "USER" || this.messageIdsDispatchedToOnMessageReceivedHook.has(s.id)) return;
576
+ const e = this.sessionCtx.sessionState.get().session;
577
+ e && (this.messageIdsDispatchedToOnMessageReceivedHook.add(s.id), (a = (t = this.config.hooks) == null ? void 0 : t.onMessageReceived) == null || a.call(t, { message: s, session: e }));
578
+ }, this.markAsDispatchedToOnMessageReceivedHook = (s) => {
579
+ s.forEach(
580
+ (e) => this.messageIdsDispatchedToOnMessageReceivedHook.add(e)
581
+ );
566
582
  }, this.sendMessage = async (s) => {
567
- var t, a, n, r, c, u, p, y, b;
583
+ var t, a, n, r, u, c, v, f, b;
568
584
  let e;
569
585
  try {
570
586
  if (!s.content.trim() && (!s.attachments || s.attachments.length === 0)) {
@@ -573,37 +589,37 @@ class Y {
573
589
  );
574
590
  return;
575
591
  }
576
- const v = this.sessionCtx.sessionState.get().session, g = (v == null ? void 0 : v.assignee.kind) === "ai", f = this.state.get().isSendingMessageToAI, z = this.state.get().messages.at(-1);
577
- if (this.config.disableSendingWhenAwaitingAIReply !== !1 && (f || // If last message is from user, then bot response did not arrive yet
578
- g && (z == null ? void 0 : z.type) === "USER")) {
592
+ const d = this.sessionCtx.sessionState.get().session, m = (d == null ? void 0 : d.assignee.kind) === "ai", w = this.state.get().isSendingMessageToAI, I = this.state.get().messages.at(-1);
593
+ if (this.config.disableSendingWhenAwaitingAIReply !== !1 && (w || // If last message is from user, then bot response did not arrive yet
594
+ m && (I == null ? void 0 : I.type) === "USER")) {
579
595
  console.warn("Cannot send messages while awaiting AI response");
580
596
  return;
581
597
  }
582
598
  this.sendMessageAbortController.abort("Superseded by a newer message"), this.sendMessageAbortController = new AbortController(), e = this.sendMessageAbortController, this.state.setPartial({
583
599
  lastAIResMightSolveUserIssue: !1,
584
600
  isSendingMessage: !0,
585
- isSendingMessageToAI: !!g || !v
601
+ isSendingMessageToAI: !!m || !d
586
602
  });
587
- const P = this.state.get().messages, j = !((t = this.sessionCtx.sessionState.get().session) != null && t.id) && P.length === 0 && ((a = this.config.advancedInitialMessages) == null ? void 0 : a.some((d) => d.persistent)), A = j ? (this.config.advancedInitialMessages || []).filter((d) => d.persistent).map(
588
- (d) => ({
603
+ const P = this.state.get().messages, T = !((t = this.sessionCtx.sessionState.get().session) != null && t.id) && P.length === 0 && ((a = this.config.advancedInitialMessages) == null ? void 0 : a.some((g) => g.persistent)), j = T ? (this.config.advancedInitialMessages || []).filter((g) => g.persistent).map(
604
+ (g) => ({
589
605
  id: C(),
590
606
  component: "bot_message",
591
607
  type: "AI",
592
608
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
593
609
  data: {
594
- message: d.message
610
+ message: g.message
595
611
  },
596
612
  agent: this.config.bot ? { ...this.config.bot, isAi: !0, id: null } : void 0
597
613
  })
598
- ) : [], I = this.toUserMessage(
614
+ ) : [], z = this.toUserMessage(
599
615
  s.content.trim(),
600
616
  s.attachments || void 0
601
617
  );
602
618
  if (this.state.setPartial({
603
619
  messages: [
604
- ...A,
620
+ ...j,
605
621
  ...P,
606
- I
622
+ z
607
623
  ]
608
624
  }), !((n = this.sessionCtx.sessionState.get().session) != null && n.id)) {
609
625
  if (!await this.sessionCtx.createSession()) {
@@ -612,17 +628,17 @@ class Y {
612
628
  }
613
629
  this.sessionCtx.refreshSessions();
614
630
  }
615
- const T = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
616
- if (!T) return;
617
- const { data: m } = await this.api.sendMessage(
631
+ const A = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
632
+ if (!A) return;
633
+ const { data: p } = await this.api.sendMessage(
618
634
  {
619
- uuid: I.id,
635
+ uuid: z.id,
620
636
  bot_token: this.config.token,
621
637
  headers: this.config.headers,
622
638
  query_params: this.config.queryParams,
623
639
  body_properties: this.config.bodyProperties,
624
- session_id: T,
625
- content: I.content,
640
+ session_id: A,
641
+ content: z.content,
626
642
  attachments: s.attachments,
627
643
  clientContext: this.config.context,
628
644
  custom_data: {
@@ -631,41 +647,41 @@ class Y {
631
647
  },
632
648
  language: this.config.language,
633
649
  exit_mode_prompt: s.exitModePrompt,
634
- initial_messages: j ? A.map((d) => ({
635
- uuid: d.id,
636
- content: d.data.message
650
+ initial_messages: T ? j.map((g) => ({
651
+ uuid: g.id,
652
+ content: g.data.message
637
653
  })) : void 0
638
654
  },
639
655
  e.signal
640
656
  );
641
- if (m != null && m.success) {
642
- const d = this.toBotMessage(m);
643
- if (d) {
657
+ if (p != null && p.success) {
658
+ const g = this.toBotMessage(p);
659
+ if (g) {
644
660
  const x = this.state.get().messages;
645
661
  if (!!x.some(
646
- (R) => R.id === d.id
662
+ (N) => N.id === g.id
647
663
  )) {
648
664
  this.state.setPartial({
649
- lastAIResMightSolveUserIssue: ((c = m.autopilotResponse) == null ? void 0 : c.mightSolveUserIssue) || ((u = m.uiResponse) == null ? void 0 : u.mightSolveUserIssue)
665
+ lastAIResMightSolveUserIssue: ((u = p.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((c = p.uiResponse) == null ? void 0 : c.mightSolveUserIssue)
650
666
  });
651
667
  return;
652
668
  }
653
669
  this.state.setPartial({
654
- messages: [...x, d],
655
- lastAIResMightSolveUserIssue: ((p = m.autopilotResponse) == null ? void 0 : p.mightSolveUserIssue) || ((y = m.uiResponse) == null ? void 0 : y.mightSolveUserIssue)
656
- });
670
+ messages: [...x, g],
671
+ lastAIResMightSolveUserIssue: ((v = p.autopilotResponse) == null ? void 0 : v.mightSolveUserIssue) || ((f = p.uiResponse) == null ? void 0 : f.mightSolveUserIssue)
672
+ }), this.dispatchToOnMessageReceivedHook(g);
657
673
  }
658
- m.session && this.sessionCtx.sessionState.setPartial({ session: m.session });
674
+ p.session && this.sessionCtx.sessionState.setPartial({ session: p.session });
659
675
  } else {
660
- const d = this.toBotErrorMessage(
661
- ((b = m == null ? void 0 : m.error) == null ? void 0 : b.message) || "Something went wrong. Please refresh the page or try again."
676
+ const g = this.toBotErrorMessage(
677
+ ((b = p == null ? void 0 : p.error) == null ? void 0 : b.message) || "Something went wrong. Please refresh the page or try again."
662
678
  ), x = this.state.get().messages;
663
679
  this.state.setPartial({
664
- messages: [...x, d]
680
+ messages: [...x, g]
665
681
  });
666
682
  }
667
- } catch (v) {
668
- e != null && e.signal.aborted || console.error("Failed to send message:", v);
683
+ } catch (d) {
684
+ e != null && e.signal.aborted || console.error("Failed to send message:", d);
669
685
  } finally {
670
686
  e != null && e.signal.aborted || this.state.setPartial({
671
687
  isSendingMessage: !1,
@@ -675,7 +691,7 @@ class Y {
675
691
  }, this.toUserMessage = (s, e) => {
676
692
  const t = (() => {
677
693
  const a = this.contactCtx.state.get().extraCollectedData;
678
- return this.state.get().messages.length === 0 && a && Object.keys(a).length > 0 ? `${Object.entries(a).filter(([r, c]) => !!c).map(([r, c]) => `${r}: ${c}`).join(`
694
+ return this.state.get().messages.length === 0 && a && Object.keys(a).length > 0 ? `${Object.entries(a).filter(([r, u]) => !!u).map(([r, u]) => `${r}: ${u}`).join(`
679
695
  `)}
680
696
 
681
697
  ${s}` : s;
@@ -740,14 +756,14 @@ class G {
740
756
  });
741
757
  }), this.sessionCtx.sessionsState.subscribe(
742
758
  ({ isInitialFetchLoading: e, data: t }) => {
743
- var a, n, r, c;
759
+ var a, n, r, u;
744
760
  if ((a = this.config.router) != null && a.chatScreenOnly && // Do not route to a chat if we are currently inside one already
745
761
  // This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
746
762
  !((n = this.sessionCtx.sessionState.get().session) != null && n.id)) {
747
- const u = (r = t.find((p) => p.isOpened)) == null ? void 0 : r.id;
748
- return u ? this.toChatScreen(u) : void 0;
763
+ const c = (r = t.find((v) => v.isOpened)) == null ? void 0 : r.id;
764
+ return c ? this.toChatScreen(c) : void 0;
749
765
  }
750
- t.length || ((c = this.config.router) == null ? void 0 : c.goToChatIfNoSessions) !== !1 && !e && this.state.get().screen !== "chat" && this.toChatScreen();
766
+ t.length || ((u = this.config.router) == null ? void 0 : u.goToChatIfNoSessions) !== !1 && !e && this.state.get().screen !== "chat" && this.toChatScreen();
751
767
  }
752
768
  );
753
769
  }, this.toSessionsScreen = () => {
@@ -783,7 +799,7 @@ class $ {
783
799
  }, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage = o, this.config = i;
784
800
  }
785
801
  }
786
- const w = class w {
802
+ const y = class y {
787
803
  constructor({
788
804
  config: o,
789
805
  storage: i,
@@ -792,7 +808,7 @@ const w = class w {
792
808
  }) {
793
809
  if (this.modes = [], this.resetChat = () => {
794
810
  this.sessionCtx.reset(), this.messageCtx.reset();
795
- }, !w.pollingIntervalsSeconds)
811
+ }, !y.pollingIntervalsSeconds)
796
812
  throw Error(
797
813
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
798
814
  );
@@ -804,7 +820,7 @@ const w = class w {
804
820
  config: this.config,
805
821
  api: this.api,
806
822
  contactCtx: this.contactCtx,
807
- sessionsPollingIntervalSeconds: w.pollingIntervalsSeconds.sessions
823
+ sessionsPollingIntervalSeconds: y.pollingIntervalsSeconds.sessions
808
824
  }), this.messageCtx = new Y({
809
825
  config: this.config,
810
826
  api: this.api,
@@ -815,12 +831,12 @@ const w = class w {
815
831
  api: this.api,
816
832
  sessionCtx: this.sessionCtx,
817
833
  messageCtx: this.messageCtx
818
- }), this.activeSessionPollingCtx = new H({
834
+ }), this.activeSessionPollingCtx = new K({
819
835
  api: this.api,
820
836
  config: this.config,
821
837
  sessionCtx: this.sessionCtx,
822
838
  messageCtx: this.messageCtx,
823
- sessionPollingIntervalSeconds: w.pollingIntervalsSeconds.session
839
+ sessionPollingIntervalSeconds: y.pollingIntervalsSeconds.session
824
840
  }), this.routerCtx = new G({
825
841
  config: this.config,
826
842
  contactCtx: this.contactCtx,
@@ -829,7 +845,7 @@ const w = class w {
829
845
  });
830
846
  }
831
847
  };
832
- w.pollingIntervalsSeconds = null, w.initialize = async ({
848
+ y.pollingIntervalsSeconds = null, y.initialize = async ({
833
849
  config: o,
834
850
  storage: i
835
851
  }) => {
@@ -839,10 +855,10 @@ w.pollingIntervalsSeconds = null, w.initialize = async ({
839
855
  }).getExternalWidgetConfig();
840
856
  if (!l.data)
841
857
  throw new Error("Failed to fetch widget config");
842
- return w.pollingIntervalsSeconds = {
858
+ return y.pollingIntervalsSeconds = {
843
859
  session: ((h = l.data) == null ? void 0 : h.sessionPollingIntervalSeconds) || 10,
844
860
  sessions: ((s = l.data) == null ? void 0 : s.sessionsPollingIntervalSeconds) || 60
845
- }, new w({
861
+ }, new y({
846
862
  config: o,
847
863
  storage: i,
848
864
  modes: ((e = l.data) == null ? void 0 : e.modes) || [],
@@ -852,7 +868,7 @@ w.pollingIntervalsSeconds = null, w.initialize = async ({
852
868
  }
853
869
  });
854
870
  };
855
- let E = w;
871
+ let E = y;
856
872
  const Z = {
857
873
  write_a_message_placeholder: "اكتب رسالة...",
858
874
  your_issue_has_been_resolved: "تم حل مشكلتك!",
@@ -1317,7 +1333,7 @@ const Z = {
1317
1333
  no_conversations_yet: "Još nema razgovora",
1318
1334
  back_to_conversations: "Natrag na razgovore",
1319
1335
  closed_conversations: "Zatvoreni razgovori"
1320
- }, ze = {
1336
+ }, Ie = {
1321
1337
  write_a_message_placeholder: "Kirjuta sõnum...",
1322
1338
  your_issue_has_been_resolved: "Teie probleem on lahendatud!",
1323
1339
  new_conversation: "Uus vestlus",
@@ -1333,7 +1349,7 @@ const Z = {
1333
1349
  no_conversations_yet: "Vestlusi pole veel",
1334
1350
  back_to_conversations: "Tagasi vestluste juurde",
1335
1351
  closed_conversations: "Suletud vestlused"
1336
- }, Ie = {
1352
+ }, ze = {
1337
1353
  write_a_message_placeholder: "Írjon üzenetet...",
1338
1354
  your_issue_has_been_resolved: "A problémája megoldódott!",
1339
1355
  new_conversation: "Új beszélgetés",
@@ -1365,7 +1381,7 @@ const Z = {
1365
1381
  no_conversations_yet: "Engin samtöl ennþá",
1366
1382
  back_to_conversations: "Til baka í samtöl",
1367
1383
  closed_conversations: "Lokuð samtöl"
1368
- }, je = {
1384
+ }, Te = {
1369
1385
  write_a_message_placeholder: "Rakstiet ziņojumu...",
1370
1386
  your_issue_has_been_resolved: "Jūsu problēma ir atrisināta!",
1371
1387
  new_conversation: "Jauna saruna",
@@ -1381,7 +1397,7 @@ const Z = {
1381
1397
  no_conversations_yet: "Pagaidām nav sarunu",
1382
1398
  back_to_conversations: "Atpakaļ pie sarunām",
1383
1399
  closed_conversations: "Slēgtās sarunas"
1384
- }, Ae = {
1400
+ }, je = {
1385
1401
  write_a_message_placeholder: "Parašykite žinutę...",
1386
1402
  your_issue_has_been_resolved: "Jūsų problema išspręsta!",
1387
1403
  new_conversation: "Naujas pokalbis",
@@ -1397,7 +1413,7 @@ const Z = {
1397
1413
  no_conversations_yet: "Pokalbių dar nėra",
1398
1414
  back_to_conversations: "Grįžti į pokalbius",
1399
1415
  closed_conversations: "Uždaryti pokalbiai"
1400
- }, Te = {
1416
+ }, Ae = {
1401
1417
  write_a_message_placeholder: "Schreift eng Noriicht...",
1402
1418
  your_issue_has_been_resolved: "Äert Problem gouf geléist!",
1403
1419
  new_conversation: "Nei Konversatioun",
@@ -1461,7 +1477,7 @@ const Z = {
1461
1477
  no_conversations_yet: "Zatiaľ žiadne konverzácie",
1462
1478
  back_to_conversations: "Späť na konverzácie",
1463
1479
  closed_conversations: "Uzavreté konverzácie"
1464
- }, O = {
1480
+ }, R = {
1465
1481
  ar: Z,
1466
1482
  bn: X,
1467
1483
  bg: Q,
@@ -1471,20 +1487,20 @@ const Z = {
1471
1487
  el: se,
1472
1488
  en: oe,
1473
1489
  es: ne,
1474
- et: ze,
1490
+ et: Ie,
1475
1491
  fi: re,
1476
1492
  fil: ie,
1477
1493
  fr: le,
1478
1494
  hi: ce,
1479
1495
  hr: xe,
1480
- hu: Ie,
1496
+ hu: ze,
1481
1497
  is: Pe,
1482
1498
  it: _e,
1483
1499
  ja: he,
1484
1500
  ko: ue,
1485
- lb: Te,
1486
- lt: Ae,
1487
- lv: je,
1501
+ lb: Ae,
1502
+ lt: je,
1503
+ lv: Te,
1488
1504
  mt: Me,
1489
1505
  nb: Ee,
1490
1506
  nl: de,
@@ -1500,19 +1516,19 @@ const Z = {
1500
1516
  ur: ke,
1501
1517
  vi: Se,
1502
1518
  "zh-cn": Ce
1503
- }, Ue = Object.keys(O);
1519
+ }, Oe = Object.keys(R);
1504
1520
  function Fe(_) {
1505
- return Ue.includes(_);
1521
+ return Oe.includes(_);
1506
1522
  }
1507
- function Be(_, o, i) {
1523
+ function He(_, o, i) {
1508
1524
  var l;
1509
- return ((l = i == null ? void 0 : i[o]) == null ? void 0 : l[_]) || O[o][_] || "";
1525
+ return ((l = i == null ? void 0 : i[o]) == null ? void 0 : l[_]) || R[o][_] || "";
1510
1526
  }
1511
1527
  export {
1512
1528
  S as PrimitiveState,
1513
1529
  E as WidgetCtx,
1514
- Be as getTranslation,
1515
- K as isExhaustive,
1530
+ He as getTranslation,
1531
+ B as isExhaustive,
1516
1532
  Fe as isSupportedLanguage
1517
1533
  };
1518
1534
  //# sourceMappingURL=index.js.map