@telia-ace/knowledge-widget-bot-provider 0.0.1-next.2 → 0.0.1-next.4

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.
@@ -0,0 +1,785 @@
1
+ var V = Object.defineProperty, j = Object.defineProperties;
2
+ var z = Object.getOwnPropertyDescriptors;
3
+ var $ = Object.getOwnPropertySymbols;
4
+ var W = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable;
5
+ var B = (i, t, e) => t in i ? V(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, K = (i, t) => {
6
+ for (var e in t || (t = {}))
7
+ W.call(t, e) && B(i, e, t[e]);
8
+ if ($)
9
+ for (var e of $(t))
10
+ _.call(t, e) && B(i, e, t[e]);
11
+ return i;
12
+ }, A = (i, t) => j(i, z(t));
13
+ var b = (i, t, e) => (B(i, typeof t != "symbol" ? t + "" : t, e), e);
14
+ var m = (i, t, e) => new Promise((n, 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 ? n(S.value) : Promise.resolve(S.value).then(a, c);
28
+ d((e = e.apply(i, t)).next());
29
+ });
30
+ import { ConversationMessageListItemType as I, ConversationPlatform as D, registerCustomMessageComponent as O } 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 R, submitButton as q } from "@telia-ace/widget-forms";
34
+ 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 || {});
35
+ const Q = (i) => {
36
+ if (i) {
37
+ const { type: t, content: e } = i;
38
+ if (t && e)
39
+ return { type: t, content: e };
40
+ }
41
+ }, G = ({
42
+ isUser: i,
43
+ items: t = [],
44
+ meta: e = {}
45
+ }) => {
46
+ const n = N();
47
+ return {
48
+ id: n,
49
+ isUser: i,
50
+ items: t.map((a) => ({
51
+ id: a.id || N(),
52
+ isUser: i,
53
+ groupId: n,
54
+ message: a.message || []
55
+ })),
56
+ meta: e
57
+ };
58
+ }, X = ({
59
+ id: i,
60
+ title: t,
61
+ defaultIcon: e,
62
+ exits: [n],
63
+ exitType: s,
64
+ confirmationText: a,
65
+ expandFormAutomatically: c,
66
+ form: d,
67
+ description: S
68
+ }, o = {}) => {
69
+ const { adapter: r } = n || { Adapter: {} }, { clientName: l = "", settings: v = {}, customClientName: L = "" } = r, { validation: w } = o, p = {
70
+ id: i.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 = R.fromLegacyForm(i.toString(), d, w).get() : p.body.form = R.fromLegacyForm(i.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 = (i) => (i == null ? void 0 : i.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching" ? I.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 : I.ButtonList, Z = (i, t) => {
85
+ const { knowledgeBotEndpoint: e } = t.properties();
86
+ if (e)
87
+ return `${e}/conversations`;
88
+ const { data: n } = i.get("$settings");
89
+ if (!n || !n.projection)
90
+ throw new Error("Missing Knowledge Bot endpoint");
91
+ return `${n.projection}/conversations`;
92
+ }, tt = (i, {
93
+ submit: t,
94
+ errors: e,
95
+ meta: n
96
+ }) => {
97
+ var s;
98
+ if ((s = i == null ? void 0 : i.body) != null && s.form) {
99
+ const { body: a } = i, c = new R(a.form);
100
+ return a.form.layout.submit || c.createComponent(q(t, "submit")), e && c.setValidationErrors(e), n && c.setMeta(n), A(K({}, a), {
101
+ form: c.get()
102
+ });
103
+ }
104
+ return (i == null ? void 0 : i.body) || {};
105
+ }, y = ({
106
+ messageId: i,
107
+ message: t,
108
+ group: e
109
+ }) => ({
110
+ id: i,
111
+ message: t,
112
+ groupId: e.id,
113
+ isUser: e.isUser
114
+ }), et = (i, 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
+ }, n = (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")), P = 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
+ })), P) {
163
+ const M = P.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(A(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 = i.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 = i.filter(
394
+ (L) => L.relation === o.id && !S(L)
395
+ ), l = G({ isUser: !1 });
396
+ (yield n(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 it {
403
+ constructor(t, e, n, 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 = n, this.container = s, this.clientId = N(), this.entries = [];
409
+ }
410
+ start(e) {
411
+ return m(this, arguments, function* ({ silent: t }) {
412
+ const n = yield this.store.read("globalState"), s = yield this.store.read("localState"), a = yield this.store.read("entries");
413
+ if (this.globalState = n || 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 n;
446
+ const { paging: e } = t.meta;
447
+ if (!!((n = e.actions) != null && n.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 : A(K({}, t), {
462
+ meta: K(K({}, t.meta), s[0].meta),
463
+ items: [
464
+ ...t.items.slice(0, a),
465
+ A(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), n = e == null ? void 0 : e.actions[t.actionKey];
480
+ if (!!n)
481
+ return this.postEnvelope({
482
+ action: {
483
+ key: t.actionKey,
484
+ content: n
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 n = yield fetch(this.endpoint, this.getHttpOptions(t));
519
+ if (!n.ok)
520
+ throw n;
521
+ const s = yield n.json();
522
+ return this.handleResponse(s, e);
523
+ } catch (n) {
524
+ process.env.NODE_ENV !== "production" && console.warn("Something went wrong when posting the envelope.");
525
+ let s = "Something went wrong";
526
+ return (n.message === "Failed to fetch" || n.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 n = t.entries.find((a) => a.type === "Widget");
547
+ 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 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
+ class nt {
568
+ constructor(t) {
569
+ b(this, "enabled", !0);
570
+ b(this, "botProviderGlobalStateKey", "bot-provider-global-state");
571
+ b(this, "botProviderLocalStateKey", "bot-provider-local-state");
572
+ b(this, "botProviderEntriesKey", "bot-provider-entries");
573
+ b(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
574
+ this.container = t;
575
+ }
576
+ getKey(t) {
577
+ let e;
578
+ switch (t) {
579
+ case "localState":
580
+ e = this.botProviderLocalStateKey;
581
+ break;
582
+ case "globalState":
583
+ e = this.botProviderGlobalStateKey;
584
+ break;
585
+ case "entries":
586
+ e = this.botProviderEntriesKey;
587
+ break;
588
+ case "meta":
589
+ e = this.botProviderMetaStateKey;
590
+ break;
591
+ }
592
+ return e;
593
+ }
594
+ read(t) {
595
+ return m(this, null, function* () {
596
+ const e = this.getKey(t);
597
+ if (!(!this.enabled || !e))
598
+ return J(this.container, e);
599
+ });
600
+ }
601
+ write(t, e) {
602
+ return m(this, null, function* () {
603
+ const n = this.getKey(e);
604
+ if (!this.enabled || !n)
605
+ return;
606
+ (yield F(this.container, n, T.Necessary))(t);
607
+ });
608
+ }
609
+ }
610
+ class st {
611
+ constructor(t, e, n) {
612
+ b(this, "agent");
613
+ b(this, "user");
614
+ b(this, "httpClient");
615
+ b(this, "events");
616
+ b(this, "groups", []);
617
+ b(this, "store");
618
+ this.container = t, this.conversation = e;
619
+ const { events: s } = this.container.get("$widget");
620
+ this.events = s, this.store = new nt(t), this.agent = e.createAgent({
621
+ id: "knowledge-bot-agent",
622
+ name: "",
623
+ avatar: void 0
624
+ }), this.user = e.user;
625
+ const a = Z(t, n);
626
+ this.httpClient = new it(a, s, this.store, this.container), this.events.subscribe("provider:widget-entry", (c, d) => {
627
+ this.onWidgetEntryReceived(d);
628
+ }), this.events.subscribe(
629
+ "provider:open-contact-method",
630
+ (c, d) => m(this, null, function* () {
631
+ const S = yield this.httpClient.showContactMethodAction(d);
632
+ S && (d.contactMethod.title && this.printUserMessage(d.contactMethod.title), this.onMessagesReceived(S));
633
+ })
634
+ );
635
+ }
636
+ initialize() {
637
+ return m(this, null, function* () {
638
+ var a;
639
+ const t = this.conversation.loading(), e = yield this.store.read("meta");
640
+ e != null && e.agent && this.agent.update({
641
+ name: e.agent.name,
642
+ avatar: e.agent.avatar
643
+ });
644
+ const n = yield this.conversation.isRehydrated(), s = yield this.httpClient.start({
645
+ silent: ((a = this.conversation.options) == null ? void 0 : a.silent) || n
646
+ });
647
+ s && this.onMessagesReceived(s), t();
648
+ });
649
+ }
650
+ onMessagesReceived(t) {
651
+ return m(this, null, function* () {
652
+ this.groups = this.groups.concat(t), t.forEach((e) => {
653
+ const n = e.items.map((s) => s.message);
654
+ e.isUser ? e.writer = this.user.print(n) : e.writer = this.agent.print(n);
655
+ });
656
+ });
657
+ }
658
+ onInput(t) {
659
+ return m(this, null, function* () {
660
+ const e = typeof t == "string" ? t : t.actionKey;
661
+ switch (e) {
662
+ case "next":
663
+ {
664
+ if (typeof t == "string")
665
+ return;
666
+ const n = this.groups.find((s) => {
667
+ var a;
668
+ return s.id === ((a = t.data) == null ? void 0 : a.groupId);
669
+ });
670
+ if (n) {
671
+ const s = yield this.httpClient.nextAction(n);
672
+ if (s) {
673
+ const a = s.items.map((c) => c.message);
674
+ n.meta.paging = s == null ? void 0 : s.meta.paging, n.writer.update(a);
675
+ }
676
+ }
677
+ }
678
+ break;
679
+ case "help":
680
+ {
681
+ const n = this.conversation.loading(), s = yield this.httpClient.helpAction();
682
+ n(), s && this.onMessagesReceived(s);
683
+ }
684
+ break;
685
+ default:
686
+ {
687
+ typeof t != "string" && t.label && this.printUserMessage(t.label);
688
+ const n = this.conversation.loading(), s = yield this.httpClient.defaultAction(e);
689
+ s && this.onMessagesReceived(s), n();
690
+ }
691
+ break;
692
+ }
693
+ });
694
+ }
695
+ printUserMessage(t) {
696
+ const e = G({
697
+ isUser: !0,
698
+ items: [
699
+ {
700
+ id: N(),
701
+ isUser: !0,
702
+ message: [I.HTML, { body: t }]
703
+ }
704
+ ]
705
+ });
706
+ return this.onMessagesReceived([e]), e;
707
+ }
708
+ onMessageSend(t) {
709
+ return m(this, null, function* () {
710
+ const e = this.conversation.loading(), n = yield this.httpClient.sendMessage(t);
711
+ this.printUserMessage(t), n && this.onMessagesReceived(n), e();
712
+ });
713
+ }
714
+ onWidgetEntryReceived(t) {
715
+ return m(this, null, function* () {
716
+ if (t.agent) {
717
+ const e = {
718
+ name: t.agent.name,
719
+ avatar: t.agent.avatar
720
+ };
721
+ this.agent.update(e), (yield F(
722
+ this.container,
723
+ "bot-provider-conversation-meta",
724
+ T.Necessary
725
+ ))({
726
+ agent: e
727
+ });
728
+ }
729
+ });
730
+ }
731
+ }
732
+ const dt = (i) => m(void 0, null, function* () {
733
+ const t = yield D.getInstance(i);
734
+ O(
735
+ i,
736
+ f.ContactList,
737
+ import("./contact-method-list.4ee58573.js")
738
+ ), O(
739
+ i,
740
+ f.ContactMethod,
741
+ import("./contact-method.37f0020e.js")
742
+ ), O(
743
+ i,
744
+ f.NotificationList,
745
+ import("./notification-list.cae1df51.js")
746
+ ), O(
747
+ i,
748
+ f.NoGoodAlternative,
749
+ import("./no-good-alternative.45aa0387.js")
750
+ ), O(
751
+ i,
752
+ f.FeedbackList,
753
+ import("./feedback-list.29c075b4.js")
754
+ ), t.registerProvider("ace-knowledge-bot", (e, n) => {
755
+ const s = new st(i, e, n);
756
+ s.initialize();
757
+ const a = [];
758
+ return a.push(
759
+ n.actions.watch("conversation.user-submit", (c, d) => {
760
+ s.onMessageSend(c.text);
761
+ })
762
+ ), a.push(
763
+ n.actions.watch("conversation.action", (c, d) => (s.onInput(c), d(c)))
764
+ ), a.push(
765
+ n.actions.create("evaluate", (c) => {
766
+ const { events: d } = i.get("$widget");
767
+ d.dispatch("bot-provider:evaluate", c);
768
+ })
769
+ ), a.push(
770
+ n.actions.create("submit", (c) => {
771
+ const { events: d } = i.get("$widget");
772
+ d.dispatch("bot-provider:form-submitted", c);
773
+ })
774
+ ), () => {
775
+ a.forEach((c) => {
776
+ c();
777
+ });
778
+ };
779
+ });
780
+ });
781
+ export {
782
+ dt as K,
783
+ tt as u
784
+ };
785
+ //# sourceMappingURL=index.e647892d.js.map