@telia-ace/widget-conversation 1.1.5 → 1.1.6

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/index.mjs CHANGED
@@ -1,34 +1,34 @@
1
1
  var B = Object.defineProperty;
2
2
  var L = (o, e, t) => e in o ? B(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var d = (o, e, t) => (L(o, typeof e != "symbol" ? e + "" : e, t), t);
3
+ var c = (o, e, t) => (L(o, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import { ComponentPlatform as R } from "@telia-ace/widget-core";
5
5
  import { createStorageWriter as E, StorageCategory as I, readStorage as f, StorageMedium as y, StorageScope as z } from "@telia-ace/widget-services";
6
- import { uuid as H, lock as K } from "@telia-ace/widget-utilities";
6
+ import { uuid as $, lock as K } from "@telia-ace/widget-utilities";
7
7
  import { FormBuilder as Q } from "@telia-ace/widget-forms";
8
8
  import { closeAllModals as M } from "@telia-ace/widget-plugins";
9
- import { createReactComponent as _ } from "@telia-ace/widget-ui";
9
+ import { createReactComponent as H } from "@telia-ace/widget-ui";
10
10
  import { lazy as U } from "react";
11
11
  class q {
12
12
  constructor(e) {
13
- d(this, "cache", /* @__PURE__ */ new Map());
14
- d(this, "subscriptions", []);
13
+ c(this, "cache", /* @__PURE__ */ new Map());
14
+ c(this, "subscriptions", []);
15
15
  this.controller = e;
16
- const { events: t } = e.container.get("$widget"), s = t.subscribe("data-client:fetched", (r, n) => {
17
- n.type === "contact-method" && this.cache.set(n.response.id, n.response);
16
+ const { events: t } = e.container.get("$widget"), s = t.subscribe("data-client:fetched", (r, i) => {
17
+ i.type === "contact-method" && this.cache.set(i.response.id, i.response);
18
18
  });
19
19
  this.subscriptions.push(s);
20
20
  }
21
21
  getConversationLogs() {
22
22
  return this.controller.messages.reduce(
23
23
  (t, s) => {
24
- const r = C(s), { key: n, content: a, type: i, sender: c, timestamp: h } = r.content, u = this.parseEntry(a, i, c, h);
24
+ const r = C(s), { key: i, content: a, type: n, sender: d, timestamp: h } = r.content, u = this.parseEntry(a, n, d, h);
25
25
  return u && t.push(u), t;
26
26
  },
27
27
  []
28
28
  );
29
29
  }
30
30
  parseEntry(e, t, s, r) {
31
- const n = (h) => {
31
+ const i = (h) => {
32
32
  let u = [], l = [], v;
33
33
  if (Array.isArray(h)) {
34
34
  const [p, m] = h;
@@ -43,20 +43,20 @@ class q {
43
43
  options: u
44
44
  };
45
45
  };
46
- let a = [], i = [];
46
+ let a = [], n = [];
47
47
  if (Array.isArray(e.items)) {
48
48
  const { items: h } = e;
49
49
  h.forEach((u) => {
50
- const l = n(u);
51
- a = [...a, ...l.options], i = [...i, ...l.messagesAsList];
50
+ const l = i(u);
51
+ a = [...a, ...l.options], n = [...n, ...l.messagesAsList];
52
52
  });
53
53
  } else {
54
- const h = n(e);
55
- a = [...a, ...h.options], i = [...i, ...h.messagesAsList];
54
+ const h = i(e);
55
+ a = [...a, ...h.options], n = [...n, ...h.messagesAsList];
56
56
  }
57
57
  return {
58
58
  options: a,
59
- message: i.length ? i.join(`
59
+ message: n.length ? n.join(`
60
60
  `) : void 0,
61
61
  source: this.createMessageSource(t),
62
62
  alias: this.createAlias(t, s),
@@ -67,7 +67,7 @@ class q {
67
67
  return e;
68
68
  }
69
69
  createAlias(e, t) {
70
- return e === w.System ? "system" : (t == null ? void 0 : t.name) || "Me";
70
+ return e === b.System ? "system" : (t == null ? void 0 : t.name) || "Me";
71
71
  }
72
72
  handleContactMethod(e) {
73
73
  if (!this.cache.has(e))
@@ -82,10 +82,10 @@ class q {
82
82
  const {
83
83
  header: s,
84
84
  title: r,
85
- label: n,
85
+ label: i,
86
86
  description: a,
87
- text: i,
88
- html: c,
87
+ text: n,
88
+ html: d,
89
89
  body: h,
90
90
  contactMethodId: u
91
91
  } = e;
@@ -94,7 +94,7 @@ class q {
94
94
  const v = this.handleContactMethod(u.toString());
95
95
  v && (l = this.appendText(l, v, t));
96
96
  }
97
- return s && (l = this.appendText(l, s, t)), r && (l = this.appendText(l, r, t)), a && (l = this.appendText(l, a, t)), i && (l = this.appendText(l, i, t)), n && (l = this.appendText(l, n, t)), c && (l = this.appendText(l, c, t)), h && typeof h == "string" && (l = this.appendText(l, h, t)), l;
97
+ return s && (l = this.appendText(l, s, t)), r && (l = this.appendText(l, r, t)), a && (l = this.appendText(l, a, t)), n && (l = this.appendText(l, n, t)), i && (l = this.appendText(l, i, t)), d && (l = this.appendText(l, d, t)), h && typeof h == "string" && (l = this.appendText(l, h, t)), l;
98
98
  }
99
99
  createMessageContent(e) {
100
100
  let t = "";
@@ -102,9 +102,9 @@ class q {
102
102
  }
103
103
  createMessageOptions(e) {
104
104
  let t = [], s = [];
105
- return Array.isArray(e == null ? void 0 : e.actions) ? s = e.actions : typeof (e == null ? void 0 : e.actions) == "object" && (s = Object.entries(e.actions).map(([r, n]) => ({
105
+ return Array.isArray(e == null ? void 0 : e.actions) ? s = e.actions : typeof (e == null ? void 0 : e.actions) == "object" && (s = Object.entries(e.actions).map(([r, i]) => ({
106
106
  actionKey: r,
107
- label: n
107
+ label: i
108
108
  }))), s.length && (t = s.map((r) => this.getDetails(r, !1))), t;
109
109
  }
110
110
  appendText(e, t, s = !0) {
@@ -119,28 +119,35 @@ ${t}` : e.length ? `${e} ${t}` : t;
119
119
  }
120
120
  class k {
121
121
  constructor(e, t) {
122
- d(this, "id");
123
- d(this, "name");
124
- d(this, "avatar");
125
- d(this, "print", (e, t, s = null) => {
122
+ c(this, "id");
123
+ c(this, "name");
124
+ c(this, "avatar");
125
+ c(this, "container");
126
+ c(this, "widget");
127
+ c(this, "print", (e, t, s = null) => {
126
128
  const r = {
127
129
  name: this.name,
128
130
  avatar: this.avatar,
129
131
  id: this.id
130
- }, n = C(e, t);
131
- return s = s ?? n.timestamp, this.provider.createEntry(
132
- n.key,
133
- n.content,
134
- w.Agent,
132
+ }, i = C(e, t);
133
+ s = s ?? i.timestamp;
134
+ const { events: a } = this.widget;
135
+ return a == null || a.dispatch("tracking:conversation-message", {
136
+ sender: "agent"
137
+ }), this.provider.createEntry(
138
+ i.key,
139
+ i.content,
140
+ b.Agent,
135
141
  r,
136
142
  s
137
143
  );
138
144
  });
139
- d(this, "typing", () => this.provider.setTypingState({
145
+ c(this, "typing", () => this.provider.setTypingState({
140
146
  name: this.name,
141
147
  avatar: this.avatar
142
148
  }));
143
- this.provider = e, this.id = t.id || H(), this.name = t.name, this.avatar = t.avatar;
149
+ var s, r;
150
+ this.provider = e, this.id = t.id || $(), this.name = t.name, this.avatar = t.avatar, this.container = (s = e.controller) == null ? void 0 : s.container, this.widget = (r = this.container) == null ? void 0 : r.get("$widget");
144
151
  }
145
152
  update(e) {
146
153
  var r;
@@ -152,9 +159,9 @@ class k {
152
159
  }
153
160
  class T {
154
161
  constructor(e, t, s) {
155
- d(this, "subscriptions", []);
156
- d(this, "options");
157
- d(this, "user");
162
+ c(this, "subscriptions", []);
163
+ c(this, "options");
164
+ c(this, "user");
158
165
  this.name = e, this.container = t, this.controller = s, this.user = s == null ? void 0 : s.user, this.options = {
159
166
  silent: !1
160
167
  };
@@ -183,9 +190,9 @@ class T {
183
190
  return this.controller ? this.controller.loader() : () => () => {
184
191
  };
185
192
  }
186
- createEntry(e, t, s, r, n) {
193
+ createEntry(e, t, s, r, i) {
187
194
  var a;
188
- return (a = this.controller) == null ? void 0 : a.createEntry(e, t, s, r, n);
195
+ return (a = this.controller) == null ? void 0 : a.createEntry(e, t, s, r, i);
189
196
  }
190
197
  dispose() {
191
198
  var e;
@@ -228,11 +235,11 @@ class T {
228
235
  }
229
236
  }
230
237
  }
231
- const $ = (o) => `conversation-${o}`;
238
+ const _ = (o) => `conversation-${o}`;
232
239
  class j {
233
240
  constructor() {
234
- d(this, "_locking", Promise.resolve());
235
- d(this, "_locks", 0);
241
+ c(this, "_locking", Promise.resolve());
242
+ c(this, "_locks", 0);
236
243
  }
237
244
  isLocked() {
238
245
  return this._locks > 0;
@@ -250,80 +257,80 @@ class j {
250
257
  }
251
258
  class F {
252
259
  constructor(e, t, s) {
253
- d(this, "sessionStorageKey");
254
- d(this, "locker", new j());
255
- d(this, "initialStoredAgents", []);
256
- this.container = e, this.conversation = t, this.enabled = s, this.sessionStorageKey = $(t.id), t.onStarted(async () => {
260
+ c(this, "sessionStorageKey");
261
+ c(this, "locker", new j());
262
+ c(this, "initialStoredAgents", []);
263
+ this.container = e, this.conversation = t, this.enabled = s, this.sessionStorageKey = _(t.id), t.onStarted(async () => {
257
264
  if (t.messages.length > 0)
258
265
  return;
259
- const { agents: r } = await this.read(), n = [];
260
- r && r.forEach((i) => {
261
- const c = t.providerIndex(i.providerName), h = c > -1 ? t.registeredProviders[c] : t.createProvider(i.providerName), u = new k(h, {
262
- name: i.name,
263
- avatar: i.avatar,
264
- id: i.id
266
+ const { agents: r } = await this.read(), i = [];
267
+ r && r.forEach((n) => {
268
+ const d = t.providerIndex(n.providerName), h = d > -1 ? t.registeredProviders[d] : t.createProvider(n.providerName), u = new k(h, {
269
+ name: n.name,
270
+ avatar: n.avatar,
271
+ id: n.id
265
272
  });
266
- n.push(u);
273
+ i.push(u);
267
274
  });
268
275
  const { messages: a } = await this.read();
269
- a.forEach((i) => {
270
- switch (i.type) {
276
+ a.forEach((n) => {
277
+ switch (n.type) {
271
278
  case "agent": {
272
- const c = n.find((h) => {
279
+ const d = i.find((h) => {
273
280
  var u;
274
- return h.id === ((u = i.sender) == null ? void 0 : u.id);
281
+ return h.id === ((u = n.sender) == null ? void 0 : u.id);
275
282
  });
276
- c && c.print(
277
- i.content.items || i.content,
283
+ d && d.print(
284
+ n.content.items || n.content,
278
285
  {
279
- key: i.key
286
+ key: n.key
280
287
  },
281
- i.timestamp
288
+ n.timestamp
282
289
  );
283
290
  return;
284
291
  }
285
292
  case "user": {
286
293
  t.user.print(
287
- i.content.items || i.content,
294
+ n.content.items || n.content,
288
295
  {
289
- key: i.key
296
+ key: n.key
290
297
  },
291
- i.timestamp
298
+ n.timestamp
292
299
  );
293
300
  return;
294
301
  }
295
302
  case "system":
296
303
  default:
297
304
  t.print(
298
- i.content.items || i.content,
299
- i.timestamp
305
+ n.content.items || n.content,
306
+ n.timestamp
300
307
  );
301
308
  }
302
309
  });
303
- }), t.onMessageCreated(async (r, n) => {
304
- this.write(n.message, "messages");
310
+ }), t.onMessageCreated(async (r, i) => {
311
+ this.write(i.message, "messages");
305
312
  }), t.events.subscribe(
306
313
  "conversation:agent-created",
307
- async (r, n) => {
314
+ async (r, i) => {
308
315
  const a = {
309
- id: n.agent.id,
310
- name: n.agent.name,
311
- avatar: n.agent.avatar,
312
- providerName: n.agent.provider.name
316
+ id: i.agent.id,
317
+ name: i.agent.name,
318
+ avatar: i.agent.avatar,
319
+ providerName: i.agent.provider.name
313
320
  };
314
321
  await this.write(a, "agents");
315
322
  }
316
323
  ), t.events.subscribe(
317
324
  "conversation:agent-updated",
318
- async (r, n) => {
325
+ async (r, i) => {
319
326
  const { agents: a } = await this.read();
320
327
  await this.write(
321
328
  [
322
- ...a.map((i) => i.id === n.agent.id ? {
323
- ...i,
324
- name: n.agent.name,
325
- avatar: n.agent.avatar
326
- } : i)
329
+ ...a.map((n) => n.id === i.agent.id ? {
330
+ ...n,
331
+ name: i.agent.name,
332
+ avatar: i.agent.avatar
333
+ } : n)
327
334
  ],
328
335
  "agents",
329
336
  "update"
@@ -350,33 +357,33 @@ class F {
350
357
  this.container,
351
358
  this.sessionStorageKey,
352
359
  I.Necessary
353
- ).then(async (n) => {
360
+ ).then(async (i) => {
354
361
  if (s === "add") {
355
362
  const a = await this.read();
356
- if (t === "messages" && a.messages.findIndex((c) => c.key === e.key) > -1) {
363
+ if (t === "messages" && a.messages.findIndex((d) => d.key === e.key) > -1) {
357
364
  r();
358
365
  return;
359
366
  }
360
- const i = {
367
+ const n = {
361
368
  ...a
362
369
  };
363
- return t === "messages" ? i.messages = [...i.messages, e] : t === "agents" && (i.agents = [...i.agents, e]), n({
370
+ return t === "messages" ? n.messages = [...n.messages, e] : t === "agents" && (n.agents = [...n.agents, e]), i({
364
371
  ...a,
365
- ...i
372
+ ...n
366
373
  }).then(() => {
367
374
  r();
368
375
  });
369
376
  }
370
377
  if (s === "update" && t === "agents") {
371
378
  const a = await this.read();
372
- return n({
379
+ return i({
373
380
  ...a,
374
381
  agents: e
375
382
  }).then(() => {
376
383
  r();
377
384
  });
378
385
  }
379
- return n(e).then(() => {
386
+ return i(e).then(() => {
380
387
  r();
381
388
  });
382
389
  });
@@ -390,35 +397,42 @@ class F {
390
397
  }
391
398
  class G {
392
399
  constructor(e) {
393
- d(this, "print", (e, t, s = null) => {
400
+ c(this, "container");
401
+ c(this, "widget");
402
+ c(this, "print", (e, t, s = null) => {
394
403
  const r = C(e, t);
395
- return s = s ?? r.timestamp, this.controller.createEntry(
404
+ s = s ?? r.timestamp;
405
+ const { events: i } = this.widget;
406
+ return i == null || i.dispatch("tracking:conversation-message", {
407
+ sender: "user"
408
+ }), this.controller.createEntry(
396
409
  r.key,
397
410
  r.content,
398
- w.User,
411
+ b.User,
399
412
  void 0,
400
413
  s
401
414
  );
402
415
  });
403
- this.controller = e;
416
+ var t;
417
+ this.controller = e, this.container = e == null ? void 0 : e.container, this.widget = (t = this.container) == null ? void 0 : t.get("$widget");
404
418
  }
405
419
  }
406
420
  const x = async (o, e, t) => {
407
421
  const s = await o.getAsync(
408
422
  "conversation"
409
- ), r = await o.getAsync("components"), n = s.controllers.find((a) => a.conversation.id === e);
410
- if (n) {
411
- const a = [...n.conversation.providers];
412
- a.forEach((c) => {
413
- n.conversation.setProviderOptions(c, { silent: !0 });
414
- }), n.conversation.queueProviders(a), n.conversation.setProviders([t]);
415
- const i = r.components().ofType("conversation");
423
+ ), r = await o.getAsync("components"), i = s.controllers.find((a) => a.conversation.id === e);
424
+ if (i) {
425
+ const a = [...i.conversation.providers];
426
+ a.forEach((d) => {
427
+ i.conversation.setProviderOptions(d, { silent: !0 });
428
+ }), i.conversation.queueProviders(a), i.conversation.setProviders([t]);
429
+ const n = r.components().ofType("conversation");
416
430
  r.write({
417
431
  key: "setConversationProvider",
418
432
  attributes: {
419
433
  properties: { providers: [t] }
420
434
  },
421
- target: i,
435
+ target: n,
422
436
  provider: "localStorage"
423
437
  });
424
438
  }
@@ -438,9 +452,9 @@ class J {
438
452
  return typeof e == "string" ? { body: e } : e.length > -1 && typeof e == "object" ? { items: e } : e;
439
453
  }
440
454
  }
441
- var w = /* @__PURE__ */ ((o) => (o.User = "user", o.Agent = "agent", o.System = "system", o))(w || {});
455
+ var b = /* @__PURE__ */ ((o) => (o.User = "user", o.Agent = "agent", o.System = "system", o))(b || {});
442
456
  const C = (o, e) => {
443
- let t, s = (e == null ? void 0 : e.key) || H(), r = Date.now();
457
+ let t, s = (e == null ? void 0 : e.key) || $(), r = Date.now();
444
458
  if (Array.isArray(o) && o.length > -1)
445
459
  typeof o[0] == "string" ? t = { items: [o] } : t = { items: o };
446
460
  else if (typeof o == "string")
@@ -455,9 +469,9 @@ const C = (o, e) => {
455
469
  actions: o.actions,
456
470
  title: o.title
457
471
  }, o.key && (s = o.key), o.timestamp && (r = o.timestamp), typeof o.form == "function") {
458
- const n = Q.create(s);
459
- o.form(n);
460
- const a = n.get();
472
+ const i = Q.create(s);
473
+ o.form(i);
474
+ const a = i.get();
461
475
  t.form = a;
462
476
  }
463
477
  o.timestamp === null && (r = null);
@@ -472,25 +486,30 @@ const C = (o, e) => {
472
486
  };
473
487
  class V {
474
488
  constructor(e, t, s) {
475
- d(this, "formHandlers", {});
489
+ c(this, "formHandlers", {});
476
490
  /**
477
491
  * Represents the current end user.
478
492
  */
479
- d(this, "user", new G(this));
480
- d(this, "events");
481
- d(this, "providers", []);
482
- d(this, "active", !1);
483
- d(this, "queuedProviders", []);
484
- d(this, "registeredProviders", []);
485
- d(this, "loaders", 0);
486
- d(this, "componentMounted", !1);
487
- d(this, "store");
488
- d(this, "messages", []);
489
- d(this, "typingActors", []);
490
- d(this, "conversationHistory");
491
- d(this, "print", (e, t = null) => {
493
+ c(this, "user", new G(this));
494
+ c(this, "widget");
495
+ c(this, "events");
496
+ c(this, "providers", []);
497
+ c(this, "active", !1);
498
+ c(this, "queuedProviders", []);
499
+ c(this, "registeredProviders", []);
500
+ c(this, "loaders", 0);
501
+ c(this, "componentMounted", !1);
502
+ c(this, "store");
503
+ c(this, "messages", []);
504
+ c(this, "typingActors", []);
505
+ c(this, "conversationHistory");
506
+ c(this, "print", (e, t = null) => {
492
507
  const s = C(e);
493
- return t = t ?? s.timestamp, this.createEntry(
508
+ t = t ?? s.timestamp;
509
+ const { events: r } = this.widget;
510
+ return r.dispatch("tracking:conversation-message", {
511
+ sender: "system"
512
+ }), this.createEntry(
494
513
  s.key,
495
514
  s.content,
496
515
  "system",
@@ -498,18 +517,16 @@ class V {
498
517
  t
499
518
  );
500
519
  });
501
- this.container = e, this.id = t;
502
- const r = e.get("$widget");
503
- this.events = r.events.createChild(this), this.store = new F(e, this, s.rehydrate), this.conversationHistory = new q(this);
520
+ this.container = e, this.id = t, this.widget = e.get("$widget"), this.events = this.widget.events.createChild(this), this.store = new F(e, this, s.rehydrate), this.conversationHistory = new q(this);
504
521
  }
505
522
  setInitialStorage(e) {
506
523
  this.store.setInitialData(e);
507
524
  }
508
525
  setProviders(e) {
509
526
  const t = [], s = [];
510
- this.providers.reduce((r, n) => (e.indexOf(n) === -1 && r.push(n), r), []).forEach((r) => {
511
- const n = this.providers.indexOf(r);
512
- n > -1 && (t.push(r), this.providers.splice(n, 1));
527
+ this.providers.reduce((r, i) => (e.indexOf(i) === -1 && r.push(i), r), []).forEach((r) => {
528
+ const i = this.providers.indexOf(r);
529
+ i > -1 && (t.push(r), this.providers.splice(i, 1));
513
530
  }), e.forEach((r) => {
514
531
  this.providers.indexOf(r) === -1 && (s.push(r), this.providers.push(r));
515
532
  }), (s.length || t.length) && this.events.dispatch("conversation:providers-changed", {
@@ -580,18 +597,18 @@ class V {
580
597
  onUnreadMessage(e) {
581
598
  return this.events.subscribe("conversation:unread-message", e);
582
599
  }
583
- createEntry(e, t, s, r, n) {
600
+ createEntry(e, t, s, r, i) {
584
601
  const a = {
585
602
  key: e,
586
603
  content: t,
587
604
  type: s,
588
605
  sender: r || null,
589
- timestamp: n || n === null ? n : Date.now()
606
+ timestamp: i || i === null ? i : Date.now()
590
607
  };
591
608
  this.messages.push(a), a.type === "agent" && N(this.typingActors, r);
592
- const i = new J((c) => {
593
- if (c !== null) {
594
- const { timestamp: h = void 0, ...u } = c;
609
+ const n = new J((d) => {
610
+ if (d !== null) {
611
+ const { timestamp: h = void 0, ...u } = d;
595
612
  a.content = u, h && (a.timestamp = h);
596
613
  } else {
597
614
  const h = this.messages.indexOf(a);
@@ -599,7 +616,7 @@ class V {
599
616
  }
600
617
  this.events.dispatch("conversation:message-updated", { message: a }), this.update();
601
618
  });
602
- return this.events.dispatch("conversation:message-created", { message: a }), this.update(), this.componentMounted || this.events.dispatch("conversation:unread-message", !0), i;
619
+ return this.events.dispatch("conversation:message-created", { message: a }), this.update(), this.componentMounted || this.events.dispatch("conversation:unread-message", !0), n;
603
620
  }
604
621
  update() {
605
622
  this.events.dispatch("conversation:updated", {
@@ -644,26 +661,26 @@ const Y = (o, e) => {
644
661
  const t = o.split("_contact");
645
662
  return e.widgets.get(t[0]);
646
663
  }, W = (o) => {
647
- const e = o.get("$widget"), { name: t, implementation: s } = o.get("$widget"), r = t.indexOf("_contact") > -1 ? Y(t, s) : e, { data: n } = o.get("$settings"), { trigger: a } = r.container.get("$settings"), i = `${t.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(i);
648
- return c && !a ? { chatWidget: c, mainWidget: r, data: n } : { mainWidget: r, data: n };
664
+ const e = o.get("$widget"), { name: t, implementation: s } = o.get("$widget"), r = t.indexOf("_contact") > -1 ? Y(t, s) : e, { data: i } = o.get("$settings"), { trigger: a } = r.container.get("$settings"), n = `${t.replace("_contact-method", "").replace("_contact", "")}_contact-method`, d = s.widgets.get(n);
665
+ return d && !a ? { chatWidget: d, mainWidget: r, data: i } : { mainWidget: r, data: i };
649
666
  }, X = (o) => {
650
667
  const { chatWidget: e } = W(o);
651
668
  return !!e;
652
669
  }, O = (o, e, t) => {
653
- const { mainWidget: s, data: r, chatWidget: n } = W(o);
654
- return n ? n.state === "activated" ? n.invoke("open").then(() => {
655
- n.container.getAsync("conversation").then((a) => {
670
+ const { mainWidget: s, data: r, chatWidget: i } = W(o);
671
+ return i ? i.state === "activated" ? i.invoke("open").then(() => {
672
+ i.container.getAsync("conversation").then((a) => {
656
673
  a.navigateToConversationIfActive(e.id).then(() => M(o));
657
674
  });
658
- }) : n.activate().then(() => {
659
- const { trigger: a } = n.container.get("$settings");
660
- return a.action = "hide", n.invoke("setSettings", () => ({
675
+ }) : i.activate().then(() => {
676
+ const { trigger: a } = i.container.get("$settings");
677
+ return a.action = "hide", i.invoke("setSettings", () => ({
661
678
  data: r,
662
679
  trigger: a,
663
680
  activate: !0
664
- })).then(() => n.container.getAsync("components").then((i) => {
665
- const c = i.components().ofType("contact-method");
666
- i.write({
681
+ })).then(() => i.container.getAsync("components").then((n) => {
682
+ const d = n.components().ofType("contact-method");
683
+ n.write({
667
684
  key: "setContactMethodId",
668
685
  attributes: {
669
686
  properties: {
@@ -671,11 +688,11 @@ const Y = (o, e) => {
671
688
  guideId: e.guideId
672
689
  }
673
690
  },
674
- target: c,
691
+ target: d,
675
692
  provider: "localStorage"
676
693
  });
677
- const h = i.components().ofType("conversation");
678
- i.write({
694
+ const h = n.components().ofType("conversation");
695
+ n.write({
679
696
  key: "setConversationProvider",
680
697
  attributes: {
681
698
  properties: { providers: [e.clientName] }
@@ -684,19 +701,19 @@ const Y = (o, e) => {
684
701
  provider: "localStorage"
685
702
  });
686
703
  }));
687
- }).then(() => n.invoke("attach", {
704
+ }).then(() => i.invoke("attach", {
688
705
  key: "contact-method",
689
706
  triggerDOMElement: t,
690
707
  withRenderState: "open"
691
708
  })).then(() => (E(
692
- n.container,
709
+ i.container,
693
710
  "activeStickyWidget",
694
711
  I.Necessary,
695
712
  {
696
713
  medium: y.Local,
697
714
  scope: z.Implementation
698
715
  }
699
- ).then((a) => a(n.name)), n.container.getAsync("conversation").then((a) => {
716
+ ).then((a) => a(i.name)), i.container.getAsync("conversation").then((a) => {
700
717
  a.setConversationEndedBehavior(
701
718
  S.Deactivate
702
719
  );
@@ -704,18 +721,18 @@ const Y = (o, e) => {
704
721
  () => a.setConversationEndedBehavior(
705
722
  S.Navigate
706
723
  )
707
- )), !n);
724
+ )), !i);
708
725
  }, Z = (o, e, t = "conversation") => {
709
726
  const { mainWidget: s, chatWidget: r } = W(o);
710
- return r ? r.container.getAsync("router").then((n) => {
711
- n.navigate(t, { id: e.id });
712
- }) : s.container.getAsync("conversation").then((n) => {
727
+ return r ? r.container.getAsync("router").then((i) => {
728
+ i.navigate(t, { id: e.id });
729
+ }) : s.container.getAsync("conversation").then((i) => {
713
730
  var a;
714
- (a = n.setConversationEndedBehavior(S.Navigate)) == null || a.then(() => {
715
- s.container.getAsync("router").then((i) => {
716
- s.container.getAsync("components").then((c) => {
717
- const h = c.components().ofType("conversation");
718
- c.write({
731
+ (a = i.setConversationEndedBehavior(S.Navigate)) == null || a.then(() => {
732
+ s.container.getAsync("router").then((n) => {
733
+ s.container.getAsync("components").then((d) => {
734
+ const h = d.components().ofType("conversation");
735
+ d.write({
719
736
  key: "setConversationProvider",
720
737
  attributes: {
721
738
  properties: { providers: [e.clientName] }
@@ -724,24 +741,24 @@ const Y = (o, e) => {
724
741
  provider: "localStorage"
725
742
  });
726
743
  }).then(() => {
727
- i.navigate(t, { id: e.id });
744
+ n.navigate(t, { id: e.id });
728
745
  });
729
746
  });
730
747
  });
731
748
  });
732
- }, b = "conversations";
749
+ }, w = "conversations";
733
750
  var S = /* @__PURE__ */ ((o) => (o.Deactivate = "deactivate", o.Navigate = "navigate", o.None = "none", o))(S || {});
734
751
  class A {
735
752
  constructor(e, t) {
736
- d(this, "events");
737
- d(this, "controllers", []);
738
- d(this, "providers", []);
739
- d(this, "disposeProviders", {});
740
- d(this, "subscriptions", []);
741
- d(this, "storageWriter", null);
742
- d(this, "router", null);
743
- d(this, "buttonQuery", null);
744
- d(this, "sessionInfo", null);
753
+ c(this, "events");
754
+ c(this, "controllers", []);
755
+ c(this, "providers", []);
756
+ c(this, "disposeProviders", {});
757
+ c(this, "subscriptions", []);
758
+ c(this, "storageWriter", null);
759
+ c(this, "router", null);
760
+ c(this, "buttonQuery", null);
761
+ c(this, "sessionInfo", null);
745
762
  this.container = e, this.components = t;
746
763
  const s = e.get("$widget");
747
764
  this.events = s.events.createChild(this);
@@ -749,26 +766,26 @@ class A {
749
766
  initialize() {
750
767
  E(
751
768
  this.container,
752
- b,
769
+ w,
753
770
  I.Necessary,
754
771
  {
755
772
  medium: y.Local
756
773
  }
757
774
  ).then((e) => this.storageWriter = e), f(
758
775
  this.container,
759
- b,
776
+ w,
760
777
  y.Local
761
778
  ).then((e) => {
762
779
  this.buttonQuery = this.components.components().ofType("conversation-return-button"), e && (this.sessionInfo = e, e.id && e.route && this.writeToComponents({ active: !0, alert: { show: !1 } }));
763
780
  }), this.container.getAsync("router").then((e) => this.router = e), this.events.subscribe("conversation:ended", (e, t) => {
764
- var s, r, n;
781
+ var s, r, i;
765
782
  switch ((s = this.sessionInfo) == null ? void 0 : s.conversationEndedBehavior) {
766
783
  case "deactivate":
767
784
  this.container.get("$widget").deactivate();
768
785
  break;
769
786
  case "navigate":
770
- const i = (r = this.router) == null ? void 0 : r.getInitialRoute();
771
- i && ((n = this.router) == null || n.navigate(i.name));
787
+ const n = (r = this.router) == null ? void 0 : r.getInitialRoute();
788
+ n && ((i = this.router) == null || i.navigate(n.name));
772
789
  break;
773
790
  }
774
791
  this.writeToComponents({ active: !1 }), this.sessionInfo = null, this.storageWriter && this.storageWriter();
@@ -780,26 +797,26 @@ class A {
780
797
  static getInstance(e, t = "conversation") {
781
798
  return K(e)(() => e.getAsync(t).then((s) => {
782
799
  let r = s;
783
- return r || R.getInstance(e).then((n) => (r = new A(e, n), r.initialize(), e.registerAsync(t, () => r), r));
800
+ return r || R.getInstance(e).then((i) => (r = new A(e, i), r.initialize(), e.registerAsync(t, () => r), r));
784
801
  }));
785
802
  }
786
803
  navigateToConversationIfActive(e) {
787
804
  return f(
788
805
  this.container,
789
- b,
806
+ w,
790
807
  y.Local
791
808
  ).then((t) => {
792
809
  var s;
793
810
  if (t && t.id === e && t.route) {
794
- const { name: r, params: n } = t.route;
795
- (s = this.router) == null || s.navigate(r, n);
811
+ const { name: r, params: i } = t.route;
812
+ (s = this.router) == null || s.navigate(r, i);
796
813
  }
797
814
  });
798
815
  }
799
816
  setConversationEndedBehavior(e) {
800
817
  return f(
801
818
  this.container,
802
- b,
819
+ w,
803
820
  y.Local
804
821
  ).then((t) => {
805
822
  let s = t;
@@ -807,9 +824,9 @@ class A {
807
824
  });
808
825
  }
809
826
  async createController(e, t) {
810
- const s = $(e), { agents: r } = await f(this.container, s) || { agents: [] }, n = this.controllers.findIndex((i) => i.conversation.id === e);
827
+ const s = _(e), { agents: r } = await f(this.container, s) || { agents: [] }, i = this.controllers.findIndex((n) => n.conversation.id === e);
811
828
  let a;
812
- return n > -1 ? a = this.controllers[n].conversation : a = new V(this.container, e, t), a.setInitialStorage({ agents: r || [] }), a;
829
+ return i > -1 ? a = this.controllers[i].conversation : a = new V(this.container, e, t), a.setInitialStorage({ agents: r || [] }), a;
813
830
  }
814
831
  registerProvider(e, t) {
815
832
  const s = {
@@ -824,52 +841,52 @@ class A {
824
841
  }
825
842
  registerController(e, t) {
826
843
  const s = this.controllers.findIndex(
827
- (n) => n.conversation.id === e.id
844
+ (i) => i.conversation.id === e.id
828
845
  );
829
846
  let r;
830
847
  if (s < 0) {
831
848
  r = { conversation: e, component: t }, this.controllers.push(r);
832
- const n = (a) => {
833
- a && this.providers.filter((i) => a.indexOf(i.name) > -1).forEach((i) => {
834
- this.invokeHandler(i, r);
849
+ const i = (a) => {
850
+ a && this.providers.filter((n) => a.indexOf(n.name) > -1).forEach((n) => {
851
+ this.invokeHandler(n, r);
835
852
  });
836
853
  };
837
854
  return this.subscriptions.push(
838
- e.onDispose((a, i) => {
839
- const c = this.controllers.findIndex(
840
- (h) => h.conversation === i
855
+ e.onDispose((a, n) => {
856
+ const d = this.controllers.findIndex(
857
+ (h) => h.conversation === n
841
858
  );
842
- c > -1 && this.controllers.splice(c, 1), this.components.components().ofType("conversation-return-button").select().writeProperties({ active: !1 }), this.events.dispatch("conversation:ended", {}, { bubbles: !0 });
859
+ d > -1 && this.controllers.splice(d, 1), this.components.components().ofType("conversation-return-button").select().writeProperties({ active: !1 }), this.events.dispatch("conversation:ended", {}, { bubbles: !0 });
843
860
  })
844
861
  ), this.subscriptions.push(
845
- e.onProvidersChange((a, i) => {
862
+ e.onProvidersChange((a, n) => {
846
863
  const {
847
- added: c,
864
+ added: d,
848
865
  removed: h = []
849
- } = i;
866
+ } = n;
850
867
  h.forEach((u) => {
851
868
  (this.disposeProviders[u] || []).forEach(
852
869
  (l) => {
853
870
  l();
854
871
  }
855
872
  );
856
- }), n(c);
873
+ }), i(d);
857
874
  })
858
875
  ), this.subscriptions.push(
859
- e.onStarted((a, i) => {
876
+ e.onStarted((a, n) => {
860
877
  var h, u;
861
- const c = {
878
+ const d = {
862
879
  id: e.id,
863
880
  route: (h = this.router) == null ? void 0 : h.getRouteData(),
864
881
  conversationEndedBehavior: (u = this.sessionInfo) == null ? void 0 : u.conversationEndedBehavior
865
882
  };
866
- this.sessionInfo = c, this.storageWriter && this.storageWriter(c), this.writeToComponents({ active: i });
883
+ this.sessionInfo = d, this.storageWriter && this.storageWriter(d), this.writeToComponents({ active: n });
867
884
  })
868
885
  ), this.subscriptions.push(
869
- e.onUnreadMessage((a, i) => {
870
- this.events.dispatch("conversation:unread-message", i), this.writeToComponents({ alert: { show: i } });
886
+ e.onUnreadMessage((a, n) => {
887
+ this.events.dispatch("conversation:unread-message", n), this.writeToComponents({ alert: { show: n } });
871
888
  })
872
- ), n(e.providers), !0;
889
+ ), i(e.providers), !0;
873
890
  }
874
891
  return r = this.controllers[s], !1;
875
892
  }
@@ -891,7 +908,7 @@ class A {
891
908
  getComponentRoute() {
892
909
  return f(
893
910
  this.container,
894
- b,
911
+ w,
895
912
  y.Local
896
913
  ).then((e) => e == null ? void 0 : e.route);
897
914
  }
@@ -907,8 +924,8 @@ class A {
907
924
  static async handleContactMethodClick(e, t, s, r) {
908
925
  if (X(t)) {
909
926
  e.preventDefault();
910
- let n = document.getElementById("humany-dynamic-anchor");
911
- n || (n = document.createElement("a"), n.setAttribute("href", "#"), n.id = "humany-dynamic-anchor", document.body.appendChild(n)), O(t, s, n);
927
+ let i = document.getElementById("humany-dynamic-anchor");
928
+ i || (i = document.createElement("a"), i.setAttribute("href", "#"), i.id = "humany-dynamic-anchor", document.body.appendChild(i)), O(t, s, i);
912
929
  }
913
930
  O(t, s);
914
931
  }
@@ -922,40 +939,40 @@ class A {
922
939
  }
923
940
  }
924
941
  const ee = (o, e) => o.reduce((t, s, r) => {
925
- var a, i;
926
- const n = {
942
+ var a, n;
943
+ const i = {
927
944
  ...s,
928
945
  content: [{ ...s.content, key: s.key }]
929
946
  };
930
- if (t.length > 0 && s.type !== w.System) {
931
- const c = t[t.length - 1];
932
- if ((!e && e !== 0 || Math.abs(c.timestamp - s.timestamp) < e) && ((a = c.sender) == null ? void 0 : a.name) === ((i = s.sender) == null ? void 0 : i.name) && c.type === s.type)
933
- return c.timestamp = s.timestamp, c.content.push({ ...s.content, key: s.key }), t;
947
+ if (t.length > 0 && s.type !== b.System) {
948
+ const d = t[t.length - 1];
949
+ if ((!e && e !== 0 || Math.abs(d.timestamp - s.timestamp) < e) && ((a = d.sender) == null ? void 0 : a.name) === ((n = s.sender) == null ? void 0 : n.name) && d.type === s.type)
950
+ return d.timestamp = s.timestamp, d.content.push({ ...s.content, key: s.key }), t;
934
951
  }
935
- return t.push(n), t;
952
+ return t.push(i), t;
936
953
  }, []), he = (o) => Promise.all([
937
954
  A.getInstance(o),
938
955
  o.getAsync("router")
939
- ]).then(([e, t]) => _(
956
+ ]).then(([e, t]) => H(
940
957
  o,
941
958
  "conversation",
942
- import("./conversation-8fab4c79.mjs"),
959
+ import("./conversation-8295aeca.mjs"),
943
960
  async (s) => {
944
- const { rehydrate: r = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", i = await e.createController(a, {
961
+ const { rehydrate: r = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", n = await e.createController(a, {
945
962
  rehydrate: r
946
- }), c = e.registerController(
947
- i,
963
+ }), d = e.registerController(
964
+ n,
948
965
  s
949
966
  ), h = 3 * 60 * 1e3, u = (g) => {
950
967
  const { providers: p = [] } = g;
951
968
  if (p) {
952
969
  const m = Array.isArray(p) ? p : [p];
953
- return i.setProviders(m), m;
970
+ return n.setProviders(m), m;
954
971
  }
955
972
  };
956
973
  u(
957
974
  s.properties(u)
958
- ), i.setComponentMountedState(!0);
975
+ ), n.setComponentMountedState(!0);
959
976
  const l = (g) => {
960
977
  const { loading: p, typingActors: m, messages: P } = g;
961
978
  s.writeProperties({
@@ -964,19 +981,19 @@ const ee = (o, e) => o.reduce((t, s, r) => {
964
981
  messages: ee(P, h)
965
982
  });
966
983
  };
967
- l(i.getMessageStream()), c && (s.writeProperties({
968
- conversationControllerId: i.id
984
+ l(n.getMessageStream()), d && (s.writeProperties({
985
+ conversationControllerId: n.id
969
986
  }), s.actions.create("user-submit", (g, p) => {
970
987
  if (p) {
971
988
  const { preventDefault: m, validationPromise: P } = p;
972
989
  if (m) {
973
990
  P && P().then((D) => {
974
- D && i.user.print(D);
991
+ D && n.user.print(D);
975
992
  });
976
993
  return;
977
994
  }
978
995
  }
979
- i.user.print(g.text);
996
+ n.user.print(g.text);
980
997
  }), s.actions.create("user-typing", (g, p) => {
981
998
  }), s.actions.create("form", (g, p) => {
982
999
  }), s.actions.create("action", (g, p) => {
@@ -1004,14 +1021,14 @@ const ee = (o, e) => o.reduce((t, s, r) => {
1004
1021
  });
1005
1022
  }
1006
1023
  ));
1007
- const v = i.events.subscribe(
1024
+ const v = n.events.subscribe(
1008
1025
  "conversation:updated",
1009
1026
  (g, p) => {
1010
1027
  l(p);
1011
1028
  }
1012
1029
  );
1013
1030
  return () => {
1014
- i.setComponentMountedState(!1), v(), i.active || l({ messages: [], typingActors: [], loading: !1 });
1031
+ n.setComponentMountedState(!1), v(), n.active || l({ messages: [], typingActors: [], loading: !1 });
1015
1032
  };
1016
1033
  },
1017
1034
  { reuseController: !0 }
@@ -1020,15 +1037,15 @@ const ee = (o, e) => o.reduce((t, s, r) => {
1020
1037
  A.getInstance(o),
1021
1038
  o.getAsync("router")
1022
1039
  ]).then(
1023
- ([e, t, s]) => _(
1040
+ ([e, t, s]) => H(
1024
1041
  o,
1025
1042
  "conversation-return-button",
1026
1043
  import("./return-button-3e542ab7.mjs"),
1027
1044
  (r) => {
1028
- r.actions.create("toggle", (n = {}) => {
1045
+ r.actions.create("toggle", (i = {}) => {
1029
1046
  var a;
1030
- (a = t.getComponentRoute()) == null || a.then((i) => {
1031
- i && s.navigate(i.name, i.params);
1047
+ (a = t.getComponentRoute()) == null || a.then((n) => {
1048
+ n && s.navigate(n.name, n.params);
1032
1049
  });
1033
1050
  });
1034
1051
  }
@@ -1050,7 +1067,7 @@ export {
1050
1067
  S as ConversationEndedBehavior,
1051
1068
  J as ConversationEntry,
1052
1069
  te as ConversationMessageListItemType,
1053
- w as ConversationMessageType,
1070
+ b as ConversationMessageType,
1054
1071
  A as ConversationPlatform,
1055
1072
  T as ConversationProvider,
1056
1073
  le as ConversationReturnButtonComponent,