@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.4 → 0.0.1-alpha.40
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.js +12 -34
- 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 +176 -57
- package/lib/interface/middleware/paging.interface.js +3 -5
- package/lib/interface/middleware/processor.interface.js +1 -3
- package/lib/plugin.d.ts +2 -2
- package/lib/plugin.js +73 -90
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +5 -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.js +4 -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 +160 -39
- package/lib-esm/plugin.d.ts +2 -2
- package/lib-esm/plugin.js +66 -55
- package/lib-esm/utils.d.ts +1 -0
- package/lib-esm/utils.js +5 -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
|
@@ -2,6 +2,7 @@ export var ServerEntryTypeEnum;
|
|
|
2
2
|
(function (ServerEntryTypeEnum) {
|
|
3
3
|
ServerEntryTypeEnum[ServerEntryTypeEnum["Widget"] = 0] = "Widget";
|
|
4
4
|
ServerEntryTypeEnum[ServerEntryTypeEnum["Text"] = 1] = "Text";
|
|
5
|
-
ServerEntryTypeEnum[ServerEntryTypeEnum["
|
|
6
|
-
ServerEntryTypeEnum[ServerEntryTypeEnum["
|
|
5
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["Contact"] = 2] = "Contact";
|
|
6
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["List"] = 3] = "List";
|
|
7
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["Error"] = 4] = "Error";
|
|
7
8
|
})(ServerEntryTypeEnum || (ServerEntryTypeEnum = {}));
|
|
@@ -5,22 +5,20 @@ var HttpHelper = /** @class */ (function () {
|
|
|
5
5
|
return basePath + path;
|
|
6
6
|
};
|
|
7
7
|
HttpHelper.getCredentials = function () {
|
|
8
|
-
return
|
|
8
|
+
return 'same-origin';
|
|
9
9
|
};
|
|
10
|
-
var _a;
|
|
11
|
-
_a = HttpHelper;
|
|
12
10
|
HttpHelper.fetchOptions = {
|
|
13
|
-
method:
|
|
11
|
+
method: 'POST',
|
|
14
12
|
headers: {
|
|
15
|
-
Accept:
|
|
16
|
-
|
|
13
|
+
Accept: 'application/json',
|
|
14
|
+
'Content-Type': 'application/json',
|
|
17
15
|
},
|
|
18
16
|
};
|
|
19
|
-
HttpHelper.managedSubdomainSuffixes = [
|
|
17
|
+
HttpHelper.managedSubdomainSuffixes = ['stage', 'alpha', 'beta', 'gamma'];
|
|
20
18
|
HttpHelper.parseSubdomain = function (input) {
|
|
21
|
-
var index = input.lastIndexOf(
|
|
19
|
+
var index = input.lastIndexOf('-');
|
|
22
20
|
var lastPart = input.substr(index + 1);
|
|
23
|
-
if (
|
|
21
|
+
if (HttpHelper.managedSubdomainSuffixes.indexOf(lastPart) > -1) {
|
|
24
22
|
return input.substr(0, index);
|
|
25
23
|
}
|
|
26
24
|
return input;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Message } from
|
|
1
|
+
import { Message } from '../contract/model/conversation-api-model/message.model';
|
|
2
2
|
export declare class MiddlewareHelper {
|
|
3
3
|
private static sessionMessageStorageVariable;
|
|
4
4
|
private static container;
|
|
@@ -34,12 +34,12 @@ 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
|
-
import { createStorageWriter, readStorage, StorageCategory } from
|
|
37
|
+
import { createStorageWriter, readStorage, StorageCategory } from '@telia-ace/widget-services';
|
|
38
38
|
var MiddlewareHelper = /** @class */ (function () {
|
|
39
39
|
function MiddlewareHelper() {
|
|
40
40
|
}
|
|
41
41
|
MiddlewareHelper.setContainer = function (container) {
|
|
42
|
-
|
|
42
|
+
MiddlewareHelper.container = container;
|
|
43
43
|
};
|
|
44
44
|
MiddlewareHelper.setWidget = function (widget) {
|
|
45
45
|
this.widget = widget;
|
|
@@ -58,10 +58,9 @@ var MiddlewareHelper = /** @class */ (function () {
|
|
|
58
58
|
MiddlewareHelper.sessionMessageStorageVariable = 'conversation-plugin-messages';
|
|
59
59
|
MiddlewareHelper.setEntrySessionStorage = function (messages) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
60
|
return __generator(_a, function (_b) {
|
|
61
|
-
createStorageWriter(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return [2 /*return*/];
|
|
61
|
+
return [2 /*return*/, createStorageWriter(MiddlewareHelper.container, MiddlewareHelper.sessionMessageStorageVariable, StorageCategory.Necessary).then(function (write) {
|
|
62
|
+
return write(messages);
|
|
63
|
+
})];
|
|
65
64
|
});
|
|
66
65
|
}); };
|
|
67
66
|
return MiddlewareHelper;
|
|
@@ -7,16 +7,17 @@ export declare class StoreHelper {
|
|
|
7
7
|
private static messageStore;
|
|
8
8
|
private static globalState;
|
|
9
9
|
constructor();
|
|
10
|
-
static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): void
|
|
11
|
-
|
|
10
|
+
static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): Promise<void>;
|
|
11
|
+
static insertMessageToStore(message: Message): void;
|
|
12
12
|
private static updateMessageInStore;
|
|
13
13
|
static checkIdInMessageStore(id: string): boolean;
|
|
14
14
|
static getLocalState(action: string): LooseObject | undefined;
|
|
15
15
|
static getGlobalState(): GlobalState;
|
|
16
|
-
static setGlobalState(state: GlobalState): void
|
|
16
|
+
static setGlobalState(state: GlobalState): Promise<void>;
|
|
17
17
|
static getAction(action: string): ClientAction;
|
|
18
18
|
static getCommand(text: string): LooseObject;
|
|
19
19
|
static getEntry(action: string): ServerEntry | undefined;
|
|
20
20
|
static getMessage(id: string): Message | undefined;
|
|
21
21
|
static getEntryStore(): ServerEntry[];
|
|
22
|
+
static rehydrateState(): Promise<void>;
|
|
22
23
|
}
|
|
@@ -1,25 +1,98 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __values = (this && this.__values) || function(o) {
|
|
38
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
39
|
+
if (m) return m.call(o);
|
|
40
|
+
if (o && typeof o.length === "number") return {
|
|
41
|
+
next: function () {
|
|
42
|
+
if (o && i >= o.length) o = void 0;
|
|
43
|
+
return { value: o && o[i++], done: !o };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
|
+
};
|
|
48
|
+
import { createStorageWriter, readStorage, StorageCategory } from '@telia-ace/widget-services';
|
|
1
49
|
import { MiddlewareHelper } from './middleware.helper';
|
|
50
|
+
var botProviderGlobalStateSessionKey = 'bot-provider-global-state';
|
|
2
51
|
var StoreHelper = /** @class */ (function () {
|
|
3
52
|
function StoreHelper() {
|
|
4
53
|
StoreHelper.globalState = {
|
|
5
54
|
completedInteractionsCount: 0,
|
|
6
55
|
lastBotGuide: 0,
|
|
7
|
-
site: '
|
|
56
|
+
site: '',
|
|
8
57
|
invincibleParameters: {},
|
|
9
58
|
};
|
|
10
59
|
}
|
|
11
60
|
StoreHelper.insertOrUpdateMessageArrayStore = function (messageArray, entry) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var _loop_1, this_1, _a, _b, message;
|
|
63
|
+
var e_1, _c;
|
|
64
|
+
return __generator(this, function (_d) {
|
|
65
|
+
switch (_d.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
_loop_1 = function (message) {
|
|
68
|
+
if (!this_1.messageStore.find(function (o) { return o.id == message.id; })) {
|
|
69
|
+
this_1.insertMessageToStore(message);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this_1.updateMessageInStore(message, entry);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
this_1 = this;
|
|
76
|
+
try {
|
|
77
|
+
for (_a = __values(messageArray.filter(function (o) { return !!o; })), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
78
|
+
message = _b.value;
|
|
79
|
+
_loop_1(message);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
+
finally {
|
|
84
|
+
try {
|
|
85
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
86
|
+
}
|
|
87
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
|
+
}
|
|
89
|
+
return [4 /*yield*/, MiddlewareHelper.setEntrySessionStorage(this.messageStore)];
|
|
90
|
+
case 1:
|
|
91
|
+
_d.sent();
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
21
95
|
});
|
|
22
|
-
MiddlewareHelper.setEntrySessionStorage(this.messageStore);
|
|
23
96
|
};
|
|
24
97
|
StoreHelper.insertMessageToStore = function (message) {
|
|
25
98
|
this.messageStore.push(message);
|
|
@@ -41,6 +114,9 @@ var StoreHelper = /** @class */ (function () {
|
|
|
41
114
|
};
|
|
42
115
|
StoreHelper.setGlobalState = function (state) {
|
|
43
116
|
StoreHelper.globalState = state;
|
|
117
|
+
return createStorageWriter(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey, StorageCategory.Necessary).then(function (write) {
|
|
118
|
+
return write(state);
|
|
119
|
+
});
|
|
44
120
|
};
|
|
45
121
|
StoreHelper.getAction = function (action) {
|
|
46
122
|
var entry = this.getEntry(action);
|
|
@@ -71,6 +147,22 @@ var StoreHelper = /** @class */ (function () {
|
|
|
71
147
|
return o.entry;
|
|
72
148
|
});
|
|
73
149
|
};
|
|
150
|
+
StoreHelper.rehydrateState = function () {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var state;
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
switch (_a.label) {
|
|
155
|
+
case 0: return [4 /*yield*/, readStorage(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey)];
|
|
156
|
+
case 1:
|
|
157
|
+
state = _a.sent();
|
|
158
|
+
if (state) {
|
|
159
|
+
this.setGlobalState(state);
|
|
160
|
+
}
|
|
161
|
+
return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
74
166
|
StoreHelper.messageStore = [];
|
|
75
167
|
return StoreHelper;
|
|
76
168
|
}());
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
1
2
|
import { Message } from '../contract/model/conversation-api-model/message.model';
|
|
2
3
|
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
3
4
|
export default class EntryInterface {
|
|
5
|
+
private container;
|
|
4
6
|
private helpActionKey;
|
|
5
7
|
private nextActionKey;
|
|
6
|
-
constructor();
|
|
7
|
-
transform(entry: ServerEntry): Message | undefined
|
|
8
|
-
|
|
8
|
+
constructor(container: Container);
|
|
9
|
+
transform(entry: ServerEntry): Promise<Message | undefined>;
|
|
10
|
+
transformContactMethod(entry: ServerEntry): Promise<any>;
|
|
11
|
+
transformArray(entryArray: ServerEntry[]): Promise<Message[]>;
|
|
9
12
|
getUserMessage(action: string): string | undefined;
|
|
10
13
|
private listTransform;
|
|
11
14
|
private getContentText;
|
|
@@ -1,48 +1,171 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __values = (this && this.__values) || function(o) {
|
|
38
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
39
|
+
if (m) return m.call(o);
|
|
40
|
+
if (o && typeof o.length === "number") return {
|
|
41
|
+
next: function () {
|
|
42
|
+
if (o && i >= o.length) o = void 0;
|
|
43
|
+
return { value: o && o[i++], done: !o };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
|
+
};
|
|
48
|
+
import { DataType } from '@telia-ace/knowledge-widget-types-grid';
|
|
1
49
|
import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation';
|
|
50
|
+
import { ContactMethodClient } from '../client/contact-method.client';
|
|
2
51
|
import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
|
|
3
52
|
import { StoreHelper } from '../helper/store.helper';
|
|
4
53
|
var EntryInterface = /** @class */ (function () {
|
|
5
|
-
function EntryInterface() {
|
|
54
|
+
function EntryInterface(container) {
|
|
55
|
+
this.container = container;
|
|
6
56
|
this.helpActionKey = 'help';
|
|
7
57
|
this.nextActionKey = 'next';
|
|
8
58
|
}
|
|
9
59
|
// transform the entry based on its type
|
|
10
60
|
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
|
-
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var entryType, _a;
|
|
63
|
+
var _b;
|
|
64
|
+
return __generator(this, function (_c) {
|
|
65
|
+
switch (_c.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
entryType = ServerEntryTypeEnum[entry.type];
|
|
68
|
+
_a = entryType;
|
|
69
|
+
switch (_a) {
|
|
70
|
+
case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
|
|
71
|
+
case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
|
|
72
|
+
case ServerEntryTypeEnum.Text: return [3 /*break*/, 3];
|
|
73
|
+
case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
|
|
74
|
+
}
|
|
75
|
+
return [3 /*break*/, 6];
|
|
76
|
+
case 1: return [2 /*return*/, {
|
|
77
|
+
id: entry.id,
|
|
78
|
+
message: this.listTransform(entry),
|
|
79
|
+
entry: entry,
|
|
80
|
+
isUser: false,
|
|
81
|
+
}];
|
|
82
|
+
case 2: return [2 /*return*/, {
|
|
83
|
+
id: entry.id,
|
|
84
|
+
message: this.textTransform(entry),
|
|
85
|
+
entry: entry,
|
|
86
|
+
isUser: false,
|
|
87
|
+
}];
|
|
88
|
+
case 3: return [2 /*return*/, {
|
|
89
|
+
id: entry.id,
|
|
90
|
+
message: this.listTransform(entry),
|
|
91
|
+
entry: entry,
|
|
92
|
+
isUser: false,
|
|
93
|
+
}];
|
|
94
|
+
case 4:
|
|
95
|
+
_b = {
|
|
96
|
+
id: entry.id
|
|
97
|
+
};
|
|
98
|
+
return [4 /*yield*/, this.transformContactMethod(entry)];
|
|
99
|
+
case 5: return [2 /*return*/, (_b.message = _c.sent(),
|
|
100
|
+
_b.entry = entry,
|
|
101
|
+
_b.isUser = false,
|
|
102
|
+
_b)];
|
|
103
|
+
case 6: return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
EntryInterface.prototype.transformContactMethod = function (entry) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var dataClient, contactMethod, cmClient;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
|
|
114
|
+
case 1:
|
|
115
|
+
dataClient = _a.sent();
|
|
116
|
+
return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
|
|
117
|
+
contactMethodId: entry.content.id,
|
|
118
|
+
})];
|
|
119
|
+
case 2:
|
|
120
|
+
contactMethod = _a.sent();
|
|
121
|
+
cmClient = new ContactMethodClient(this.container);
|
|
122
|
+
cmClient.addContactMethod(contactMethod);
|
|
123
|
+
return [2 /*return*/];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
35
127
|
};
|
|
36
128
|
// transform an array of entries
|
|
37
129
|
EntryInterface.prototype.transformArray = function (entryArray) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var returnArray, entryArray_1, entryArray_1_1, o, x, e_1_1;
|
|
132
|
+
var e_1, _a;
|
|
133
|
+
return __generator(this, function (_b) {
|
|
134
|
+
switch (_b.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
returnArray = [];
|
|
137
|
+
_b.label = 1;
|
|
138
|
+
case 1:
|
|
139
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
140
|
+
entryArray_1 = __values(entryArray), entryArray_1_1 = entryArray_1.next();
|
|
141
|
+
_b.label = 2;
|
|
142
|
+
case 2:
|
|
143
|
+
if (!!entryArray_1_1.done) return [3 /*break*/, 5];
|
|
144
|
+
o = entryArray_1_1.value;
|
|
145
|
+
return [4 /*yield*/, this.transform(o)];
|
|
146
|
+
case 3:
|
|
147
|
+
x = _b.sent();
|
|
148
|
+
if (!!x)
|
|
149
|
+
returnArray.push(x);
|
|
150
|
+
_b.label = 4;
|
|
151
|
+
case 4:
|
|
152
|
+
entryArray_1_1 = entryArray_1.next();
|
|
153
|
+
return [3 /*break*/, 2];
|
|
154
|
+
case 5: return [3 /*break*/, 8];
|
|
155
|
+
case 6:
|
|
156
|
+
e_1_1 = _b.sent();
|
|
157
|
+
e_1 = { error: e_1_1 };
|
|
158
|
+
return [3 /*break*/, 8];
|
|
159
|
+
case 7:
|
|
160
|
+
try {
|
|
161
|
+
if (entryArray_1_1 && !entryArray_1_1.done && (_a = entryArray_1.return)) _a.call(entryArray_1);
|
|
162
|
+
}
|
|
163
|
+
finally { if (e_1) throw e_1.error; }
|
|
164
|
+
return [7 /*endfinally*/];
|
|
165
|
+
case 8: return [2 /*return*/, returnArray];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
44
168
|
});
|
|
45
|
-
return returnArray;
|
|
46
169
|
};
|
|
47
170
|
// gets the text that should be printed as a user message on action
|
|
48
171
|
EntryInterface.prototype.getUserMessage = function (action) {
|
|
@@ -50,8 +173,11 @@ var EntryInterface = /** @class */ (function () {
|
|
|
50
173
|
return this.getTitleFromEntry(entry, action);
|
|
51
174
|
};
|
|
52
175
|
EntryInterface.prototype.listTransform = function (entry) {
|
|
176
|
+
if (entry.type === 'Contact') {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
53
179
|
if (!entry.content)
|
|
54
|
-
return
|
|
180
|
+
return;
|
|
55
181
|
var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
|
|
56
182
|
return object;
|
|
57
183
|
};
|
|
@@ -73,10 +199,7 @@ var EntryInterface = /** @class */ (function () {
|
|
|
73
199
|
var _this = this;
|
|
74
200
|
var list = [];
|
|
75
201
|
var mainListContent = {};
|
|
76
|
-
var mainList = [
|
|
77
|
-
this.getListType(state),
|
|
78
|
-
{ actions: mainListContent },
|
|
79
|
-
];
|
|
202
|
+
var mainList = [this.getListType(state), { actions: mainListContent }];
|
|
80
203
|
if (text && text.title) {
|
|
81
204
|
list.push([ConversationMessageListItemType.Header, text.title]);
|
|
82
205
|
}
|
|
@@ -97,12 +220,10 @@ var EntryInterface = /** @class */ (function () {
|
|
|
97
220
|
case _this.nextActionKey: {
|
|
98
221
|
if (!!actions['next'] && actions['next'].take === items.length + 1)
|
|
99
222
|
mainListContent[o.actionKey] = o.title;
|
|
100
|
-
// console.log(actions['next'], actions['next'].take, items.length, items.length - 2)
|
|
101
223
|
break;
|
|
102
224
|
}
|
|
103
225
|
default: {
|
|
104
226
|
mainListContent[o.actionKey] = o.title;
|
|
105
|
-
// mainListContent.push(this.getItemObject(o))
|
|
106
227
|
}
|
|
107
228
|
}
|
|
108
229
|
});
|
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;
|