@opencx/widget 3.0.75 → 3.0.77

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.
Files changed (33) hide show
  1. package/dist/designs.cjs +3 -3
  2. package/dist/designs.cjs.map +1 -1
  3. package/dist/designs.js +10 -9
  4. package/dist/designs.js.map +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/react.cjs +1 -1
  8. package/dist/react.js +2 -2
  9. package/dist/src/headless/core/__tests__/test-utils.d.ts +41 -2
  10. package/dist/src/headless/core/api/api-caller.d.ts +42 -3
  11. package/dist/src/headless/core/api/schema.d.ts +61 -3
  12. package/dist/src/headless/core/context/active-session-polling.ctx.d.ts +1 -1
  13. package/dist/src/headless/core/context/message.ctx.d.ts +1 -1
  14. package/dist/src/headless/core/context/session.ctx.d.ts +2 -1
  15. package/dist/src/headless/core/index.d.ts +1 -1
  16. package/dist/src/headless/core/types/{schemas.d.ts → dtos.d.ts} +1 -0
  17. package/dist/src/headless/core/types/json-value.d.ts +7 -0
  18. package/dist/src/headless/core/types/messages.d.ts +1 -1
  19. package/dist/src/headless/core/types/widget-config.d.ts +8 -6
  20. package/dist/{useWidgetTrigger-CiYy4rS2.cjs → useWidgetTrigger-Bj4tpdxy.cjs} +2 -2
  21. package/dist/{useWidgetTrigger-CiYy4rS2.cjs.map → useWidgetTrigger-Bj4tpdxy.cjs.map} +1 -1
  22. package/dist/{useWidgetTrigger-CwB0x_Pe.js → useWidgetTrigger-TmZa8JFh.js} +3 -3
  23. package/dist/{useWidgetTrigger-CwB0x_Pe.js.map → useWidgetTrigger-TmZa8JFh.js.map} +1 -1
  24. package/dist/{widget.ctx-COUAUyWX.js → widget.ctx-DRC-z8Ql.js} +113 -102
  25. package/dist/widget.ctx-DRC-z8Ql.js.map +1 -0
  26. package/dist/widget.ctx-sL-dW2kY.cjs +5 -0
  27. package/dist/widget.ctx-sL-dW2kY.cjs.map +1 -0
  28. package/dist-embed/script.js +5 -5
  29. package/dist-embed/script.js.map +1 -1
  30. package/package.json +1 -1
  31. package/dist/widget.ctx-COUAUyWX.js.map +0 -1
  32. package/dist/widget.ctx-DUaeXkNb.cjs +0 -5
  33. package/dist/widget.ctx-DUaeXkNb.cjs.map +0 -1
@@ -1,43 +1,43 @@
1
1
  import M from "openapi-fetch";
2
2
  import O from "lodash.isequal";
3
3
  import { v4 as E } from "uuid";
