@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.4 → 0.0.1-alpha.42
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/lib/client/chat.client.d.ts +3 -2
- package/lib/client/chat.client.js +98 -33
- package/lib/client/contact-method.client.d.ts +9 -1
- package/lib/client/contact-method.client.js +48 -32
- package/lib/client/http.client.d.ts +11 -7
- package/lib/client/http.client.js +138 -41
- package/lib/client/middleware.client.d.ts +4 -3
- package/lib/client/middleware.client.js +100 -35
- package/lib/contract/custom-component/contact-method-item.d.ts +1 -0
- package/lib/contract/custom-component/contact-method-item.js +10 -64
- package/lib/contract/custom-component/contact-method-list.js +6 -34
- package/lib/contract/custom-component/contact-method.js +12 -17
- package/lib/contract/enum/server-entry-type.enum.d.ts +3 -2
- package/lib/contract/enum/server-entry-type.enum.js +5 -7
- package/lib/contract/model/conversation-api-model/list.model.js +1 -2
- package/lib/contract/model/conversation-api-model/message.model.js +1 -2
- package/lib/contract/model/http/action.model.js +1 -2
- package/lib/contract/model/http/client-action.model.js +1 -2
- package/lib/contract/model/http/client-envelope.model.js +1 -2
- package/lib/contract/model/http/connect-options.model.js +1 -2
- package/lib/contract/model/http/global-state.model.js +1 -2
- package/lib/contract/model/http/http-client-options.model.js +1 -2
- package/lib/contract/model/http/server-entry.model.js +1 -2
- package/lib/contract/model/http/server-envelope.model.js +1 -2
- package/lib/contract/model/middleware/aggregator-state.model.js +1 -2
- package/lib/contract/model/shared/loose-object.model.js +1 -2
- package/lib/helper/chat.helper.js +1 -4
- package/lib/helper/http.helper.d.ts +1 -1
- package/lib/helper/http.helper.js +8 -13
- package/lib/helper/middleware.helper.d.ts +1 -1
- package/lib/helper/middleware.helper.js +7 -11
- package/lib/helper/store.helper.d.ts +4 -3
- package/lib/helper/store.helper.js +105 -16
- package/lib/index.js +2 -8
- package/lib/interface/entry.interface.d.ts +6 -3
- package/lib/interface/entry.interface.js +207 -63
- package/lib/interface/middleware/paging.interface.js +3 -5
- package/lib/interface/middleware/processor.interface.js +2 -4
- package/lib/plugin.d.ts +2 -2
- package/lib/plugin.js +73 -90
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +79 -0
- package/lib-esm/client/chat.client.d.ts +3 -2
- package/lib-esm/client/chat.client.js +81 -11
- package/lib-esm/client/contact-method.client.d.ts +9 -1
- package/lib-esm/client/contact-method.client.js +28 -6
- package/lib-esm/client/http.client.d.ts +11 -7
- package/lib-esm/client/http.client.js +125 -22
- package/lib-esm/client/middleware.client.d.ts +4 -3
- package/lib-esm/client/middleware.client.js +89 -19
- package/lib-esm/contract/custom-component/contact-method-item.d.ts +1 -0
- package/lib-esm/contract/custom-component/contact-method-item.js +7 -36
- package/lib-esm/contract/custom-component/contact-method-list.js +1 -1
- package/lib-esm/contract/enum/server-entry-type.enum.d.ts +3 -2
- package/lib-esm/contract/enum/server-entry-type.enum.js +3 -2
- package/lib-esm/helper/http.helper.d.ts +1 -1
- package/lib-esm/helper/http.helper.js +7 -9
- package/lib-esm/helper/middleware.helper.d.ts +1 -1
- package/lib-esm/helper/middleware.helper.js +5 -6
- package/lib-esm/helper/store.helper.d.ts +4 -3
- package/lib-esm/helper/store.helper.js +103 -11
- package/lib-esm/interface/entry.interface.d.ts +6 -3
- package/lib-esm/interface/entry.interface.js +191 -45
- package/lib-esm/interface/middleware/processor.interface.js +1 -1
- package/lib-esm/plugin.d.ts +2 -2
- package/lib-esm/plugin.js +66 -55
- package/lib-esm/utils.d.ts +2 -0
- package/lib-esm/utils.js +79 -0
- package/package.json +45 -45
- 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
|
@@ -1,60 +1,196 @@
|
|
|
1
|
-
|
|
2
|
-
Object.
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __values = (this && this.__values) || function(o) {
|
|
49
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
50
|
+
if (m) return m.call(o);
|
|
51
|
+
if (o && typeof o.length === "number") return {
|
|
52
|
+
next: function () {
|
|
53
|
+
if (o && i >= o.length) o = void 0;
|
|
54
|
+
return { value: o && o[i++], done: !o };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
58
|
+
};
|
|
59
|
+
import { DataType } from '@telia-ace/knowledge-widget-types-grid';
|
|
60
|
+
import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation';
|
|
61
|
+
import { ContactMethodClient } from '../client/contact-method.client';
|
|
62
|
+
import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
|
|
63
|
+
import { StoreHelper } from '../helper/store.helper';
|
|
64
|
+
import { contactMethodFromLegacy } from '../utils';
|
|
6
65
|
var EntryInterface = /** @class */ (function () {
|
|
7
|
-
function EntryInterface() {
|
|
66
|
+
function EntryInterface(container) {
|
|
67
|
+
this.container = container;
|
|
8
68
|
this.helpActionKey = 'help';
|
|
9
69
|
this.nextActionKey = 'next';
|
|
10
70
|
}
|
|
11
71
|
// transform the entry based on its type
|
|
12
|
-
EntryInterface.prototype.transform = function (entry) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
72
|
+
EntryInterface.prototype.transform = function (entry, feedbackEntry) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
var entryType, _a;
|
|
75
|
+
var _b;
|
|
76
|
+
return __generator(this, function (_c) {
|
|
77
|
+
switch (_c.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
entryType = ServerEntryTypeEnum[entry.type];
|
|
80
|
+
_a = entryType;
|
|
81
|
+
switch (_a) {
|
|
82
|
+
case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
|
|
83
|
+
case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
|
|
84
|
+
case ServerEntryTypeEnum.Contact: return [3 /*break*/, 3];
|
|
85
|
+
}
|
|
86
|
+
return [3 /*break*/, 5];
|
|
87
|
+
case 1: return [2 /*return*/, {
|
|
88
|
+
id: entry.id,
|
|
89
|
+
message: this.listTransform(entry, feedbackEntry),
|
|
90
|
+
entry: entry,
|
|
91
|
+
isUser: false,
|
|
92
|
+
}];
|
|
93
|
+
case 2: return [2 /*return*/, {
|
|
94
|
+
id: entry.id,
|
|
95
|
+
message: this.textTransform(entry, feedbackEntry),
|
|
96
|
+
entry: entry,
|
|
97
|
+
isUser: false,
|
|
98
|
+
}];
|
|
99
|
+
case 3:
|
|
100
|
+
_b = {
|
|
101
|
+
id: entry.id
|
|
102
|
+
};
|
|
103
|
+
return [4 /*yield*/, this.transformContactMethod(entry)];
|
|
104
|
+
case 4: return [2 /*return*/, (_b.message = _c.sent(),
|
|
105
|
+
_b.entry = entry,
|
|
106
|
+
_b.isUser = false,
|
|
107
|
+
_b)];
|
|
108
|
+
case 5: return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
EntryInterface.prototype.transformContactMethod = function (entry) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var dataClient, contactMethod, cmClient;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
|
|
119
|
+
case 1:
|
|
120
|
+
dataClient = _a.sent();
|
|
121
|
+
return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
|
|
122
|
+
contactMethodId: entry.content.id,
|
|
123
|
+
})];
|
|
124
|
+
case 2:
|
|
125
|
+
contactMethod = _a.sent();
|
|
126
|
+
cmClient = new ContactMethodClient(this.container);
|
|
127
|
+
cmClient.addContactMethod(contactMethod);
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
37
132
|
};
|
|
38
133
|
// transform an array of entries
|
|
39
134
|
EntryInterface.prototype.transformArray = function (entryArray) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var feedbackEntry, returnArray, _a, _b, o, x, e_1_1;
|
|
137
|
+
var e_1, _c;
|
|
138
|
+
return __generator(this, function (_d) {
|
|
139
|
+
switch (_d.label) {
|
|
140
|
+
case 0:
|
|
141
|
+
feedbackEntry = entryArray.find(function (o) {
|
|
142
|
+
return o.tags.find(function (t) { return t == 'gentle' || t == 'feedback'; });
|
|
143
|
+
});
|
|
144
|
+
returnArray = [];
|
|
145
|
+
_d.label = 1;
|
|
146
|
+
case 1:
|
|
147
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
148
|
+
_a = __values(entryArray.filter(function (t) { return t !== feedbackEntry; })), _b = _a.next();
|
|
149
|
+
_d.label = 2;
|
|
150
|
+
case 2:
|
|
151
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
152
|
+
o = _b.value;
|
|
153
|
+
return [4 /*yield*/, this.transform(o, feedbackEntry)];
|
|
154
|
+
case 3:
|
|
155
|
+
x = _d.sent();
|
|
156
|
+
if (!!x)
|
|
157
|
+
returnArray.push(x);
|
|
158
|
+
_d.label = 4;
|
|
159
|
+
case 4:
|
|
160
|
+
_b = _a.next();
|
|
161
|
+
return [3 /*break*/, 2];
|
|
162
|
+
case 5: return [3 /*break*/, 8];
|
|
163
|
+
case 6:
|
|
164
|
+
e_1_1 = _d.sent();
|
|
165
|
+
e_1 = { error: e_1_1 };
|
|
166
|
+
return [3 /*break*/, 8];
|
|
167
|
+
case 7:
|
|
168
|
+
try {
|
|
169
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
170
|
+
}
|
|
171
|
+
finally { if (e_1) throw e_1.error; }
|
|
172
|
+
return [7 /*endfinally*/];
|
|
173
|
+
case 8: return [2 /*return*/, returnArray];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
46
176
|
});
|
|
47
|
-
return returnArray;
|
|
48
177
|
};
|
|
49
178
|
// gets the text that should be printed as a user message on action
|
|
50
179
|
EntryInterface.prototype.getUserMessage = function (action) {
|
|
51
|
-
var entry =
|
|
180
|
+
var entry = StoreHelper.getEntry(action);
|
|
52
181
|
return this.getTitleFromEntry(entry, action);
|
|
53
182
|
};
|
|
54
|
-
EntryInterface.prototype.listTransform = function (entry) {
|
|
183
|
+
EntryInterface.prototype.listTransform = function (entry, feedbackEntry) {
|
|
184
|
+
if (entry.type === 'Contact') {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
55
187
|
if (!entry.content)
|
|
56
|
-
return
|
|
188
|
+
return;
|
|
57
189
|
var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
|
|
190
|
+
if (!!feedbackEntry) {
|
|
191
|
+
var feedbackObject = this.getListActions(feedbackEntry.content.items, this.getContentText(feedbackEntry), feedbackEntry.actions, feedbackEntry.localState);
|
|
192
|
+
return object.concat(feedbackObject);
|
|
193
|
+
}
|
|
58
194
|
return object;
|
|
59
195
|
};
|
|
60
196
|
EntryInterface.prototype.getContentText = function (entry) {
|
|
@@ -63,11 +199,11 @@ var EntryInterface = /** @class */ (function () {
|
|
|
63
199
|
if (entry.content.header)
|
|
64
200
|
return { title: entry.content.header };
|
|
65
201
|
};
|
|
66
|
-
EntryInterface.prototype.textTransform = function (entry) {
|
|
202
|
+
EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
|
|
67
203
|
if (!!entry.content.items)
|
|
68
|
-
return this.listTransform(entry);
|
|
204
|
+
return this.listTransform(entry, feedbackEntry);
|
|
69
205
|
return [
|
|
70
|
-
|
|
206
|
+
ConversationMessageListItemType.HTML,
|
|
71
207
|
{ body: entry.content.html.replace('\n', '') },
|
|
72
208
|
];
|
|
73
209
|
};
|
|
@@ -75,23 +211,27 @@ var EntryInterface = /** @class */ (function () {
|
|
|
75
211
|
var _this = this;
|
|
76
212
|
var list = [];
|
|
77
213
|
var mainListContent = {};
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
214
|
+
var mainListType = this.getListType(state);
|
|
215
|
+
var mainList = [mainListType, { actions: mainListContent }];
|
|
216
|
+
if (mainListType === 'ace-knowledge-contact-method') {
|
|
217
|
+
mainList[1] = __assign(__assign({}, mainList[1]), { contactMethods: items.map(function (item) {
|
|
218
|
+
var formatted = contactMethodFromLegacy(item.data);
|
|
219
|
+
return formatted;
|
|
220
|
+
}) });
|
|
221
|
+
}
|
|
82
222
|
if (text && text.title) {
|
|
83
|
-
list.push([
|
|
223
|
+
list.push([ConversationMessageListItemType.Header, text.title]);
|
|
84
224
|
}
|
|
85
225
|
if (text && text.body) {
|
|
86
|
-
list.push([
|
|
226
|
+
list.push([ConversationMessageListItemType.HTML, { body: text.body }]);
|
|
87
227
|
}
|
|
88
228
|
list.push(mainList);
|
|
89
229
|
items.forEach(function (o) {
|
|
90
230
|
switch (o.actionKey) {
|
|
91
231
|
case _this.helpActionKey: {
|
|
92
|
-
list.push([
|
|
232
|
+
list.push([ConversationMessageListItemType.Separator, undefined]);
|
|
93
233
|
list.push([
|
|
94
|
-
|
|
234
|
+
ConversationMessageListItemType.NoGoodAlternative,
|
|
95
235
|
{ body: o.title },
|
|
96
236
|
]);
|
|
97
237
|
break;
|
|
@@ -99,33 +239,37 @@ var EntryInterface = /** @class */ (function () {
|
|
|
99
239
|
case _this.nextActionKey: {
|
|
100
240
|
if (!!actions['next'] && actions['next'].take === items.length + 1)
|
|
101
241
|
mainListContent[o.actionKey] = o.title;
|
|
102
|
-
// console.log(actions['next'], actions['next'].take, items.length, items.length - 2)
|
|
103
242
|
break;
|
|
104
243
|
}
|
|
105
244
|
default: {
|
|
106
245
|
mainListContent[o.actionKey] = o.title;
|
|
107
|
-
// mainListContent.push(this.getItemObject(o))
|
|
108
246
|
}
|
|
109
247
|
}
|
|
110
248
|
});
|
|
111
249
|
return list;
|
|
112
250
|
};
|
|
113
251
|
EntryInterface.prototype.getListType = function (state) {
|
|
114
|
-
if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
|
|
115
|
-
return
|
|
252
|
+
if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching') {
|
|
253
|
+
return ConversationMessageListItemType.LinkList;
|
|
254
|
+
}
|
|
116
255
|
else if ((state === null || state === void 0 ? void 0 : state.$type) ===
|
|
117
|
-
'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
|
|
118
|
-
return
|
|
256
|
+
'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching') {
|
|
257
|
+
return ConversationMessageListItemType.FeedbackList;
|
|
258
|
+
}
|
|
259
|
+
else if ((state === null || state === void 0 ? void 0 : state.$type) ===
|
|
260
|
+
'Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching') {
|
|
261
|
+
return 'ace-knowledge-contact-method';
|
|
262
|
+
}
|
|
119
263
|
else
|
|
120
|
-
return
|
|
264
|
+
return ConversationMessageListItemType.ButtonList;
|
|
121
265
|
};
|
|
122
266
|
EntryInterface.prototype.getTitleFromEntry = function (entry, action) {
|
|
123
267
|
if (!!entry) {
|
|
124
|
-
var entryType =
|
|
268
|
+
var entryType = ServerEntryTypeEnum[entry.type];
|
|
125
269
|
switch (entryType) {
|
|
126
|
-
case
|
|
270
|
+
case ServerEntryTypeEnum.List:
|
|
127
271
|
return this.getTitleFromList(entry, action);
|
|
128
|
-
case
|
|
272
|
+
case ServerEntryTypeEnum.Text:
|
|
129
273
|
return this.textTransform(entry);
|
|
130
274
|
}
|
|
131
275
|
}
|
|
@@ -135,4 +279,4 @@ var EntryInterface = /** @class */ (function () {
|
|
|
135
279
|
};
|
|
136
280
|
return EntryInterface;
|
|
137
281
|
}());
|
|
138
|
-
|
|
282
|
+
export default EntryInterface;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __assign = (this && this.__assign) || function () {
|
|
3
2
|
__assign = Object.assign || function(t) {
|
|
4
3
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -10,15 +9,14 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
9
|
};
|
|
11
10
|
return __assign.apply(this, arguments);
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
var store_helper_1 = require("../../helper/store.helper");
|
|
12
|
+
import { StoreHelper } from "../../helper/store.helper";
|
|
15
13
|
var PagingInterface = /** @class */ (function () {
|
|
16
14
|
function PagingInterface() {
|
|
17
15
|
}
|
|
18
16
|
PagingInterface.prototype.process = function (entries) {
|
|
19
17
|
var pagingEntry = entries.find(function (e) { return e.tags.indexOf("paging") > -1; });
|
|
20
18
|
if (pagingEntry) {
|
|
21
|
-
var stream =
|
|
19
|
+
var stream = StoreHelper.getEntryStore().filter(function (e) { return e.tags.indexOf("paging") > -1 && e.id === pagingEntry.id; });
|
|
22
20
|
if (stream.length > 0) {
|
|
23
21
|
// Get the paging entry with the highest take count
|
|
24
22
|
var last_1 = stream.reduce(function (acc, entry) {
|
|
@@ -52,4 +50,4 @@ var PagingInterface = /** @class */ (function () {
|
|
|
52
50
|
};
|
|
53
51
|
return PagingInterface;
|
|
54
52
|
}());
|
|
55
|
-
|
|
53
|
+
export default PagingInterface;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
var ProcessorInterface = /** @class */ (function () {
|
|
4
2
|
function ProcessorInterface() {
|
|
5
3
|
}
|
|
@@ -87,7 +85,7 @@ var ProcessorInterface = /** @class */ (function () {
|
|
|
87
85
|
return target.localState;
|
|
88
86
|
};
|
|
89
87
|
entries.forEach(function (entry) {
|
|
90
|
-
if (entry.relation) {
|
|
88
|
+
if (entry.relation && !entry.tags.find(function (o) { return o == 'gentle' || o == 'feedback'; })) {
|
|
91
89
|
var existingEntry = entries.find(function (o) { return o.id == entry.relation; });
|
|
92
90
|
if (existingEntry) {
|
|
93
91
|
var existingIndex = output.indexOf(existingEntry);
|
|
@@ -117,4 +115,4 @@ var ProcessorInterface = /** @class */ (function () {
|
|
|
117
115
|
};
|
|
118
116
|
return ProcessorInterface;
|
|
119
117
|
}());
|
|
120
|
-
|
|
118
|
+
export default ProcessorInterface;
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Container } from '@webprovisions/platform';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const KnowledgeBotProviderPlugin: (container: Container) => Promise<void>;
|
|
3
|
+
export default KnowledgeBotProviderPlugin;
|
package/lib/plugin.js
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -58,107 +34,114 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
58
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
35
|
}
|
|
60
36
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
37
|
+
import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
|
|
38
|
+
import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
|
|
39
|
+
import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
|
|
40
|
+
import { v4 } from 'uuid';
|
|
41
|
+
import ChatClient from './client/chat.client';
|
|
42
|
+
import { ContactMethodClient } from './client/contact-method.client';
|
|
43
|
+
import { HttpClient } from './client/http.client';
|
|
44
|
+
import MiddlewareClient from './client/middleware.client';
|
|
45
|
+
import { getContactMethodEntry } from './utils';
|
|
46
|
+
var getKnowledgeBotEndpoint = function (container, component /*: ComponentNodeController */
|
|
47
|
+
// ComponentNodeController type differs from component passed into registerProvider
|
|
48
|
+
) {
|
|
49
|
+
var knowledgeBotEndpoint = component.properties().knowledgeBotEndpoint;
|
|
50
|
+
if (knowledgeBotEndpoint) {
|
|
51
|
+
return "".concat(knowledgeBotEndpoint, "/conversations");
|
|
67
52
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
finally { if (e) throw e.error; }
|
|
74
|
-
}
|
|
75
|
-
return ar;
|
|
76
|
-
};
|
|
77
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
78
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
|
+
var data = container.get('$settings').data;
|
|
54
|
+
if (!data || !data.projection)
|
|
55
|
+
throw new Error('Missing Knowledge Bot endpoint');
|
|
56
|
+
return "".concat(data.projection, "/conversations");
|
|
79
57
|
};
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var chat_client_1 = __importDefault(require("./client/chat.client"));
|
|
86
|
-
var contact_method_client_1 = require("./client/contact-method.client");
|
|
87
|
-
var http_client_1 = require("./client/http.client");
|
|
88
|
-
var middleware_client_1 = __importDefault(require("./client/middleware.client"));
|
|
89
|
-
var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var platform, contactMethodPlatform, dataClient, compPlatform, _a, component, endpoint;
|
|
91
|
-
return __generator(this, function (_b) {
|
|
92
|
-
switch (_b.label) {
|
|
93
|
-
case 0: return [4 /*yield*/, widget_conversation_1.ConversationPlatform.getInstance(container)];
|
|
58
|
+
var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
+
var dataClient, platform, contactMethodPlatform;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0: return [4 /*yield*/, DataClient.getInstance(container)];
|
|
94
63
|
case 1:
|
|
95
|
-
|
|
96
|
-
return [4 /*yield*/,
|
|
64
|
+
dataClient = _a.sent();
|
|
65
|
+
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
97
66
|
case 2:
|
|
98
|
-
|
|
99
|
-
return [4 /*yield*/,
|
|
67
|
+
platform = _a.sent();
|
|
68
|
+
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
100
69
|
case 3:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
case 4:
|
|
104
|
-
compPlatform = _b.sent();
|
|
105
|
-
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
106
|
-
endpoint = '';
|
|
107
|
-
setTimeout(function () {
|
|
108
|
-
endpoint = component.attributes.properties.knowledgeBotEndpoint;
|
|
109
|
-
});
|
|
70
|
+
contactMethodPlatform = _a.sent();
|
|
71
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
110
72
|
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
111
|
-
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
73
|
+
var endpoint = getKnowledgeBotEndpoint(container, component);
|
|
74
|
+
var clientId = v4();
|
|
75
|
+
var agent = conversation.createAgent({
|
|
76
|
+
name: '',
|
|
77
|
+
avatar: undefined,
|
|
78
|
+
});
|
|
79
|
+
// passes the user and the agent to the Chat Helper
|
|
80
|
+
ChatClient.initialize(conversation.user, agent);
|
|
115
81
|
// passes the conversation provider to the Contact Method Client
|
|
116
|
-
|
|
82
|
+
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
117
83
|
// passes the container and the widget to the Middleware Store
|
|
118
|
-
|
|
84
|
+
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
119
85
|
// executes to decide on what to do on first load
|
|
120
|
-
var httpClient = new
|
|
121
|
-
|
|
86
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
87
|
+
var firstLoader = conversation.loading();
|
|
88
|
+
httpClient.firstHit().then(firstLoader);
|
|
122
89
|
component.actions.create('evaluate', function (input) {
|
|
123
|
-
var cmClient = new
|
|
90
|
+
var cmClient = new ContactMethodClient(container);
|
|
124
91
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
125
92
|
});
|
|
126
93
|
component.actions.create('validate', function (input) {
|
|
127
|
-
var cmClient = new
|
|
94
|
+
var cmClient = new ContactMethodClient(container);
|
|
128
95
|
cmClient.validate(input.form);
|
|
129
96
|
});
|
|
130
97
|
component.actions.create('submit', function (input) {
|
|
131
|
-
var
|
|
98
|
+
var _a;
|
|
99
|
+
if ((_a = input === null || input === void 0 ? void 0 : input.form) === null || _a === void 0 ? void 0 : _a.schema.id) {
|
|
100
|
+
var contactMethodEntry = getContactMethodEntry(input.form.schema.id);
|
|
101
|
+
if (contactMethodEntry) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
var cmClient = new ContactMethodClient(container);
|
|
132
105
|
cmClient.validate(input.form);
|
|
133
106
|
});
|
|
134
107
|
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
135
108
|
return next(input);
|
|
136
109
|
});
|
|
137
110
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
138
|
-
var httpClient = new
|
|
139
|
-
|
|
111
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
112
|
+
var loader = conversation.loading();
|
|
113
|
+
httpClient.handlePhrase(input.text).then(loader);
|
|
140
114
|
return next(input);
|
|
141
115
|
});
|
|
142
116
|
component.actions.watch('conversation.form', function (input, next) {
|
|
143
117
|
return next(input);
|
|
144
118
|
});
|
|
145
119
|
component.actions.watch('conversation.action', function (input, next) {
|
|
146
|
-
var chatClient = new
|
|
147
|
-
var cmClient = new
|
|
148
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
149
|
-
|
|
120
|
+
var chatClient = new ChatClient(container);
|
|
121
|
+
var cmClient = new ContactMethodClient(container);
|
|
122
|
+
// if (input === 'contact' || input.split('/').length > 1) {
|
|
123
|
+
// cmClient.handleContactMethod(input);
|
|
124
|
+
// return next(input);
|
|
125
|
+
// }
|
|
126
|
+
var loader = conversation.loading();
|
|
127
|
+
if (input.split('/').length > 1) {
|
|
128
|
+
cmClient.handleContactMethod(input).then(loader);
|
|
129
|
+
return next(input);
|
|
130
|
+
}
|
|
131
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
132
|
+
if (input == 'burger-clicked') {
|
|
133
|
+
httpClient.handleCategories().then(loader);
|
|
150
134
|
return next(input);
|
|
151
135
|
}
|
|
152
|
-
var middlewareClient = new
|
|
136
|
+
var middlewareClient = new MiddlewareClient(container);
|
|
153
137
|
// this is an update check, as it requires
|
|
154
138
|
// a lot different logic and no user message
|
|
155
139
|
if (middlewareClient.checkForUpdate(input)) {
|
|
156
|
-
|
|
140
|
+
httpClient.handleUpdate(input).then(loader);
|
|
157
141
|
return next(input);
|
|
158
142
|
}
|
|
159
143
|
chatClient.printUserMessageAndStoreIt(input);
|
|
160
|
-
|
|
161
|
-
httpClient.handleInput(input);
|
|
144
|
+
httpClient.handleInput(input).then(loader);
|
|
162
145
|
return next(input);
|
|
163
146
|
});
|
|
164
147
|
});
|
|
@@ -166,4 +149,4 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
166
149
|
}
|
|
167
150
|
});
|
|
168
151
|
}); };
|
|
169
|
-
|
|
152
|
+
export default KnowledgeBotProviderPlugin;
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const getContactMethodEntry: (contactMethodId: string) => import("./contract/model/http/server-entry.model").ServerEntry | undefined;
|
|
2
|
+
export declare const contactMethodFromLegacy: ({ id, title, defaultIcon, exits: [exit], exitType, confirmationText, expandFormAutomatically, form, description, }: any, validation?: any) => any;
|