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