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