@telia-ace/knowledge-widget-bot-provider 0.0.15-experimental.9 → 0.0.15

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 (41) hide show
  1. package/dist/contact-method-list.70f5e518.js +94 -0
  2. package/dist/contact-method-list.70f5e518.js.map +1 -0
  3. package/dist/contact-method.4b049dad.js +123 -0
  4. package/dist/contact-method.4b049dad.js.map +1 -0
  5. package/dist/feedback-list.73d8aa69.js +76 -0
  6. package/dist/feedback-list.73d8aa69.js.map +1 -0
  7. package/dist/index.a7a0d62d.js +787 -0
  8. package/dist/index.a7a0d62d.js.map +1 -0
  9. package/dist/index.js +6 -779
  10. package/dist/index.js.map +1 -1
  11. package/dist/no-good-alternative.e5e48f22.js +50 -0
  12. package/dist/no-good-alternative.e5e48f22.js.map +1 -0
  13. package/dist/notification-list.c3df3ee1.js +66 -0
  14. package/dist/notification-list.c3df3ee1.js.map +1 -0
  15. package/dist/styles.a00306c5.js +12 -0
  16. package/dist/styles.a00306c5.js.map +1 -0
  17. package/dist/ui/contact-method-list.d.ts +8 -1
  18. package/dist/ui/feedback-list.d.ts +6 -1
  19. package/dist/ui/no-good-alternative.d.ts +4 -1
  20. package/dist/ui/notification-list.d.ts +9 -1
  21. package/dist/utils.d.ts +2 -3
  22. package/package.json +10 -14
  23. package/dist/contact-method-list.2b3b6ea5.js +0 -5
  24. package/dist/contact-method-list.2b3b6ea5.js.map +0 -1
  25. package/dist/contact-method.016a8ec5.js +0 -5
  26. package/dist/contact-method.016a8ec5.js.map +0 -1
  27. package/dist/feedback-list.042775aa.js +0 -5
  28. package/dist/feedback-list.042775aa.js.map +0 -1
  29. package/dist/new-feedback-list.4dc450c7.js +0 -61
  30. package/dist/new-feedback-list.4dc450c7.js.map +0 -1
  31. package/dist/new-no-good-alternative.63439a76.js +0 -48
  32. package/dist/new-no-good-alternative.63439a76.js.map +0 -1
  33. package/dist/new-notification-list.8acdfeb4.js +0 -60
  34. package/dist/new-notification-list.8acdfeb4.js.map +0 -1
  35. package/dist/no-good-alternative.4e277f5b.js +0 -5
  36. package/dist/no-good-alternative.4e277f5b.js.map +0 -1
  37. package/dist/notification-list.399e34ff.js +0 -5
  38. package/dist/notification-list.399e34ff.js.map +0 -1
  39. package/dist/ui/new-feedback-list.d.ts +0 -13
  40. package/dist/ui/new-no-good-alternative.d.ts +0 -8
  41. package/dist/ui/new-notification-list.d.ts +0 -11
