@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.62 → 0.0.1-alpha.63

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 (58) 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/dist/index.js +6 -669
  12. package/dist/index.js.map +1 -1
  13. package/dist/no-good-alternative.45aa0387.js +41 -0
  14. package/dist/no-good-alternative.45aa0387.js.map +1 -0
  15. package/dist/notification-list.cae1df51.js +62 -0
  16. package/dist/notification-list.cae1df51.js.map +1 -0
  17. package/dist/provider.d.ts +25 -0
  18. package/dist/store.d.ts +15 -0
  19. package/dist/styles.6c010dfc.js +15 -0
  20. package/dist/styles.6c010dfc.js.map +1 -0
  21. package/dist/types.d.ts +79 -0
  22. package/dist/ui/contact-method-list.d.ts +10 -0
  23. package/dist/ui/contact-method.d.ts +9 -0
  24. package/dist/ui/feedback-list.d.ts +8 -0
  25. package/dist/ui/no-good-alternative.d.ts +6 -0
  26. package/dist/ui/notification-list.d.ts +11 -0
  27. package/dist/ui/styles.d.ts +1 -0
  28. package/dist/utils.d.ts +26 -0
  29. package/package.json +11 -14
  30. package/dist/client/chat.client.d.ts +0 -16
  31. package/dist/client/contact-method.client.d.ts +0 -25
  32. package/dist/client/http.client.d.ts +0 -23
  33. package/dist/client/middleware.client.d.ts +0 -14
  34. package/dist/contact-method.15886c3d.js +0 -66
  35. package/dist/contact-method.15886c3d.js.map +0 -1
  36. package/dist/contract/custom-component/contact-method-item.d.ts +0 -8
  37. package/dist/contract/custom-component/contact-method-list.d.ts +0 -7
  38. package/dist/contract/custom-component/contact-method.d.ts +0 -3
  39. package/dist/contract/enum/server-entry-type.enum.d.ts +0 -7
  40. package/dist/contract/model/conversation-api-model/list.model.d.ts +0 -5
  41. package/dist/contract/model/conversation-api-model/message.model.d.ts +0 -7
  42. package/dist/contract/model/http/action.model.d.ts +0 -3
  43. package/dist/contract/model/http/client-action.model.d.ts +0 -4
  44. package/dist/contract/model/http/client-envelope.model.d.ts +0 -9
  45. package/dist/contract/model/http/connect-options.model.d.ts +0 -5
  46. package/dist/contract/model/http/global-state.model.d.ts +0 -8
  47. package/dist/contract/model/http/http-client-options.model.d.ts +0 -5
  48. package/dist/contract/model/http/server-entry.model.d.ts +0 -11
  49. package/dist/contract/model/http/server-envelope.model.d.ts +0 -10
  50. package/dist/contract/model/middleware/aggregator-state.model.d.ts +0 -4
  51. package/dist/contract/model/shared/loose-object.model.d.ts +0 -3
  52. package/dist/helper/chat.helper.d.ts +0 -8
  53. package/dist/helper/http.helper.d.ts +0 -13
  54. package/dist/helper/middleware.helper.d.ts +0 -12
  55. package/dist/helper/store.helper.d.ts +0 -22
  56. package/dist/interface/entry.interface.d.ts +0 -20
  57. package/dist/interface/middleware/paging.interface.d.ts +0 -4
  58. package/dist/interface/middleware/processor.interface.d.ts +0 -10
