@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,58 +1,196 @@
|
|
|
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';
|
|
1
60
|
import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation';
|
|
61
|
+
import { ContactMethodClient } from '../client/contact-method.client';
|
|
2
62
|
import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
|
|
3
63
|
import { StoreHelper } from '../helper/store.helper';
|
|
64
|
+
import { contactMethodFromLegacy } from '../utils';
|
|
4
65
|
var EntryInterface = /** @class */ (function () {
|
|
5
|
-
function EntryInterface() {
|
|
66
|
+
function EntryInterface(container) {
|
|
67
|
+
this.container = container;
|
|
6
68
|
this.helpActionKey = 'help';
|
|
7
69
|
this.nextActionKey = 'next';
|
|
8
70
|
}
|
|
9
71
|
// transform the entry based on its type
|
|
10
|
-
EntryInterface.prototype.transform = function (entry) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
});
|
|
35
132
|
};
|
|
36
133
|
// transform an array of entries
|
|
37
134
|
EntryInterface.prototype.transformArray = function (entryArray) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
});
|
|
44
176
|
});
|
|
45
|
-
return returnArray;
|
|
46
177
|
};
|
|
47
178
|
// gets the text that should be printed as a user message on action
|
|
48
179
|
EntryInterface.prototype.getUserMessage = function (action) {
|
|
49
180
|
var entry = StoreHelper.getEntry(action);
|
|
50
181
|
return this.getTitleFromEntry(entry, action);
|
|
51
182
|
};
|
|
52
|
-
EntryInterface.prototype.listTransform = function (entry) {
|
|
183
|
+
EntryInterface.prototype.listTransform = function (entry, feedbackEntry) {
|
|
184
|
+
if (entry.type === 'Contact') {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
53
187
|
if (!entry.content)
|
|
54
|
-
return
|
|
188
|
+
return;
|
|
55
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
|
+
}
|
|
56
194
|
return object;
|
|
57
195
|
};
|
|
58
196
|
EntryInterface.prototype.getContentText = function (entry) {
|
|
@@ -61,9 +199,9 @@ var EntryInterface = /** @class */ (function () {
|
|
|
61
199
|
if (entry.content.header)
|
|
62
200
|
return { title: entry.content.header };
|
|
63
201
|
};
|
|
64
|
-
EntryInterface.prototype.textTransform = function (entry) {
|
|
202
|
+
EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
|
|
65
203
|
if (!!entry.content.items)
|
|
66
|
-
return this.listTransform(entry);
|
|
204
|
+
return this.listTransform(entry, feedbackEntry);
|
|
67
205
|
return [
|
|
68
206
|
ConversationMessageListItemType.HTML,
|
|
69
207
|
{ body: entry.content.html.replace('\n', '') },
|
|
@@ -73,10 +211,14 @@ var EntryInterface = /** @class */ (function () {
|
|
|
73
211
|
var _this = this;
|
|
74
212
|
var list = [];
|
|
75
213
|
var mainListContent = {};
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
}
|
|
80
222
|
if (text && text.title) {
|
|
81
223
|
list.push([ConversationMessageListItemType.Header, text.title]);
|
|
82
224
|
}
|
|
@@ -97,23 +239,27 @@ var EntryInterface = /** @class */ (function () {
|
|
|
97
239
|
case _this.nextActionKey: {
|
|
98
240
|
if (!!actions['next'] && actions['next'].take === items.length + 1)
|
|
99
241
|
mainListContent[o.actionKey] = o.title;
|
|
100
|
-
// console.log(actions['next'], actions['next'].take, items.length, items.length - 2)
|
|
101
242
|
break;
|
|
102
243
|
}
|
|
103
244
|
default: {
|
|
104
245
|
mainListContent[o.actionKey] = o.title;
|
|
105
|
-
// mainListContent.push(this.getItemObject(o))
|
|
106
246
|
}
|
|
107
247
|
}
|
|
108
248
|
});
|
|
109
249
|
return list;
|
|
110
250
|
};
|
|
111
251
|
EntryInterface.prototype.getListType = function (state) {
|
|
112
|
-
if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
|
|
252
|
+
if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching') {
|
|
113
253
|
return ConversationMessageListItemType.LinkList;
|
|
254
|
+
}
|
|
114
255
|
else if ((state === null || state === void 0 ? void 0 : state.$type) ===
|
|
115
|
-
'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
|
|
256
|
+
'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching') {
|
|
116
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
|
+
}
|
|
117
263
|
else
|
|
118
264
|
return ConversationMessageListItemType.ButtonList;
|
|
119
265
|
};
|
|
@@ -85,7 +85,7 @@ var ProcessorInterface = /** @class */ (function () {
|
|
|
85
85
|
return target.localState;
|
|
86
86
|
};
|
|
87
87
|
entries.forEach(function (entry) {
|
|
88
|
-
if (entry.relation) {
|
|
88
|
+
if (entry.relation && !entry.tags.find(function (o) { return o == 'gentle' || o == 'feedback'; })) {
|
|
89
89
|
var existingEntry = entries.find(function (o) { return o.id == entry.relation; });
|
|
90
90
|
if (existingEntry) {
|
|
91
91
|
var existingIndex = output.indexOf(existingEntry);
|
package/lib-esm/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-esm/plugin.js
CHANGED
|
@@ -34,103 +34,114 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
38
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
-
if (!m) return o;
|
|
40
|
-
var i = m.call(o), r, ar = [], e;
|
|
41
|
-
try {
|
|
42
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
-
}
|
|
44
|
-
catch (error) { e = { error: error }; }
|
|
45
|
-
finally {
|
|
46
|
-
try {
|
|
47
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
-
}
|
|
49
|
-
finally { if (e) throw e.error; }
|
|
50
|
-
}
|
|
51
|
-
return ar;
|
|
52
|
-
};
|
|
53
37
|
import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
|
|
54
|
-
import { ComponentPlatform } from '@telia-ace/knowledge-widget-core';
|
|
55
38
|
import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
|
|
56
39
|
import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
|
|
40
|
+
import { v4 } from 'uuid';
|
|
57
41
|
import ChatClient from './client/chat.client';
|
|
58
42
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
59
43
|
import { HttpClient } from './client/http.client';
|
|
60
44
|
import MiddlewareClient from './client/middleware.client';
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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");
|
|
52
|
+
}
|
|
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");
|
|
57
|
+
};
|
|
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)];
|
|
66
63
|
case 1:
|
|
67
|
-
|
|
68
|
-
return [4 /*yield*/,
|
|
64
|
+
dataClient = _a.sent();
|
|
65
|
+
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
69
66
|
case 2:
|
|
70
|
-
|
|
71
|
-
return [4 /*yield*/,
|
|
67
|
+
platform = _a.sent();
|
|
68
|
+
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
72
69
|
case 3:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
case 4:
|
|
76
|
-
compPlatform = _b.sent();
|
|
77
|
-
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
78
|
-
endpoint = '';
|
|
79
|
-
setTimeout(function () {
|
|
80
|
-
endpoint = component.attributes.properties.knowledgeBotEndpoint;
|
|
81
|
-
});
|
|
70
|
+
contactMethodPlatform = _a.sent();
|
|
71
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
82
72
|
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
|
|
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
|
|
86
80
|
ChatClient.initialize(conversation.user, agent);
|
|
87
81
|
// passes the conversation provider to the Contact Method Client
|
|
88
|
-
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
82
|
+
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
89
83
|
// passes the container and the widget to the Middleware Store
|
|
90
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
91
85
|
// executes to decide on what to do on first load
|
|
92
|
-
var httpClient = new HttpClient(endpoint);
|
|
93
|
-
|
|
86
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
87
|
+
var firstLoader = conversation.loading();
|
|
88
|
+
httpClient.firstHit().then(firstLoader);
|
|
94
89
|
component.actions.create('evaluate', function (input) {
|
|
95
|
-
var cmClient = new ContactMethodClient();
|
|
90
|
+
var cmClient = new ContactMethodClient(container);
|
|
96
91
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
97
92
|
});
|
|
98
93
|
component.actions.create('validate', function (input) {
|
|
99
|
-
var cmClient = new ContactMethodClient();
|
|
94
|
+
var cmClient = new ContactMethodClient(container);
|
|
100
95
|
cmClient.validate(input.form);
|
|
101
96
|
});
|
|
102
97
|
component.actions.create('submit', function (input) {
|
|
103
|
-
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);
|
|
104
105
|
cmClient.validate(input.form);
|
|
105
106
|
});
|
|
106
107
|
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
107
108
|
return next(input);
|
|
108
109
|
});
|
|
109
110
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
110
|
-
var httpClient = new HttpClient(endpoint);
|
|
111
|
-
|
|
111
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
112
|
+
var loader = conversation.loading();
|
|
113
|
+
httpClient.handlePhrase(input.text).then(loader);
|
|
112
114
|
return next(input);
|
|
113
115
|
});
|
|
114
116
|
component.actions.watch('conversation.form', function (input, next) {
|
|
115
117
|
return next(input);
|
|
116
118
|
});
|
|
117
119
|
component.actions.watch('conversation.action', function (input, next) {
|
|
118
|
-
var chatClient = new ChatClient();
|
|
119
|
-
var cmClient = new ContactMethodClient();
|
|
120
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
121
|
-
|
|
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);
|
|
122
134
|
return next(input);
|
|
123
135
|
}
|
|
124
|
-
var middlewareClient = new MiddlewareClient();
|
|
136
|
+
var middlewareClient = new MiddlewareClient(container);
|
|
125
137
|
// this is an update check, as it requires
|
|
126
138
|
// a lot different logic and no user message
|
|
127
139
|
if (middlewareClient.checkForUpdate(input)) {
|
|
128
|
-
|
|
140
|
+
httpClient.handleUpdate(input).then(loader);
|
|
129
141
|
return next(input);
|
|
130
142
|
}
|
|
131
143
|
chatClient.printUserMessageAndStoreIt(input);
|
|
132
|
-
|
|
133
|
-
httpClient.handleInput(input);
|
|
144
|
+
httpClient.handleInput(input).then(loader);
|
|
134
145
|
return next(input);
|
|
135
146
|
});
|
|
136
147
|
});
|
|
@@ -138,4 +149,4 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
138
149
|
}
|
|
139
150
|
});
|
|
140
151
|
}); };
|
|
141
|
-
export default
|
|
152
|
+
export default KnowledgeBotProviderPlugin;
|
|
@@ -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;
|
package/lib-esm/utils.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
import { FormBuilder } from '@telia-ace/widget-forms';
|
|
18
|
+
import { StoreHelper } from './helper/store.helper';
|
|
19
|
+
export var getContactMethodEntry = function (contactMethodId) {
|
|
20
|
+
var entries = StoreHelper.getEntryStore();
|
|
21
|
+
return entries.find(function (e) { return e.content.id === +contactMethodId; });
|
|
22
|
+
};
|
|
23
|
+
var convertLegacySymbol = function (symbol) {
|
|
24
|
+
if (symbol) {
|
|
25
|
+
var type = symbol.type, content = symbol.content;
|
|
26
|
+
if (type && content) {
|
|
27
|
+
return { type: type, content: content };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export var contactMethodFromLegacy = function (_a, validation) {
|
|
32
|
+
var id = _a.id, title = _a.title, defaultIcon = _a.defaultIcon, _b = __read(_a.exits, 1), exit = _b[0], exitType = _a.exitType, confirmationText = _a.confirmationText, expandFormAutomatically = _a.expandFormAutomatically, form = _a.form, description = _a.description;
|
|
33
|
+
var adapter = (exit || { Adapter: {} }).adapter;
|
|
34
|
+
var _c = adapter.clientName, clientName = _c === void 0 ? '' : _c, _d = adapter.settings, adapterSettings = _d === void 0 ? {} : _d, _e = adapter.customClientName, customClientName = _e === void 0 ? '' : _e;
|
|
35
|
+
var settings = {
|
|
36
|
+
id: id.toString(),
|
|
37
|
+
title: title,
|
|
38
|
+
description: description,
|
|
39
|
+
symbol: convertLegacySymbol(defaultIcon),
|
|
40
|
+
clientName: clientName === 'custom.adapter' ? customClientName : clientName,
|
|
41
|
+
expanded: true,
|
|
42
|
+
inline: true,
|
|
43
|
+
body: {},
|
|
44
|
+
};
|
|
45
|
+
if (clientName.indexOf('phone') > -1 || clientName.indexOf('freetext') > -1) {
|
|
46
|
+
var displayTextBeforeClick = adapterSettings.displayTextBeforeClick, textBeforeClick = adapterSettings.textBeforeClick;
|
|
47
|
+
if (displayTextBeforeClick === 'true') {
|
|
48
|
+
settings.expanded = false;
|
|
49
|
+
settings.title = textBeforeClick;
|
|
50
|
+
}
|
|
51
|
+
if (clientName.indexOf('phone.text') > -1) {
|
|
52
|
+
settings.body.phoneNumber = adapterSettings.phoneNumber;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
settings.body.freetext = adapterSettings.freetext;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (clientName.indexOf('chat.popup') > -1 ||
|
|
59
|
+
clientName.indexOf('link') > -1 ||
|
|
60
|
+
(clientName === 'custom.adapter' && exitType === 'custom')) {
|
|
61
|
+
settings.body = adapterSettings;
|
|
62
|
+
settings.body.confirmationFallback = confirmationText;
|
|
63
|
+
}
|
|
64
|
+
if (clientName.indexOf('ace') > -1) {
|
|
65
|
+
settings.body = adapterSettings;
|
|
66
|
+
}
|
|
67
|
+
if (form && form.hasValueComponents) {
|
|
68
|
+
if (validation) {
|
|
69
|
+
settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form, validation).get();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form).get();
|
|
73
|
+
}
|
|
74
|
+
if (!expandFormAutomatically) {
|
|
75
|
+
settings.expanded = settings.inline = false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return settings;
|
|
79
|
+
};
|