@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.50 → 0.0.1-alpha.53
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.js +111 -0
- package/dist/contact-method-list.js.map +1 -0
- package/dist/contact-method.js +119 -77
- package/dist/contact-method.js.map +1 -1
- package/dist/entry-handler.d.ts +2 -0
- package/dist/feedback-list.js +20 -55
- package/dist/feedback-list.js.map +1 -1
- package/dist/http-client.d.ts +42 -0
- package/dist/index.js +5 -1173
- package/dist/index.js.map +1 -1
- package/dist/index2.js +914 -0
- package/dist/index2.js.map +1 -0
- package/dist/no-good-alternative.js +20 -7
- package/dist/no-good-alternative.js.map +1 -1
- package/dist/notification-list.js +74 -0
- package/dist/notification-list.js.map +1 -0
- package/dist/provider.d.ts +25 -0
- package/dist/store.d.ts +15 -0
- package/dist/styles.js +13 -0
- package/dist/styles.js.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/ui/contact-method-list.d.ts +10 -0
- package/dist/ui/contact-method.d.ts +9 -0
- package/dist/ui/feedback-list.d.ts +1 -1
- package/dist/ui/notification-list.d.ts +11 -0
- package/dist/ui/styles.d.ts +1 -0
- package/dist/utils.d.ts +26 -2
- package/package.json +10 -10
- package/dist/client/chat.client.d.ts +0 -13
- package/dist/client/contact-method.client.d.ts +0 -35
- package/dist/client/http.client.d.ts +0 -26
- package/dist/client/middleware.client.d.ts +0 -14
- package/dist/contract/custom-component/contact-method-item.d.ts +0 -11
- package/dist/contract/custom-component/contact-method-list.d.ts +0 -8
- package/dist/contract/custom-component/contact-method.d.ts +0 -3
- package/dist/contract/custom-component/entry-context.d.ts +0 -5
- package/dist/contract/enum/server-entry-type.enum.d.ts +0 -7
- package/dist/contract/model/conversation-api-model/list.model.d.ts +0 -5
- package/dist/contract/model/conversation-api-model/message.model.d.ts +0 -7
- package/dist/contract/model/http/action.model.d.ts +0 -3
- package/dist/contract/model/http/client-action.model.d.ts +0 -4
- package/dist/contract/model/http/client-envelope.model.d.ts +0 -9
- package/dist/contract/model/http/connect-options.model.d.ts +0 -5
- package/dist/contract/model/http/global-state.model.d.ts +0 -8
- package/dist/contract/model/http/http-client-options.model.d.ts +0 -5
- package/dist/contract/model/http/server-entry.model.d.ts +0 -11
- package/dist/contract/model/http/server-envelope.model.d.ts +0 -10
- package/dist/contract/model/middleware/aggregator-state.model.d.ts +0 -4
- package/dist/contract/model/shared/loose-object.model.d.ts +0 -3
- package/dist/helper/chat.helper.d.ts +0 -8
- package/dist/helper/http.helper.d.ts +0 -13
- package/dist/helper/middleware.helper.d.ts +0 -12
- package/dist/helper/store.helper.d.ts +0 -23
- package/dist/interface/entry.interface.d.ts +0 -23
- package/dist/interface/middleware/paging.interface.d.ts +0 -4
- package/dist/interface/middleware/processor.interface.d.ts +0 -10
package/dist/index.js
CHANGED
|
@@ -1,1174 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
import { ContactMethodPlatform } from "@telia-ace/knowledge-widget-adapters";
|
|
41
|
-
import { DataType, DataClient } from "@telia-ace/knowledge-widget-types-grid";
|
|
42
|
-
import { ConversationMessageListItemType, ConversationPlatform } from "@telia-ace/widget-conversation";
|
|
43
|
-
import { v4 } from "uuid";
|
|
44
|
-
import { createStorageWriter, StorageCategory, readStorage } from "@telia-ace/widget-services";
|
|
45
|
-
import { FormBuilder, submitButton } from "@telia-ace/widget-forms";
|
|
46
|
-
var ServerEntryTypeEnum = /* @__PURE__ */ ((ServerEntryTypeEnum2) => {
|
|
47
|
-
ServerEntryTypeEnum2[ServerEntryTypeEnum2["Widget"] = 0] = "Widget";
|
|
48
|
-
ServerEntryTypeEnum2[ServerEntryTypeEnum2["Text"] = 1] = "Text";
|
|
49
|
-
ServerEntryTypeEnum2[ServerEntryTypeEnum2["Contact"] = 2] = "Contact";
|
|
50
|
-
ServerEntryTypeEnum2[ServerEntryTypeEnum2["List"] = 3] = "List";
|
|
51
|
-
ServerEntryTypeEnum2[ServerEntryTypeEnum2["Error"] = 4] = "Error";
|
|
52
|
-
return ServerEntryTypeEnum2;
|
|
53
|
-
})(ServerEntryTypeEnum || {});
|
|
54
|
-
class ChatHelper {
|
|
55
|
-
static setUser(user) {
|
|
56
|
-
this.user = user;
|
|
57
|
-
}
|
|
58
|
-
static setAgent(agent) {
|
|
59
|
-
this.agent = agent;
|
|
60
|
-
}
|
|
61
|
-
static getUser() {
|
|
62
|
-
return this.user;
|
|
63
|
-
}
|
|
64
|
-
static getAgent() {
|
|
65
|
-
return this.agent;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const _MiddlewareHelper = class {
|
|
69
|
-
static setContainer(container) {
|
|
70
|
-
_MiddlewareHelper.container = container;
|
|
71
|
-
}
|
|
72
|
-
static setWidget(widget) {
|
|
73
|
-
this.widget = widget;
|
|
74
|
-
}
|
|
75
|
-
static getContainer() {
|
|
76
|
-
return this.container;
|
|
77
|
-
}
|
|
78
|
-
static getWidget() {
|
|
79
|
-
return this.widget;
|
|
80
|
-
}
|
|
81
|
-
static getEntrySessionStorage() {
|
|
82
|
-
return readStorage(this.container, this.sessionMessageStorageVariable);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
let MiddlewareHelper = _MiddlewareHelper;
|
|
86
|
-
MiddlewareHelper.sessionMessageStorageVariable = "conversation-plugin-messages";
|
|
87
|
-
MiddlewareHelper.setEntrySessionStorage = (messages) => __async(this, null, function* () {
|
|
88
|
-
return createStorageWriter(_MiddlewareHelper.container, _MiddlewareHelper.sessionMessageStorageVariable, StorageCategory.Necessary).then((write) => {
|
|
89
|
-
return write(messages);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
const botProviderGlobalStateSessionKey = "bot-provider-global-state";
|
|
93
|
-
const _StoreHelper = class {
|
|
94
|
-
constructor() {
|
|
95
|
-
_StoreHelper.globalState = {
|
|
96
|
-
completedInteractionsCount: 0,
|
|
97
|
-
lastBotGuide: 0,
|
|
98
|
-
site: "",
|
|
99
|
-
invincibleParameters: {}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
static insertOrUpdateMessageArrayStore(messageArray, entry) {
|
|
103
|
-
return __async(this, null, function* () {
|
|
104
|
-
for (const message of messageArray.filter((o) => !!o)) {
|
|
105
|
-
if (!this.messageStore.find((o) => o.id == message.id)) {
|
|
106
|
-
this.insertMessageToStore(message);
|
|
107
|
-
} else {
|
|
108
|
-
this.updateMessageInStore(message, entry);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
yield MiddlewareHelper.setEntrySessionStorage(this.messageStore);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
static insertMessageToStore(message) {
|
|
115
|
-
this.messageStore.push(message);
|
|
116
|
-
}
|
|
117
|
-
static updateMessageInStore(message, entry) {
|
|
118
|
-
message.conversationEntry = entry;
|
|
119
|
-
let index = this.messageStore.findIndex((o) => o.id == message.id);
|
|
120
|
-
this.messageStore[index] = message;
|
|
121
|
-
}
|
|
122
|
-
static checkIdInMessageStore(id) {
|
|
123
|
-
return this.messageStore.find((o) => o.id == id) === void 0;
|
|
124
|
-
}
|
|
125
|
-
static getLocalState(action) {
|
|
126
|
-
const entry = this.getEntry(action);
|
|
127
|
-
return entry == null ? void 0 : entry.localState;
|
|
128
|
-
}
|
|
129
|
-
static getGlobalState() {
|
|
130
|
-
return _StoreHelper.globalState;
|
|
131
|
-
}
|
|
132
|
-
static setGlobalState(state) {
|
|
133
|
-
_StoreHelper.globalState = state;
|
|
134
|
-
return createStorageWriter(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey, StorageCategory.Necessary).then((write) => {
|
|
135
|
-
return write(state);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
static getAction(action) {
|
|
139
|
-
const entry = this.getEntry(action);
|
|
140
|
-
return {
|
|
141
|
-
key: action,
|
|
142
|
-
content: entry == null ? void 0 : entry.actions[action]
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
static getCommand(text) {
|
|
146
|
-
return { phrase: text };
|
|
147
|
-
}
|
|
148
|
-
static getEntry(action) {
|
|
149
|
-
let entry = void 0;
|
|
150
|
-
this.getEntryStore().forEach((o) => {
|
|
151
|
-
if (o.actions[action]) {
|
|
152
|
-
entry = o;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
return entry;
|
|
156
|
-
}
|
|
157
|
-
static getMessage(id) {
|
|
158
|
-
return this.messageStore.find((o) => o.id == id);
|
|
159
|
-
}
|
|
160
|
-
static getEntryStore() {
|
|
161
|
-
return this.messageStore.filter((o) => !!o.entry).map((o) => {
|
|
162
|
-
return o.entry;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
static rehydrateState() {
|
|
166
|
-
return __async(this, null, function* () {
|
|
167
|
-
const state = yield readStorage(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey);
|
|
168
|
-
if (state) {
|
|
169
|
-
this.setGlobalState(state);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
let StoreHelper = _StoreHelper;
|
|
175
|
-
StoreHelper.messageStore = [];
|
|
176
|
-
class ChatClient {
|
|
177
|
-
constructor() {
|
|
178
|
-
}
|
|
179
|
-
static initialize(user, agent) {
|
|
180
|
-
ChatHelper.setUser(user);
|
|
181
|
-
ChatHelper.setAgent(agent);
|
|
182
|
-
}
|
|
183
|
-
processMessageArrayAndStoreIt(messages) {
|
|
184
|
-
return __async(this, null, function* () {
|
|
185
|
-
for (const message of messages.filter((o) => o && o != null && !!o.message)) {
|
|
186
|
-
if (message.isUser)
|
|
187
|
-
this.postUserMessage(message);
|
|
188
|
-
else
|
|
189
|
-
this.postAgentMessage(message);
|
|
190
|
-
}
|
|
191
|
-
yield StoreHelper.insertOrUpdateMessageArrayStore(messages);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
updateMessageArrayAndStoreIt(messages) {
|
|
195
|
-
let conversationEntry = void 0;
|
|
196
|
-
messages.forEach((o) => {
|
|
197
|
-
let message = StoreHelper.getMessage(o.id);
|
|
198
|
-
message == null ? void 0 : message.conversationEntry.update(o.message);
|
|
199
|
-
conversationEntry = message == null ? void 0 : message.conversationEntry;
|
|
200
|
-
});
|
|
201
|
-
StoreHelper.insertOrUpdateMessageArrayStore(messages, conversationEntry);
|
|
202
|
-
}
|
|
203
|
-
printUserMessageAndStoreIt(action) {
|
|
204
|
-
if (action == "next" || action == "help")
|
|
205
|
-
return;
|
|
206
|
-
let entry = StoreHelper.getEntry(action);
|
|
207
|
-
let message = {
|
|
208
|
-
id: v4(),
|
|
209
|
-
message: !entry ? action : this.getTitleFromEntry(entry, action),
|
|
210
|
-
isUser: true
|
|
211
|
-
};
|
|
212
|
-
this.postUserMessage(message);
|
|
213
|
-
StoreHelper.insertOrUpdateMessageArrayStore([message]);
|
|
214
|
-
}
|
|
215
|
-
postUserMessage(message) {
|
|
216
|
-
ChatHelper.getUser().print(message.message);
|
|
217
|
-
}
|
|
218
|
-
postAgentMessage(message) {
|
|
219
|
-
message.conversationEntry = ChatHelper.getAgent().print(message.message);
|
|
220
|
-
}
|
|
221
|
-
getTitleFromEntry(entry, action) {
|
|
222
|
-
const entryType = ServerEntryTypeEnum[entry.type];
|
|
223
|
-
switch (entryType) {
|
|
224
|
-
case ServerEntryTypeEnum.List:
|
|
225
|
-
return this.getTitleFromList(entry, action);
|
|
226
|
-
case ServerEntryTypeEnum.Text:
|
|
227
|
-
return this.getTitleFromText(entry, action);
|
|
228
|
-
default:
|
|
229
|
-
return "";
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
getTitleFromText(entry, action) {
|
|
233
|
-
if (!!entry.content.items)
|
|
234
|
-
return this.getTitleFromList(entry, action);
|
|
235
|
-
else
|
|
236
|
-
return entry.content.html;
|
|
237
|
-
}
|
|
238
|
-
getTitleFromList(entry, action) {
|
|
239
|
-
return entry.content.items.find((o) => o.actionKey == action).title;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const _ContactMethodClient = class {
|
|
243
|
-
constructor(container) {
|
|
244
|
-
this.handleNewForm = (errors, entry) => __async(this, null, function* () {
|
|
245
|
-
this.updateForm(entry.contactMethods, {
|
|
246
|
-
submit: "Submit",
|
|
247
|
-
errors
|
|
248
|
-
});
|
|
249
|
-
entry.entry.update({
|
|
250
|
-
contactMethods: entry.contactMethods,
|
|
251
|
-
type: "ace-knowledge-contact-method",
|
|
252
|
-
noPadding: true
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
this.handleContactMethod = (input = "") => __async(this, null, function* () {
|
|
256
|
-
var _a;
|
|
257
|
-
if (input == "contact") {
|
|
258
|
-
yield this.handleContactCategoryList(input);
|
|
259
|
-
} else {
|
|
260
|
-
let contactMethods = yield this.loadContactMethods(input.split("/")[1], input.split("/")[0]);
|
|
261
|
-
if (!!((_a = contactMethods.body) == null ? void 0 : _a.form)) {
|
|
262
|
-
this.handleForm(input, contactMethods);
|
|
263
|
-
} else if (!contactMethods.expanded && contactMethods.inline) {
|
|
264
|
-
this.handleSingleContactMethod(contactMethods);
|
|
265
|
-
} else if (!!contactMethods.contactMethods) {
|
|
266
|
-
this.handleContactMethodList(input, contactMethods);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
this.handleContactCategoryList = (input) => __async(this, null, function* () {
|
|
271
|
-
let newGuid = v4();
|
|
272
|
-
let type = DataType.ContactMethodCategories;
|
|
273
|
-
let contactMethods = yield this.loadContactMethods(type);
|
|
274
|
-
this.chatClient.printUserMessageAndStoreIt(input);
|
|
275
|
-
this.printMessage(newGuid, contactMethods);
|
|
276
|
-
});
|
|
277
|
-
this.updateForm = (contactMethod, properties) => {
|
|
278
|
-
var _a;
|
|
279
|
-
if ((_a = contactMethod == null ? void 0 : contactMethod.body) == null ? void 0 : _a.form) {
|
|
280
|
-
const { body } = contactMethod;
|
|
281
|
-
const builder = new FormBuilder(body.form);
|
|
282
|
-
if (!body.form.layout || !body.form.layout.submit) {
|
|
283
|
-
builder.createComponent(submitButton(properties.submit, "submit"));
|
|
284
|
-
}
|
|
285
|
-
if (properties.errors) {
|
|
286
|
-
builder.setValidationErrors(properties.errors);
|
|
287
|
-
}
|
|
288
|
-
return __spreadProps(__spreadValues({}, body), {
|
|
289
|
-
form: builder.get()
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
return (contactMethod == null ? void 0 : contactMethod.body) || {};
|
|
293
|
-
};
|
|
294
|
-
this.chatClient = new ChatClient();
|
|
295
|
-
}
|
|
296
|
-
static initialize(container, dataClient, contactMethodPlatform, agent) {
|
|
297
|
-
this.dataClient = dataClient;
|
|
298
|
-
this.contactMethodPlatform = contactMethodPlatform;
|
|
299
|
-
this.agent = agent;
|
|
300
|
-
this.container = container;
|
|
301
|
-
}
|
|
302
|
-
validate(form) {
|
|
303
|
-
let entry = _ContactMethodClient.contactMessageEntryArray.find((o) => o.id == form.schema.id);
|
|
304
|
-
_ContactMethodClient.contactMethodPlatform.validate(entry.contactMethods).then((result) => {
|
|
305
|
-
this.handleNewForm(result.errors, entry);
|
|
306
|
-
if (result.valid) {
|
|
307
|
-
this.submit(entry);
|
|
308
|
-
this.removeForm(entry);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
handleForm(input, contactMethods) {
|
|
313
|
-
let title = input.split("/")[2];
|
|
314
|
-
contactMethods.expanded = true;
|
|
315
|
-
this.updateForm(contactMethods, {
|
|
316
|
-
submit: "Submit",
|
|
317
|
-
errors: void 0
|
|
318
|
-
});
|
|
319
|
-
this.printMessage(contactMethods.id, contactMethods, title);
|
|
320
|
-
}
|
|
321
|
-
addContactMethod(contactMethod) {
|
|
322
|
-
contactMethod.expanded = true;
|
|
323
|
-
this.updateForm(contactMethod, {
|
|
324
|
-
submit: "Submit",
|
|
325
|
-
errors: void 0
|
|
326
|
-
});
|
|
327
|
-
return this.printMessage(contactMethod.id, contactMethod);
|
|
328
|
-
}
|
|
329
|
-
expandContactMethod(input) {
|
|
330
|
-
const message = StoreHelper.getMessage(input.entryId);
|
|
331
|
-
if ((message == null ? void 0 : message.conversationEntry) && Array.isArray(message.message)) {
|
|
332
|
-
const messageItemIndex = message.message.findIndex(([listType]) => listType === "ace-knowledge-contact-method");
|
|
333
|
-
if (messageItemIndex > -1) {
|
|
334
|
-
const [messageItemType, messageItemContent] = message.message[messageItemIndex];
|
|
335
|
-
const updatedMessageItemContent = __spreadProps(__spreadValues({}, messageItemContent), {
|
|
336
|
-
contactMethods: this.getNewContactMethods(messageItemContent.contactMethods)
|
|
337
|
-
});
|
|
338
|
-
const updatedMessageItems = [
|
|
339
|
-
...message.message.slice(0, messageItemIndex),
|
|
340
|
-
[messageItemType, updatedMessageItemContent],
|
|
341
|
-
...message.message.slice(messageItemIndex + 1)
|
|
342
|
-
];
|
|
343
|
-
message.conversationEntry.writer({ items: updatedMessageItems });
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
getNewContactMethods(contactMethods) {
|
|
348
|
-
if (Array.isArray(contactMethods)) {
|
|
349
|
-
return contactMethods.map((cm) => {
|
|
350
|
-
cm.expanded = true;
|
|
351
|
-
return cm;
|
|
352
|
-
});
|
|
353
|
-
} else {
|
|
354
|
-
contactMethods.expanded = true;
|
|
355
|
-
return contactMethods;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
handleContactMethodList(input, contactMethods) {
|
|
359
|
-
let title = input.split("/")[2];
|
|
360
|
-
let newGuid = v4();
|
|
361
|
-
this.printMessage(newGuid, contactMethods, title);
|
|
362
|
-
}
|
|
363
|
-
handleSingleContactMethod(contactMethods) {
|
|
364
|
-
let entry = _ContactMethodClient.contactMessageEntryArray.find((o) => o.contactMethods.contactMethods.find((t) => t.id == contactMethods.id));
|
|
365
|
-
let curCM = entry.contactMethods.contactMethods.find((t) => t.id == contactMethods.id);
|
|
366
|
-
curCM.expanded = true;
|
|
367
|
-
let message = {
|
|
368
|
-
contactMethods: entry.contactMethods,
|
|
369
|
-
type: "ace-knowledge-contact-method",
|
|
370
|
-
noPadding: true
|
|
371
|
-
};
|
|
372
|
-
StoreHelper.insertOrUpdateMessageArrayStore([
|
|
373
|
-
{
|
|
374
|
-
id: entry.id,
|
|
375
|
-
message,
|
|
376
|
-
isUser: false
|
|
377
|
-
}
|
|
378
|
-
]);
|
|
379
|
-
entry.entry.update(message);
|
|
380
|
-
}
|
|
381
|
-
submit(entry) {
|
|
382
|
-
_ContactMethodClient.contactMethodPlatform.submit(entry.contactMethods).then((result) => {
|
|
383
|
-
if (!!result)
|
|
384
|
-
_ContactMethodClient.agent.print(result);
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
removeForm(entry) {
|
|
388
|
-
entry.entry.remove();
|
|
389
|
-
_ContactMethodClient.contactMessageEntryArray.splice(_ContactMethodClient.contactMessageEntryArray.indexOf(entry), 1);
|
|
390
|
-
}
|
|
391
|
-
printMessage(newGuid, contactMethods, title = void 0) {
|
|
392
|
-
if (_ContactMethodClient.contactMessageEntryArray.find((o) => o.id == contactMethods.id)) {
|
|
393
|
-
let entry = _ContactMethodClient.contactMessageEntryArray.find((o) => o.id == contactMethods.id);
|
|
394
|
-
let message = {
|
|
395
|
-
contactMethods,
|
|
396
|
-
type: "ace-knowledge-contact-method",
|
|
397
|
-
noPadding: true
|
|
398
|
-
};
|
|
399
|
-
entry.entry.update(message);
|
|
400
|
-
StoreHelper.insertOrUpdateMessageArrayStore([
|
|
401
|
-
{
|
|
402
|
-
id: entry.guid,
|
|
403
|
-
message,
|
|
404
|
-
isUser: false
|
|
405
|
-
}
|
|
406
|
-
]);
|
|
407
|
-
return message;
|
|
408
|
-
} else {
|
|
409
|
-
if (title)
|
|
410
|
-
this.chatClient.printUserMessageAndStoreIt(title);
|
|
411
|
-
let message = {
|
|
412
|
-
contactMethods,
|
|
413
|
-
type: "ace-knowledge-contact-method",
|
|
414
|
-
noPadding: true
|
|
415
|
-
};
|
|
416
|
-
let entry = _ContactMethodClient.agent.print(message);
|
|
417
|
-
StoreHelper.insertOrUpdateMessageArrayStore([
|
|
418
|
-
{
|
|
419
|
-
id: newGuid,
|
|
420
|
-
message,
|
|
421
|
-
isUser: false
|
|
422
|
-
}
|
|
423
|
-
]);
|
|
424
|
-
_ContactMethodClient.contactMessageEntryArray.push({
|
|
425
|
-
id: newGuid,
|
|
426
|
-
contactMethods,
|
|
427
|
-
entry
|
|
428
|
-
});
|
|
429
|
-
return message;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
loadContactMethods(dataType, id = void 0, guideId = void 0) {
|
|
433
|
-
switch (dataType) {
|
|
434
|
-
case DataType.ContactMethodCategories: {
|
|
435
|
-
return _ContactMethodClient.container.getAsync("matchingClient").then((matchingClient) => {
|
|
436
|
-
return matchingClient.customRequest("/contactmethods", "GET", {});
|
|
437
|
-
}).then((contactMethods) => {
|
|
438
|
-
return contactMethods;
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
case DataType.ContactMethods: {
|
|
442
|
-
if (!!id && !!guideId) {
|
|
443
|
-
return _ContactMethodClient.dataClient.fetch(DataType.ContactMethod, { contactMethodId: id, guideId }).then((contactMethods) => contactMethods);
|
|
444
|
-
} else if (!!id) {
|
|
445
|
-
return _ContactMethodClient.dataClient.fetch(DataType.ContactMethod, { contactMethodId: id }).then((contactMethods) => contactMethods);
|
|
446
|
-
} else {
|
|
447
|
-
return _ContactMethodClient.dataClient.fetch(DataType.ContactMethods, {}).then((contactMethods) => contactMethods);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
case DataType.ContactMethodCategories: {
|
|
451
|
-
return _ContactMethodClient.dataClient.fetch(DataType.ContactMethods, { contactMethodCategoryId: id }).then((contactMethods) => contactMethods);
|
|
452
|
-
}
|
|
453
|
-
default: {
|
|
454
|
-
return Promise.resolve(void 0);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
let ContactMethodClient = _ContactMethodClient;
|
|
460
|
-
ContactMethodClient.contactMessageEntryArray = [];
|
|
461
|
-
const _HttpHelper = class {
|
|
462
|
-
static combineUrl(basePath, path) {
|
|
463
|
-
return basePath + path;
|
|
464
|
-
}
|
|
465
|
-
static getCredentials() {
|
|
466
|
-
return "same-origin";
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
let HttpHelper = _HttpHelper;
|
|
470
|
-
HttpHelper.fetchOptions = {
|
|
471
|
-
method: "POST",
|
|
472
|
-
headers: {
|
|
473
|
-
Accept: "application/json",
|
|
474
|
-
"Content-Type": "application/json"
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
HttpHelper.managedSubdomainSuffixes = ["stage", "alpha", "beta", "gamma"];
|
|
478
|
-
HttpHelper.parseSubdomain = (input) => {
|
|
479
|
-
const index = input.lastIndexOf("-");
|
|
480
|
-
const lastPart = input.substr(index + 1);
|
|
481
|
-
if (_HttpHelper.managedSubdomainSuffixes.indexOf(lastPart) > -1) {
|
|
482
|
-
return input.substr(0, index);
|
|
483
|
-
}
|
|
484
|
-
return input;
|
|
485
|
-
};
|
|
486
|
-
const getContactMethodEntry = (contactMethodId) => {
|
|
487
|
-
const entries = StoreHelper.getEntryStore();
|
|
488
|
-
return entries.find((e) => e.content.id === +contactMethodId);
|
|
489
|
-
};
|
|
490
|
-
const convertLegacySymbol = (symbol) => {
|
|
491
|
-
if (symbol) {
|
|
492
|
-
const { type, content } = symbol;
|
|
493
|
-
if (type && content) {
|
|
494
|
-
return { type, content };
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
const contactMethodFromLegacy = ({
|
|
499
|
-
id,
|
|
500
|
-
title,
|
|
501
|
-
defaultIcon,
|
|
502
|
-
exits: [exit],
|
|
503
|
-
exitType,
|
|
504
|
-
confirmationText,
|
|
505
|
-
expandFormAutomatically,
|
|
506
|
-
form,
|
|
507
|
-
description
|
|
508
|
-
}, validation) => {
|
|
509
|
-
const { adapter } = exit || { Adapter: {} };
|
|
510
|
-
const { clientName = "", settings: adapterSettings = {}, customClientName = "" } = adapter;
|
|
511
|
-
const settings = {
|
|
512
|
-
id: id.toString(),
|
|
513
|
-
title,
|
|
514
|
-
description,
|
|
515
|
-
symbol: convertLegacySymbol(defaultIcon),
|
|
516
|
-
clientName: clientName === "custom.adapter" ? customClientName : clientName,
|
|
517
|
-
expanded: true,
|
|
518
|
-
inline: true,
|
|
519
|
-
body: {}
|
|
520
|
-
};
|
|
521
|
-
if (clientName.indexOf("phone") > -1 || clientName.indexOf("freetext") > -1) {
|
|
522
|
-
const { displayTextBeforeClick, textBeforeClick } = adapterSettings;
|
|
523
|
-
if (displayTextBeforeClick === "true") {
|
|
524
|
-
settings.expanded = false;
|
|
525
|
-
settings.title = textBeforeClick;
|
|
526
|
-
}
|
|
527
|
-
if (clientName.indexOf("phone.text") > -1) {
|
|
528
|
-
settings.body.phoneNumber = adapterSettings.phoneNumber;
|
|
529
|
-
} else {
|
|
530
|
-
settings.body.freetext = adapterSettings.freetext;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
if (clientName.indexOf("chat.popup") > -1 || clientName.indexOf("link") > -1 || clientName === "custom.adapter" && exitType === "custom") {
|
|
534
|
-
settings.body = adapterSettings;
|
|
535
|
-
settings.body.confirmationFallback = confirmationText;
|
|
536
|
-
}
|
|
537
|
-
if (clientName.indexOf("ace") > -1) {
|
|
538
|
-
settings.body = adapterSettings;
|
|
539
|
-
}
|
|
540
|
-
if (form && form.hasValueComponents) {
|
|
541
|
-
if (validation) {
|
|
542
|
-
settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form, validation).get();
|
|
543
|
-
} else {
|
|
544
|
-
settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form).get();
|
|
545
|
-
}
|
|
546
|
-
if (!expandFormAutomatically) {
|
|
547
|
-
settings.expanded = settings.inline = false;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return settings;
|
|
551
|
-
};
|
|
552
|
-
const _EntryInterface = class {
|
|
553
|
-
constructor(container) {
|
|
554
|
-
this.container = container;
|
|
555
|
-
this.helpActionKey = "help";
|
|
556
|
-
this.nextActionKey = "next";
|
|
557
|
-
this.contactMethodClient = void 0;
|
|
558
|
-
this.contactMethodClient = new ContactMethodClient(container);
|
|
559
|
-
}
|
|
560
|
-
transform(entry, feedbackEntry) {
|
|
561
|
-
return __async(this, null, function* () {
|
|
562
|
-
const entryType = ServerEntryTypeEnum[entry.type];
|
|
563
|
-
switch (entryType) {
|
|
564
|
-
case ServerEntryTypeEnum.List:
|
|
565
|
-
return {
|
|
566
|
-
id: entry.id,
|
|
567
|
-
message: this.listTransform(entry, feedbackEntry),
|
|
568
|
-
entry,
|
|
569
|
-
isUser: false
|
|
570
|
-
};
|
|
571
|
-
case ServerEntryTypeEnum.Text:
|
|
572
|
-
return {
|
|
573
|
-
id: entry.id,
|
|
574
|
-
message: yield this.textTransform(entry, feedbackEntry),
|
|
575
|
-
entry,
|
|
576
|
-
isUser: false
|
|
577
|
-
};
|
|
578
|
-
case ServerEntryTypeEnum.Contact:
|
|
579
|
-
return {
|
|
580
|
-
id: entry.id,
|
|
581
|
-
message: yield this.transformContactMethod(entry),
|
|
582
|
-
entry,
|
|
583
|
-
isUser: false
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
transformContactMethod(entry) {
|
|
589
|
-
return __async(this, null, function* () {
|
|
590
|
-
var _a;
|
|
591
|
-
const dataClient = yield this.container.getAsync("dataClient");
|
|
592
|
-
const contactMethod = yield dataClient.fetch(DataType.ContactMethod, {
|
|
593
|
-
contactMethodId: entry.content.id
|
|
594
|
-
});
|
|
595
|
-
(_a = this.contactMethodClient) == null ? void 0 : _a.addContactMethod(contactMethod);
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
transformArray(entryArray) {
|
|
599
|
-
return __async(this, null, function* () {
|
|
600
|
-
let feedbackEntry = entryArray.find((o) => o.tags.find((t) => t == "gentle" || t == "feedback"));
|
|
601
|
-
let returnArray = [];
|
|
602
|
-
for (const o of entryArray.filter((t) => t !== feedbackEntry)) {
|
|
603
|
-
let x = yield this.transform(o, feedbackEntry);
|
|
604
|
-
if (!!x)
|
|
605
|
-
returnArray.push(x);
|
|
606
|
-
}
|
|
607
|
-
return returnArray;
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
getUserMessage(action) {
|
|
611
|
-
return __async(this, null, function* () {
|
|
612
|
-
let entry = StoreHelper.getEntry(action);
|
|
613
|
-
return yield this.getTitleFromEntry(entry, action);
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
listTransform(entry, feedbackEntry) {
|
|
617
|
-
if (entry.type === "Contact" || !entry.content)
|
|
618
|
-
return;
|
|
619
|
-
let object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState, entry.id);
|
|
620
|
-
if (!!feedbackEntry)
|
|
621
|
-
return this.addFeedbackToEntry(object, feedbackEntry);
|
|
622
|
-
return object;
|
|
623
|
-
}
|
|
624
|
-
getContentText(entry) {
|
|
625
|
-
if (entry.content.html)
|
|
626
|
-
return { body: entry.content.html };
|
|
627
|
-
if (entry.content.header)
|
|
628
|
-
return { title: entry.content.header };
|
|
629
|
-
}
|
|
630
|
-
textTransform(entry, feedbackEntry) {
|
|
631
|
-
return __async(this, null, function* () {
|
|
632
|
-
var _a;
|
|
633
|
-
if (!!entry.content.items)
|
|
634
|
-
return this.listTransform(entry, feedbackEntry);
|
|
635
|
-
let returnObj = [
|
|
636
|
-
[ConversationMessageListItemType.HTML, { body: entry.content.html.replace("\n", "") }]
|
|
637
|
-
];
|
|
638
|
-
if (!!entry.actions.submitted) {
|
|
639
|
-
let contactMethod = yield (_a = this.contactMethodClient) == null ? void 0 : _a.loadContactMethods(DataType.ContactMethods, entry.actions.submitted.id.toString(), entry.actions.submitted.guideId.toString());
|
|
640
|
-
returnObj.push([
|
|
641
|
-
"ace-knowledge-contact-method",
|
|
642
|
-
{
|
|
643
|
-
contactMethods: contactMethod,
|
|
644
|
-
entry: { entryId: entry.id },
|
|
645
|
-
guideId: entry.actions.submitted.guideId
|
|
646
|
-
}
|
|
647
|
-
]);
|
|
648
|
-
}
|
|
649
|
-
if (!!feedbackEntry)
|
|
650
|
-
return this.addFeedbackToEntry(returnObj, feedbackEntry);
|
|
651
|
-
return returnObj;
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
getListActions(items, text, actions, state, id) {
|
|
655
|
-
let list = [];
|
|
656
|
-
const mainListType = this.getListType(state);
|
|
657
|
-
const createMainList = (type) => {
|
|
658
|
-
if (type === ConversationMessageListItemType.ButtonList) {
|
|
659
|
-
return [];
|
|
660
|
-
}
|
|
661
|
-
return {};
|
|
662
|
-
};
|
|
663
|
-
let mainListContent = createMainList(mainListType);
|
|
664
|
-
let mainList = [mainListType, { actions: mainListContent }];
|
|
665
|
-
if (mainListType === "ace-knowledge-contact-method") {
|
|
666
|
-
mainList[1] = __spreadProps(__spreadValues({}, mainList[1]), {
|
|
667
|
-
contactMethods: items.map((item) => {
|
|
668
|
-
const formatted = contactMethodFromLegacy(item.data);
|
|
669
|
-
return formatted;
|
|
670
|
-
}),
|
|
671
|
-
entry: {
|
|
672
|
-
entryId: id
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
if (text && text.title) {
|
|
677
|
-
list.push([ConversationMessageListItemType.Header, text.title]);
|
|
678
|
-
}
|
|
679
|
-
if (text && text.body) {
|
|
680
|
-
list.push([ConversationMessageListItemType.HTML, { body: text.body }]);
|
|
681
|
-
}
|
|
682
|
-
list.push(mainList);
|
|
683
|
-
items.forEach((o) => {
|
|
684
|
-
switch (o.actionKey) {
|
|
685
|
-
case this.helpActionKey: {
|
|
686
|
-
list.push([ConversationMessageListItemType.Separator, void 0]);
|
|
687
|
-
list.push(["no-good-alternative", { body: o.title }]);
|
|
688
|
-
break;
|
|
689
|
-
}
|
|
690
|
-
case this.nextActionKey: {
|
|
691
|
-
if (!_EntryInterface.pagingAmount)
|
|
692
|
-
_EntryInterface.pagingAmount = actions["next"].take - items.filter((o2) => o2.actionKey !== "help" && o2.actionKey !== "next").length;
|
|
693
|
-
if (!!actions["next"] && actions["next"].take === items.filter((o2) => o2.actionKey !== "help" && o2.actionKey !== "next").length + _EntryInterface.pagingAmount) {
|
|
694
|
-
if (Array.isArray(mainListContent)) {
|
|
695
|
-
mainListContent.push({
|
|
696
|
-
label: o.title,
|
|
697
|
-
actionKey: o.actionKey
|
|
698
|
-
});
|
|
699
|
-
} else {
|
|
700
|
-
mainListContent[o.actionKey] = o.title;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
default: {
|
|
706
|
-
if (Array.isArray(mainListContent)) {
|
|
707
|
-
mainListContent.push({
|
|
708
|
-
label: o.title,
|
|
709
|
-
actionKey: o.actionKey,
|
|
710
|
-
symbol: o.symbol
|
|
711
|
-
});
|
|
712
|
-
} else {
|
|
713
|
-
mainListContent[o.actionKey] = o.title;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
return list;
|
|
719
|
-
}
|
|
720
|
-
getListType(state) {
|
|
721
|
-
if ((state == null ? void 0 : state.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching") {
|
|
722
|
-
return ConversationMessageListItemType.LinkList;
|
|
723
|
-
} else if ((state == null ? void 0 : state.$type) === "Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching") {
|
|
724
|
-
return "feedback-list";
|
|
725
|
-
} else if ((state == null ? void 0 : state.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching") {
|
|
726
|
-
return "ace-knowledge-contact-method";
|
|
727
|
-
} else
|
|
728
|
-
return ConversationMessageListItemType.ButtonList;
|
|
729
|
-
}
|
|
730
|
-
getTitleFromEntry(entry, action) {
|
|
731
|
-
return __async(this, null, function* () {
|
|
732
|
-
if (!!entry) {
|
|
733
|
-
const entryType = ServerEntryTypeEnum[entry.type];
|
|
734
|
-
switch (entryType) {
|
|
735
|
-
case ServerEntryTypeEnum.List:
|
|
736
|
-
return this.getTitleFromList(entry, action);
|
|
737
|
-
case ServerEntryTypeEnum.Text:
|
|
738
|
-
return yield this.textTransform(entry);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
getTitleFromList(entry, action) {
|
|
744
|
-
return entry.content.items.find((o) => o.actionKey == action).title;
|
|
745
|
-
}
|
|
746
|
-
addFeedbackToEntry(current, feedbackEntry) {
|
|
747
|
-
let feedbackObject = this.getListActions(feedbackEntry.content.items, this.getContentText(feedbackEntry), feedbackEntry.actions, feedbackEntry.localState, feedbackEntry.id);
|
|
748
|
-
StoreHelper.insertMessageToStore({
|
|
749
|
-
id: feedbackEntry.id,
|
|
750
|
-
message: void 0,
|
|
751
|
-
entry: feedbackEntry,
|
|
752
|
-
isUser: false
|
|
753
|
-
});
|
|
754
|
-
return current.concat(feedbackObject);
|
|
755
|
-
}
|
|
756
|
-
};
|
|
757
|
-
let EntryInterface = _EntryInterface;
|
|
758
|
-
EntryInterface.pagingAmount = void 0;
|
|
759
|
-
class PagingInterface {
|
|
760
|
-
process(entries) {
|
|
761
|
-
const pagingEntry = entries.find((e) => e.tags.indexOf("paging") > -1);
|
|
762
|
-
if (pagingEntry) {
|
|
763
|
-
const stream = StoreHelper.getEntryStore().filter((e) => e.tags.indexOf("paging") > -1 && e.id === pagingEntry.id);
|
|
764
|
-
if (stream.length > 0) {
|
|
765
|
-
const last = stream.reduce((acc, entry) => {
|
|
766
|
-
if (entry.actions.next && entry.actions.next.take >= acc.actions.next.take) {
|
|
767
|
-
return entry;
|
|
768
|
-
}
|
|
769
|
-
return acc;
|
|
770
|
-
}, stream[0]);
|
|
771
|
-
if (last.actions.next.take > pagingEntry.actions.next.take) {
|
|
772
|
-
entries.forEach((entry) => {
|
|
773
|
-
if (entry.id === pagingEntry.id) {
|
|
774
|
-
entry.actions.next = __spreadProps(__spreadValues({}, entry.actions.next), {
|
|
775
|
-
take: last.actions.next.take,
|
|
776
|
-
skip: last.actions.next.skip
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
entries.forEach((entry) => {
|
|
783
|
-
if (entry.id === pagingEntry.id && entry.content && entry.content.timestamp) {
|
|
784
|
-
entry.content = __spreadProps(__spreadValues({}, entry.content), {
|
|
785
|
-
items: entry.content && entry.content.items || []
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
return entries;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
class ProcessorInterface {
|
|
794
|
-
process(entries) {
|
|
795
|
-
let processedEntries = entries;
|
|
796
|
-
processedEntries = this.deletePaging(processedEntries);
|
|
797
|
-
processedEntries = this.delete(processedEntries);
|
|
798
|
-
processedEntries = this.merge(processedEntries);
|
|
799
|
-
processedEntries = this.moveLoader(processedEntries);
|
|
800
|
-
return processedEntries;
|
|
801
|
-
}
|
|
802
|
-
processUpdate(entry, updateEntryArray) {
|
|
803
|
-
updateEntryArray.filter((t) => t.type == "List").forEach((o) => {
|
|
804
|
-
var _a;
|
|
805
|
-
(_a = o.content) == null ? void 0 : _a.items.forEach((t) => {
|
|
806
|
-
if (!(entry == null ? void 0 : entry.content.items.find((p) => p.actionKey == t.actionKey)))
|
|
807
|
-
entry == null ? void 0 : entry.content.items.push(t);
|
|
808
|
-
});
|
|
809
|
-
Object.keys(o.actions).forEach((t) => {
|
|
810
|
-
this.handleActionUpdateOrInsert(entry == null ? void 0 : entry.actions, t, o.actions);
|
|
811
|
-
});
|
|
812
|
-
});
|
|
813
|
-
var itemArray = entry == null ? void 0 : entry.content.items;
|
|
814
|
-
if (itemArray.find((o) => o.actionKey == "next")) {
|
|
815
|
-
itemArray.push(itemArray.splice(itemArray.indexOf(itemArray.find((o) => o.actionKey == "next")), 1)[0]);
|
|
816
|
-
}
|
|
817
|
-
if (itemArray.find((o) => o.actionKey == "help")) {
|
|
818
|
-
itemArray.push(itemArray.splice(itemArray.indexOf(itemArray.find((o) => o.actionKey == "help")), 1)[0]);
|
|
819
|
-
}
|
|
820
|
-
return entry ? [entry] : [];
|
|
821
|
-
}
|
|
822
|
-
handleActionUpdateOrInsert(currentArray, actionKey, action) {
|
|
823
|
-
if (!!currentArray)
|
|
824
|
-
currentArray[actionKey] = action[actionKey];
|
|
825
|
-
}
|
|
826
|
-
deletePaging(entries) {
|
|
827
|
-
return entries.filter((entry) => {
|
|
828
|
-
const isEmptyPaging = entry.type === "List" && entry.tags && entry.tags.indexOf("paging") > -1 && typeof entry.content === "undefined";
|
|
829
|
-
return !isEmptyPaging;
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
delete(entries) {
|
|
833
|
-
return entries.filter((entry) => entry.content !== null);
|
|
834
|
-
}
|
|
835
|
-
merge(entries) {
|
|
836
|
-
const output = [];
|
|
837
|
-
const merge = (source, target = {}) => {
|
|
838
|
-
const content = {};
|
|
839
|
-
if (source == null) {
|
|
840
|
-
return null;
|
|
841
|
-
}
|
|
842
|
-
if (target) {
|
|
843
|
-
Object.keys(target).forEach((key) => {
|
|
844
|
-
content[key] = target[key];
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
Object.keys(source).forEach((key) => {
|
|
848
|
-
if (key == "items") {
|
|
849
|
-
if (!content[key])
|
|
850
|
-
content[key] = [];
|
|
851
|
-
content[key] = content[key].concat(source[key]);
|
|
852
|
-
} else if (key == "html")
|
|
853
|
-
content[key] = content[key] + source[key];
|
|
854
|
-
else
|
|
855
|
-
content[key] = source[key];
|
|
856
|
-
});
|
|
857
|
-
return content;
|
|
858
|
-
};
|
|
859
|
-
const mergeLocalState = (source, target) => {
|
|
860
|
-
if (source == null)
|
|
861
|
-
return null;
|
|
862
|
-
if (Object.keys(source.actions).length === 0)
|
|
863
|
-
return target.localState;
|
|
864
|
-
if (Object.keys(target.actions).length === 0)
|
|
865
|
-
return source.localState;
|
|
866
|
-
return target.localState;
|
|
867
|
-
};
|
|
868
|
-
entries.forEach((entry) => {
|
|
869
|
-
if (entry.relation && !entry.tags.find((o) => o == "gentle" || o == "feedback")) {
|
|
870
|
-
let existingEntry = entries.find((o) => o.id == entry.relation);
|
|
871
|
-
if (existingEntry) {
|
|
872
|
-
const existingIndex = output.indexOf(existingEntry);
|
|
873
|
-
existingEntry.localState = mergeLocalState(entry, existingEntry);
|
|
874
|
-
existingEntry.content = merge(entry.content, existingEntry.content);
|
|
875
|
-
existingEntry.actions = merge(entry.actions, existingEntry.actions);
|
|
876
|
-
output[existingIndex] = existingEntry;
|
|
877
|
-
}
|
|
878
|
-
} else {
|
|
879
|
-
output.push(entry);
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
return output;
|
|
883
|
-
}
|
|
884
|
-
moveLoader(entries) {
|
|
885
|
-
const loaderEntry = entries.find((e) => e.id === "loader");
|
|
886
|
-
if (!loaderEntry) {
|
|
887
|
-
return entries;
|
|
888
|
-
}
|
|
889
|
-
const loaderIndex = entries.indexOf(loaderEntry);
|
|
890
|
-
if (loaderIndex > -1) {
|
|
891
|
-
entries.splice(entries.length - 1, 0, entries.splice(loaderIndex, 1)[0]);
|
|
892
|
-
}
|
|
893
|
-
return entries;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
class MiddlewareClient {
|
|
897
|
-
constructor(container) {
|
|
898
|
-
this.paging = new PagingInterface();
|
|
899
|
-
this.processor = new ProcessorInterface();
|
|
900
|
-
this.entryInterface = new EntryInterface(container);
|
|
901
|
-
this.chatClient = new ChatClient();
|
|
902
|
-
}
|
|
903
|
-
static initialize(container, widget) {
|
|
904
|
-
MiddlewareHelper.setContainer(container);
|
|
905
|
-
MiddlewareHelper.setWidget(widget);
|
|
906
|
-
}
|
|
907
|
-
handleEntries(entries, action) {
|
|
908
|
-
return __async(this, null, function* () {
|
|
909
|
-
const widgetEntry = (entries || []).find((e) => e.type === "Widget");
|
|
910
|
-
if (widgetEntry) {
|
|
911
|
-
const agent = ChatHelper.getAgent();
|
|
912
|
-
if (agent) {
|
|
913
|
-
agent.update({
|
|
914
|
-
name: widgetEntry.content.agent.name,
|
|
915
|
-
avatar: widgetEntry.content.agent.avatar
|
|
916
|
-
});
|
|
917
|
-
const write = yield createStorageWriter(MiddlewareHelper.getContainer(), "bot-provider-conversation-meta", StorageCategory.Necessary);
|
|
918
|
-
write({
|
|
919
|
-
agent: {
|
|
920
|
-
name: widgetEntry.content.agent.name,
|
|
921
|
-
avatar: widgetEntry.content.agent.avatar
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
let o = this.executeMiddlewares(entries, false, action);
|
|
927
|
-
let messageArray = yield this.entryInterface.transformArray(o);
|
|
928
|
-
this.chatClient.processMessageArrayAndStoreIt(messageArray);
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
handleUpdate(entries, action) {
|
|
932
|
-
return __async(this, null, function* () {
|
|
933
|
-
let o = this.executeMiddlewares(entries, true, action);
|
|
934
|
-
let messageArray = yield this.entryInterface.transformArray(o);
|
|
935
|
-
this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
checkForUpdate(input) {
|
|
939
|
-
return input === "next";
|
|
940
|
-
}
|
|
941
|
-
executeMiddlewares(entries, isUpdate, action) {
|
|
942
|
-
if (isUpdate && action)
|
|
943
|
-
entries = this.processor.processUpdate(StoreHelper.getEntry(action), entries);
|
|
944
|
-
else {
|
|
945
|
-
entries = this.processor.process(entries);
|
|
946
|
-
}
|
|
947
|
-
entries = this.paging.process(entries);
|
|
948
|
-
return entries;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
class HttpClient {
|
|
952
|
-
constructor(endpoint, clientId, container) {
|
|
953
|
-
this.options = {
|
|
954
|
-
credentials: HttpHelper.getCredentials(),
|
|
955
|
-
clientId
|
|
956
|
-
};
|
|
957
|
-
this.apiEndpoint = endpoint;
|
|
958
|
-
this.projectionPath = window.location.href;
|
|
959
|
-
this.endpointUrl = HttpHelper.combineUrl(this.projectionPath, "conversations");
|
|
960
|
-
this.clientId = this.options.clientId;
|
|
961
|
-
this.middlewareClient = new MiddlewareClient(container);
|
|
962
|
-
this.chatClient = new ChatClient();
|
|
963
|
-
this.container = container;
|
|
964
|
-
}
|
|
965
|
-
firstHit() {
|
|
966
|
-
return __async(this, null, function* () {
|
|
967
|
-
const entries = yield MiddlewareHelper.getEntrySessionStorage();
|
|
968
|
-
if (entries && entries.length > 0) {
|
|
969
|
-
yield StoreHelper.rehydrateState();
|
|
970
|
-
const meta = yield readStorage(this.container, "bot-provider-conversation-meta");
|
|
971
|
-
if (meta == null ? void 0 : meta.agent) {
|
|
972
|
-
const agent = ChatHelper.getAgent();
|
|
973
|
-
agent.update({
|
|
974
|
-
name: meta.agent.name,
|
|
975
|
-
avatar: meta.agent.avatar
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
yield this.chatClient.processMessageArrayAndStoreIt(entries);
|
|
979
|
-
} else {
|
|
980
|
-
let envelope = this.constructFirstHitEnvelope();
|
|
981
|
-
yield this.postAndHandleTheData(envelope);
|
|
982
|
-
}
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
handleUpdate(action) {
|
|
986
|
-
let envelope = this.constructInputEnvelope(action);
|
|
987
|
-
return this.postAndHandleTheUpdateData(envelope, action);
|
|
988
|
-
}
|
|
989
|
-
handleInput(action) {
|
|
990
|
-
let envelope = this.constructInputEnvelope(action);
|
|
991
|
-
return this.postAndHandleTheData(envelope, action);
|
|
992
|
-
}
|
|
993
|
-
handleCategories() {
|
|
994
|
-
let envelope = this.constructCategoriesEnvelope();
|
|
995
|
-
return this.postAndHandleTheData(envelope);
|
|
996
|
-
}
|
|
997
|
-
handlePhrase(phrase) {
|
|
998
|
-
const envelope = this.constructPhraseEnvelope(phrase);
|
|
999
|
-
const id = v4();
|
|
1000
|
-
const entry = {
|
|
1001
|
-
id,
|
|
1002
|
-
type: "Text",
|
|
1003
|
-
timestamp: new Date(),
|
|
1004
|
-
content: {
|
|
1005
|
-
$type: "Humany.Matching.Bots.Conversations.Content.Text, Humany.Matching",
|
|
1006
|
-
html: `${phrase}`
|
|
1007
|
-
},
|
|
1008
|
-
actions: {},
|
|
1009
|
-
tags: {}
|
|
1010
|
-
};
|
|
1011
|
-
const message = {
|
|
1012
|
-
id,
|
|
1013
|
-
message: ["html", { body: `<p>${phrase}</p>` }],
|
|
1014
|
-
entry,
|
|
1015
|
-
isUser: true,
|
|
1016
|
-
conversationEntry: {}
|
|
1017
|
-
};
|
|
1018
|
-
StoreHelper.insertMessageToStore(message);
|
|
1019
|
-
return this.postAndHandleTheData(envelope);
|
|
1020
|
-
}
|
|
1021
|
-
postAndHandleTheData(envelope, action) {
|
|
1022
|
-
return fetch(this.apiEndpoint, this.getHttpOptions(envelope)).then((response) => {
|
|
1023
|
-
if (response.ok)
|
|
1024
|
-
return response.json();
|
|
1025
|
-
throw response;
|
|
1026
|
-
}).then((data) => {
|
|
1027
|
-
this.handleResponseData(data, action);
|
|
1028
|
-
}).catch((err) => console.log(err));
|
|
1029
|
-
}
|
|
1030
|
-
postAndHandleTheUpdateData(envelope, action) {
|
|
1031
|
-
return fetch(this.apiEndpoint, this.getHttpOptions(envelope)).then((response) => {
|
|
1032
|
-
if (response.ok)
|
|
1033
|
-
return response.json();
|
|
1034
|
-
throw response;
|
|
1035
|
-
}).then((data) => {
|
|
1036
|
-
this.handleUpdateResponseData(data, action);
|
|
1037
|
-
}).catch((err) => console.log(err));
|
|
1038
|
-
}
|
|
1039
|
-
getHttpOptions(envelope) {
|
|
1040
|
-
return Object.assign({}, HttpHelper.fetchOptions, {
|
|
1041
|
-
body: JSON.stringify(envelope),
|
|
1042
|
-
credentials: this.options.credentials
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
|
-
constructInputEnvelope(action) {
|
|
1046
|
-
return {
|
|
1047
|
-
action: StoreHelper.getAction(action),
|
|
1048
|
-
localState: StoreHelper.getLocalState(action),
|
|
1049
|
-
globalState: StoreHelper.getGlobalState(),
|
|
1050
|
-
clientId: this.clientId
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
constructCategoriesEnvelope() {
|
|
1054
|
-
return {
|
|
1055
|
-
action: {
|
|
1056
|
-
content: {
|
|
1057
|
-
$type: "Humany.Matching.Bots.Conversations.Actions.BrowseCategories, Humany.Matching"
|
|
1058
|
-
},
|
|
1059
|
-
key: "browseCategories"
|
|
1060
|
-
},
|
|
1061
|
-
globalState: StoreHelper.getGlobalState(),
|
|
1062
|
-
clientId: this.clientId
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
constructPhraseEnvelope(phrase) {
|
|
1066
|
-
return {
|
|
1067
|
-
command: { phrase },
|
|
1068
|
-
globalState: StoreHelper.getGlobalState(),
|
|
1069
|
-
clientId: this.clientId
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
constructFirstHitEnvelope() {
|
|
1073
|
-
return {
|
|
1074
|
-
command: { site: this.endpointUrl },
|
|
1075
|
-
clientId: this.clientId,
|
|
1076
|
-
globalState: {}
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
|
-
handleResponseData(envelope, action) {
|
|
1080
|
-
StoreHelper.setGlobalState(envelope.globalState);
|
|
1081
|
-
return this.middlewareClient.handleEntries(envelope.entries, action);
|
|
1082
|
-
}
|
|
1083
|
-
handleUpdateResponseData(envelope, action) {
|
|
1084
|
-
return this.middlewareClient.handleUpdate(envelope.entries, action);
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
const getKnowledgeBotEndpoint = (container, component) => {
|
|
1088
|
-
const { knowledgeBotEndpoint } = component.properties();
|
|
1089
|
-
if (knowledgeBotEndpoint) {
|
|
1090
|
-
return `${knowledgeBotEndpoint}/conversations`;
|
|
1091
|
-
}
|
|
1092
|
-
const { data } = container.get("$settings");
|
|
1093
|
-
if (!data || !data.projection)
|
|
1094
|
-
throw new Error("Missing Knowledge Bot endpoint");
|
|
1095
|
-
return `${data.projection}/conversations`;
|
|
1096
|
-
};
|
|
1097
|
-
const KnowledgeBotProviderPlugin = (container) => __async(this, null, function* () {
|
|
1098
|
-
const dataClient = yield DataClient.getInstance(container);
|
|
1099
|
-
const platform = yield ConversationPlatform.getInstance(container);
|
|
1100
|
-
const contactMethodPlatform = yield ContactMethodPlatform.getInstance(container);
|
|
1101
|
-
platform.registerConversationItem("ace-knowledge-contact-method", import("./contact-method.js"));
|
|
1102
|
-
platform.registerConversationItem("no-good-alternative", import("./no-good-alternative.js"));
|
|
1103
|
-
platform.registerConversationItem("feedback-list", import("./feedback-list.js"));
|
|
1104
|
-
platform.registerProvider("chat.bot", (conversation, component) => {
|
|
1105
|
-
const endpoint = getKnowledgeBotEndpoint(container, component);
|
|
1106
|
-
const clientId = v4();
|
|
1107
|
-
const agent = conversation.createAgent({
|
|
1108
|
-
name: "",
|
|
1109
|
-
avatar: void 0
|
|
1110
|
-
});
|
|
1111
|
-
ChatClient.initialize(conversation.user, agent);
|
|
1112
|
-
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
1113
|
-
MiddlewareClient.initialize(container, container.get("$widget"));
|
|
1114
|
-
const httpClient = new HttpClient(endpoint, clientId, container);
|
|
1115
|
-
const firstLoader = conversation.loading();
|
|
1116
|
-
httpClient.firstHit().then(firstLoader);
|
|
1117
|
-
component.actions.create("expand", (input) => {
|
|
1118
|
-
const cmClient = new ContactMethodClient(container);
|
|
1119
|
-
cmClient.expandContactMethod(input);
|
|
1120
|
-
});
|
|
1121
|
-
component.actions.create("evaluate", (input) => {
|
|
1122
|
-
const cmClient = new ContactMethodClient(container);
|
|
1123
|
-
cmClient.handleNewForm(input.form, input.form.id);
|
|
1124
|
-
});
|
|
1125
|
-
component.actions.create("validate", (input) => {
|
|
1126
|
-
const cmClient = new ContactMethodClient(container);
|
|
1127
|
-
cmClient.validate(input.form);
|
|
1128
|
-
});
|
|
1129
|
-
component.actions.create("submit", (input) => {
|
|
1130
|
-
var _a;
|
|
1131
|
-
if ((_a = input == null ? void 0 : input.form) == null ? void 0 : _a.schema.id) {
|
|
1132
|
-
getContactMethodEntry(input.form.schema.id);
|
|
1133
|
-
}
|
|
1134
|
-
const cmClient = new ContactMethodClient(container);
|
|
1135
|
-
cmClient.validate(input.form);
|
|
1136
|
-
});
|
|
1137
|
-
component.actions.watch("conversation.user-typing", (input, next) => {
|
|
1138
|
-
return next(input);
|
|
1139
|
-
});
|
|
1140
|
-
component.actions.watch("conversation.user-submit", (input, next) => {
|
|
1141
|
-
const httpClient2 = new HttpClient(endpoint, clientId, container);
|
|
1142
|
-
const loader = conversation.loading();
|
|
1143
|
-
httpClient2.handlePhrase(input.text).then(loader);
|
|
1144
|
-
return next(input);
|
|
1145
|
-
});
|
|
1146
|
-
component.actions.watch("conversation.form", (input, next) => {
|
|
1147
|
-
return next(input);
|
|
1148
|
-
});
|
|
1149
|
-
component.actions.watch("conversation.action", (input, next) => {
|
|
1150
|
-
const chatClient = new ChatClient();
|
|
1151
|
-
const cmClient = new ContactMethodClient(container);
|
|
1152
|
-
const loader = conversation.loading();
|
|
1153
|
-
if (input.split("/").length > 1) {
|
|
1154
|
-
cmClient.handleContactMethod(input).then(loader);
|
|
1155
|
-
return next(input);
|
|
1156
|
-
}
|
|
1157
|
-
const httpClient2 = new HttpClient(endpoint, clientId, container);
|
|
1158
|
-
if (input == "burger-clicked") {
|
|
1159
|
-
httpClient2.handleCategories().then(loader);
|
|
1160
|
-
return next(input);
|
|
1161
|
-
}
|
|
1162
|
-
const middlewareClient = new MiddlewareClient(container);
|
|
1163
|
-
if (middlewareClient.checkForUpdate(input)) {
|
|
1164
|
-
httpClient2.handleUpdate(input).then(loader);
|
|
1165
|
-
return next(input);
|
|
1166
|
-
}
|
|
1167
|
-
chatClient.printUserMessageAndStoreIt(input);
|
|
1168
|
-
httpClient2.handleInput(input).then(loader);
|
|
1169
|
-
return next(input);
|
|
1170
|
-
});
|
|
1171
|
-
});
|
|
1172
|
-
});
|
|
1173
|
-
export { KnowledgeBotProviderPlugin as ConversationPlugin };
|
|
1
|
+
export { K as ConversationPlugin } from "./index2.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";
|
|
1174
6
|
//# sourceMappingURL=index.js.map
|