@telia-ace/knowledge-widget-bot-provider 0.0.19 → 0.0.20-next.0

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