package/dist/index.js CHANGED
@@ -1,672 +1,9 @@
1
- var D = Object.defineProperty, G = Object.defineProperties;
2
- var B = Object.getOwnPropertyDescriptors;
3
- var H = Object.getOwnPropertySymbols;
4
- var W = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable;
5
- var P = (s, t, e) => t in s ? D(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, b = (s, t) => {
6
- for (var e in t || (t = {}))
7
- W.call(t, e) && P(s, e, t[e]);
8
- if (H)
9
- for (var e of H(t))
10
- z.call(t, e) && P(s, e, t[e]);
11
- return s;
12
- }, x = (s, t) => G(s, B(t));
13
- var p = (s, t, e) => new Promise((i, n) => {
14
- var a = (o) => {
15
- try {
16
- c(e.next(o));
17
- } catch (A) {
18
- n(A);
19
- }
20
- }, r = (o) => {
21
- try {
22
- c(e.throw(o));
23
- } catch (A) {
24
- n(A);
25
- }
26
- }, c = (o) => o.done ? i(o.value) : Promise.resolve(o.value).then(a, r);
27
- c((e = e.apply(s, t)).next());
28
- });
29
- import { ContactMethodPlatform as N } from "@telia-ace/knowledge-widget-adapters";
30
- import { DataType as m, DataClient as $ } from "@telia-ace/knowledge-widget-types-grid";
31
- import { ConversationMessageListItemType as u, ConversationPlatform as R, registerCustomMessageComponent as V } from "@telia-ace/widget-conversation";
32
- import { v4 as E } from "uuid";
33
- import { createStorageWriter as _, StorageCategory as q, readStorage as J } from "@telia-ace/widget-services";
34
- import { FormBuilder as Q, submitButton as X } from "@telia-ace/widget-forms";
35
- var f = /* @__PURE__ */ ((s) => (s[s.Widget = 0] = "Widget", s[s.Text = 1] = "Text", s[s.Contact = 2] = "Contact", s[s.List = 3] = "List", s[s.Error = 4] = "Error", s))(f || {});
36
- class w {
37
- static setUser(t) {
38
- this.user = t;
39
- }
40
- static setAgent(t) {
41
- this.agent = t;
42
- }
43
- static getUser() {
44
- return this.user;
45
- }
46
- static getAgent() {
47
- return this.agent;
48
- }
49
- }
50
- const I = class {
51
- static setContainer(s) {
52
- I.container = s;
53
- }
54
- static setWidget(s) {
55
- this.widget = s;
56
- }
57
- static getContainer() {
58
- return this.container;
59
- }
60
- static getWidget() {
61
- return this.widget;
62
- }
63
- static getEntrySessionStorage() {
64
- return J(this.container, this.sessionMessageStorageVariable);
65
- }
66
- };
67
- let S = I;
68
- S.sessionMessageStorageVariable = "conversation-plugin-messages";
69
- S.setEntrySessionStorage = (s) => p(void 0, null, function* () {
70
- _(I.container, I.sessionMessageStorageVariable, q.Necessary).then((t) => t(s));
71
- });
72
- const v = class {
73
- constructor() {
74
- v.globalState = {
75
- completedInteractionsCount: 0,
76
- lastBotGuide: 0,
77
- site: "https://localhost:8080/",
78
- invincibleParameters: {}
79
- };
80
- }
81
- static insertOrUpdateMessageArrayStore(s, t) {
82
- s.filter((e) => !!e).forEach((e) => {
83
- this.messageStore.find((i) => i.id == e.id) ? this.updateMessageInStore(e, t) : this.insertMessageToStore(e);
84
- }), S.setEntrySessionStorage(this.messageStore);
85
- }
86
- static insertMessageToStore(s) {
87
- this.messageStore.push(s);
88
- }
89
- static updateMessageInStore(s, t) {
90
- s.conversationEntry = t;
91
- let e = this.messageStore.findIndex((i) => i.id == s.id);
92
- this.messageStore[e] = s;
93
- }
94
- static checkIdInMessageStore(s) {
95
- return this.messageStore.find((t) => t.id == s) === void 0;
96
- }
97
- static getLocalState(s) {
98
- const t = this.getEntry(s);
99
- return t == null ? void 0 : t.localState;
100
- }
101
- static getGlobalState() {
102
- return v.globalState;
103
- }
104
- static setGlobalState(s) {
105
- v.globalState = s;
106
- }
107
- static getAction(s) {
108
- const t = this.getEntry(s);
109
- return {
110
- key: s,
111
- content: t == null ? void 0 : t.actions[s]
112
- };
113
- }
114
- static getCommand(s) {
115
- return { phrase: s };
116
- }
117
- static getEntry(s) {
118
- let t;
119
- return this.getEntryStore().forEach((e) => {
120
- e.actions[s] && (t = e);
121
- }), t;
122
- }
123
- static getMessage(s) {
124
- return this.messageStore.find((t) => t.id == s);
125
- }
126
- static getEntryStore() {
127
- return this.messageStore.filter((s) => !!s.entry).map((s) => s.entry);
128
- }
129
- };
130
- let d = v;
131
- d.messageStore = [];
132
- class F {
133
- constructor(t) {
134
- this.container = t, this.helpActionKey = "help", this.nextActionKey = "next";
135
- }
136
- transform(t) {
137
- return p(this, null, function* () {
138
- switch (f[t.type]) {
139
- case f.List:
140
- return {
141
- id: t.id,
142
- message: this.listTransform(t),
143
- entry: t,
144
- isUser: !1
145
- };
146
- case f.Text:
147
- return {
148
- id: t.id,
149
- message: this.textTransform(t),
150
- entry: t,
151
- isUser: !1
152
- };
153
- case f.Text:
154
- return {
155
- id: t.id,
156
- message: this.listTransform(t),
157
- entry: t,
158
- isUser: !1
159
- };
160
- case f.Contact:
161
- return {
162
- id: t.id,
163
- message: yield this.transformContactMethod(t),
164
- entry: t,
165
- isUser: !1
166
- };
167
- }
168
- });
169
- }
170
- transformContactMethod(t) {
171
- return p(this, null, function* () {
172
- const e = yield this.container.getAsync("dataClient"), i = [], n = yield e.fetch(m.ContactMethod, {
173
- contactMethodId: t.content.id
174
- });
175
- return n && (n.expanded = !0, i.push(n)), {
176
- type: "ace-knowledge-contact-method",
177
- contactMethods: i
178
- };
179
- });
180
- }
181
- transformArray(t) {
182
- return p(this, null, function* () {
183
- let e = [];
184
- for (const i of t) {
185
- let n = yield this.transform(i);
186
- n && e.push(n);
187
- }
188
- return e;
189
- });
190
- }
191
- getUserMessage(t) {
192
- let e = d.getEntry(t);
193
- return this.getTitleFromEntry(e, t);
194
- }
195
- listTransform(t) {
196
- return t.type === "Contact" || !t.content ? void 0 : this.getListActions(t.content.items, this.getContentText(t), t.actions, t.localState);
197
- }
198
- getContentText(t) {
199
- if (t.content.html)
200
- return { body: t.content.html };
201
- if (t.content.header)
202
- return { title: t.content.header };
203
- }
204
- textTransform(t) {
205
- return t.content.items ? this.listTransform(t) : [
206
- u.HTML,
207
- { body: t.content.html.replace(`
208
- `, "") }
209
- ];
210
- }
211
- getListActions(t, e, i, n) {
212
- let a = [], r = {}, c = [this.getListType(n), { actions: r }];
213
- return e && e.title && a.push([u.Header, e.title]), e && e.body && a.push([u.HTML, { body: e.body }]), a.push(c), t.forEach((o) => {
214
- switch (o.actionKey) {
215
- case this.helpActionKey: {
216
- a.push([u.Separator, void 0]), a.push([
217
- u.NoGoodAlternative,
218
- { body: o.title }
219
- ]);
220
- break;
221
- }
222
- case this.nextActionKey: {
223
- !!i.next && i.next.take === t.length + 1 && (r[o.actionKey] = o.title);
224
- break;
225
- }
226
- default:
227
- r[o.actionKey] = o.title;
228
- }
229
- }), a;
230
- }
231
- getListType(t) {
232
- return (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching" ? u.LinkList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching" ? u.FeedbackList : u.ButtonList;
233
- }
234
- getTitleFromEntry(t, e) {
235
- if (t)
236
- switch (f[t.type]) {
237
- case f.List:
238
- return this.getTitleFromList(t, e);
239
- case f.Text:
240
- return this.textTransform(t);
241
- }
242
- }
243
- getTitleFromList(t, e) {
244
- return t.content.items.find((i) => i.actionKey == e).title;
245
- }
246
- }
247
- class y {
248
- constructor(t) {
249
- this.entryInterface = new F(t);
250
- }
251
- static initialize(t, e) {
252
- w.setUser(t), w.setAgent(e);
253
- }
254
- processMessageArrayAndStoreIt(t) {
255
- t.filter((e) => e && e != null).forEach((e) => {
256
- e.isUser ? this.postUserMessage(e) : this.postAgentMessage(e);
257
- }), d.insertOrUpdateMessageArrayStore(t);
258
- }
259
- updateMessageArrayAndStoreIt(t) {
260
- let e;
261
- t.forEach((i) => {
262
- let n = d.getMessage(i.id);
263
- n == null || n.conversationEntry.update(i.message), e = n == null ? void 0 : n.conversationEntry;
264
- }), d.insertOrUpdateMessageArrayStore(t, e);
265
- }
266
- printUserMessageAndStoreIt(t) {
267
- if (t == "next" || t == "help")
268
- return;
269
- let e = d.getEntry(t), i = {
270
- id: E(),
271
- message: e ? this.getTitleFromEntry(e, t) : t,
272
- isUser: !0
273
- };
274
- this.postUserMessage(i), d.insertOrUpdateMessageArrayStore([i]);
275
- }
276
- postUserMessage(t) {
277
- w.getUser().print(t.message);
278
- }
279
- postAgentMessage(t) {
280
- t.conversationEntry = w.getAgent().print(t.message);
281
- }
282
- getTitleFromEntry(t, e) {
283
- switch (f[t.type]) {
284
- case f.List:
285
- return this.getTitleFromList(t, e);
286
- case f.Text:
287
- return this.getTitleFromText(t, e);
288
- default:
289
- return "";
290
- }
291
- }
292
- getTitleFromText(t, e) {
293
- return t.content.items ? this.getTitleFromList(t, e) : t.content.html;
294
- }
295
- getTitleFromList(t, e) {
296
- return t.content.items.find((i) => i.actionKey == e).title;
297
- }
298
- }
299
- const h = class {
300
- constructor(s) {
301
- this.handleNewForm = (t, e) => p(this, null, function* () {
302
- this.updateForm(e.contactMethods, {
303
- submit: "Submit",
304
- errors: t
305
- }), e.entry.update({
306
- contactMethods: e.contactMethods,
307
- type: "ace-knowledge-contact-method",
308
- noPadding: !0
309
- });
310
- }), this.handleContactMethod = (t = "") => p(this, null, function* () {
311
- var e;
312
- if (t == "contact")
313
- yield this.handleContactCategoryList(t);
314
- else {
315
- let i = yield this.loadContactMethods(t.split("/")[1], t.split("/")[0]);
316
- (e = i.body) != null && e.form ? this.handleForm(t, i) : !i.expanded && i.inline ? this.handleSingleContactMethod(i) : i.contactMethods && this.handleContactMethodList(t, i);
317
- }
318
- }), this.handleContactCategoryList = (t) => p(this, null, function* () {
319
- let e = E(), i = m.ContactMethodCategories, n = yield this.loadContactMethods(i);
320
- this.chatClient.printUserMessageAndStoreIt(t), this.printMessage(e, n);
321
- }), this.updateForm = (t, e) => {
322
- var i;
323
- if ((i = t == null ? void 0 : t.body) != null && i.form) {
324
- const { body: n } = t, a = new Q(n.form);
325
- return (!n.form.layout || !n.form.layout.submit) && a.createComponent(X(e.submit, "submit")), e.errors && a.setValidationErrors(e.errors), x(b({}, n), {
326
- form: a.get()
327
- });
328
- }
329
- return (t == null ? void 0 : t.body) || {};
330
- }, this.chatClient = new y(s);
331
- }
332
- static initialize(s, t, e, i) {
333
- this.dataClient = t, this.contactMethodPlatform = e, this.agent = i, this.container = s;
334
- }
335
- validate(s) {
336
- let t = h.contactMessageEntryArray.find((e) => e.id == s.schema.id);
337
- h.contactMethodPlatform.validate(t.contactMethods).then((e) => {
338
- this.handleNewForm(e.errors, t), e.valid && (this.submit(t), this.removeForm(t));
339
- });
340
- }
341
- handleForm(s, t) {
342
- let e = s.split("/")[2];
343
- t.expanded = !0, this.updateForm(t, {
344
- submit: "Submit",
345
- errors: void 0
346
- }), this.printMessage(t.id, t, e);
347
- }
348
- handleContactMethodList(s, t) {
349
- let e = s.split("/")[2], i = E();
350
- this.printMessage(i, t, e);
351
- }
352
- handleSingleContactMethod(s) {
353
- let t = h.contactMessageEntryArray.find((n) => n.contactMethods.contactMethods.find((a) => a.id == s.id)), e = t.contactMethods.contactMethods.find((n) => n.id == s.id);
354
- e.expanded = !0;
355
- let i = {
356
- contactMethods: t.contactMethods,
357
- type: "ace-knowledge-contact-method",
358
- noPadding: !0
359
- };
360
- d.insertOrUpdateMessageArrayStore([
361
- {
362
- id: t.id,
363
- message: i,
364
- isUser: !1
365
- }
366
- ]), t.entry.update(i);
367
- }
368
- submit(s) {
369
- h.contactMethodPlatform.submit(s.contactMethods).then((t) => {
370
- t && h.agent.print(t);
371
- });
372
- }
373
- removeForm(s) {
374
- s.entry.remove(), h.contactMessageEntryArray.splice(h.contactMessageEntryArray.indexOf(s), 1);
375
- }
376
- printMessage(s, t, e = void 0) {
377
- if (h.contactMessageEntryArray.find((i) => i.id == t.id)) {
378
- let i = h.contactMessageEntryArray.find((a) => a.id == t.id), n = {
379
- contactMethods: t,
380
- type: "ace-knowledge-contact-method",
381
- noPadding: !0
382
- };
383
- i.entry.update(n), d.insertOrUpdateMessageArrayStore([
384
- {
385
- id: i.guid,
386
- message: n,
387
- isUser: !1
388
- }
389
- ]);
390
- } else {
391
- e && this.chatClient.printUserMessageAndStoreIt(e);
392
- let i = {
393
- contactMethods: t,
394
- type: "ace-knowledge-contact-method",
395
- noPadding: !0
396
- }, n = h.agent.print(i);
397
- d.insertOrUpdateMessageArrayStore([
398
- {
399
- id: s,
400
- message: i,
401
- isUser: !1
402
- }
403
- ]), h.contactMessageEntryArray.push({
404
- id: s,
405
- contactMethods: t,
406
- entry: n
407
- });
408
- }
409
- }
410
- loadContactMethods(s, t = void 0) {
411
- switch (s) {
412
- case m.ContactMethodCategories:
413
- return h.container.getAsync("matchingClient").then((e) => e.customRequest("/contactmethods", "GET", {})).then((e) => e);
414
- case m.ContactMethods:
415
- return t ? h.dataClient.fetch(m.ContactMethod, { contactMethodId: t }).then((e) => e) : h.dataClient.fetch(m.ContactMethods, {}).then((e) => e);
416
- case m.ContactMethodCategories:
417
- return h.dataClient.fetch(m.ContactMethods, { contactMethodCategoryId: t }).then((e) => e);
418
- default:
419
- return Promise.resolve(void 0);
420
- }
421
- }
422
- };
423
- let C = h;
424
- C.contactMessageEntryArray = [];
425
- const k = class {
426
- static combineUrl(s, t) {
427
- return s + t;
428
- }
429
- static getCredentials() {
430
- return "same-origin";
431
- }
432
- };
433
- let M = k;
434
- M.fetchOptions = {
435
- method: "POST",
436
- headers: {
437
- Accept: "application/json",
438
- "Content-Type": "application/json"
439
- }
440
- };
441
- M.managedSubdomainSuffixes = ["stage", "alpha", "beta", "gamma"];
442
- M.parseSubdomain = (s) => {
443
- const t = s.lastIndexOf("-"), e = s.substr(t + 1);
444
- return k.managedSubdomainSuffixes.indexOf(e) > -1 ? s.substr(0, t) : s;
445
- };
446
- class Y {
447
- process(t) {
448
- const e = t.find((i) => i.tags.indexOf("paging") > -1);
449
- if (e) {
450
- const i = d.getEntryStore().filter((n) => n.tags.indexOf("paging") > -1 && n.id === e.id);
451
- if (i.length > 0) {
452
- const n = i.reduce((a, r) => r.actions.next && r.actions.next.take >= a.actions.next.take ? r : a, i[0]);
453
- n.actions.next.take > e.actions.next.take && t.forEach((a) => {
454
- a.id === e.id && (a.actions.next = x(b({}, a.actions.next), {
455
- take: n.actions.next.take,
456
- skip: n.actions.next.skip
457
- }));
458
- });
459
- }
460
- t.forEach((n) => {
461
- n.id === e.id && n.content && n.content.timestamp && (n.content = x(b({}, n.content), {
462
- items: n.content && n.content.items || []
463
- }));
464
- });
465
- }
466
- return t;
467
- }
468
- }
469
- class Z {
470
- process(t) {
471
- let e = t;
472
- return e = this.deletePaging(e), e = this.delete(e), e = this.merge(e), e = this.moveLoader(e), e;
473
- }
474
- processUpdate(t, e) {
475
- e.filter((n) => n.type == "List").forEach((n) => {
476
- var a;
477
- (a = n.content) == null || a.items.forEach((r) => {
478
- t != null && t.content.items.find((c) => c.actionKey == r.actionKey) || t == null || t.content.items.push(r);
479
- }), Object.keys(n.actions).forEach((r) => {
480
- this.handleActionUpdateOrInsert(t == null ? void 0 : t.actions, r, n.actions);
481
- });
482
- });
483
- var i = t == null ? void 0 : t.content.items;
484
- return i.find((n) => n.actionKey == "next") && i.push(i.splice(i.indexOf(i.find((n) => n.actionKey == "next")), 1)[0]), i.find((n) => n.actionKey == "help") && i.push(i.splice(i.indexOf(i.find((n) => n.actionKey == "help")), 1)[0]), t ? [t] : [];
485
- }
486
- handleActionUpdateOrInsert(t, e, i) {
487
- t && (t[e] = i[e]);
488
- }
489
- deletePaging(t) {
490
- return t.filter((e) => !(e.type === "List" && e.tags && e.tags.indexOf("paging") > -1 && typeof e.content == "undefined"));
491
- }
492
- delete(t) {
493
- return t.filter((e) => e.content !== null);
494
- }
495
- merge(t) {
496
- const e = [], i = (a, r = {}) => {
497
- const c = {};
498
- return a == null ? null : (r && Object.keys(r).forEach((o) => {
499
- c[o] = r[o];
500
- }), Object.keys(a).forEach((o) => {
501
- o == "items" ? (c[o] || (c[o] = []), c[o] = c[o].concat(a[o])) : o == "html" ? c[o] = c[o] + a[o] : c[o] = a[o];
502
- }), c);
503
- }, n = (a, r) => a == null ? null : Object.keys(a.actions).length === 0 ? r.localState : Object.keys(r.actions).length === 0 ? a.localState : r.localState;
504
- return t.forEach((a) => {
505
- if (a.relation) {
506
- let r = t.find((c) => c.id == a.relation);
507
- if (r) {
508
- const c = e.indexOf(r);
509
- r.localState = n(a, r), r.content = i(a.content, r.content), r.actions = i(a.actions, r.actions), e[c] = r;
510
- }
511
- } else
512
- e.push(a);
513
- }), e;
514
- }
515
- moveLoader(t) {
516
- const e = t.find((n) => n.id === "loader");
517
- if (!e)
518
- return t;
519
- const i = t.indexOf(e);
520
- return i > -1 && t.splice(t.length - 1, 0, t.splice(i, 1)[0]), t;
521
- }
522
- }
523
- class T {
524
- constructor(t) {
525
- this.paging = new Y(), this.processor = new Z(), this.entryInterface = new F(t), this.chatClient = new y(t);
526
- }
527
- static initialize(t, e) {
528
- S.setContainer(t), S.setWidget(e);
529
- }
530
- handleEntries(t, e) {
531
- return p(this, null, function* () {
532
- const i = (t || []).find((r) => r.type === "Widget");
533
- if (i) {
534
- const r = w.getAgent();
535
- r && r.update({
536
- name: i.content.agent.name,
537
- avatar: i.content.agent.avatar
538
- });
539
- }
540
- let n = this.executeMiddlewares(t, !1, e), a = yield this.entryInterface.transformArray(n);
541
- this.chatClient.processMessageArrayAndStoreIt(a);
542
- });
543
- }
544
- handleUpdate(t, e) {
545
- return p(this, null, function* () {
546
- let i = this.executeMiddlewares(t, !0, e), n = yield this.entryInterface.transformArray(i);
547
- this.chatClient.updateMessageArrayAndStoreIt(n);
548
- });
549
- }
550
- checkForUpdate(t) {
551
- return t === "next";
552
- }
553
- executeMiddlewares(t, e, i) {
554
- return e && i ? t = this.processor.processUpdate(d.getEntry(i), t) : t = this.processor.process(t), t = this.paging.process(t), t;
555
- }
556
- }
557
- class U {
558
- constructor(t, e, i) {
559
- this.options = {
560
- credentials: M.getCredentials(),
561
- clientId: e
562
- }, this.apiEndpoint = t, this.projectionPath = window.location.href, this.endpointUrl = M.combineUrl(this.projectionPath, "conversations"), this.clientId = this.options.clientId, this.middlewareClient = new T(i), this.chatClient = new y(i);
563
- }
564
- firstHit() {
565
- S.getEntrySessionStorage().then((t) => {
566
- if (t && t.length > 0)
567
- this.chatClient.processMessageArrayAndStoreIt(t);
568
- else {
569
- let e = this.constructFirstHitEnvelope();
570
- this.postAndHandleTheData(e);
571
- }
572
- });
573
- }
574
- handleUpdate(t) {
575
- let e = this.constructInputEnvelope(t);
576
- this.postAndHandleTheUpdateData(e, t);
577
- }
578
- handleInput(t) {
579
- let e = this.constructInputEnvelope(t);
580
- this.postAndHandleTheData(e, t);
581
- }
582
- handlePhrase(t) {
583
- let e = this.constructPhraseEnvelope(t);
584
- this.postAndHandleTheData(e);
585
- }
586
- postAndHandleTheData(t, e) {
587
- return fetch(this.apiEndpoint, this.getHttpOptions(t)).then((i) => {
588
- if (i.ok)
589
- return i.json();
590
- throw i;
591
- }).then((i) => {
592
- this.handleResponseData(i, e);
593
- }).catch((i) => console.log(i));
594
- }
595
- postAndHandleTheUpdateData(t, e) {
596
- return fetch(this.apiEndpoint, this.getHttpOptions(t)).then((i) => {
597
- if (i.ok)
598
- return i.json();
599
- throw i;
600
- }).then((i) => {
601
- this.handleUpdateResponseData(i, e);
602
- }).catch((i) => console.log(i));
603
- }
604
- getHttpOptions(t) {
605
- return Object.assign({}, M.fetchOptions, {
606
- body: JSON.stringify(t),
607
- credentials: this.options.credentials
608
- });
609
- }
610
- constructInputEnvelope(t) {
611
- return {
612
- action: d.getAction(t),
613
- localState: d.getLocalState(t),
614
- globalState: d.getGlobalState(),
615
- clientId: this.clientId
616
- };
617
- }
618
- constructPhraseEnvelope(t) {
619
- return {
620
- command: { phrase: t },
621
- globalState: d.getGlobalState(),
622
- clientId: this.clientId
623
- };
624
- }
625
- constructFirstHitEnvelope() {
626
- return {
627
- command: { site: this.endpointUrl },
628
- clientId: this.clientId,
629
- globalState: {}
630
- };
631
- }
632
- handleResponseData(t, e) {
633
- d.setGlobalState(t.globalState), this.middlewareClient.handleEntries(t.entries, e);
634
- }
635
- handleUpdateResponseData(t, e) {
636
- this.middlewareClient.handleUpdate(t.entries, e);
637
- }
638
- }
639
- const tt = (s, t) => {
640
- const { knowledgeBotEndpoint: e } = t.properties();
641
- if (e)
642
- return `${e}/conversations`;
643
- const { data: i } = s.get("$settings");
644
- if (!i || !i.projection)
645
- throw new Error("Missing Knowledge Bot endpoint");
646
- return `${i.projection}/conversations`;
647
- }, ct = (s) => p(void 0, null, function* () {
648
- const t = yield $.getInstance(s), e = yield R.getInstance(s), i = yield N.getInstance(s);
649
- V(s, "ace-knowledge-contact-method", import("./contact-method.15886c3d.js")), e.registerProvider("chat.bot", (n, a) => {
650
- const r = tt(s, a), c = E(), o = n.createAgent({
651
- name: "",
652
- avatar: void 0
653
- });
654
- y.initialize(n.user, o), C.initialize(s, t, i, o), T.initialize(s, s.get("$widget")), new U(r, c, s).firstHit(), a.actions.create("evaluate", (l) => {
655
- new C(s).handleNewForm(l.form, l.form.id);
656
- }), a.actions.create("validate", (l) => {
657
- new C(s).validate(l.form);
658
- }), a.actions.create("submit", (l) => {
659
- new C(s).validate(l.form);
660
- }), a.actions.watch("conversation.user-typing", (l, g) => g(l)), a.actions.watch("conversation.user-submit", (l, g) => (new U(r, c, s).handlePhrase(l.text), g(l))), a.actions.watch("conversation.form", (l, g) => g(l)), a.actions.watch("conversation.action", (l, g) => {
661
- let L = new y(s), K = new C(s);
662
- if (l.split("/").length > 1)
663
- return K.handleContactMethod(l), g(l);
664
- let j = new T(s), O = new U(r, c, s);
665
- return j.checkForUpdate(l) ? (O.handleUpdate(l), g(l)) : (L.printUserMessageAndStoreIt(l), O.handleInput(l), g(l));
666
- });
667
- });
668
- });
1
+ import { K as n } from "./index.76a36f22.js";
2
+ import "@telia-ace/widget-conversation";
3
+ import "@telia-ace/widget-services";
4
+ import "@telia-ace/widget-utilities";
5
+ import "@telia-ace/widget-forms";
669
6
  export {
670
- ct as ConversationPlugin
7
+ n as ConversationPlugin
671
8
  };
672
9
  //# sourceMappingURL=index.js.map