4
- const F = (d) => {
5
- console.log(d.error);
6
- }, _ = (d) => {
4
+ const F = (g) => {
5
+ console.log(g.error);
6
+ }, _ = (g) => {
7
7
  const n = M({
8
- baseUrl: d.baseUrl
8
+ baseUrl: g.baseUrl
9
9
  }), i = {
10
- onRequest: d.onRequest,
11
- onResponse: d.onResponse,
12
- onError: d.onError || F
10
+ onRequest: g.onRequest,
11
+ onResponse: g.onResponse,
12
+ onError: g.onError || F
13
13
  };
14
14
  return n.use(i), n;
15
15
  };
16
16
  class T {
17
17
  constructor({ config: n }) {
18
- var o, s;
18
+ var a, s;
19
19
  this.userToken = null, this.constructClientOptions = (t) => {
20
- const e = this.config.apiUrl || "https://api.open.cx", a = {
20
+ const e = this.config.apiUrl || "https://api.open.cx", o = {
21
21
  "X-Bot-Token": this.config.token,
22
22
  "Content-Type": "application/json",
23
23
  Accept: "application/json",
24
24
  Authorization: t ? `Bearer ${t}` : void 0
25
25
  };
26
- return { baseUrl: e, headers: a };
26
+ return { baseUrl: e, headers: o };
27
27
  }, this.createOpenAPIClient = ({
28
28
  baseUrl: t,
29
29
  headers: e
30
30
  }) => _({
31
31
  baseUrl: t,
32
- onRequest: ({ request: a }) => {
32
+ onRequest: ({ request: o }) => {
33
33
  Object.entries(e).forEach(([l, r]) => {
34
- r && a.headers.set(l, r);
34
+ r && o.headers.set(l, r);
35
35
  });
36
36
  }
37
37
  }), this.setAuthToken = (t) => {
38
38
  this.userToken = t;
39
- const { baseUrl: e, headers: a } = this.constructClientOptions(t);
40
- this.client = this.createOpenAPIClient({ baseUrl: e, headers: a });
39
+ const { baseUrl: e, headers: o } = this.constructClientOptions(t);
40
+ this.client = this.createOpenAPIClient({ baseUrl: e, headers: o });
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.widgetPrelude = async () => await this.client.GET("/backend/widget/v2/prelude", {
@@ -56,28 +56,28 @@ class T {
56
56
  }), this.pollSessionAndHistory = async ({
57
57
  sessionId: t,
58
58
  lastMessageTimestamp: e,
59
- abortSignal: a
59
+ abortSignal: o
60
60
  }) => {
61
61
  const l = e ? { lastMessageTimestamp: e } : void 0;
62
62
  return await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
63
63
  params: { path: { sessionId: t }, query: l },
64
- signal: a
64
+ signal: o
65
65
  });
66
66
  }, this.getSessions = async ({
67
67
  cursor: t,
68
68
  filters: e,
69
- abortSignal: a
69
+ abortSignal: o
70
70
  }) => await this.client.GET("/backend/widget/v2/sessions", {
71
71
  params: { query: { cursor: t, filters: JSON.stringify(e) } },
72
- signal: a
72
+ signal: o
73
73
  }), this.uploadFile = async ({
74
74
  file: t,
75
75
  abortSignal: e,
76
- onProgress: a
76
+ onProgress: o
77
77
  }) => new Promise((l, r) => {
78
78
  var v;
79
- const g = new FormData();
80
- g.append("file", t);
79
+ const d = new FormData();
80
+ d.append("file", t);
81
81
  const c = new XMLHttpRequest();
82
82
  if (e && (e.addEventListener("abort", () => {
83
83
  c.abort(), r(new DOMException("Aborted", "AbortError"));
@@ -86,9 +86,9 @@ class T {
86
86
  return;
87
87
  }
88
88
  c.upload.addEventListener("progress", (u) => {
89
- if (u.lengthComputable && a) {
90
- const m = Math.round(u.loaded / u.total * 100);
91
- a(m);
89
+ if (u.lengthComputable && o) {
90
+ const S = Math.round(u.loaded / u.total * 100);
91
+ o(S);
92
92
  }
93
93
  }), c.addEventListener("load", () => {
94
94
  if (c.status >= 200 && c.status < 300)
@@ -106,8 +106,11 @@ class T {
106
106
  r(new Error("Upload timed out"));
107
107
  });
108
108
  const { baseUrl: C } = this.constructClientOptions(this.userToken), p = `${C}/backend/widget/v2/upload`;
109
- c.open("POST", p), c.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((v = this.config.user) == null ? void 0 : v.token) ? c.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), c.send(g);
110
- }), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.config = n, this.userToken = ((o = n.user) == null ? void 0 : o.token) || null;
109
+ c.open("POST", p), c.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((v = this.config.user) == null ? void 0 : v.token) ? c.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), c.send(d);
110
+ }), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.resolveSession = async (t, e) => await this.client.POST("/backend/widget/v2/session/resolve", {
111
+ body: t,
112
+ signal: e
113
+ }), this.config = n, this.userToken = ((a = n.user) == null ? void 0 : a.token) || null;
111
114
  const { baseUrl: i, headers: h } = this.constructClientOptions(
112
115
  (s = n.user) == null ? void 0 : s.token
113
116
  );
@@ -125,9 +128,9 @@ class P {
125
128
  }, this.reset = () => {
126
129
  this.set(this.initialState);
127
130
  }, this.notifySubscribers = (i) => {
128
- Array.from(this.subscribers).forEach((o) => {
131
+ Array.from(this.subscribers).forEach((a) => {
129
132
  try {
130
- o(i);
133
+ a(i);
131
134
  } catch (s) {
132
135
  console.error(s);
133
136
  }
@@ -147,7 +150,7 @@ class A {
147
150
  this.abortController.abort("Resetting poller"), (n = this.stopPolling) == null || n.call(this), this.stopPolling = null;
148
151
  }, this.stopPolling = null, this.startPolling = (n, i) => {
149
152
  if (this.stopPolling) return;
150
- const h = [], o = async () => {
153
+ const h = [], a = async () => {
151
154
  this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
152
155
  try {
153
156
  await n(this.abortController.signal);
@@ -158,17 +161,17 @@ class A {
158
161
  } finally {
159
162
  this.state.setPartial({ isPolling: !1 });
160
163
  }
161
- this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : h.push(setTimeout(o, i));
164
+ this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : h.push(setTimeout(a, i));
162
165
  };
163
- o(), this.stopPolling = () => {
166
+ a(), this.stopPolling = () => {
164
167
  h.forEach(clearTimeout), this.state.reset();
165
168
  };
166
169
  };
167
170
  }
168
171
  }
169
- function D(d) {
172
+ function D(g) {
170
173
  try {
171
- const n = d();
174
+ const n = g();
172
175
  return n instanceof Promise ? n.then((i) => ({ data: i })).catch((i) => ({ error: i })) : { data: n };
173
176
  } catch (n) {
174
177
  return { error: n };
@@ -179,7 +182,7 @@ class L {
179
182
  api: n,
180
183
  config: i,
181
184
  sessionCtx: h,
182
- messageCtx: o,
185
+ messageCtx: a,
183
186
  sessionPollingIntervalSeconds: s
184
187
  }) {
185
188
  this.poller = new A(), this.registerPolling = () => {
@@ -189,9 +192,9 @@ class L {
189
192
  }, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
190
193
  });
191
194
  }, this.hackAndSlash = async (t, e) => {
192
- var g;
195
+ var d;
193
196
  this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
194
- const a = this.messageCtx.state.get().messages, l = a.length > 0 ? (g = a[a.length - 1]) == null ? void 0 : g.timestamp : void 0, { data: r } = await this.api.pollSessionAndHistory({
197
+ const o = this.messageCtx.state.get().messages, l = o.length > 0 ? (d = o[o.length - 1]) == null ? void 0 : d.timestamp : void 0, { data: r } = await this.api.pollSessionAndHistory({
195
198
  sessionId: t,
196
199
  abortSignal: e,
197
200
  lastMessageTimestamp: l
@@ -234,7 +237,7 @@ class L {
234
237
  isAi: !1
235
238
  }
236
239
  };
237
- const a = t.actionCalls && t.actionCalls.length > 0 ? t.actionCalls[t.actionCalls.length - 1] : void 0;
240
+ const o = t.actionCalls && t.actionCalls.length > 0 ? t.actionCalls[t.actionCalls.length - 1] : void 0;
238
241
  return {
239
242
  ...e,
240
243
  type: "FROM_BOT",
@@ -247,9 +250,9 @@ class L {
247
250
  },
248
251
  data: {
249
252
  message: t.content.text || "",
250
- action: a ? {
251
- name: a.actionName,
252
- data: this.extractActionResult(a)
253
+ action: o ? {
254
+ name: o.actionName,
255
+ data: this.extractActionResult(o)
253
256
  } : void 0
254
257
  }
255
258
  };
@@ -257,11 +260,11 @@ class L {
257
260
  const e = t.result;
258
261
  if (e === null || typeof e != "object") return e;
259
262
  if ("responseBodyText" in e && typeof e.responseBodyText == "string") {
260
- const a = e.responseBodyText, l = D(() => JSON.parse(a)).data;
263
+ const o = e.responseBodyText, l = D(() => JSON.parse(o)).data;
261
264
  if (l) return l;
262
265
  }
263
266
  return t.result;
264
- }, this.api = n, this.config = i, this.sessionCtx = h, this.messageCtx = o, this.sessionPollingIntervalSeconds = s, this.registerPolling();
267
+ }, this.api = n, this.config = i, this.sessionCtx = h, this.messageCtx = a, this.sessionPollingIntervalSeconds = s, this.registerPolling();
265
268
  }
266
269
  }
267
270
  class B {
@@ -270,24 +273,24 @@ class B {
270
273
  api: i,
271
274
  storageCtx: h
272
275
  }) {
273
- var o;
276
+ var a;
274
277
  this.shouldCollectData = () => {
275
278
  var s;
276
279
  return !!(!((s = this.state.get().contact) != null && s.token) && this.config.collectUserData);
277
280
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
278
- var s, t, e, a, l, r, g, c, C, x, p, b, v, u;
281
+ var s, t, e, o, l, r, d, c, C, x, p, b, v, u;
279
282
  if (!((s = this.config.user) != null && s.token)) {
280
283
  if (this.config.collectUserData && !((e = (t = this.config.user) == null ? void 0 : t.data) != null && e.email)) {
281
- if ((a = this.config.extraDataCollectionFields) != null && a.length)
284
+ if ((o = this.config.extraDataCollectionFields) != null && o.length)
282
285
  return;
283
- const m = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
284
- m && await this.setUnverifiedContact(m);
286
+ const S = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
287
+ S && await this.setUnverifiedContact(S);
285
288
  return;
286
289
  }
287
- if (!((g = (r = this.config.user) == null ? void 0 : r.data) != null && g.email)) {
288
- const m = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
289
- if (m) {
290
- await this.setUnverifiedContact(m);
290
+ if (!((d = (r = this.config.user) == null ? void 0 : r.data) != null && d.email)) {
291
+ const S = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
292
+ if (S) {
293
+ await this.setUnverifiedContact(S);
291
294
  return;
292
295
  }
293
296
  }
@@ -310,11 +313,11 @@ class B {
310
313
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
311
314
  }
312
315
  }, this.setUnverifiedContact = async (s) => {
313
- var a, l, r, g;
314
- const t = await ((a = this.storageCtx) == null ? void 0 : a.getExternalContactId()), e = ((l = this.config.user) == null ? void 0 : l.externalId) || t || E();
315
- this.api.setAuthToken(s), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(s)), await ((g = this.storageCtx) == null ? void 0 : g.setExternalContactId(e)), this.state.setPartial({ contact: { token: s, externalId: e } });
316
+ var o, l, r, d;
317
+ const t = await ((o = this.storageCtx) == null ? void 0 : o.getExternalContactId()), e = ((l = this.config.user) == null ? void 0 : l.externalId) || t || E();
318
+ this.api.setAuthToken(s), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(s)), await ((d = this.storageCtx) == null ? void 0 : d.setExternalContactId(e)), this.state.setPartial({ contact: { token: s, externalId: e } });
316
319
  }, this.config = n, this.storageCtx = h, this.api = i, this.state = new P({
317
- contact: (o = n.user) != null && o.token ? {
320
+ contact: (a = n.user) != null && a.token ? {
318
321
  token: n.user.token,
319
322
  // Set optional externalId from config... not local storage
320
323
  externalId: n.user.externalId
@@ -325,7 +328,7 @@ class B {
325
328
  }), this.autoCreateUnverifiedUserIfNotExists();
326
329
  }
327
330
  }
328
- function k() {
331
+ function y() {
329
332
  return E();
330
333
  }
331
334
  class q {
@@ -349,9 +352,9 @@ class q {
349
352
  }), this.reset = async () => {
350
353
  this.sessionState.reset();
351
354
  }, this.registerSessionsRefresherWrapper = () => {
352
- var o;
355
+ var a;
353
356
  // If the widget config was initially provided with a contact token, no state change would be triggered, so we just fetch
354
- (o = this.contactCtx.state.get().contact) != null && o.token && !this.sessionsState.get().didStartInitialFetch ? this.registerSessionsRefresher() : this.contactCtx.state.subscribe(({ contact: s }) => {
357
+ (a = this.contactCtx.state.get().contact) != null && a.token && !this.sessionsState.get().didStartInitialFetch ? this.registerSessionsRefresher() : this.contactCtx.state.subscribe(({ contact: s }) => {
355
358
  s != null && s.token && !this.sessionsState.get().didStartInitialFetch && this.registerSessionsRefresher();
356
359
  });
357
360
  }, this.registerSessionsRefresher = () => {
@@ -361,45 +364,52 @@ class q {
361
364
  }, this.createSession = async () => {
362
365
  var e;
363
366
  this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
364
- const o = (e = this.contactCtx.state.get().contact) == null ? void 0 : e.externalId, { data: s, error: t } = await this.api.createSession({
365
- customData: o ? {
366
- external_id: o
367
+ const a = (e = this.contactCtx.state.get().contact) == null ? void 0 : e.externalId, { data: s, error: t } = await this.api.createSession({
368
+ customData: a ? {
369
+ external_id: a
367
370
  } : void 0
368
371
  });
369
372
  return s ? (this.sessionState.setPartial({ session: s, isCreatingSession: !1 }), s) : (console.error("Failed to create session:", t), null);
370
373
  }, this.loadMoreSessions = async () => {
371
374
  if (this.sessionsState.get().isLastPage) return;
372
- const { data: o } = await this.getSessions({
375
+ const { data: a } = await this.getSessions({
373
376
  cursor: this.sessionsState.get().cursor
374
377
  });
375
- if (o) {
376
- const t = [...this.sessionsState.get().data, ...o.items].filter(
377
- (e, a, l) => a === l.findIndex((r) => e.id === r.id)
378
+ if (a) {
379
+ const t = [...this.sessionsState.get().data, ...a.items].filter(
380
+ (e, o, l) => o === l.findIndex((r) => e.id === r.id)
378
381
  );
379
382
  this.sessionsState.setPartial({
380
383
  data: t,
381
- cursor: o.next || void 0,
382
- isLastPage: o.next === null
384
+ cursor: a.next || void 0,
385
+ isLastPage: a.next === null
383
386
  });
384
387
  }
385
- }, this.getSessions = async ({ cursor: o }) => {
388
+ }, this.getSessions = async ({ cursor: a }) => {
386
389
  var t, e;
387
390
  if (!((t = this.contactCtx.state.get().contact) != null && t.token)) return { data: null };
388
391
  const s = (e = this.contactCtx.state.get().contact) == null ? void 0 : e.externalId;
389
392
  return await this.api.getSessions({
390
- cursor: o,
393
+ cursor: a,
391
394
  filters: s ? {
392
395
  external_id: s
393
396
  } : {}
394
397
  });
395
- }, this.setSessions = (o) => {
396
- const s = [...o, ...this.sessionsState.get().data].filter(
397
- (t, e, a) => e === a.findIndex((l) => t.id === l.id)
398
+ }, this.setSessions = (a) => {
399
+ const s = [...a, ...this.sessionsState.get().data].filter(
400
+ (t, e, o) => e === o.findIndex((l) => t.id === l.id)
398
401
  );
399
402
  this.sessionsState.setPartial({ data: s });
400
403
  }, this.refreshSessions = async () => {
401
- const { data: o } = await this.getSessions({ cursor: void 0 });
402
- o && this.setSessions(o.items);
404
+ const { data: a } = await this.getSessions({ cursor: void 0 });
405
+ a && this.setSessions(a.items);
406
+ }, this.resolveSession = async () => {
407
+ const a = this.sessionState.get().session;
408
+ if (!a || !a.isOpened) return;
409
+ const { data: s } = await this.api.resolveSession({
410
+ session_id: a.id
411
+ });
412
+ s && this.sessionState.setPartial({ session: s });
403
413
  }, this.api = n, this.contactCtx = i, this.sessionsPollingIntervalSeconds = h, this.registerSessionsRefresherWrapper();
404
414
  }
405
415
  }
@@ -408,7 +418,7 @@ class $ {
408
418
  config: n,
409
419
  api: i,
410
420
  sessionCtx: h,
411
- contactCtx: o
421
+ contactCtx: a
412
422
  }) {
413
423
  this.state = new P({
414
424
  messages: [],
@@ -418,12 +428,12 @@ class $ {
418
428
  }), this.sendMessageAbortController = new AbortController(), this.reset = () => {
419
429
  this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
420
430
  }, this.sendMessage = async (s) => {
421
- var r, g, c, C, x, p, b, v;
431
+ var r, d, c, C, x, p, b, v;
422
432
  if (!s.content.trim() && (!s.attachments || s.attachments.length === 0)) {
423
433
  console.warn("Cannot send an empty message of no content or attachments");
424
434
  return;
425
435
  }
426
- const t = this.state.get().isSendingMessage, e = ((r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.assignee.kind) === "ai", a = this.state.get().messages, l = a.length > 0 ? a[a.length - 1] : void 0;
436
+ const t = this.state.get().isSendingMessage, e = ((r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.assignee.kind) === "ai", o = this.state.get().messages, l = o.length > 0 ? o[o.length - 1] : void 0;
427
437
  if (e && t || // If last message is from user, then bot response did not arrive yet
428
438
  e && (l == null ? void 0 : l.type) === "FROM_USER") {
429
439
  console.warn("Cannot send messages while awaiting AI response");
@@ -435,25 +445,26 @@ class $ {
435
445
  const u = this.toUserMessage(
436
446
  s.content.trim(),
437
447
  s.attachments || void 0
438
- ), m = this.state.get().messages;
448
+ ), S = this.state.get().messages;
439
449
  if (this.state.setPartial({
440
- messages: [...m, u]
441
- }), !((g = this.sessionCtx.sessionState.get().session) != null && g.id)) {
450
+ messages: [...S, u]
451
+ }), !((d = this.sessionCtx.sessionState.get().session) != null && d.id)) {
442
452
  if (!await this.sessionCtx.createSession()) {
443
453
  console.error("Failed to create session");
444
454
  return;
445
455
  }
446
456
  this.sessionCtx.refreshSessions();
447
457
  }
448
- const y = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
449
- if (!y) return;
458
+ const k = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
459
+ if (!k) return;
450
460
  const { data: f } = await this.api.sendMessage(
451
461
  {
452
462
  uuid: u.id,
453
463
  bot_token: this.config.token,
454
464
  headers: this.config.headers,
455
465
  query_params: this.config.queryParams,
456
- session_id: y,
466
+ body_properties: this.config.bodyProperties,
467
+ session_id: k,
457
468
  content: u.content,
458
469
  attachments: s.attachments,
459
470
  clientContext: this.config.context
@@ -492,14 +503,14 @@ class $ {
492
503
  }
493
504
  }, this.toUserMessage = (s, t) => {
494
505
  const e = (() => {
495
- const a = this.contactCtx.state.get().extraCollectedData;
496
- return this.state.get().messages.length === 0 && a && Object.keys(a).length > 0 ? `${Object.entries(a).filter(([r, g]) => !!g).map(([r, g]) => `${r}: ${g}`).join(`
506
+ const o = this.contactCtx.state.get().extraCollectedData;
507
+ return this.state.get().messages.length === 0 && o && Object.keys(o).length > 0 ? `${Object.entries(o).filter(([r, d]) => !!d).map(([r, d]) => `${r}: ${d}`).join(`
497
508
  `)}
498
509
 
499
510
  ${s}` : s;
500
511
  })();
501
512
  return {
502
- id: k(),
513
+ id: y(),
503
514
  type: "FROM_USER",
504
515
  content: e,
505
516
  deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -510,7 +521,7 @@ ${s}` : s;
510
521
  var t;
511
522
  return s.success && s.autopilotResponse ? {
512
523
  type: "FROM_BOT",
513
- id: s.autopilotResponse.id || k(),
524
+ id: s.autopilotResponse.id || y(),
514
525
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
515
526
  component: "bot_message",
516
527
  agent: this.config.bot ? {
@@ -529,7 +540,7 @@ ${s}` : s;
529
540
  } : null;
530
541
  }, this.toBotErrorMessage = (s) => ({
531
542
  type: "FROM_BOT",
532
- id: k(),
543
+ id: y(),
533
544
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
534
545
  component: "TEXT",
535
546
  data: {
@@ -537,7 +548,7 @@ ${s}` : s;
537
548
  variant: "error",
538
549
  action: void 0
539
550
  }
540
- }), this.config = n, this.api = i, this.sessionCtx = h, this.contactCtx = o;
551
+ }), this.config = n, this.api = i, this.sessionCtx = h, this.contactCtx = a;
541
552
  }
542
553
  }
543
554
  class N {
@@ -545,7 +556,7 @@ class N {
545
556
  config: n,
546
557
  contactCtx: i,
547
558
  sessionCtx: h,
548
- resetChat: o
559
+ resetChat: a
549
560
  }) {
550
561
  this.registerRoutingListener = () => {
551
562
  this.contactCtx.state.subscribe(({ contact: s }) => {
@@ -567,7 +578,7 @@ class N {
567
578
  this.state.setPartial({ screen: "chat" });
568
579
  }, this.state = new P({
569
580
  screen: i.shouldCollectData() ? "welcome" : "sessions"
570
- }), this.config = n, this.contactCtx = i, this.sessionCtx = h, this.resetChat = o, this.registerRoutingListener();
581
+ }), this.config = n, this.contactCtx = i, this.sessionCtx = h, this.resetChat = a, this.registerRoutingListener();
571
582
  }
572
583
  }
573
584
  class H {
@@ -582,14 +593,14 @@ class H {
582
593
  }, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId), this.storage = n;
583
594
  }
584
595
  }
585
- const S = class S {
596
+ const m = class m {
586
597
  constructor({
587
598
  config: n,
588
599
  storage: i
589
600
  }) {
590
601
  if (this.resetChat = () => {
591
602
  this.sessionCtx.reset(), this.messageCtx.reset();
592
- }, !S.pollingIntervalsSeconds)
603
+ }, !m.pollingIntervalsSeconds)
593
604
  throw Error(
594
605
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
595
606
  );
@@ -600,7 +611,7 @@ const S = class S {
600
611
  }), this.sessionCtx = new q({
601
612
  api: this.api,
602
613
  contactCtx: this.contactCtx,
603
- sessionsPollingIntervalSeconds: S.pollingIntervalsSeconds.sessions
614
+ sessionsPollingIntervalSeconds: m.pollingIntervalsSeconds.sessions
604
615
  }), this.messageCtx = new $({
605
616
  config: this.config,
606
617
  api: this.api,
@@ -611,7 +622,7 @@ const S = class S {
611
622
  config: this.config,
612
623
  sessionCtx: this.sessionCtx,
613
624
  messageCtx: this.messageCtx,
614
- sessionPollingIntervalSeconds: S.pollingIntervalsSeconds.session
625
+ sessionPollingIntervalSeconds: m.pollingIntervalsSeconds.session
615
626
  }), this.routerCtx = new N({
616
627
  config: this.config,
617
628
  contactCtx: this.contactCtx,
@@ -620,25 +631,25 @@ const S = class S {
620
631
  });
621
632
  }
622
633
  };
623
- S.pollingIntervalsSeconds = null, S.initialize = async ({
634
+ m.pollingIntervalsSeconds = null, m.initialize = async ({
624
635
  config: n,
625
636
  storage: i
626
637
  }) => {
627
- var o, s;
638
+ var a, s;
628
639
  const h = await new T({
629
640
  config: n
630
641
  }).getExternalWidgetConfig();
631
- return S.pollingIntervalsSeconds = {
632
- session: ((o = h.data) == null ? void 0 : o.sessionPollingIntervalSeconds) || 10,
642
+ return m.pollingIntervalsSeconds = {
643
+ session: ((a = h.data) == null ? void 0 : a.sessionPollingIntervalSeconds) || 10,
633
644
  sessions: ((s = h.data) == null ? void 0 : s.sessionsPollingIntervalSeconds) || 60
634
- }, new S({
645
+ }, new m({
635
646
  config: n,
636
647
  storage: i
637
648
  });
638
649
  };
639
- let U = S;
650
+ let U = m;
640
651
  export {
641
652
  P,
642
653
  U as W
643
654
  };
644
- //# sourceMappingURL=widget.ctx-COUAUyWX.js.map
655
+ //# sourceMappingURL=widget.ctx-DRC-z8Ql.js.map