@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.5 → 0.0.1-alpha.52
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 +154 -0
- package/dist/contact-method.js.map +1 -0
- package/dist/entry-handler.d.ts +2 -0
- package/dist/feedback-list.js +72 -0
- package/dist/feedback-list.js.map +1 -0
- package/dist/http-client.d.ts +42 -0
- package/{lib-esm → dist}/index.d.ts +0 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/index2.js +914 -0
- package/dist/index2.js.map +1 -0
- package/dist/no-good-alternative.js +46 -0
- package/dist/no-good-alternative.js.map +1 -0
- package/dist/notification-list.js +74 -0
- package/dist/notification-list.js.map +1 -0
- package/dist/plugin.d.ts +3 -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 +8 -0
- package/dist/ui/no-good-alternative.d.ts +6 -0
- package/dist/ui/notification-list.d.ts +11 -0
- package/dist/ui/styles.d.ts +1 -0
- package/dist/utils.d.ts +26 -0
- package/package.json +44 -45
- package/lib/client/chat.client.d.ts +0 -15
- package/lib/client/chat.client.js +0 -80
- package/lib/client/contact-method.client.d.ts +0 -22
- package/lib/client/contact-method.client.js +0 -276
- package/lib/client/http.client.d.ts +0 -22
- package/lib/client/http.client.js +0 -114
- package/lib/client/middleware.client.d.ts +0 -13
- package/lib/client/middleware.client.js +0 -60
- package/lib/contract/custom-component/contact-method-item.d.ts +0 -8
- package/lib/contract/custom-component/contact-method-item.js +0 -76
- package/lib/contract/custom-component/contact-method-list.d.ts +0 -7
- package/lib/contract/custom-component/contact-method-list.js +0 -41
- package/lib/contract/custom-component/contact-method.d.ts +0 -3
- package/lib/contract/custom-component/contact-method.js +0 -38
- package/lib/contract/enum/server-entry-type.enum.d.ts +0 -6
- package/lib/contract/enum/server-entry-type.enum.js +0 -10
- package/lib/contract/model/conversation-api-model/list.model.d.ts +0 -5
- package/lib/contract/model/conversation-api-model/list.model.js +0 -2
- package/lib/contract/model/conversation-api-model/message.model.d.ts +0 -7
- package/lib/contract/model/conversation-api-model/message.model.js +0 -2
- package/lib/contract/model/http/action.model.d.ts +0 -3
- package/lib/contract/model/http/action.model.js +0 -2
- package/lib/contract/model/http/client-action.model.d.ts +0 -4
- package/lib/contract/model/http/client-action.model.js +0 -3
- package/lib/contract/model/http/client-envelope.model.d.ts +0 -9
- package/lib/contract/model/http/client-envelope.model.js +0 -2
- package/lib/contract/model/http/connect-options.model.d.ts +0 -5
- package/lib/contract/model/http/connect-options.model.js +0 -2
- package/lib/contract/model/http/global-state.model.d.ts +0 -8
- package/lib/contract/model/http/global-state.model.js +0 -2
- package/lib/contract/model/http/http-client-options.model.d.ts +0 -5
- package/lib/contract/model/http/http-client-options.model.js +0 -2
- package/lib/contract/model/http/server-entry.model.d.ts +0 -11
- package/lib/contract/model/http/server-entry.model.js +0 -2
- package/lib/contract/model/http/server-envelope.model.d.ts +0 -10
- package/lib/contract/model/http/server-envelope.model.js +0 -2
- package/lib/contract/model/middleware/aggregator-state.model.d.ts +0 -4
- package/lib/contract/model/middleware/aggregator-state.model.js +0 -3
- package/lib/contract/model/shared/loose-object.model.d.ts +0 -3
- package/lib/contract/model/shared/loose-object.model.js +0 -2
- package/lib/helper/chat.helper.d.ts +0 -8
- package/lib/helper/chat.helper.js +0 -21
- package/lib/helper/http.helper.d.ts +0 -13
- package/lib/helper/http.helper.js +0 -33
- package/lib/helper/middleware.helper.d.ts +0 -12
- package/lib/helper/middleware.helper.js +0 -72
- package/lib/helper/store.helper.d.ts +0 -22
- package/lib/helper/store.helper.js +0 -80
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -8
- package/lib/interface/entry.interface.d.ts +0 -17
- package/lib/interface/entry.interface.js +0 -138
- package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
- package/lib/interface/middleware/contact-expanded.interface.js +0 -50
- package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
- package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
- package/lib/interface/middleware/paging.interface.d.ts +0 -4
- package/lib/interface/middleware/paging.interface.js +0 -55
- package/lib/interface/middleware/processor.interface.d.ts +0 -10
- package/lib/interface/middleware/processor.interface.js +0 -120
- package/lib/plugin.d.ts +0 -3
- package/lib/plugin.js +0 -172
- package/lib-esm/client/chat.client.d.ts +0 -15
- package/lib-esm/client/chat.client.js +0 -75
- package/lib-esm/client/contact-method.client.d.ts +0 -22
- package/lib-esm/client/contact-method.client.js +0 -270
- package/lib-esm/client/http.client.d.ts +0 -22
- package/lib-esm/client/http.client.js +0 -108
- package/lib-esm/client/middleware.client.d.ts +0 -13
- package/lib-esm/client/middleware.client.js +0 -55
- package/lib-esm/contract/custom-component/contact-method-item.d.ts +0 -8
- package/lib-esm/contract/custom-component/contact-method-item.js +0 -51
- package/lib-esm/contract/custom-component/contact-method-list.d.ts +0 -7
- package/lib-esm/contract/custom-component/contact-method-list.js +0 -13
- package/lib-esm/contract/custom-component/contact-method.d.ts +0 -3
- package/lib-esm/contract/custom-component/contact-method.js +0 -33
- package/lib-esm/contract/enum/server-entry-type.enum.d.ts +0 -6
- package/lib-esm/contract/enum/server-entry-type.enum.js +0 -7
- package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +0 -5
- package/lib-esm/contract/model/conversation-api-model/list.model.js +0 -1
- package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +0 -7
- package/lib-esm/contract/model/conversation-api-model/message.model.js +0 -1
- package/lib-esm/contract/model/http/action.model.d.ts +0 -3
- package/lib-esm/contract/model/http/action.model.js +0 -1
- package/lib-esm/contract/model/http/client-action.model.d.ts +0 -4
- package/lib-esm/contract/model/http/client-action.model.js +0 -2
- package/lib-esm/contract/model/http/client-envelope.model.d.ts +0 -9
- package/lib-esm/contract/model/http/client-envelope.model.js +0 -1
- package/lib-esm/contract/model/http/connect-options.model.d.ts +0 -5
- package/lib-esm/contract/model/http/connect-options.model.js +0 -1
- package/lib-esm/contract/model/http/global-state.model.d.ts +0 -8
- package/lib-esm/contract/model/http/global-state.model.js +0 -1
- package/lib-esm/contract/model/http/http-client-options.model.d.ts +0 -5
- package/lib-esm/contract/model/http/http-client-options.model.js +0 -1
- package/lib-esm/contract/model/http/server-entry.model.d.ts +0 -11
- package/lib-esm/contract/model/http/server-entry.model.js +0 -1
- package/lib-esm/contract/model/http/server-envelope.model.d.ts +0 -10
- package/lib-esm/contract/model/http/server-envelope.model.js +0 -1
- package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +0 -4
- package/lib-esm/contract/model/middleware/aggregator-state.model.js +0 -2
- package/lib-esm/contract/model/shared/loose-object.model.d.ts +0 -3
- package/lib-esm/contract/model/shared/loose-object.model.js +0 -1
- package/lib-esm/helper/chat.helper.d.ts +0 -8
- package/lib-esm/helper/chat.helper.js +0 -18
- package/lib-esm/helper/http.helper.d.ts +0 -13
- package/lib-esm/helper/http.helper.js +0 -30
- package/lib-esm/helper/middleware.helper.d.ts +0 -12
- package/lib-esm/helper/middleware.helper.js +0 -69
- package/lib-esm/helper/store.helper.d.ts +0 -22
- package/lib-esm/helper/store.helper.js +0 -77
- package/lib-esm/index.js +0 -2
- package/lib-esm/interface/entry.interface.d.ts +0 -17
- package/lib-esm/interface/entry.interface.js +0 -136
- package/lib-esm/interface/middleware/paging.interface.d.ts +0 -4
- package/lib-esm/interface/middleware/paging.interface.js +0 -53
- package/lib-esm/interface/middleware/processor.interface.d.ts +0 -10
- package/lib-esm/interface/middleware/processor.interface.js +0 -118
- package/lib-esm/plugin.d.ts +0 -3
- package/lib-esm/plugin.js +0 -144
package/dist/index2.js
ADDED
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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 { ConversationMessageListItemType, ConversationPlatform, registerCustomMessageComponent } from "@telia-ace/widget-conversation";
|
|
41
|
+
import { readStorage, createStorageWriter, StorageCategory } from "@telia-ace/widget-services";
|
|
42
|
+
import { uuid } from "@telia-ace/widget-utilities";
|
|
43
|
+
import { FormBuilder, submitButton } from "@telia-ace/widget-forms";
|
|
44
|
+
var CustomMessageTypes = /* @__PURE__ */ ((CustomMessageTypes2) => {
|
|
45
|
+
CustomMessageTypes2["ContactMethod"] = "ace-knowledge-bot-contact-method";
|
|
46
|
+
CustomMessageTypes2["ContactList"] = "ace-knowledge-bot-contact-list";
|
|
47
|
+
CustomMessageTypes2["FeedbackList"] = "ace-knowledge-bot-feedback-list";
|
|
48
|
+
CustomMessageTypes2["NotificationList"] = "ace-knowledge-bot-notification-list";
|
|
49
|
+
CustomMessageTypes2["NoGoodAlternative"] = "ace-knowledge-bot-no-good-alternative";
|
|
50
|
+
return CustomMessageTypes2;
|
|
51
|
+
})(CustomMessageTypes || {});
|
|
52
|
+
const convertLegacySymbol = (symbol) => {
|
|
53
|
+
if (symbol) {
|
|
54
|
+
const { type, content } = symbol;
|
|
55
|
+
if (type && content) {
|
|
56
|
+
return { type, content };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const createGroup = ({
|
|
61
|
+
isUser,
|
|
62
|
+
items = [],
|
|
63
|
+
meta = {}
|
|
64
|
+
}) => {
|
|
65
|
+
const groupId = uuid();
|
|
66
|
+
const group = {
|
|
67
|
+
id: groupId,
|
|
68
|
+
isUser,
|
|
69
|
+
items: items.map((i) => {
|
|
70
|
+
return {
|
|
71
|
+
id: i.id || uuid(),
|
|
72
|
+
isUser,
|
|
73
|
+
groupId,
|
|
74
|
+
message: i.message || []
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
meta
|
|
78
|
+
};
|
|
79
|
+
return group;
|
|
80
|
+
};
|
|
81
|
+
const contactMethodFromLegacy = ({
|
|
82
|
+
id,
|
|
83
|
+
title,
|
|
84
|
+
defaultIcon,
|
|
85
|
+
exits: [exit],
|
|
86
|
+
exitType,
|
|
87
|
+
confirmationText,
|
|
88
|
+
expandFormAutomatically,
|
|
89
|
+
form,
|
|
90
|
+
description
|
|
91
|
+
}, options = {}) => {
|
|
92
|
+
const { adapter } = exit || { Adapter: {} };
|
|
93
|
+
const { clientName = "", settings: adapterSettings = {}, customClientName = "" } = adapter;
|
|
94
|
+
const { validation } = options;
|
|
95
|
+
const settings = {
|
|
96
|
+
id: id.toString(),
|
|
97
|
+
title,
|
|
98
|
+
description,
|
|
99
|
+
symbol: convertLegacySymbol(defaultIcon),
|
|
100
|
+
clientName: clientName === "custom.adapter" ? customClientName : clientName,
|
|
101
|
+
expanded: true,
|
|
102
|
+
inline: true,
|
|
103
|
+
body: {}
|
|
104
|
+
};
|
|
105
|
+
if (clientName.indexOf("phone") > -1 || clientName.indexOf("freetext") > -1) {
|
|
106
|
+
const { displayTextBeforeClick, textBeforeClick } = adapterSettings;
|
|
107
|
+
if (displayTextBeforeClick === "true") {
|
|
108
|
+
settings.expanded = false;
|
|
109
|
+
settings.title = textBeforeClick;
|
|
110
|
+
}
|
|
111
|
+
if (clientName.indexOf("phone.text") > -1) {
|
|
112
|
+
settings.body.phoneNumber = adapterSettings.phoneNumber;
|
|
113
|
+
} else {
|
|
114
|
+
settings.body.freetext = adapterSettings.freetext;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (clientName.indexOf("chat.popup") > -1 || clientName.indexOf("link") > -1 || clientName === "custom.adapter" && exitType === "custom") {
|
|
118
|
+
settings.body = adapterSettings;
|
|
119
|
+
settings.body.confirmationFallback = confirmationText;
|
|
120
|
+
}
|
|
121
|
+
if (clientName.indexOf("ace") > -1) {
|
|
122
|
+
settings.body = adapterSettings;
|
|
123
|
+
}
|
|
124
|
+
if (form && form.hasValueComponents) {
|
|
125
|
+
if (validation) {
|
|
126
|
+
settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form, validation).get();
|
|
127
|
+
} else {
|
|
128
|
+
settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form).get();
|
|
129
|
+
}
|
|
130
|
+
if (!expandFormAutomatically) {
|
|
131
|
+
settings.expanded = settings.inline = false;
|
|
132
|
+
}
|
|
133
|
+
settings.body = updateForm(settings, { submit: "Submit" });
|
|
134
|
+
}
|
|
135
|
+
if (options.guideId) {
|
|
136
|
+
settings.body.guideId = options.guideId;
|
|
137
|
+
}
|
|
138
|
+
return settings;
|
|
139
|
+
};
|
|
140
|
+
const getListType = (state) => {
|
|
141
|
+
if ((state == null ? void 0 : state.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching") {
|
|
142
|
+
return ConversationMessageListItemType.LinkList;
|
|
143
|
+
} else if ((state == null ? void 0 : state.$type) === "Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching") {
|
|
144
|
+
return CustomMessageTypes.FeedbackList;
|
|
145
|
+
} else if ((state == null ? void 0 : state.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching") {
|
|
146
|
+
return CustomMessageTypes.ContactList;
|
|
147
|
+
} else
|
|
148
|
+
return ConversationMessageListItemType.ButtonList;
|
|
149
|
+
};
|
|
150
|
+
const getKnowledgeBotEndpoint = (container, component) => {
|
|
151
|
+
const { knowledgeBotEndpoint } = component.properties();
|
|
152
|
+
if (knowledgeBotEndpoint) {
|
|
153
|
+
return `${knowledgeBotEndpoint}/conversations`;
|
|
154
|
+
}
|
|
155
|
+
const { data } = container.get("$settings");
|
|
156
|
+
if (!data || !data.projection)
|
|
157
|
+
throw new Error("Missing Knowledge Bot endpoint");
|
|
158
|
+
return `${data.projection}/conversations`;
|
|
159
|
+
};
|
|
160
|
+
const updateForm = (contactMethod, {
|
|
161
|
+
submit,
|
|
162
|
+
errors,
|
|
163
|
+
meta
|
|
164
|
+
}) => {
|
|
165
|
+
var _a;
|
|
166
|
+
if ((_a = contactMethod == null ? void 0 : contactMethod.body) == null ? void 0 : _a.form) {
|
|
167
|
+
const { body } = contactMethod;
|
|
168
|
+
const builder = new FormBuilder(body.form);
|
|
169
|
+
if (!body.form.layout.submit) {
|
|
170
|
+
builder.createComponent(submitButton(submit, "submit"));
|
|
171
|
+
}
|
|
172
|
+
if (errors) {
|
|
173
|
+
builder.setValidationErrors(errors);
|
|
174
|
+
}
|
|
175
|
+
if (meta) {
|
|
176
|
+
builder.setMeta(meta);
|
|
177
|
+
}
|
|
178
|
+
return __spreadProps(__spreadValues({}, body), {
|
|
179
|
+
form: builder.get()
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return (contactMethod == null ? void 0 : contactMethod.body) || {};
|
|
183
|
+
};
|
|
184
|
+
const createGroupItem = ({
|
|
185
|
+
messageId,
|
|
186
|
+
message,
|
|
187
|
+
group
|
|
188
|
+
}) => {
|
|
189
|
+
return {
|
|
190
|
+
id: messageId,
|
|
191
|
+
message,
|
|
192
|
+
groupId: group.id,
|
|
193
|
+
isUser: group.isUser
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
const processEntries = (entries, prevGroup) => __async(this, null, function* () {
|
|
197
|
+
const createListContent = (listType, entry, groupId, listContent = {
|
|
198
|
+
actions: [],
|
|
199
|
+
entryId: entry.id,
|
|
200
|
+
groupId
|
|
201
|
+
}) => {
|
|
202
|
+
const contactMethodIds = [];
|
|
203
|
+
listContent.actions = entry.content.items.map((i) => {
|
|
204
|
+
var _a;
|
|
205
|
+
const action = {
|
|
206
|
+
label: i.title,
|
|
207
|
+
actionKey: i.actionKey
|
|
208
|
+
};
|
|
209
|
+
if (i.data) {
|
|
210
|
+
const entryAction = entry.actions[i.actionKey];
|
|
211
|
+
if (listType === CustomMessageTypes.ContactList) {
|
|
212
|
+
contactMethodIds.push(i.data.id);
|
|
213
|
+
action.data = contactMethodFromLegacy(i.data, {
|
|
214
|
+
guideId: (_a = entryAction == null ? void 0 : entryAction.guideId) == null ? void 0 : _a.toString()
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
action.data = i.data;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return action;
|
|
221
|
+
});
|
|
222
|
+
if (listType === CustomMessageTypes.ContactList) {
|
|
223
|
+
listContent.contactMethodIds = contactMethodIds;
|
|
224
|
+
}
|
|
225
|
+
return listContent;
|
|
226
|
+
};
|
|
227
|
+
const transform = (_0, _1, ..._2) => __async(this, [_0, _1, ..._2], function* (entry, group, related = [], prevGroup2) {
|
|
228
|
+
const messageId = uuid();
|
|
229
|
+
switch (entry.type) {
|
|
230
|
+
case "List": {
|
|
231
|
+
const { header, items, html } = entry.content;
|
|
232
|
+
const result2 = [];
|
|
233
|
+
let listContent = {
|
|
234
|
+
actions: [],
|
|
235
|
+
entryId: entry.id,
|
|
236
|
+
groupId: group.id
|
|
237
|
+
};
|
|
238
|
+
if (header) {
|
|
239
|
+
listContent.header = header;
|
|
240
|
+
}
|
|
241
|
+
if ((items == null ? void 0 : items.length) > 0) {
|
|
242
|
+
const listType = getListType(entry.localState);
|
|
243
|
+
listContent = createListContent(listType, entry, group.id, listContent);
|
|
244
|
+
if (!!related.length) {
|
|
245
|
+
const pagingEntry = related.find((e) => e.tags.includes("paging"));
|
|
246
|
+
const fallbackEntry = related.find((e) => e.tags.includes("fallback"));
|
|
247
|
+
if (pagingEntry == null ? void 0 : pagingEntry.content) {
|
|
248
|
+
group.meta.paging = {
|
|
249
|
+
actions: pagingEntry.actions,
|
|
250
|
+
items: pagingEntry.content.items,
|
|
251
|
+
localState: pagingEntry.localState
|
|
252
|
+
};
|
|
253
|
+
pagingEntry.content.items.forEach((i) => {
|
|
254
|
+
listContent.actions.push({
|
|
255
|
+
label: i.title,
|
|
256
|
+
actionKey: i.actionKey,
|
|
257
|
+
data: {
|
|
258
|
+
groupId: !!prevGroup2 ? prevGroup2.id : group.id
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (fallbackEntry) {
|
|
264
|
+
const fallbackAction = fallbackEntry.content.items.find((i) => i.actionKey === "help");
|
|
265
|
+
if (fallbackAction) {
|
|
266
|
+
result2.push(createGroupItem({
|
|
267
|
+
messageId,
|
|
268
|
+
message: [
|
|
269
|
+
ConversationMessageListItemType.Separator,
|
|
270
|
+
void 0
|
|
271
|
+
],
|
|
272
|
+
group
|
|
273
|
+
}));
|
|
274
|
+
result2.push(createGroupItem({
|
|
275
|
+
messageId,
|
|
276
|
+
message: [
|
|
277
|
+
CustomMessageTypes.NoGoodAlternative,
|
|
278
|
+
{ body: fallbackAction.title }
|
|
279
|
+
],
|
|
280
|
+
group
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
result2.unshift(createGroupItem({
|
|
286
|
+
messageId,
|
|
287
|
+
message: [listType, listContent],
|
|
288
|
+
group
|
|
289
|
+
}));
|
|
290
|
+
}
|
|
291
|
+
if (html) {
|
|
292
|
+
result2.unshift(createGroupItem({
|
|
293
|
+
messageId,
|
|
294
|
+
message: [ConversationMessageListItemType.HTML, { body: html }],
|
|
295
|
+
group
|
|
296
|
+
}));
|
|
297
|
+
}
|
|
298
|
+
return result2;
|
|
299
|
+
}
|
|
300
|
+
case "Text": {
|
|
301
|
+
const result2 = [];
|
|
302
|
+
result2.push(createGroupItem({
|
|
303
|
+
messageId,
|
|
304
|
+
message: [
|
|
305
|
+
ConversationMessageListItemType.HTML,
|
|
306
|
+
{ body: entry.content.html }
|
|
307
|
+
],
|
|
308
|
+
group
|
|
309
|
+
}));
|
|
310
|
+
if (!!related.length) {
|
|
311
|
+
const contactMethodListEntry = related.find((e) => {
|
|
312
|
+
var _a;
|
|
313
|
+
return e.type === "List" && ((_a = e.localState) == null ? void 0 : _a.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
|
|
314
|
+
});
|
|
315
|
+
const dialogListEntry = related.find((e) => e.tags.includes("dialog"));
|
|
316
|
+
const feedbackEntry = related.find((e) => e.tags.includes("feedback"));
|
|
317
|
+
if (dialogListEntry) {
|
|
318
|
+
result2.push(createGroupItem({
|
|
319
|
+
messageId,
|
|
320
|
+
message: [
|
|
321
|
+
ConversationMessageListItemType.ButtonList,
|
|
322
|
+
{
|
|
323
|
+
actions: dialogListEntry.content.items.map((i) => {
|
|
324
|
+
return {
|
|
325
|
+
label: i.title,
|
|
326
|
+
actionKey: i.actionKey
|
|
327
|
+
};
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
],
|
|
331
|
+
group
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
if (contactMethodListEntry) {
|
|
335
|
+
const listContent = createListContent(CustomMessageTypes.ContactList, contactMethodListEntry, group.id);
|
|
336
|
+
result2.push(createGroupItem({
|
|
337
|
+
messageId,
|
|
338
|
+
message: [ConversationMessageListItemType.Separator, void 0],
|
|
339
|
+
group
|
|
340
|
+
}));
|
|
341
|
+
result2.push(createGroupItem({
|
|
342
|
+
messageId,
|
|
343
|
+
message: [CustomMessageTypes.ContactList, listContent],
|
|
344
|
+
group
|
|
345
|
+
}));
|
|
346
|
+
}
|
|
347
|
+
if (feedbackEntry) {
|
|
348
|
+
if (feedbackEntry.content.html) {
|
|
349
|
+
result2.push(createGroupItem({
|
|
350
|
+
messageId,
|
|
351
|
+
group,
|
|
352
|
+
message: [
|
|
353
|
+
ConversationMessageListItemType.HTML,
|
|
354
|
+
{
|
|
355
|
+
body: feedbackEntry.content.html
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
}));
|
|
359
|
+
}
|
|
360
|
+
result2.push(createGroupItem({
|
|
361
|
+
messageId,
|
|
362
|
+
group,
|
|
363
|
+
message: [
|
|
364
|
+
CustomMessageTypes.FeedbackList,
|
|
365
|
+
{
|
|
366
|
+
actions: feedbackEntry.content.items.map((i) => {
|
|
367
|
+
return {
|
|
368
|
+
actionKey: i.actionKey,
|
|
369
|
+
label: i.title
|
|
370
|
+
};
|
|
371
|
+
})
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return result2;
|
|
378
|
+
}
|
|
379
|
+
case "Contact": {
|
|
380
|
+
return [
|
|
381
|
+
createGroupItem({
|
|
382
|
+
messageId,
|
|
383
|
+
message: [
|
|
384
|
+
CustomMessageTypes.ContactMethod,
|
|
385
|
+
{
|
|
386
|
+
contactMethodId: entry.content.id,
|
|
387
|
+
groupId: group.id,
|
|
388
|
+
guideId: entry.content.guideId
|
|
389
|
+
}
|
|
390
|
+
],
|
|
391
|
+
group
|
|
392
|
+
})
|
|
393
|
+
];
|
|
394
|
+
}
|
|
395
|
+
case "CategorizedNoticeList": {
|
|
396
|
+
const result2 = [
|
|
397
|
+
createGroupItem({
|
|
398
|
+
messageId,
|
|
399
|
+
message: [
|
|
400
|
+
CustomMessageTypes.NotificationList,
|
|
401
|
+
{
|
|
402
|
+
id: entry.content.item.id.toString(),
|
|
403
|
+
header: entry.content.item.title,
|
|
404
|
+
items: entry.content.item.listNotices,
|
|
405
|
+
symbol: entry.content.item.defaultIcon
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
group
|
|
409
|
+
})
|
|
410
|
+
];
|
|
411
|
+
(entry.content.notices || []).forEach((notice) => {
|
|
412
|
+
result2.push(createGroupItem({
|
|
413
|
+
messageId,
|
|
414
|
+
message: [
|
|
415
|
+
ConversationMessageListItemType.HTML,
|
|
416
|
+
{
|
|
417
|
+
body: notice.body
|
|
418
|
+
}
|
|
419
|
+
],
|
|
420
|
+
group
|
|
421
|
+
}));
|
|
422
|
+
});
|
|
423
|
+
return result2;
|
|
424
|
+
}
|
|
425
|
+
case "footerNotice": {
|
|
426
|
+
return [
|
|
427
|
+
createGroupItem({
|
|
428
|
+
messageId,
|
|
429
|
+
message: [
|
|
430
|
+
ConversationMessageListItemType.HTML,
|
|
431
|
+
{
|
|
432
|
+
body: entry.content.item.body
|
|
433
|
+
}
|
|
434
|
+
],
|
|
435
|
+
group
|
|
436
|
+
})
|
|
437
|
+
];
|
|
438
|
+
}
|
|
439
|
+
case "Error": {
|
|
440
|
+
return [
|
|
441
|
+
createGroupItem({
|
|
442
|
+
messageId,
|
|
443
|
+
message: [
|
|
444
|
+
ConversationMessageListItemType.HTML,
|
|
445
|
+
{
|
|
446
|
+
body: entry.content.message || "Something went wrong."
|
|
447
|
+
}
|
|
448
|
+
],
|
|
449
|
+
group
|
|
450
|
+
})
|
|
451
|
+
];
|
|
452
|
+
}
|
|
453
|
+
default:
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
const splitEntry = (entry) => {
|
|
458
|
+
if (["CategorizedNoticeList", "NoticeList"].includes(entry.type)) {
|
|
459
|
+
return (entry.content.items || []).reduce((acc, item) => {
|
|
460
|
+
if (!entry.content.isInitialNotices) {
|
|
461
|
+
return acc;
|
|
462
|
+
}
|
|
463
|
+
acc.push(__spreadProps(__spreadValues({}, entry), {
|
|
464
|
+
id: uuid(),
|
|
465
|
+
type: item.type || entry.type,
|
|
466
|
+
content: {
|
|
467
|
+
$type: entry.content.$type,
|
|
468
|
+
isInitialNotices: entry.content.isInitialNotices,
|
|
469
|
+
notices: item.notices,
|
|
470
|
+
item
|
|
471
|
+
}
|
|
472
|
+
}));
|
|
473
|
+
return acc;
|
|
474
|
+
}, []);
|
|
475
|
+
}
|
|
476
|
+
return entry;
|
|
477
|
+
};
|
|
478
|
+
const sortMap = /* @__PURE__ */ new Map([
|
|
479
|
+
["Text", 1],
|
|
480
|
+
["List", 2],
|
|
481
|
+
["Contact", 3],
|
|
482
|
+
["CategorizedNoticeList", 10]
|
|
483
|
+
]);
|
|
484
|
+
const result = [];
|
|
485
|
+
const filteredEntries = entries.sort((item, other) => {
|
|
486
|
+
const defaultSortValue = 20;
|
|
487
|
+
var sortValue = sortMap.get(item.type) || defaultSortValue;
|
|
488
|
+
var sortValueOther = sortMap.get(other.type) || defaultSortValue;
|
|
489
|
+
return sortValue - sortValueOther;
|
|
490
|
+
}).filter((entry) => !entry.relation).reduce((acc, entry) => {
|
|
491
|
+
return acc.concat(splitEntry(entry));
|
|
492
|
+
}, []);
|
|
493
|
+
for (const entry of filteredEntries) {
|
|
494
|
+
const relatedEntries = entries.filter((other) => other.relation === entry.id);
|
|
495
|
+
const group = createGroup({ isUser: false });
|
|
496
|
+
const items = yield transform(entry, group, relatedEntries, prevGroup);
|
|
497
|
+
items.forEach((item) => {
|
|
498
|
+
group.items.push(item);
|
|
499
|
+
});
|
|
500
|
+
if (group.items.length) {
|
|
501
|
+
result.push(group);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return result;
|
|
505
|
+
});
|
|
506
|
+
class HttpClient {
|
|
507
|
+
constructor(endpoint, events, store, container) {
|
|
508
|
+
this.endpoint = endpoint;
|
|
509
|
+
this.events = events;
|
|
510
|
+
this.store = store;
|
|
511
|
+
this.container = container;
|
|
512
|
+
this.clientId = uuid();
|
|
513
|
+
this.entries = [];
|
|
514
|
+
}
|
|
515
|
+
start() {
|
|
516
|
+
return __async(this, null, function* () {
|
|
517
|
+
const storedMessages = yield this.store.read();
|
|
518
|
+
if (storedMessages && storedMessages.length > 0) {
|
|
519
|
+
const storedGlobalState = this.store.readGlobalState();
|
|
520
|
+
this.globalState = storedGlobalState;
|
|
521
|
+
return storedMessages;
|
|
522
|
+
} else {
|
|
523
|
+
const envelope = this.createInitialEnvelope();
|
|
524
|
+
const initialResponse = yield this.postEnvelope(envelope);
|
|
525
|
+
return initialResponse;
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
sendMessage(message) {
|
|
530
|
+
return __async(this, null, function* () {
|
|
531
|
+
const envelope = {
|
|
532
|
+
command: { phrase: message },
|
|
533
|
+
globalState: this.globalState,
|
|
534
|
+
clientId: this.clientId
|
|
535
|
+
};
|
|
536
|
+
const result = yield this.postEnvelope(envelope);
|
|
537
|
+
return result;
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
helpAction() {
|
|
541
|
+
return __async(this, null, function* () {
|
|
542
|
+
return this.postEnvelope({
|
|
543
|
+
action: {
|
|
544
|
+
key: "help",
|
|
545
|
+
content: {
|
|
546
|
+
$type: "Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
globalState: this.globalState,
|
|
550
|
+
clientId: this.clientId
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
nextAction(group) {
|
|
555
|
+
return __async(this, null, function* () {
|
|
556
|
+
var _a;
|
|
557
|
+
const { paging } = group.meta;
|
|
558
|
+
if (!((_a = paging.actions) == null ? void 0 : _a.next)) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
return this.postEnvelope({
|
|
562
|
+
action: {
|
|
563
|
+
key: "next",
|
|
564
|
+
content: paging.actions.next
|
|
565
|
+
},
|
|
566
|
+
localState: paging.localState,
|
|
567
|
+
globalState: this.globalState,
|
|
568
|
+
clientId: this.clientId
|
|
569
|
+
}, group).then((response) => {
|
|
570
|
+
const listItemIndex = group.items.findIndex((item) => item.message[0] === "link-list");
|
|
571
|
+
if (listItemIndex === -1 || !response) {
|
|
572
|
+
return group;
|
|
573
|
+
}
|
|
574
|
+
return __spreadProps(__spreadValues({}, group), {
|
|
575
|
+
meta: __spreadValues(__spreadValues({}, group.meta), response[0].meta),
|
|
576
|
+
items: [
|
|
577
|
+
...group.items.slice(0, listItemIndex),
|
|
578
|
+
__spreadProps(__spreadValues({}, group.items[listItemIndex]), {
|
|
579
|
+
message: [
|
|
580
|
+
response[0].items[0].message[0],
|
|
581
|
+
__spreadValues(__spreadValues({}, group.items[listItemIndex].message[1]), response[0].items[0].message[1])
|
|
582
|
+
]
|
|
583
|
+
}),
|
|
584
|
+
...group.items.slice(listItemIndex + 1)
|
|
585
|
+
]
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
showContactMethodAction(data) {
|
|
591
|
+
return __async(this, null, function* () {
|
|
592
|
+
const entry = this.entries.find((e) => e.id === data.entryId);
|
|
593
|
+
const actionItem = entry == null ? void 0 : entry.actions[data.actionKey];
|
|
594
|
+
if (!actionItem) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
return this.postEnvelope({
|
|
598
|
+
action: {
|
|
599
|
+
key: data.actionKey,
|
|
600
|
+
content: actionItem
|
|
601
|
+
},
|
|
602
|
+
localState: entry.localState,
|
|
603
|
+
globalState: this.globalState,
|
|
604
|
+
clientId: this.clientId
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
defaultAction(action) {
|
|
609
|
+
return __async(this, null, function* () {
|
|
610
|
+
const entry = this.getEntryOfAction(action);
|
|
611
|
+
if (!entry) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
return this.postEnvelope({
|
|
615
|
+
action: {
|
|
616
|
+
key: action,
|
|
617
|
+
content: entry.actions[action]
|
|
618
|
+
},
|
|
619
|
+
localState: entry.localState,
|
|
620
|
+
globalState: this.globalState,
|
|
621
|
+
clientId: this.clientId
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
createInitialEnvelope() {
|
|
626
|
+
return {
|
|
627
|
+
command: { site: this.endpoint },
|
|
628
|
+
clientId: this.clientId,
|
|
629
|
+
globalState: {}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
postEnvelope(envelope, prevGroup) {
|
|
633
|
+
return __async(this, null, function* () {
|
|
634
|
+
try {
|
|
635
|
+
const response = yield fetch(this.endpoint, this.getHttpOptions(envelope));
|
|
636
|
+
if (!response.ok) {
|
|
637
|
+
throw response;
|
|
638
|
+
}
|
|
639
|
+
const data = yield response.json();
|
|
640
|
+
return this.handleResponse(data, prevGroup);
|
|
641
|
+
} catch (error) {
|
|
642
|
+
let message = "Something went wrong";
|
|
643
|
+
if (error.message === "Failed to fetch") {
|
|
644
|
+
message = "Lost connection... Please try again.";
|
|
645
|
+
}
|
|
646
|
+
return this.handleResponse({
|
|
647
|
+
entries: [
|
|
648
|
+
{
|
|
649
|
+
id: uuid(),
|
|
650
|
+
type: "Error",
|
|
651
|
+
timestamp: new Date().toISOString(),
|
|
652
|
+
content: {
|
|
653
|
+
message
|
|
654
|
+
},
|
|
655
|
+
actions: {},
|
|
656
|
+
tags: []
|
|
657
|
+
}
|
|
658
|
+
]
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
handleResponse(data, prevGroup) {
|
|
664
|
+
return __async(this, null, function* () {
|
|
665
|
+
this.entries = this.entries.concat(data.entries);
|
|
666
|
+
const widgetEntry = data.entries.find((e) => e.type === "Widget");
|
|
667
|
+
if (widgetEntry) {
|
|
668
|
+
this.events.dispatch("provider:widget-entry", widgetEntry.content);
|
|
669
|
+
}
|
|
670
|
+
if (data.globalState) {
|
|
671
|
+
this.globalState = data.globalState;
|
|
672
|
+
}
|
|
673
|
+
const groups = yield processEntries(data.entries, prevGroup);
|
|
674
|
+
return groups;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
getHttpOptions(envelope) {
|
|
678
|
+
const fetchOptions = {
|
|
679
|
+
method: "POST",
|
|
680
|
+
headers: {
|
|
681
|
+
Accept: "application/json",
|
|
682
|
+
"Content-Type": "application/json"
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
return Object.assign({}, fetchOptions, {
|
|
686
|
+
body: JSON.stringify(envelope),
|
|
687
|
+
credentials: "same-origin"
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
getEntryOfAction(action) {
|
|
691
|
+
return this.entries.find((entry) => !!entry.actions[action]);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
class Store {
|
|
695
|
+
constructor(container) {
|
|
696
|
+
this.container = container;
|
|
697
|
+
this.enabled = false;
|
|
698
|
+
this.sessionMessageStorageVariable = "knowledge-bot-messages";
|
|
699
|
+
this.botProviderGlobalStateKey = "bot-provider-global-state";
|
|
700
|
+
this.botProviderMetaStateKey = "bot-provider-conversation-meta";
|
|
701
|
+
}
|
|
702
|
+
readGlobalState() {
|
|
703
|
+
return __async(this, null, function* () {
|
|
704
|
+
if (!this.enabled) {
|
|
705
|
+
return void 0;
|
|
706
|
+
}
|
|
707
|
+
const state = yield readStorage(this.container, this.botProviderGlobalStateKey);
|
|
708
|
+
return state;
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
readMetaState() {
|
|
712
|
+
return __async(this, null, function* () {
|
|
713
|
+
if (!this.enabled) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
return readStorage(this.container, this.botProviderMetaStateKey);
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
write(groups) {
|
|
720
|
+
return __async(this, null, function* () {
|
|
721
|
+
if (!this.enabled) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
return createStorageWriter(this.container, this.sessionMessageStorageVariable, StorageCategory.Necessary).then((write) => {
|
|
725
|
+
return write(groups);
|
|
726
|
+
});
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
read() {
|
|
730
|
+
return __async(this, null, function* () {
|
|
731
|
+
if (!this.enabled) {
|
|
732
|
+
return [];
|
|
733
|
+
}
|
|
734
|
+
return readStorage(this.container, this.sessionMessageStorageVariable).then((groups) => {
|
|
735
|
+
return groups || [];
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
class KnowledgeBotProvider {
|
|
741
|
+
constructor(container, conversation, component) {
|
|
742
|
+
this.container = container;
|
|
743
|
+
this.conversation = conversation;
|
|
744
|
+
this.groups = [];
|
|
745
|
+
const { events } = this.container.get("$widget");
|
|
746
|
+
this.events = events;
|
|
747
|
+
this.store = new Store(container);
|
|
748
|
+
this.agent = conversation.createAgent({
|
|
749
|
+
name: "",
|
|
750
|
+
avatar: void 0
|
|
751
|
+
});
|
|
752
|
+
this.user = conversation.user;
|
|
753
|
+
const endpoint = getKnowledgeBotEndpoint(container, component);
|
|
754
|
+
this.httpClient = new HttpClient(endpoint, events, this.store, this.container);
|
|
755
|
+
this.events.subscribe("provider:widget-entry", (_event, data) => {
|
|
756
|
+
this.onWidgetEntryReceived(data);
|
|
757
|
+
});
|
|
758
|
+
this.events.subscribe("provider:open-contact-method", (_event, data) => __async(this, null, function* () {
|
|
759
|
+
const response = yield this.httpClient.showContactMethodAction(data);
|
|
760
|
+
if (response) {
|
|
761
|
+
if (!!data.contactMethod.title)
|
|
762
|
+
this.printUserMessage(data.contactMethod.title);
|
|
763
|
+
this.onMessagesReceived(response);
|
|
764
|
+
}
|
|
765
|
+
}));
|
|
766
|
+
}
|
|
767
|
+
initialize() {
|
|
768
|
+
return __async(this, null, function* () {
|
|
769
|
+
const loader = this.conversation.loading();
|
|
770
|
+
const storedMeta = yield this.store.readMetaState();
|
|
771
|
+
if (storedMeta == null ? void 0 : storedMeta.agent) {
|
|
772
|
+
this.agent.update({
|
|
773
|
+
name: storedMeta.agent.name,
|
|
774
|
+
avatar: storedMeta.agent.avatar
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
const response = yield this.httpClient.start();
|
|
778
|
+
if (response) {
|
|
779
|
+
this.onMessagesReceived(response);
|
|
780
|
+
}
|
|
781
|
+
loader();
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
onMessagesReceived(groups) {
|
|
785
|
+
return __async(this, null, function* () {
|
|
786
|
+
this.groups = this.groups.concat(groups);
|
|
787
|
+
yield this.store.write(this.groups);
|
|
788
|
+
groups.forEach((group) => {
|
|
789
|
+
const items = group.items.map((item) => item.message);
|
|
790
|
+
if (group.isUser) {
|
|
791
|
+
group.writer = this.user.print(items);
|
|
792
|
+
} else {
|
|
793
|
+
group.writer = this.agent.print(items);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
onInput(action) {
|
|
799
|
+
return __async(this, null, function* () {
|
|
800
|
+
const actionKey = typeof action === "string" ? action : action.actionKey;
|
|
801
|
+
switch (actionKey) {
|
|
802
|
+
case "next":
|
|
803
|
+
{
|
|
804
|
+
if (typeof action === "string") {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
const group = this.groups.find((other) => {
|
|
808
|
+
var _a;
|
|
809
|
+
return other.id === ((_a = action.data) == null ? void 0 : _a.groupId);
|
|
810
|
+
});
|
|
811
|
+
if (group) {
|
|
812
|
+
const response = yield this.httpClient.nextAction(group);
|
|
813
|
+
if (response) {
|
|
814
|
+
const combined = response.items.map((item) => item.message);
|
|
815
|
+
group.meta.paging = response == null ? void 0 : response.meta.paging;
|
|
816
|
+
group.writer.update(combined);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
break;
|
|
821
|
+
case "help":
|
|
822
|
+
{
|
|
823
|
+
const loader = this.conversation.loading();
|
|
824
|
+
const response = yield this.httpClient.helpAction();
|
|
825
|
+
loader();
|
|
826
|
+
if (response) {
|
|
827
|
+
this.onMessagesReceived(response);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
break;
|
|
831
|
+
default:
|
|
832
|
+
{
|
|
833
|
+
if (typeof action !== "string" && action.label) {
|
|
834
|
+
this.printUserMessage(action.label);
|
|
835
|
+
}
|
|
836
|
+
const loader = this.conversation.loading();
|
|
837
|
+
const response = yield this.httpClient.defaultAction(actionKey);
|
|
838
|
+
if (response) {
|
|
839
|
+
this.onMessagesReceived(response);
|
|
840
|
+
}
|
|
841
|
+
loader();
|
|
842
|
+
}
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
printUserMessage(message) {
|
|
848
|
+
const group = createGroup({
|
|
849
|
+
isUser: true,
|
|
850
|
+
items: [
|
|
851
|
+
{
|
|
852
|
+
id: uuid(),
|
|
853
|
+
isUser: true,
|
|
854
|
+
message: [ConversationMessageListItemType.HTML, { body: message }]
|
|
855
|
+
}
|
|
856
|
+
]
|
|
857
|
+
});
|
|
858
|
+
this.onMessagesReceived([group]);
|
|
859
|
+
return group;
|
|
860
|
+
}
|
|
861
|
+
onMessageSend(message) {
|
|
862
|
+
return __async(this, null, function* () {
|
|
863
|
+
const loader = this.conversation.loading();
|
|
864
|
+
const response = yield this.httpClient.sendMessage(message);
|
|
865
|
+
this.printUserMessage(message);
|
|
866
|
+
if (response) {
|
|
867
|
+
this.onMessagesReceived(response);
|
|
868
|
+
}
|
|
869
|
+
loader();
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
onWidgetEntryReceived(data) {
|
|
873
|
+
return __async(this, null, function* () {
|
|
874
|
+
const agentSettings = {
|
|
875
|
+
name: data.agent.name,
|
|
876
|
+
avatar: data.agent.avatar
|
|
877
|
+
};
|
|
878
|
+
this.agent.update(agentSettings);
|
|
879
|
+
const write = yield createStorageWriter(this.container, "bot-provider-conversation-meta", StorageCategory.Necessary);
|
|
880
|
+
write({
|
|
881
|
+
agent: agentSettings
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
const KnowledgeBotProviderPlugin = (container) => __async(this, null, function* () {
|
|
887
|
+
const platform = yield ConversationPlatform.getInstance(container);
|
|
888
|
+
registerCustomMessageComponent(container, CustomMessageTypes.ContactList, import("./contact-method-list.js"));
|
|
889
|
+
registerCustomMessageComponent(container, CustomMessageTypes.ContactMethod, import("./contact-method.js"));
|
|
890
|
+
registerCustomMessageComponent(container, CustomMessageTypes.NotificationList, import("./notification-list.js"));
|
|
891
|
+
registerCustomMessageComponent(container, CustomMessageTypes.NoGoodAlternative, import("./no-good-alternative.js"));
|
|
892
|
+
registerCustomMessageComponent(container, CustomMessageTypes.FeedbackList, import("./feedback-list.js"));
|
|
893
|
+
platform.registerProvider("ace-knowledge-bot", (conversation, component) => {
|
|
894
|
+
const provider = new KnowledgeBotProvider(container, conversation, component);
|
|
895
|
+
provider.initialize();
|
|
896
|
+
component.actions.watch("conversation.user-submit", (input, next) => {
|
|
897
|
+
provider.onMessageSend(input.text);
|
|
898
|
+
});
|
|
899
|
+
component.actions.watch("conversation.action", (input, next) => {
|
|
900
|
+
provider.onInput(input);
|
|
901
|
+
return next(input);
|
|
902
|
+
});
|
|
903
|
+
component.actions.create("evaluate", (input) => {
|
|
904
|
+
const { events } = container.get("$widget");
|
|
905
|
+
events.dispatch("bot-provider:evaluate", input);
|
|
906
|
+
});
|
|
907
|
+
component.actions.create("submit", (input) => {
|
|
908
|
+
const { events } = container.get("$widget");
|
|
909
|
+
events.dispatch("bot-provider:form-submitted", input);
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
export { KnowledgeBotProviderPlugin as K, updateForm as u };
|
|
914
|
+
//# sourceMappingURL=index2.js.map
|