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