@telia-ace/widget-conversation 1.0.36 → 1.0.37-next.1

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
@@ -1,49 +1,140 @@
1
1
  var j = Object.defineProperty, G = Object.defineProperties;
2
2
  var J = Object.getOwnPropertyDescriptors;
3
- var A = Object.getOwnPropertySymbols;
4
- var B = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable;
5
- var E = (r, e, t) => e in r ? j(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, g = (r, e) => {
3
+ var x = Object.getOwnPropertySymbols;
4
+ var $ = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable;
5
+ var T = (r, e, t) => e in r ? j(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, m = (r, e) => {
6
6
  for (var t in e || (e = {}))
7
- B.call(e, t) && E(r, t, e[t]);
8
- if (A)
9
- for (var t of A(e))
10
- M.call(e, t) && E(r, t, e[t]);
7
+ $.call(e, t) && T(r, t, e[t]);
8
+ if (x)
9
+ for (var t of x(e))
10
+ _.call(e, t) && T(r, t, e[t]);
11
11
  return r;
12
- }, m = (r, e) => G(r, J(e));
13
- var $ = (r, e) => {
12
+ }, b = (r, e) => G(r, J(e));
13
+ var B = (r, e) => {
14
14
  var t = {};
15
15
  for (var s in r)
16
- B.call(r, s) && e.indexOf(s) < 0 && (t[s] = r[s]);
17
- if (r != null && A)
18
- for (var s of A(r))
19
- e.indexOf(s) < 0 && M.call(r, s) && (t[s] = r[s]);
16
+ $.call(r, s) && e.indexOf(s) < 0 && (t[s] = r[s]);
17
+ if (r != null && x)
18
+ for (var s of x(r))
19
+ e.indexOf(s) < 0 && _.call(r, s) && (t[s] = r[s]);
20
20
  return t;
21
21
  };
22
- var d = (r, e, t) => (E(r, typeof e != "symbol" ? e + "" : e, t), t);
23
- var v = (r, e, t) => new Promise((s, n) => {
24
- var i = (c) => {
22
+ var d = (r, e, t) => (T(r, typeof e != "symbol" ? e + "" : e, t), t);
23
+ var v = (r, e, t) => new Promise((s, i) => {
24
+ var n = (c) => {
25
25
  try {
26
26
  o(t.next(c));
27
27
  } catch (h) {
28
- n(h);
28
+ i(h);
29
29
  }
30
30
  }, a = (c) => {
31
31
  try {
32
32
  o(t.throw(c));
33
33
  } catch (h) {
34
- n(h);
34
+ i(h);
35
35
  }
36
- }, o = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(i, a);
36
+ }, o = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(n, a);
37
37
  o((t = t.apply(r, e)).next());
38
38
  });
39
39
  import { ComponentPlatform as K } from "@telia-ace/widget-core";
40
- import { createStorageWriter as N, StorageCategory as R, readStorage as b, StorageMedium as w, StorageScope as V } from "@telia-ace/widget-services";
41
- import { uuid as L, lock as Y } from "@telia-ace/widget-utilities";
40
+ import { createStorageWriter as D, StorageCategory as N, readStorage as w, StorageMedium as A, StorageScope as V } from "@telia-ace/widget-services";
41
+ import { uuid as U, lock as Y } from "@telia-ace/widget-utilities";
42
42
  import { FormBuilder as X } from "@telia-ace/widget-forms";
43
- import { closeAllModals as z } from "@telia-ace/widget-plugins";
44
- import { createReactComponent as U } from "@telia-ace/widget-ui";
43
+ import { closeAllModals as L } from "@telia-ace/widget-plugins";
44
+ import { createReactComponent as q } from "@telia-ace/widget-ui";
45
45
  import { lazy as Z } from "react";
46
- class x {
46
+ class ee {
47
+ constructor(e) {
48
+ d(this, "cache", /* @__PURE__ */ new Map());
49
+ d(this, "subscriptions", []);
50
+ this.controller = e;
51
+ const { events: t } = e.container.get("$widget"), s = t.subscribe("data-client:fetched", (i, n) => {
52
+ n.type === "contact-method" && this.cache.set(n.response.id, n.response);
53
+ });
54
+ this.subscriptions.push(s);
55
+ }
56
+ getConversationLogs() {
57
+ return this.controller.messages.reduce((t, s) => {
58
+ const i = I(s), { key: n, content: a, type: o, sender: c, timestamp: h } = i.content, u = this.parseEntry(a, o, c, h);
59
+ return u && t.push(u), t;
60
+ }, []);
61
+ }
62
+ parseEntry(e, t, s, i) {
63
+ const n = (h) => {
64
+ let u = [], l = [], f;
65
+ if (Array.isArray(h)) {
66
+ const [p, y] = h;
67
+ f = y;
68
+ } else
69
+ f = h;
70
+ return this.createMessageContent(f).length && (l = [...l, this.createMessageContent(f)]), u = [...u, ...this.createMessageOptions(f)], {
71
+ messagesAsList: l,
72
+ options: u
73
+ };
74
+ };
75
+ let a = [], o = [];
76
+ if (Array.isArray(e.items)) {
77
+ const { items: h } = e;
78
+ h.forEach((u) => {
79
+ const l = n(u);
80
+ a = [...a, ...l.options], o = [...o, ...l.messagesAsList];
81
+ });
82
+ } else {
83
+ const h = n(e);
84
+ a = [...a, ...h.options], o = [...o, ...h.messagesAsList];
85
+ }
86
+ return {
87
+ options: a,
88
+ message: o.length ? o.join(`
89
+ `) : void 0,
90
+ source: this.createMessageSource(t),
91
+ alias: this.createAlias(t, s),
92
+ timestamp: i
93
+ };
94
+ }
95
+ createMessageSource(e) {
96
+ return e;
97
+ }
98
+ createAlias(e, t) {
99
+ return e === S.System ? "system" : (t == null ? void 0 : t.name) || "Me";
100
+ }
101
+ handleContactMethod(e) {
102
+ if (!this.cache.has(e))
103
+ return;
104
+ const t = this.cache.get(e);
105
+ let s = "";
106
+ return s = this.appendText(s, `${t.clientName}:`), s = this.appendText(s, t.title), t.description && (s = this.appendText(s, t.title)), s;
107
+ }
108
+ getDetails(e, t = !0) {
109
+ if (!e)
110
+ return "";
111
+ const { header: s, title: i, label: n, description: a, text: o, html: c, body: h, contactMethodId: u } = e;
112
+ let l = "";
113
+ if (u) {
114
+ const f = this.handleContactMethod(u.toString());
115
+ f && (l = this.appendText(l, f, t));
116
+ }
117
+ return s && (l = this.appendText(l, s, t)), i && (l = this.appendText(l, i, t)), a && (l = this.appendText(l, a, t)), o && (l = this.appendText(l, o, 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;
118
+ }
119
+ createMessageContent(e) {
120
+ let t = "";
121
+ return t = this.getDetails(e), t;
122
+ }
123
+ createMessageOptions(e) {
124
+ let t = [];
125
+ return e != null && e.actions && (t = e.actions.map((s) => this.getDetails(s, !1))), t;
126
+ }
127
+ appendText(e, t, s = !0) {
128
+ return s && e.length ? `${e}
129
+ ${t}` : e.length ? `${e} ${t}` : t;
130
+ }
131
+ dispose() {
132
+ this.subscriptions.forEach((e) => {
133
+ e();
134
+ });
135
+ }
136
+ }
137
+ class M {
47
138
  constructor(e, t) {
48
139
  d(this, "id");
49
140
  d(this, "name");
@@ -53,27 +144,27 @@ class x {
53
144
  name: this.name,
54
145
  avatar: this.avatar,
55
146
  id: this.id
56
- }, n = D(e, t);
147
+ }, i = I(e, t);
57
148
  return this.provider.createEntry(
58
- n.key,
59
- n.content,
60
- I.Agent,
149
+ i.key,
150
+ i.content,
151
+ S.Agent,
61
152
  s,
62
- n.timestamp
153
+ i.timestamp
63
154
  );
64
155
  });
65
156
  d(this, "typing", () => this.provider.setTypingState({ name: this.name, avatar: this.avatar }));
66
- this.provider = e, this.id = t.id || L(), this.name = t.name, this.avatar = t.avatar;
157
+ this.provider = e, this.id = t.id || U(), this.name = t.name, this.avatar = t.avatar;
67
158
  }
68
159
  update(e) {
69
- var n;
160
+ var i;
70
161
  const { name: t, avatar: s } = e;
71
- s === null ? this.avatar = void 0 : s && (this.avatar = s), t === null ? this.name = void 0 : t && (this.name = t), (n = this.provider.controller) == null || n.events.dispatch("conversation:agent-updated", {
162
+ s === null ? this.avatar = void 0 : s && (this.avatar = s), t === null ? this.name = void 0 : t && (this.name = t), (i = this.provider.controller) == null || i.events.dispatch("conversation:agent-updated", {
72
163
  agent: this
73
164
  });
74
165
  }
75
166
  }
76
- class T {
167
+ class R {
77
168
  constructor(e, t, s) {
78
169
  d(this, "subscriptions", []);
79
170
  d(this, "options");
@@ -83,15 +174,15 @@ class T {
83
174
  };
84
175
  }
85
176
  static create(e, t, s) {
86
- return new T(e, t, s);
177
+ return new R(e, t, s);
87
178
  }
88
179
  createAgent(e = {}) {
89
180
  var t;
90
181
  if (this.controller) {
91
- const s = this.controller.getAgentById(e.id), n = s ? new x(this, g(g({}, s), e)) : new x(this, e);
182
+ const s = this.controller.getAgentById(e.id), i = s ? new M(this, m(m({}, s), e)) : new M(this, e);
92
183
  return s || (t = this.controller) == null || t.events.dispatch("conversation:agent-created", {
93
- agent: n
94
- }), n;
184
+ agent: i
185
+ }), i;
95
186
  }
96
187
  }
97
188
  print(e) {
@@ -106,9 +197,9 @@ class T {
106
197
  return this.controller ? this.controller.loader() : () => () => {
107
198
  };
108
199
  }
109
- createEntry(e, t, s, n, i) {
200
+ createEntry(e, t, s, i, n) {
110
201
  var a;
111
- return (a = this.controller) == null ? void 0 : a.createEntry(e, t, s, n, i);
202
+ return (a = this.controller) == null ? void 0 : a.createEntry(e, t, s, i, n);
112
203
  }
113
204
  dispose() {
114
205
  var e;
@@ -118,6 +209,10 @@ class T {
118
209
  var e;
119
210
  return ((e = this.controller) == null ? void 0 : e.isRehydrated()) || Promise.resolve(!1);
120
211
  }
212
+ getHistory() {
213
+ var e;
214
+ return ((e = this.controller) == null ? void 0 : e.getHistory()) || [];
215
+ }
121
216
  complete() {
122
217
  var e;
123
218
  (e = this.controller) == null || e.onCompleteProvider();
@@ -147,8 +242,8 @@ class T {
147
242
  }
148
243
  }
149
244
  }
150
- const q = (r) => `conversation-${r}`;
151
- class ee {
245
+ const F = (r) => `conversation-${r}`;
246
+ class te {
152
247
  constructor() {
153
248
  d(this, "_locking", Promise.resolve());
154
249
  d(this, "_locks", 0);
@@ -159,31 +254,31 @@ class ee {
159
254
  lock() {
160
255
  this._locks += 1;
161
256
  let e, t = new Promise(
162
- (n) => e = () => {
163
- this._locks -= 1, n();
257
+ (i) => e = () => {
258
+ this._locks -= 1, i();
164
259
  }
165
260
  ), s = this._locking.then(() => e);
166
261
  return this._locking = this._locking.then(() => t), s;
167
262
  }
168
263
  }
169
- class te {
264
+ class se {
170
265
  constructor(e, t, s) {
171
266
  d(this, "sessionStorageKey");
172
- d(this, "locker", new ee());
267
+ d(this, "locker", new te());
173
268
  d(this, "initialStoredAgents", []);
174
- this.container = e, this.conversation = t, this.enabled = s, this.sessionStorageKey = q(t.id), t.onStarted(() => v(this, null, function* () {
269
+ this.container = e, this.conversation = t, this.enabled = s, this.sessionStorageKey = F(t.id), t.onStarted(() => v(this, null, function* () {
175
270
  if (t.messages.length > 0)
176
271
  return;
177
- const { agents: n } = yield this.read(), i = [];
178
- n && n.forEach((o) => {
179
- const c = t.providerIndex(o.providerName), h = c > -1 ? t.registeredProviders[c] : t.createProvider(o.providerName), u = new x(h, { name: o.name, avatar: o.avatar, id: o.id });
180
- i.push(u);
272
+ const { agents: i } = yield this.read(), n = [];
273
+ i && i.forEach((o) => {
274
+ const c = t.providerIndex(o.providerName), h = c > -1 ? t.registeredProviders[c] : t.createProvider(o.providerName), u = new M(h, { name: o.name, avatar: o.avatar, id: o.id });
275
+ n.push(u);
181
276
  });
182
277
  const { messages: a } = yield this.read();
183
278
  a.forEach((o) => {
184
279
  switch (o.type) {
185
280
  case "agent": {
186
- const c = i.find((h) => {
281
+ const c = n.find((h) => {
187
282
  var u;
188
283
  return h.id === ((u = o.sender) == null ? void 0 : u.id);
189
284
  });
@@ -203,23 +298,23 @@ class te {
203
298
  t.print(o.content.items || o.content);
204
299
  }
205
300
  });
206
- })), t.onMessageCreated((n, i) => v(this, null, function* () {
207
- this.write(i.message, "messages");
208
- })), t.events.subscribe("conversation:agent-created", (n, i) => v(this, null, function* () {
301
+ })), t.onMessageCreated((i, n) => v(this, null, function* () {
302
+ this.write(n.message, "messages");
303
+ })), t.events.subscribe("conversation:agent-created", (i, n) => v(this, null, function* () {
209
304
  const a = {
210
- id: i.agent.id,
211
- name: i.agent.name,
212
- avatar: i.agent.avatar,
213
- providerName: i.agent.provider.name
305
+ id: n.agent.id,
306
+ name: n.agent.name,
307
+ avatar: n.agent.avatar,
308
+ providerName: n.agent.provider.name
214
309
  };
215
310
  yield this.write(a, "agents");
216
- })), t.events.subscribe("conversation:agent-updated", (n, i) => v(this, null, function* () {
311
+ })), t.events.subscribe("conversation:agent-updated", (i, n) => v(this, null, function* () {
217
312
  const { agents: a } = yield this.read();
218
313
  yield this.write(
219
314
  [
220
- ...a.map((o) => o.id === i.agent.id ? m(g({}, o), {
221
- name: i.agent.name,
222
- avatar: i.agent.avatar
315
+ ...a.map((o) => o.id === n.agent.id ? b(m({}, o), {
316
+ name: n.agent.name,
317
+ avatar: n.agent.avatar
223
318
  }) : o)
224
319
  ],
225
320
  "agents",
@@ -244,55 +339,55 @@ class te {
244
339
  return v(this, null, function* () {
245
340
  if (!this.enabled)
246
341
  return;
247
- const n = yield this.locker.lock();
248
- return N(
342
+ const i = yield this.locker.lock();
343
+ return D(
249
344
  this.container,
250
345
  this.sessionStorageKey,
251
- R.Necessary
252
- ).then((i) => v(this, null, function* () {
346
+ N.Necessary
347
+ ).then((n) => v(this, null, function* () {
253
348
  if (s === "add") {
254
349
  const a = yield this.read();
255
350
  if (t === "messages" && a.messages.findIndex((c) => c.key === e.key) > -1) {
256
- n();
351
+ i();
257
352
  return;
258
353
  }
259
- let o = g({}, a);
260
- return t === "messages" ? o.messages = [...o.messages, e] : t === "agents" && (o.agents = [...o.agents, e]), i(g(g({}, a), o)).then(() => {
261
- n();
354
+ let o = m({}, a);
355
+ return t === "messages" ? o.messages = [...o.messages, e] : t === "agents" && (o.agents = [...o.agents, e]), n(m(m({}, a), o)).then(() => {
356
+ i();
262
357
  });
263
358
  }
264
359
  if (s === "update" && t === "agents") {
265
360
  const a = yield this.read();
266
- return i(m(g({}, a), {
361
+ return n(b(m({}, a), {
267
362
  agents: e
268
363
  })).then(() => {
269
- n();
364
+ i();
270
365
  });
271
366
  }
272
- return i(e).then(() => {
273
- n();
367
+ return n(e).then(() => {
368
+ i();
274
369
  });
275
370
  }));
276
371
  });
277
372
  }
278
373
  read() {
279
374
  return v(this, null, function* () {
280
- return b(this.container, this.sessionStorageKey).then((e) => e || {
375
+ return w(this.container, this.sessionStorageKey).then((e) => e || {
281
376
  messages: [],
282
377
  agents: []
283
378
  });
284
379
  });
285
380
  }
286
381
  }
287
- const se = te;
288
- class re {
382
+ const re = se;
383
+ class ie {
289
384
  constructor(e) {
290
385
  d(this, "print", (e, t) => {
291
- const s = D(e, t);
386
+ const s = I(e, t);
292
387
  return this.controller.createEntry(
293
388
  s.key,
294
389
  s.content,
295
- I.User,
390
+ S.User,
296
391
  void 0,
297
392
  s.timestamp
298
393
  );
@@ -301,14 +396,14 @@ class re {
301
396
  }
302
397
  }
303
398
  const W = (r, e, t) => v(void 0, null, function* () {
304
- const s = yield r.getAsync("conversation"), n = yield r.getAsync("components"), i = s.controllers.find((a) => a.conversation.id === e);
305
- if (i) {
306
- const a = [...i.conversation.providers];
399
+ const s = yield r.getAsync("conversation"), i = yield r.getAsync("components"), n = s.controllers.find((a) => a.conversation.id === e);
400
+ if (n) {
401
+ const a = [...n.conversation.providers];
307
402
  a.forEach((c) => {
308
- i.conversation.setProviderOptions(c, { silent: !0 });
309
- }), i.conversation.queueProviders(a), i.conversation.setProviders([t]);
310
- const o = n.components().ofType("conversation");
311
- n.write({
403
+ n.conversation.setProviderOptions(c, { silent: !0 });
404
+ }), n.conversation.queueProviders(a), n.conversation.setProviders([t]);
405
+ const o = i.components().ofType("conversation");
406
+ i.write({
312
407
  key: "setConversationProvider",
313
408
  attributes: {
314
409
  properties: { providers: [t] }
@@ -333,40 +428,40 @@ class ne {
333
428
  return typeof e == "string" ? { body: e } : e.length > -1 && typeof e == "object" ? { items: e } : e;
334
429
  }
335
430
  }
336
- var I = /* @__PURE__ */ ((r) => (r.User = "user", r.Agent = "agent", r.System = "system", r))(I || {});
337
- const D = (r, e) => {
338
- let t, s = (e == null ? void 0 : e.key) || L(), n = Date.now();
431
+ var S = /* @__PURE__ */ ((r) => (r.User = "user", r.Agent = "agent", r.System = "system", r))(S || {});
432
+ const I = (r, e) => {
433
+ let t, s = (e == null ? void 0 : e.key) || U(), i = Date.now();
339
434
  if (Array.isArray(r) && r.length > -1)
340
435
  typeof r[0] == "string" ? t = { items: [r] } : t = { items: r };
341
436
  else if (typeof r == "string")
342
437
  t = { body: r };
343
438
  else if (r = r || {}, r.type)
344
- t = g({}, r);
439
+ t = m({}, r);
345
440
  else {
346
441
  if (t = {
347
442
  body: r.body,
348
443
  actions: r.actions,
349
444
  title: r.title
350
- }, r.key && (s = r.key), r.timestamp && (n = r.timestamp), typeof r.form == "function") {
351
- const i = X.create(s);
352
- r.form(i);
353
- const a = i.get();
445
+ }, r.key && (s = r.key), r.timestamp && (i = r.timestamp), typeof r.form == "function") {
446
+ const n = X.create(s);
447
+ r.form(n);
448
+ const a = n.get();
354
449
  t.form = a;
355
450
  }
356
- r.timestamp === null && (n = null);
451
+ r.timestamp === null && (i = null);
357
452
  }
358
- return { content: t, key: s, timestamp: n };
359
- }, H = (r, e) => {
453
+ return { content: t, key: s, timestamp: i };
454
+ }, z = (r, e) => {
360
455
  if (!e)
361
456
  return;
362
- const t = JSON.stringify(e), s = r.findIndex((n) => t === JSON.stringify(n));
457
+ const t = JSON.stringify(e), s = r.findIndex((i) => t === JSON.stringify(i));
363
458
  if (s > -1)
364
459
  return r.splice(s, 1);
365
460
  };
366
- class ie {
461
+ class oe {
367
462
  constructor(e, t, s) {
368
463
  d(this, "formHandlers", {});
369
- d(this, "user", new re(this));
464
+ d(this, "user", new ie(this));
370
465
  d(this, "events");
371
466
  d(this, "providers", []);
372
467
  d(this, "active", !1);
@@ -377,8 +472,9 @@ class ie {
377
472
  d(this, "store");
378
473
  d(this, "messages", []);
379
474
  d(this, "typingActors", []);
475
+ d(this, "conversationHistory");
380
476
  d(this, "print", (e) => {
381
- const t = D(e);
477
+ const t = I(e);
382
478
  return this.createEntry(
383
479
  t.key,
384
480
  t.content,
@@ -388,26 +484,26 @@ class ie {
388
484
  );
389
485
  });
390
486
  this.container = e, this.id = t;
391
- const n = e.get("$widget");
392
- this.events = n.events.createChild(this), this.store = new se(e, this, s.rehydrate);
487
+ const i = e.get("$widget");
488
+ this.events = i.events.createChild(this), this.store = new re(e, this, s.rehydrate), this.conversationHistory = new ee(this);
393
489
  }
394
490
  setInitialStorage(e) {
395
491
  this.store.setInitialData(e);
396
492
  }
397
493
  setProviders(e) {
398
494
  const t = [], s = [];
399
- this.providers.reduce((n, i) => (e.indexOf(i) === -1 && n.push(i), n), []).forEach((n) => {
400
- const i = this.providers.indexOf(n);
401
- i > -1 && (t.push(n), this.providers.splice(i, 1));
402
- }), e.forEach((n) => {
403
- this.providers.indexOf(n) === -1 && (s.push(n), this.providers.push(n));
495
+ this.providers.reduce((i, n) => (e.indexOf(n) === -1 && i.push(n), i), []).forEach((i) => {
496
+ const n = this.providers.indexOf(i);
497
+ n > -1 && (t.push(i), this.providers.splice(n, 1));
498
+ }), e.forEach((i) => {
499
+ this.providers.indexOf(i) === -1 && (s.push(i), this.providers.push(i));
404
500
  }), (s.length || t.length) && this.events.dispatch("conversation:providers-changed", { added: s, removed: t });
405
501
  }
406
502
  createProvider(e) {
407
503
  const t = this.providerIndex(e);
408
504
  if (t > -1)
409
505
  return this.registeredProviders[t];
410
- const s = T.create(e, this.container, this);
506
+ const s = R.create(e, this.container, this);
411
507
  return this.registeredProviders.push(s), s;
412
508
  }
413
509
  providerIndex(e) {
@@ -418,7 +514,7 @@ class ie {
418
514
  return this.store.getStoredAgent(e);
419
515
  }
420
516
  dispose() {
421
- this.registeredProviders.forEach((e) => e.dispose()), this.messages = [], this.events.dispatch("conversation:controller-disposed", this), this.active = !1;
517
+ this.conversationHistory.dispose(), this.registeredProviders.forEach((e) => e.dispose()), this.messages = [], this.events.dispatch("conversation:controller-disposed", this), this.active = !1;
422
518
  }
423
519
  onDispose(e) {
424
520
  return this.events.subscribe("conversation:controller-disposed", e);
@@ -462,19 +558,19 @@ class ie {
462
558
  onUnreadMessage(e) {
463
559
  return this.events.subscribe("conversation:unread-message", e);
464
560
  }
465
- createEntry(e, t, s, n, i) {
561
+ createEntry(e, t, s, i, n) {
466
562
  const a = {
467
563
  key: e,
468
564
  content: t,
469
565
  type: s,
470
- sender: n || null,
471
- timestamp: i || i === null ? i : Date.now()
566
+ sender: i || null,
567
+ timestamp: n || n === null ? n : Date.now()
472
568
  };
473
- this.messages.push(a), a.type === "agent" && H(this.typingActors, n);
569
+ this.messages.push(a), a.type === "agent" && z(this.typingActors, i);
474
570
  const o = new ne((c) => {
475
571
  if (c !== null) {
476
- const h = c, { timestamp: u = void 0 } = h, f = $(h, ["timestamp"]);
477
- a.content = f, u && (a.timestamp = u);
572
+ const h = c, { timestamp: u = void 0 } = h, l = B(h, ["timestamp"]);
573
+ a.content = l, u && (a.timestamp = u);
478
574
  } else {
479
575
  const u = this.messages.indexOf(a);
480
576
  a.content = null, u > -1 && this.messages.splice(u, 1);
@@ -499,7 +595,7 @@ class ie {
499
595
  }
500
596
  setTypingState(e, t) {
501
597
  return this.typingActors.indexOf(e) === -1 && (this.typingActors.push(e), this.update()), () => {
502
- H(this.typingActors, e), this.update();
598
+ z(this.typingActors, e), this.update();
503
599
  };
504
600
  }
505
601
  loader() {
@@ -510,34 +606,37 @@ class ie {
510
606
  };
511
607
  }
512
608
  submitForm(e, t) {
513
- this.formHandlers[e] = m(g({}, this.formHandlers[e]), { submit: t });
609
+ this.formHandlers[e] = b(m({}, this.formHandlers[e]), { submit: t });
514
610
  }
515
611
  validateForm(e, t) {
516
- this.formHandlers[e] = m(g({}, this.formHandlers[e]), { validate: t });
612
+ this.formHandlers[e] = b(m({}, this.formHandlers[e]), { validate: t });
613
+ }
614
+ getHistory() {
615
+ return this.conversationHistory.getConversationLogs();
517
616
  }
518
617
  }
519
- const oe = (r, e) => {
618
+ const ae = (r, e) => {
520
619
  const t = r.split("_contact");
521
620
  return e.widgets.get(t[0]);
522
621
  }, O = (r) => {
523
- const e = r.get("$widget"), { name: t, implementation: s } = r.get("$widget"), n = t.indexOf("_contact") > -1 ? oe(t, s) : e, { data: i } = r.get("$settings"), { trigger: a } = n.container.get("$settings"), o = `${t.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(o);
524
- return c && !a ? { chatWidget: c, mainWidget: n, data: i } : { mainWidget: n, data: i };
525
- }, ae = (r) => {
622
+ const e = r.get("$widget"), { name: t, implementation: s } = r.get("$widget"), i = t.indexOf("_contact") > -1 ? ae(t, s) : e, { data: n } = r.get("$settings"), { trigger: a } = i.container.get("$settings"), o = `${t.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(o);
623
+ return c && !a ? { chatWidget: c, mainWidget: i, data: n } : { mainWidget: i, data: n };
624
+ }, ce = (r) => {
526
625
  const { chatWidget: e } = O(r);
527
626
  return !!e;
528
627
  }, Q = (r, e, t) => {
529
- const { mainWidget: s, data: n, chatWidget: i } = O(r);
530
- return i ? i.state === "activated" ? i.invoke("open").then(() => {
531
- i.container.getAsync("conversation").then((a) => {
532
- a.navigateToConversationIfActive(e.id).then(() => z(r));
628
+ const { mainWidget: s, data: i, chatWidget: n } = O(r);
629
+ return n ? n.state === "activated" ? n.invoke("open").then(() => {
630
+ n.container.getAsync("conversation").then((a) => {
631
+ a.navigateToConversationIfActive(e.id).then(() => L(r));
533
632
  });
534
- }) : i.activate().then(() => {
535
- const { trigger: a } = i.container.get("$settings");
536
- return a.action = "hide", i.invoke("setSettings", () => ({
537
- data: n,
633
+ }) : n.activate().then(() => {
634
+ const { trigger: a } = n.container.get("$settings");
635
+ return a.action = "hide", n.invoke("setSettings", () => ({
636
+ data: i,
538
637
  trigger: a,
539
638
  activate: !0
540
- })).then(() => i.container.getAsync("components").then((o) => {
639
+ })).then(() => n.container.getAsync("components").then((o) => {
541
640
  const c = o.components().ofType("contact-method");
542
641
  o.write({
543
642
  key: "setContactMethodId",
@@ -560,28 +659,28 @@ const oe = (r, e) => {
560
659
  provider: "localStorage"
561
660
  });
562
661
  }));
563
- }).then(() => i.invoke("attach", {
662
+ }).then(() => n.invoke("attach", {
564
663
  key: "contact-method",
565
664
  triggerDOMElement: t,
566
665
  withRenderState: "open"
567
- })).then(() => (N(
568
- i.container,
666
+ })).then(() => (D(
667
+ n.container,
569
668
  "activeStickyWidget",
570
- R.Necessary,
669
+ N.Necessary,
571
670
  {
572
- medium: w.Local,
671
+ medium: A.Local,
573
672
  scope: V.Implementation
574
673
  }
575
- ).then((a) => a(i.name)), i.container.getAsync("conversation").then((a) => {
576
- a.setConversationEndedBehavior(C.Deactivate);
577
- }).then(() => z(r)).then(() => !1))) : (s.container.getAsync("conversation").then((a) => a.navigateToConversationIfActive(e.id).then(() => a.setConversationEndedBehavior(C.Navigate))), !i);
578
- }, ce = (r, e, t = "conversation") => {
579
- const { mainWidget: s, chatWidget: n } = O(r);
580
- return n ? n.container.getAsync("router").then((i) => {
581
- i.navigate(t, { id: e.id });
582
- }) : s.container.getAsync("conversation").then((i) => {
674
+ ).then((a) => a(n.name)), n.container.getAsync("conversation").then((a) => {
675
+ a.setConversationEndedBehavior(E.Deactivate);
676
+ }).then(() => L(r)).then(() => !1))) : (s.container.getAsync("conversation").then((a) => a.navigateToConversationIfActive(e.id).then(() => a.setConversationEndedBehavior(E.Navigate))), !n);
677
+ }, de = (r, e, t = "conversation") => {
678
+ const { mainWidget: s, chatWidget: i } = O(r);
679
+ return i ? i.container.getAsync("router").then((n) => {
680
+ n.navigate(t, { id: e.id });
681
+ }) : s.container.getAsync("conversation").then((n) => {
583
682
  var a;
584
- (a = i.setConversationEndedBehavior(C.Navigate)) == null || a.then(() => {
683
+ (a = n.setConversationEndedBehavior(E.Navigate)) == null || a.then(() => {
585
684
  s.container.getAsync("router").then((o) => {
586
685
  s.container.getAsync("components").then((c) => {
587
686
  const h = c.components().ofType("conversation");
@@ -598,8 +697,8 @@ const oe = (r, e) => {
598
697
  });
599
698
  });
600
699
  }, P = "conversations";
601
- var C = /* @__PURE__ */ ((r) => (r.Deactivate = "deactivate", r.Navigate = "navigate", r.None = "none", r))(C || {});
602
- class k {
700
+ var E = /* @__PURE__ */ ((r) => (r.Deactivate = "deactivate", r.Navigate = "navigate", r.None = "none", r))(E || {});
701
+ class C {
603
702
  constructor(e, t) {
604
703
  d(this, "events");
605
704
  d(this, "controllers", []);
@@ -615,21 +714,21 @@ class k {
615
714
  this.events = s.events.createChild(this);
616
715
  }
617
716
  initialize() {
618
- N(this.container, P, R.Necessary, {
619
- medium: w.Local
620
- }).then((e) => this.storageWriter = e), b(this.container, P, w.Local).then(
717
+ D(this.container, P, N.Necessary, {
718
+ medium: A.Local
719
+ }).then((e) => this.storageWriter = e), w(this.container, P, A.Local).then(
621
720
  (e) => {
622
721
  this.buttonQuery = this.components.components().ofType("conversation-return-button"), e && (this.sessionInfo = e, e.id && e.route && this.writeToComponents({ active: !0, alert: { show: !1 } }));
623
722
  }
624
723
  ), this.container.getAsync("router").then((e) => this.router = e), this.events.subscribe("conversation:ended", (e, t) => {
625
- var s, n, i;
724
+ var s, i, n;
626
725
  switch ((s = this.sessionInfo) == null ? void 0 : s.conversationEndedBehavior) {
627
726
  case "deactivate":
628
727
  this.container.get("$widget").deactivate();
629
728
  break;
630
729
  case "navigate":
631
- const o = (n = this.router) == null ? void 0 : n.getInitialRoute();
632
- o && ((i = this.router) == null || i.navigate(o.name));
730
+ const o = (i = this.router) == null ? void 0 : i.getInitialRoute();
731
+ o && ((n = this.router) == null || n.navigate(o.name));
633
732
  break;
634
733
  }
635
734
  this.writeToComponents({ active: !1 }), this.sessionInfo = null, this.storageWriter && this.storageWriter();
@@ -640,23 +739,23 @@ class k {
640
739
  }
641
740
  static getInstance(e, t = "conversation") {
642
741
  return Y(e)(() => e.getAsync(t).then((s) => {
643
- let n = s;
644
- return n || K.getInstance(e).then((i) => (n = new k(e, i), n.initialize(), e.registerAsync(t, () => n), n));
742
+ let i = s;
743
+ return i || K.getInstance(e).then((n) => (i = new C(e, n), i.initialize(), e.registerAsync(t, () => i), i));
645
744
  }));
646
745
  }
647
746
  navigateToConversationIfActive(e) {
648
- return b(this.container, P, w.Local).then(
747
+ return w(this.container, P, A.Local).then(
649
748
  (t) => {
650
749
  var s;
651
750
  if (t && t.id === e && t.route) {
652
- const { name: n, params: i } = t.route;
653
- (s = this.router) == null || s.navigate(n, i);
751
+ const { name: i, params: n } = t.route;
752
+ (s = this.router) == null || s.navigate(i, n);
654
753
  }
655
754
  }
656
755
  );
657
756
  }
658
757
  setConversationEndedBehavior(e) {
659
- return b(this.container, P, w.Local).then(
758
+ return w(this.container, P, A.Local).then(
660
759
  (t) => {
661
760
  let s = t;
662
761
  return s ? s.conversationEndedBehavior = e : s = { conversationEndedBehavior: e }, this.sessionInfo = s, this.storageWriter && this.storageWriter(this.sessionInfo) || Promise.resolve();
@@ -665,12 +764,12 @@ class k {
665
764
  }
666
765
  createController(e, t) {
667
766
  return v(this, null, function* () {
668
- const s = q(e), { agents: n } = (yield b(
767
+ const s = F(e), { agents: i } = (yield w(
669
768
  this.container,
670
769
  s
671
- )) || { agents: [] }, i = this.controllers.findIndex((o) => o.conversation.id === e);
770
+ )) || { agents: [] }, n = this.controllers.findIndex((o) => o.conversation.id === e);
672
771
  let a;
673
- return i > -1 ? a = this.controllers[i].conversation : a = new ie(this.container, e, t), a.setInitialStorage({ agents: n || [] }), a;
772
+ return n > -1 ? a = this.controllers[n].conversation : a = new oe(this.container, e, t), a.setInitialStorage({ agents: i || [] }), a;
674
773
  });
675
774
  }
676
775
  registerProvider(e, t) {
@@ -678,18 +777,18 @@ class k {
678
777
  name: e,
679
778
  handler: t
680
779
  };
681
- this.providers.push(s), this.controllers.filter((n) => n.conversation.providers.indexOf(e) > -1).forEach((n) => {
682
- this.invokeHandler(s, n);
780
+ this.providers.push(s), this.controllers.filter((i) => i.conversation.providers.indexOf(e) > -1).forEach((i) => {
781
+ this.invokeHandler(s, i);
683
782
  });
684
783
  }
685
784
  registerController(e, t) {
686
- const s = this.controllers.findIndex((i) => i.conversation.id === e.id);
687
- let n;
785
+ const s = this.controllers.findIndex((n) => n.conversation.id === e.id);
786
+ let i;
688
787
  if (s < 0) {
689
- n = { conversation: e, component: t }, this.controllers.push(n);
690
- const i = (a) => {
788
+ i = { conversation: e, component: t }, this.controllers.push(i);
789
+ const n = (a) => {
691
790
  a && this.providers.filter((o) => a.indexOf(o.name) > -1).forEach((o) => {
692
- this.invokeHandler(o, n);
791
+ this.invokeHandler(o, i);
693
792
  });
694
793
  };
695
794
  return this.subscriptions.push(
@@ -701,10 +800,10 @@ class k {
701
800
  e.onProvidersChange((a, o) => {
702
801
  const { added: c, removed: h = [] } = o;
703
802
  h.forEach((u) => {
704
- (this.disposeProviders[u] || []).forEach((f) => {
705
- f();
803
+ (this.disposeProviders[u] || []).forEach((l) => {
804
+ l();
706
805
  });
707
- }), i(c);
806
+ }), n(c);
708
807
  })
709
808
  ), this.subscriptions.push(
710
809
  e.onStarted((a, o) => {
@@ -720,9 +819,9 @@ class k {
720
819
  e.onUnreadMessage((a, o) => {
721
820
  this.events.dispatch("conversation:unread-message", o), this.writeToComponents({ alert: { show: o } });
722
821
  })
723
- ), i(e.providers), !0;
822
+ ), n(e.providers), !0;
724
823
  }
725
- return n = this.controllers[s], !1;
824
+ return i = this.controllers[s], !1;
726
825
  }
727
826
  writeToComponents(e, t = "conversationReturnButtonState") {
728
827
  this.buttonQuery && this.components.write({
@@ -740,7 +839,7 @@ class k {
740
839
  s && (this.disposeProviders[e.name] || (this.disposeProviders[e.name] = []), this.disposeProviders[e.name].push(s));
741
840
  }
742
841
  getComponentRoute() {
743
- return b(this.container, P, w.Local).then(
842
+ return w(this.container, P, A.Local).then(
744
843
  (e) => e == null ? void 0 : e.route
745
844
  );
746
845
  }
@@ -753,116 +852,116 @@ class k {
753
852
  e();
754
853
  }), this.controllers = [], this.providers = [];
755
854
  }
756
- static handleContactMethodClick(e, t, s, n) {
855
+ static handleContactMethodClick(e, t, s, i) {
757
856
  return v(this, null, function* () {
758
- if (ae(t)) {
857
+ if (ce(t)) {
759
858
  e.preventDefault();
760
- let i = document.getElementById("humany-dynamic-anchor");
761
- i || (i = document.createElement("a"), i.setAttribute("href", "#"), i.id = "humany-dynamic-anchor", document.body.appendChild(i)), Q(t, s, i);
859
+ let n = document.getElementById("humany-dynamic-anchor");
860
+ n || (n = document.createElement("a"), n.setAttribute("href", "#"), n.id = "humany-dynamic-anchor", document.body.appendChild(n)), Q(t, s, n);
762
861
  }
763
862
  Q(t, s);
764
863
  });
765
864
  }
766
865
  static handleContactMethodSubmit(e, t) {
767
866
  return v(this, null, function* () {
768
- var s, n;
769
- return (n = (s = t == null ? void 0 : t.body.form.meta) == null ? void 0 : s.conversation) != null && n.id ? W(
867
+ var s, i;
868
+ return (i = (s = t == null ? void 0 : t.body.form.meta) == null ? void 0 : s.conversation) != null && i.id ? W(
770
869
  e,
771
870
  t.body.form.meta.conversation.id,
772
871
  t.clientName
773
- ) : ce(e, t);
872
+ ) : de(e, t);
774
873
  });
775
874
  }
776
875
  }
777
- const de = (r, e) => r.reduce((t, s, n) => {
876
+ const he = (r, e) => r.reduce((t, s, i) => {
778
877
  var a, o;
779
- const i = m(g({}, s), {
780
- content: [m(g({}, s.content), { key: s.key })]
878
+ const n = b(m({}, s), {
879
+ content: [b(m({}, s.content), { key: s.key })]
781
880
  });
782
- if (t.length > 0 && s.type !== I.System) {
881
+ if (t.length > 0 && s.type !== S.System) {
783
882
  const c = t[t.length - 1];
784
883
  if ((!e && e !== 0 || Math.abs(c.timestamp - s.timestamp) < e) && ((a = c.sender) == null ? void 0 : a.name) === ((o = s.sender) == null ? void 0 : o.name) && c.type === s.type)
785
- return c.timestamp = s.timestamp, c.content.push(m(g({}, s.content), { key: s.key })), t;
884
+ return c.timestamp = s.timestamp, c.content.push(b(m({}, s.content), { key: s.key })), t;
786
885
  }
787
- return t.push(i), t;
788
- }, []), be = (r) => Promise.all([
789
- k.getInstance(r),
886
+ return t.push(n), t;
887
+ }, []), we = (r) => Promise.all([
888
+ C.getInstance(r),
790
889
  r.getAsync("router")
791
- ]).then(([e, t]) => U(
890
+ ]).then(([e, t]) => q(
792
891
  r,
793
892
  "conversation",
794
- import("./conversation.bc31361a.js"),
893
+ import("./conversation.d6cacfa5.js"),
795
894
  (s) => v(void 0, null, function* () {
796
- const { rehydrate: n = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", o = yield e.createController(a, { rehydrate: n }), c = e.registerController(o, s), h = 3 * 60 * 1e3, u = (p) => {
797
- const { providers: l = [] } = p;
798
- if (l) {
799
- const y = Array.isArray(l) ? l : [l];
895
+ const { rehydrate: i = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", o = yield e.createController(a, { rehydrate: i }), c = e.registerController(o, s), h = 3 * 60 * 1e3, u = (g) => {
896
+ const { providers: p = [] } = g;
897
+ if (p) {
898
+ const y = Array.isArray(p) ? p : [p];
800
899
  return o.setProviders(y), y;
801
900
  }
802
901
  };
803
902
  u(s.properties(u)), o.setComponentMountedState(!0);
804
- const f = (p) => {
805
- const { loading: l, typingActors: y, messages: S } = p;
903
+ const l = (g) => {
904
+ const { loading: p, typingActors: y, messages: k } = g;
806
905
  s.writeProperties({
807
- loading: l,
906
+ loading: p,
808
907
  typingActors: y,
809
- messages: de(S, h)
908
+ messages: he(k, h)
810
909
  });
811
910
  };
812
- f(o.getMessageStream()), c && (s.writeProperties({ conversationControllerId: o.id }), s.actions.create("user-submit", (p, l) => {
813
- if (l) {
814
- const { preventDefault: y, validationPromise: S } = l;
911
+ l(o.getMessageStream()), c && (s.writeProperties({ conversationControllerId: o.id }), s.actions.create("user-submit", (g, p) => {
912
+ if (p) {
913
+ const { preventDefault: y, validationPromise: k } = p;
815
914
  if (y) {
816
- S && S().then((_) => {
817
- _ && o.user.print(_);
915
+ k && k().then((H) => {
916
+ H && o.user.print(H);
818
917
  });
819
918
  return;
820
919
  }
821
920
  }
822
- o.user.print(p.text);
823
- }), s.actions.create("user-typing", (p, l) => {
824
- }), s.actions.create("form", (p, l) => {
825
- }), s.actions.create("action", (p, l) => {
826
- }), s.actions.create("overlay-mounted", (p, l) => {
827
- }), s.actions.create("show-overlay", (p, l) => {
921
+ o.user.print(g.text);
922
+ }), s.actions.create("user-typing", (g, p) => {
923
+ }), s.actions.create("form", (g, p) => {
924
+ }), s.actions.create("action", (g, p) => {
925
+ }), s.actions.create("overlay-mounted", (g, p) => {
926
+ }), s.actions.create("show-overlay", (g, p) => {
828
927
  s.writeProperties({
829
928
  overlay: { conversation: !1, secondary: !1 }
830
929
  });
831
- }), s.actions.create("hide-overlay", (p, l) => {
930
+ }), s.actions.create("hide-overlay", (g, p) => {
832
931
  s.writeProperties({
833
932
  overlay: null
834
933
  });
835
- }), s.actions.create("show-overlay-conversation", (p, l) => {
934
+ }), s.actions.create("show-overlay-conversation", (g, p) => {
836
935
  s.writeProperties({
837
936
  overlay: { conversation: !0, secondary: !1 }
838
937
  });
839
- }), s.actions.create("hide-overlay-conversation", (p, l) => {
938
+ }), s.actions.create("hide-overlay-conversation", (g, p) => {
840
939
  s.writeProperties({
841
940
  overlay: { conversation: !1, secondary: !1 }
842
941
  });
843
942
  }));
844
- const F = o.events.subscribe(
943
+ const f = o.events.subscribe(
845
944
  "conversation:updated",
846
- (p, l) => {
847
- f(l);
945
+ (g, p) => {
946
+ l(p);
848
947
  }
849
948
  );
850
949
  return () => {
851
- o.setComponentMountedState(!1), F(), o.active || f({ messages: [], typingActors: [], loading: !1 });
950
+ o.setComponentMountedState(!1), f(), o.active || l({ messages: [], typingActors: [], loading: !1 });
852
951
  };
853
952
  }),
854
953
  { reuseController: !0 }
855
- )), we = (r) => Promise.all([
954
+ )), Ae = (r) => Promise.all([
856
955
  K.getInstance(r),
857
- k.getInstance(r),
956
+ C.getInstance(r),
858
957
  r.getAsync("router")
859
958
  ]).then(
860
- ([e, t, s]) => U(
959
+ ([e, t, s]) => q(
861
960
  r,
862
961
  "conversation-return-button",
863
962
  import("./return-button.fb63a16e.js"),
864
- (n) => {
865
- n.actions.create("toggle", (i = {}) => {
963
+ (i) => {
964
+ i.actions.create("toggle", (n = {}) => {
866
965
  var a;
867
966
  (a = t.getComponentRoute()) == null || a.then((o) => {
868
967
  o && s.navigate(o.name, o.params);
@@ -871,9 +970,9 @@ const de = (r, e) => r.reduce((t, s, n) => {
871
970
  }
872
971
  )
873
972
  );
874
- var he = /* @__PURE__ */ ((r) => (r.LinkList = "link-list", r.Separator = "separator", r.ButtonList = "button-list", r.Text = "text", r.HTML = "html", r.VideoRequest = "video-request", r))(he || {});
973
+ var le = /* @__PURE__ */ ((r) => (r.LinkList = "link-list", r.Separator = "separator", r.ButtonList = "button-list", r.Text = "text", r.HTML = "html", r.VideoRequest = "video-request", r))(le || {});
875
974
  const Pe = (r, e, t) => r.getAsync("componentResolver").then((s) => v(void 0, null, function* () {
876
- (yield k.getInstance(r)).addSubscription(
975
+ (yield C.getInstance(r)).addSubscription(
877
976
  s.registerComponent(
878
977
  e,
879
978
  Z(() => t)
@@ -881,14 +980,14 @@ const Pe = (r, e, t) => r.getAsync("componentResolver").then((s) => v(void 0, nu
881
980
  );
882
981
  }));
883
982
  export {
884
- be as ConversationComponent,
885
- ie as ConversationController,
886
- C as ConversationEndedBehavior,
983
+ we as ConversationComponent,
984
+ oe as ConversationController,
985
+ E as ConversationEndedBehavior,
887
986
  ne as ConversationEntry,
888
- he as ConversationMessageListItemType,
889
- I as ConversationMessageType,
890
- k as ConversationPlatform,
891
- we as ConversationReturnButtonComponent,
987
+ le as ConversationMessageListItemType,
988
+ S as ConversationMessageType,
989
+ C as ConversationPlatform,
990
+ Ae as ConversationReturnButtonComponent,
892
991
  Pe as registerCustomMessageComponent
893
992
  };
894
993
  //# sourceMappingURL=index.js.map