@telia-ace/knowledge-widget-bot-provider 0.0.1-next.2 → 0.0.1-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{contact-method-list.d45b8f36.js → contact-method-list.4ee58573.js} +3 -3
- package/dist/{contact-method-list.d45b8f36.js.map → contact-method-list.4ee58573.js.map} +1 -1
- package/dist/contact-method.37f0020e.js +120 -0
- package/dist/contact-method.37f0020e.js.map +1 -0
- package/dist/http-client.d.ts +3 -1
- package/dist/index.e647892d.js +785 -0
- package/dist/index.e647892d.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/store.d.ts +16 -6
- package/dist/types.d.ts +1 -2
- package/package.json +5 -5
- package/dist/contact-method.fb45a5e2.js +0 -119
- package/dist/contact-method.fb45a5e2.js.map +0 -1
- package/dist/index.76a36f22.js +0 -767
- package/dist/index.76a36f22.js.map +0 -1
package/dist/index.76a36f22.js
DELETED
|
@@ -1,767 +0,0 @@
|
|
|
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
|