@@ -0,0 +1,787 @@
1
+ var V = Object.defineProperty, j = Object.defineProperties;
2
+ var z = Object.getOwnPropertyDescriptors;
3
+ var R = Object.getOwnPropertySymbols;
4
+ var W = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable;
5
+ var P = (n, t, e) => t in n ? V(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, K = (n, t) => {
6
+ for (var e in t || (t = {}))
7
+ W.call(t, e) && P(n, e, t[e]);
8
+ if (R)
9
+ for (var e of R(t))
10
+ _.call(t, e) && P(n, e, t[e]);
11
+ return n;
12
+ }, $ = (n, t) => j(n, z(t));
13
+ var b = (n, t, e) => (P(n, typeof t != "symbol" ? t + "" : t, e), e);
14
+ var m = (n, t, e) => new Promise((i, s) => {
15
+ var a = (S) => {
16
+ try {
17
+ d(e.next(S));
18
+ } catch (o) {
19
+ s(o);
20
+ }
21
+ }, c = (S) => {
22
+ try {
23
+ d(e.throw(S));
24
+ } catch (o) {
25
+ s(o);
26
+ }
27
+ }, d = (S) => S.done ? i(S.value) : Promise.resolve(S.value).then(a, c);
28
+ d((e = e.apply(n, t)).next());
29
+ });
30
+ import { ConversationMessageListItemType as I, ConversationPlatform as D, registerCustomMessageComponent as B } from "@telia-ace/widget-conversation";
31
+ import { readStorage as J, createStorageWriter as F, StorageCategory as T } from "@telia-ace/widget-services";
32
+ import { uuid as N } from "@telia-ace/widget-utilities";
33
+ import { FormBuilder as A, submitButton as q } from "@telia-ace/widget-forms";
34
+ var f = /* @__PURE__ */ ((n) => (n.ContactMethod = "ace-knowledge-bot-contact-method", n.ContactList = "ace-knowledge-bot-contact-list", n.FeedbackList = "ace-knowledge-bot-feedback-list", n.NotificationList = "ace-knowledge-bot-notification-list", n.NoGoodAlternative = "ace-knowledge-bot-no-good-alternative", n))(f || {});
35
+ const Q = (n) => {
36
+ if (n) {
37
+ const { type: t, content: e } = n;
38
+ if (t && e)
39
+ return { type: t, content: e };
40
+ }
41
+ }, G = ({
42
+ isUser: n,
43
+ items: t = [],
44
+ meta: e = {}
45
+ }) => {
46
+ const i = N();
47
+ return {
48
+ id: i,
49
+ isUser: n,
50
+ items: t.map((a) => ({
51
+ id: a.id || N(),
52
+ isUser: n,
53
+ groupId: i,
54
+ message: a.message || []
55
+ })),
56
+ meta: e
57
+ };
58
+ }, X = ({
59
+ id: n,
60
+ title: t,
61
+ defaultIcon: e,
62
+ exits: [i],
63
+ exitType: s,
64
+ confirmationText: a,
65
+ expandFormAutomatically: c,
66
+ form: d,
67
+ description: S
68
+ }, o = {}) => {
69
+ const { adapter: r } = i || { Adapter: {} }, { clientName: l = "", settings: v = {}, customClientName: L = "" } = r, { validation: w } = o, p = {
70
+ id: n.toString(),
71
+ title: t,
72
+ description: S,
73
+ symbol: Q(e),
74
+ clientName: l === "custom.adapter" ? L : l,
75
+ expanded: !0,
76
+ inline: !0,
77
+ body: {}
78
+ };
79
+ if (l.indexOf("phone") > -1 || l.indexOf("freetext") > -1) {
80
+ const { displayTextBeforeClick: h, textBeforeClick: g } = v;
81
+ h === "true" && (p.expanded = !1, p.title = g), l.indexOf("phone.text") > -1 ? p.body.phoneNumber = v.phoneNumber : p.body.freetext = v.freetext;
82
+ }
83
+ return (l.indexOf("chat.popup") > -1 || l.indexOf("link") > -1 || l === "custom.adapter" && s === "custom") && (p.body = v, p.body.confirmationFallback = a), l.indexOf("ace") > -1 && (p.body = v), d && d.hasValueComponents && (w ? p.body.form = A.fromLegacyForm(n.toString(), d, w).get() : p.body.form = A.fromLegacyForm(n.toString(), d).get(), c || (p.expanded = p.inline = !1), p.body = tt(p, { submit: "Submit" })), o.guideId && (p.body.guideId = o.guideId), p;
84
+ }, Y = (n) => (n == null ? void 0 : n.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching" ? I.LinkList : (n == null ? void 0 : n.$type) === "Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching" ? f.FeedbackList : (n == null ? void 0 : n.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching" ? f.ContactList : I.ButtonList, Z = (n, t) => {
85
+ const { knowledgeBotEndpoint: e } = t.properties();
86
+ if (e)
87
+ return `${e}/conversations`;
88
+ const { data: i } = n.get("$settings");
89
+ if (!i || !i.projection)
90
+ throw new Error("Missing Knowledge Bot endpoint");
91
+ return `${i.projection}/conversations`;
92
+ }, tt = (n, {
93
+ submit: t,
94
+ errors: e,
95
+ meta: i
96
+ }) => {
97
+ var s;
98
+ if ((s = n == null ? void 0 : n.body) != null && s.form) {
99
+ const { body: a } = n, c = new A(a.form);
100
+ return a.form.layout.submit || c.createComponent(q(t, "submit")), e && c.setValidationErrors(e), i && c.setMeta(i), $(K({}, a), {
101
+ form: c.get()
102
+ });
103
+ }
104
+ return (n == null ? void 0 : n.body) || {};
105
+ }, y = ({
106
+ messageId: n,
107
+ message: t,
108
+ group: e
109
+ }) => ({
110
+ id: n,
111
+ message: t,
112
+ groupId: e.id,
113
+ isUser: e.isUser
114
+ }), et = (n, t) => m(void 0, null, function* () {
115
+ const e = (o, r, l, v = {
116
+ actions: [],
117
+ entryId: r.id,
118
+ groupId: l
119
+ }) => {
120
+ const L = [];
121
+ return v.actions = r.content.items.map((w) => {
122
+ var h;
123
+ const p = {
124
+ label: w.title,
125
+ actionKey: w.actionKey,
126
+ symbol: w.symbol ? w.symbol : void 0
127
+ };
128
+ if (w.data) {
129
+ const g = r.actions[w.actionKey];
130
+ o === f.ContactList ? (L.push(w.data.id), p.data = X(w.data, {
131
+ guideId: (h = g == null ? void 0 : g.guideId) == null ? void 0 : h.toString()
132
+ })) : p.data = w.data;
133
+ }
134
+ return p;
135
+ }), o === f.ContactList && (v.contactMethodIds = L), v;
136
+ }, i = (L, w, ...p) => m(void 0, [L, w, ...p], function* (o, r, l = [], v) {
137
+ const h = N();
138
+ switch (o.type) {
139
+ case "List": {
140
+ const { header: g, items: x, html: H } = o.content, C = [];
141
+ let E = {
142
+ actions: [],
143
+ entryId: o.id,
144
+ groupId: r.id
145
+ };
146
+ if (g && (E.header = g), (x == null ? void 0 : x.length) > 0) {
147
+ const u = Y(o.localState);
148
+ if (E = e(u, o, r.id, E), l.length) {
149
+ const k = l.find((M) => M.tags.includes("paging")), O = l.find((M) => M.tags.includes("fallback"));
150
+ if (k != null && k.content && (r.meta.paging = {
151
+ actions: k.actions,
152
+ items: k.content.items,
153
+ localState: k.localState
154
+ }, k.content.items.forEach((M) => {
155
+ E.actions.push({
156
+ label: M.title,
157
+ actionKey: M.actionKey,
158
+ data: {
159
+ groupId: v ? v.id : r.id
160
+ }
161
+ });
162
+ })), O) {
163
+ const M = O.content.items.find(
164
+ (U) => U.actionKey === "help"
165
+ );
166
+ M && (C.push(
167
+ y({
168
+ messageId: h,
169
+ message: [
170
+ I.Separator,
171
+ void 0
172
+ ],
173
+ group: r
174
+ })
175
+ ), C.push(
176
+ y({
177
+ messageId: h,
178
+ message: [
179
+ f.NoGoodAlternative,
180
+ { body: M.title }
181
+ ],
182
+ group: r
183
+ })
184
+ ));
185
+ }
186
+ }
187
+ C.unshift(
188
+ y({
189
+ messageId: h,
190
+ message: [u, E],
191
+ group: r
192
+ })
193
+ );
194
+ }
195
+ return H && C.unshift(
196
+ y({
197
+ messageId: h,
198
+ message: [I.HTML, { body: H }],
199
+ group: r
200
+ })
201
+ ), C;
202
+ }
203
+ case "Text": {
204
+ const g = [];
205
+ if (g.push(
206
+ y({
207
+ messageId: h,
208
+ message: [
209
+ I.HTML,
210
+ { body: o.content.html }
211
+ ],
212
+ group: r
213
+ })
214
+ ), l.length) {
215
+ const x = l.find(
216
+ (u) => {
217
+ var k;
218
+ return u.type === "List" && ((k = u.localState) == null ? void 0 : k.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
219
+ }
220
+ ), H = l.find((u) => u.tags.includes("dialog")), C = l.find((u) => u.tags.includes("feedback")), E = l.find(
221
+ (u) => u.tags.includes("contact") && u.type === "Contact"
222
+ );
223
+ if (E && g.push(
224
+ y({
225
+ messageId: h,
226
+ message: [
227
+ f.ContactMethod,
228
+ {
229
+ contactMethodId: E.content.id,
230
+ groupId: r.id,
231
+ guideId: E.content.guideId
232
+ }
233
+ ],
234
+ group: r
235
+ })
236
+ ), H && g.push(
237
+ y({
238
+ messageId: h,
239
+ message: [
240
+ I.ButtonList,
241
+ {
242
+ actions: H.content.items.map((u) => ({
243
+ label: u.title,
244
+ actionKey: u.actionKey
245
+ }))
246
+ }
247
+ ],
248
+ group: r
249
+ })
250
+ ), x) {
251
+ const u = e(
252
+ f.ContactList,
253
+ x,
254
+ r.id
255
+ );
256
+ g.push(
257
+ y({
258
+ messageId: h,
259
+ message: [I.Separator, void 0],
260
+ group: r
261
+ })
262
+ ), g.push(
263
+ y({
264
+ messageId: h,
265
+ message: [f.ContactList, u],
266
+ group: r
267
+ })
268
+ );
269
+ }
270
+ C && (C.content.html && g.push(
271
+ y({
272
+ messageId: h,
273
+ group: r,
274
+ message: [
275
+ I.HTML,
276
+ {
277
+ body: C.content.html
278
+ }
279
+ ]
280
+ })
281
+ ), g.push(
282
+ y({
283
+ messageId: h,
284
+ group: r,
285
+ message: [
286
+ f.FeedbackList,
287
+ {
288
+ actions: C.content.items.map((u) => ({
289
+ actionKey: u.actionKey,
290
+ label: u.title
291
+ }))
292
+ }
293
+ ]
294
+ })
295
+ ));
296
+ }
297
+ return g;
298
+ }
299
+ case "Contact":
300
+ return [
301
+ y({
302
+ messageId: h,
303
+ message: [
304
+ f.ContactMethod,
305
+ {
306
+ contactMethodId: o.content.id,
307
+ groupId: r.id,
308
+ guideId: o.content.guideId
309
+ }
310
+ ],
311
+ group: r
312
+ })
313
+ ];
314
+ case "CategorizedNoticeList": {
315
+ const g = [
316
+ y({
317
+ messageId: h,
318
+ message: [
319
+ f.NotificationList,
320
+ {
321
+ id: o.content.item.id.toString(),
322
+ header: o.content.item.title,
323
+ items: o.content.item.listNotices,
324
+ symbol: o.content.item.defaultIcon
325
+ }
326
+ ],
327
+ group: r
328
+ })
329
+ ];
330
+ return (o.content.notices || []).forEach((x) => {
331
+ g.push(
332
+ y({
333
+ messageId: h,
334
+ message: [
335
+ I.HTML,
336
+ {
337
+ body: x.body
338
+ }
339
+ ],
340
+ group: r
341
+ })
342
+ );
343
+ }), g;
344
+ }
345
+ case "footerNotice":
346
+ return [
347
+ y({
348
+ messageId: h,
349
+ message: [
350
+ I.HTML,
351
+ {
352
+ body: o.content.item.body
353
+ }
354
+ ],
355
+ group: r
356
+ })
357
+ ];
358
+ case "Error":
359
+ return [
360
+ y({
361
+ messageId: h,
362
+ message: [
363
+ I.HTML,
364
+ {
365
+ body: o.content.message || "Something went wrong."
366
+ }
367
+ ],
368
+ group: r
369
+ })
370
+ ];
371
+ default:
372
+ return [];
373
+ }
374
+ }), s = (o) => ["CategorizedNoticeList", "NoticeList"].includes(o.type) ? (o.content.items || []).reduce((r, l) => (o.content.isInitialNotices && r.push($(K({}, o), {
375
+ id: N(),
376
+ type: l.type || o.type,
377
+ content: {
378
+ $type: o.content.$type,
379
+ isInitialNotices: o.content.isInitialNotices,
380
+ notices: l.notices,
381
+ item: l
382
+ }
383
+ })), r), []) : o, a = /* @__PURE__ */ new Map([
384
+ ["Text", 1],
385
+ ["List", 2],
386
+ ["Contact", 3],
387
+ ["CategorizedNoticeList", 10]
388
+ ]), c = [], d = n.sort((o, r) => {
389
+ var v = a.get(o.type) || 20, L = a.get(r.type) || 20;
390
+ return v - L;
391
+ }).filter((o) => !o.relation).reduce((o, r) => o.concat(s(r)), []), S = (o) => typeof o.actions.selector != "undefined";
392
+ for (const o of d) {
393
+ const r = n.filter(
394
+ (L) => L.relation === o.id && !S(L)
395
+ ), l = G({ isUser: !1 });
396
+ (yield i(o, l, r, t)).forEach((L) => {
397
+ l.items.push(L);
398
+ }), l.items.length && c.push(l);
399
+ }
400
+ return c;
401
+ });
402
+ class nt {
403
+ constructor(t, e, i, s) {
404
+ b(this, "globalState");
405
+ b(this, "localState");
406
+ b(this, "clientId");
407
+ b(this, "entries");
408
+ this.endpoint = t, this.events = e, this.store = i, this.container = s, this.clientId = N(), this.entries = [];
409
+ }
410
+ start(e) {
411
+ return m(this, arguments, function* ({ silent: t }) {
412
+ const i = yield this.store.read("globalState"), s = yield this.store.read("localState"), a = yield this.store.read("entries");
413
+ if (this.globalState = i || this.globalState, this.localState = s || this.localState, this.entries = a || this.entries, t)
414
+ return;
415
+ const c = this.createInitialEnvelope();
416
+ return yield this.postEnvelope(c);
417
+ });
418
+ }
419
+ sendMessage(t) {
420
+ return m(this, null, function* () {
421
+ const e = {
422
+ command: { phrase: t },
423
+ globalState: this.globalState,
424
+ clientId: this.clientId
425
+ };
426
+ return yield this.postEnvelope(e);
427
+ });
428
+ }
429
+ helpAction() {
430
+ return m(this, null, function* () {
431
+ return this.postEnvelope({
432
+ action: {
433
+ key: "help",
434
+ content: {
435
+ $type: "Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"
436
+ }
437
+ },
438
+ globalState: this.globalState,
439
+ clientId: this.clientId
440
+ });
441
+ });
442
+ }
443
+ nextAction(t) {
444
+ return m(this, null, function* () {
445
+ var i;
446
+ const { paging: e } = t.meta;
447
+ if (!!((i = e.actions) != null && i.next))
448
+ return this.postEnvelope(
449
+ {
450
+ action: {
451
+ key: "next",
452
+ content: e.actions.next
453
+ },
454
+ localState: e.localState,
455
+ globalState: this.globalState,
456
+ clientId: this.clientId
457
+ },
458
+ t
459
+ ).then((s) => {
460
+ const a = t.items.findIndex((c) => c.message[0] === "link-list");
461
+ return a === -1 || !s ? t : $(K({}, t), {
462
+ meta: K(K({}, t.meta), s[0].meta),
463
+ items: [
464
+ ...t.items.slice(0, a),
465
+ $(K({}, t.items[a]), {
466
+ message: [
467
+ s[0].items[0].message[0],
468
+ K(K({}, t.items[a].message[1]), s[0].items[0].message[1])
469
+ ]
470
+ }),
471
+ ...t.items.slice(a + 1)
472
+ ]
473
+ });
474
+ });
475
+ });
476
+ }
477
+ showContactMethodAction(t) {
478
+ return m(this, null, function* () {
479
+ const e = this.entries.find((s) => s.id === t.entryId), i = e == null ? void 0 : e.actions[t.actionKey];
480
+ if (!!i)
481
+ return this.postEnvelope({
482
+ action: {
483
+ key: t.actionKey,
484
+ content: i
485
+ },
486
+ localState: e.localState,
487
+ globalState: this.globalState,
488
+ clientId: this.clientId
489
+ });
490
+ });
491
+ }
492
+ defaultAction(t) {
493
+ return m(this, null, function* () {
494
+ const e = this.getEntryOfAction(t);
495
+ if (!!e)
496
+ return this.postEnvelope({
497
+ action: {
498
+ key: t,
499
+ content: e.actions[t]
500
+ },
501
+ localState: e.localState,
502
+ globalState: this.globalState,
503
+ clientId: this.clientId
504
+ });
505
+ });
506
+ }
507
+ createInitialEnvelope() {
508
+ return {
509
+ command: { site: this.endpoint },
510
+ clientId: this.clientId,
511
+ globalState: {},
512
+ funnel: this.container.get("$widget").name
513
+ };
514
+ }
515
+ postEnvelope(t, e) {
516
+ return m(this, null, function* () {
517
+ try {
518
+ const i = yield fetch(this.endpoint, this.getHttpOptions(t));
519
+ if (!i.ok)
520
+ throw i;
521
+ const s = yield i.json();
522
+ return this.handleResponse(s, e);
523
+ } catch (i) {
524
+ process.env.NODE_ENV !== "production" && console.warn("Something went wrong when posting the envelope.");
525
+ let s = "Something went wrong";
526
+ return (i.message === "Failed to fetch" || i.message === "NetworkError when attempting to fetch resource.") && (s = "Lost connection... Please try again."), this.handleResponse({
527
+ entries: [
528
+ {
529
+ id: N(),
530
+ type: "Error",
531
+ timestamp: new Date().toISOString(),
532
+ content: {
533
+ message: s
534
+ },
535
+ actions: {},
536
+ tags: []
537
+ }
538
+ ]
539
+ });
540
+ }
541
+ });
542
+ }
543
+ handleResponse(t, e) {
544
+ return m(this, null, function* () {
545
+ this.entries = this.entries.concat(t.entries), this.store.write(this.entries, "entries");
546
+ const i = t.entries.find((a) => a.type === "Widget");
547
+ return i && this.events.dispatch("provider:widget-entry", i.content), t.globalState && (this.globalState = t.globalState, this.store.write(t.globalState, "globalState")), this.localState = t.entries.reduce((a, c) => c.localState ? c.localState : a, void 0), this.store.write(this.localState, "localState"), yield et(t.entries, e);
548
+ });
549
+ }
550
+ getHttpOptions(t) {
551
+ const e = {
552
+ method: "POST",
553
+ headers: {
554
+ Accept: "application/json",
555
+ "Content-Type": "application/json"
556
+ }
557
+ };
558
+ return t.funnel = this.container.get("$widget").name, t.localState = t.localState || this.localState, Object.assign({}, e, {
559
+ body: JSON.stringify(t),
560
+ credentials: "same-origin"
561
+ });
562
+ }
563
+ getEntryOfAction(t) {
564
+ return this.entries.find((e) => !!e.actions[t]);
565
+ }
566
+ }
567
+ const it = nt;
568
+ class st {
569
+ constructor(t) {
570
+ b(this, "enabled", !0);
571
+ b(this, "botProviderGlobalStateKey", "bot-provider-global-state");
572
+ b(this, "botProviderLocalStateKey", "bot-provider-local-state");
573
+ b(this, "botProviderEntriesKey", "bot-provider-entries");
574
+ b(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
575
+ this.container = t;
576
+ }
577
+ getKey(t) {
578
+ let e;
579
+ switch (t) {
580
+ case "localState":
581
+ e = this.botProviderLocalStateKey;
582
+ break;
583
+ case "globalState":
584
+ e = this.botProviderGlobalStateKey;
585
+ break;
586
+ case "entries":
587
+ e = this.botProviderEntriesKey;
588
+ break;
589
+ case "meta":
590
+ e = this.botProviderMetaStateKey;
591
+ break;
592
+ }
593
+ return e;
594
+ }
595
+ read(t) {
596
+ return m(this, null, function* () {
597
+ const e = this.getKey(t);
598
+ if (!(!this.enabled || !e))
599
+ return J(this.container, e);
600
+ });
601
+ }
602
+ write(t, e) {
603
+ return m(this, null, function* () {
604
+ const i = this.getKey(e);
605
+ if (!this.enabled || !i)
606
+ return;
607
+ (yield F(this.container, i, T.Necessary))(t);
608
+ });
609
+ }
610
+ }
611
+ const ot = st;
612
+ class at {
613
+ constructor(t, e, i) {
614
+ b(this, "agent");
615
+ b(this, "user");
616
+ b(this, "httpClient");
617
+ b(this, "events");
618
+ b(this, "groups", []);
619
+ b(this, "store");
620
+ this.container = t, this.conversation = e;
621
+ const { events: s } = this.container.get("$widget");
622
+ this.events = s, this.store = new ot(t), this.agent = e.createAgent({
623
+ id: "knowledge-bot-agent",
624
+ name: "",
625
+ avatar: void 0
626
+ }), this.user = e.user;
627
+ const a = Z(t, i);
628
+ this.httpClient = new it(a, s, this.store, this.container), this.events.subscribe("provider:widget-entry", (c, d) => {
629
+ this.onWidgetEntryReceived(d);
630
+ }), this.events.subscribe(
631
+ "provider:open-contact-method",
632
+ (c, d) => m(this, null, function* () {
633
+ const S = yield this.httpClient.showContactMethodAction(d);
634
+ S && (d.contactMethod.title && this.printUserMessage(d.contactMethod.title), this.onMessagesReceived(S));
635
+ })
636
+ );
637
+ }
638
+ initialize() {
639
+ return m(this, null, function* () {
640
+ var a;
641
+ const t = this.conversation.loading(), e = yield this.store.read("meta");
642
+ e != null && e.agent && this.agent.update({
643
+ name: e.agent.name,
644
+ avatar: e.agent.avatar
645
+ });
646
+ const i = yield this.conversation.isRehydrated(), s = yield this.httpClient.start({
647
+ silent: ((a = this.conversation.options) == null ? void 0 : a.silent) || i
648
+ });
649
+ s && this.onMessagesReceived(s), t();
650
+ });
651
+ }
652
+ onMessagesReceived(t) {
653
+ return m(this, null, function* () {
654
+ this.groups = this.groups.concat(t), t.forEach((e) => {
655
+ const i = e.items.map((s) => s.message);
656
+ e.isUser ? e.writer = this.user.print(i) : e.writer = this.agent.print(i);
657
+ });
658
+ });
659
+ }
660
+ onInput(t) {
661
+ return m(this, null, function* () {
662
+ const e = typeof t == "string" ? t : t.actionKey;
663
+ switch (e) {
664
+ case "next":
665
+ {
666
+ if (typeof t == "string")
667
+ return;
668
+ const i = this.groups.find((s) => {
669
+ var a;
670
+ return s.id === ((a = t.data) == null ? void 0 : a.groupId);
671
+ });
672
+ if (i) {
673
+ const s = yield this.httpClient.nextAction(i);
674
+ if (s) {
675
+ const a = s.items.map((c) => c.message);
676
+ i.meta.paging = s == null ? void 0 : s.meta.paging, i.writer.update(a);
677
+ }
678
+ }
679
+ }
680
+ break;
681
+ case "help":
682
+ {
683
+ const i = this.conversation.loading(), s = yield this.httpClient.helpAction();
684
+ i(), s && this.onMessagesReceived(s);
685
+ }
686
+ break;
687
+ default:
688
+ {
689
+ typeof t != "string" && t.label && this.printUserMessage(t.label);
690
+ const i = this.conversation.loading(), s = yield this.httpClient.defaultAction(e);
691
+ s && this.onMessagesReceived(s), i();
692
+ }
693
+ break;
694
+ }
695
+ });
696
+ }
697
+ printUserMessage(t) {
698
+ const e = G({
699
+ isUser: !0,
700
+ items: [
701
+ {
702
+ id: N(),
703
+ isUser: !0,
704
+ message: [I.HTML, { body: t }]
705
+ }
706
+ ]
707
+ });
708
+ return this.onMessagesReceived([e]), e;
709
+ }
710
+ onMessageSend(t) {
711
+ return m(this, null, function* () {
712
+ const e = this.conversation.loading(), i = yield this.httpClient.sendMessage(t);
713
+ this.printUserMessage(t), i && this.onMessagesReceived(i), e();
714
+ });
715
+ }
716
+ onWidgetEntryReceived(t) {
717
+ return m(this, null, function* () {
718
+ if (t.agent) {
719
+ const e = {
720
+ name: t.agent.name,
721
+ avatar: t.agent.avatar
722
+ };
723
+ this.agent.update(e), (yield F(
724
+ this.container,
725
+ "bot-provider-conversation-meta",
726
+ T.Necessary
727
+ ))({
728
+ agent: e
729
+ });
730
+ }
731
+ });
732
+ }
733
+ }
734
+ const rt = at, ct = (n) => m(void 0, null, function* () {
735
+ const t = yield D.getInstance(n);
736
+ B(
737
+ n,
738
+ f.ContactList,
739
+ import("./contact-method-list.70f5e518.js")
740
+ ), B(
741
+ n,
742
+ f.ContactMethod,
743
+ import("./contact-method.4b049dad.js")
744
+ ), B(
745
+ n,
746
+ f.NotificationList,
747
+ import("./notification-list.c3df3ee1.js")
748
+ ), B(
749
+ n,
750
+ f.NoGoodAlternative,
751
+ import("./no-good-alternative.e5e48f22.js")
752
+ ), B(
753
+ n,
754
+ f.FeedbackList,
755
+ import("./feedback-list.73d8aa69.js")
756
+ ), t.registerProvider("ace-knowledge-bot", (e, i) => {
757
+ const s = new rt(n, e, i);
758
+ s.initialize();
759
+ const a = [];
760
+ return a.push(
761
+ i.actions.watch("conversation.user-submit", (c, d) => {
762
+ s.onMessageSend(c.text);
763
+ })
764
+ ), a.push(
765
+ i.actions.watch("conversation.action", (c, d) => (s.onInput(c), d(c)))
766
+ ), a.push(
767
+ i.actions.create("evaluate", (c) => {
768
+ const { events: d } = n.get("$widget");
769
+ d.dispatch("bot-provider:evaluate", c);
770
+ })
771
+ ), a.push(
772
+ i.actions.create("submit", (c) => {
773
+ const { events: d } = n.get("$widget");
774
+ d.dispatch("bot-provider:form-submitted", c);
775
+ })
776
+ ), () => {
777
+ a.forEach((c) => {
778
+ c();
779
+ });
780
+ };
781
+ });
782
+ }), mt = ct;
783
+ export {
784
+ mt as K,
785
+ tt as u
786
+ };
787
+ //# sourceMappingURL=index.a7a0d62d.js.map