@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.38 → 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 +1 -1
- package/lib/client/chat.client.js +75 -9
- package/lib/client/contact-method.client.d.ts +5 -0
- package/lib/client/contact-method.client.js +10 -0
- package/lib/client/http.client.d.ts +7 -4
- package/lib/client/http.client.js +116 -18
- package/lib/client/middleware.client.js +21 -11
- package/lib/contract/custom-component/contact-method.js +0 -1
- package/lib/helper/middleware.helper.js +3 -4
- package/lib/helper/store.helper.d.ts +4 -3
- package/lib/helper/store.helper.js +103 -11
- package/lib/interface/entry.interface.js +8 -14
- package/lib/plugin.js +21 -7
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +5 -0
- package/lib-esm/client/chat.client.d.ts +1 -1
- package/lib-esm/client/chat.client.js +75 -9
- package/lib-esm/client/contact-method.client.d.ts +5 -0
- package/lib-esm/client/contact-method.client.js +10 -0
- package/lib-esm/client/http.client.d.ts +7 -4
- package/lib-esm/client/http.client.js +116 -18
- package/lib-esm/client/middleware.client.js +21 -11
- package/lib-esm/contract/custom-component/contact-method.js +0 -1
- package/lib-esm/helper/middleware.helper.js +3 -4
- 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.js +8 -14
- package/lib-esm/plugin.js +21 -7
- package/lib-esm/utils.d.ts +1 -0
- package/lib-esm/utils.js +5 -0
- package/package.json +5 -5
|
@@ -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
|
}());
|
|
@@ -46,7 +46,8 @@ var __values = (this && this.__values) || function(o) {
|
|
|
46
46
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
47
|
};
|
|
48
48
|
import { DataType } from '@telia-ace/knowledge-widget-types-grid';
|
|
49
|
-
import { ConversationMessageListItemType } from '@telia-ace/widget-conversation';
|
|
49
|
+
import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation';
|
|
50
|
+
import { ContactMethodClient } from '../client/contact-method.client';
|
|
50
51
|
import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
|
|
51
52
|
import { StoreHelper } from '../helper/store.helper';
|
|
52
53
|
var EntryInterface = /** @class */ (function () {
|
|
@@ -106,26 +107,20 @@ var EntryInterface = /** @class */ (function () {
|
|
|
106
107
|
};
|
|
107
108
|
EntryInterface.prototype.transformContactMethod = function (entry) {
|
|
108
109
|
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
-
var dataClient,
|
|
110
|
+
var dataClient, contactMethod, cmClient;
|
|
110
111
|
return __generator(this, function (_a) {
|
|
111
112
|
switch (_a.label) {
|
|
112
113
|
case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
|
|
113
114
|
case 1:
|
|
114
115
|
dataClient = _a.sent();
|
|
115
|
-
contactMethods = [];
|
|
116
116
|
return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
|
|
117
117
|
contactMethodId: entry.content.id,
|
|
118
118
|
})];
|
|
119
119
|
case 2:
|
|
120
120
|
contactMethod = _a.sent();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
return [2 /*return*/, {
|
|
126
|
-
type: 'ace-knowledge-contact-method',
|
|
127
|
-
contactMethods: contactMethods,
|
|
128
|
-
}];
|
|
121
|
+
cmClient = new ContactMethodClient(this.container);
|
|
122
|
+
cmClient.addContactMethod(contactMethod);
|
|
123
|
+
return [2 /*return*/];
|
|
129
124
|
}
|
|
130
125
|
});
|
|
131
126
|
});
|
|
@@ -179,11 +174,10 @@ var EntryInterface = /** @class */ (function () {
|
|
|
179
174
|
};
|
|
180
175
|
EntryInterface.prototype.listTransform = function (entry) {
|
|
181
176
|
if (entry.type === 'Contact') {
|
|
182
|
-
|
|
183
|
-
return undefined;
|
|
177
|
+
return;
|
|
184
178
|
}
|
|
185
179
|
if (!entry.content)
|
|
186
|
-
return
|
|
180
|
+
return;
|
|
187
181
|
var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
|
|
188
182
|
return object;
|
|
189
183
|
};
|
package/lib-esm/plugin.js
CHANGED
|
@@ -36,12 +36,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
|
|
38
38
|
import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
|
|
39
|
-
import { ConversationPlatform, registerCustomMessageComponent } from '@telia-ace/widget-conversation';
|
|
39
|
+
import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
|
|
40
40
|
import { v4 } from 'uuid';
|
|
41
41
|
import ChatClient from './client/chat.client';
|
|
42
42
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
43
43
|
import { HttpClient } from './client/http.client';
|
|
44
44
|
import MiddlewareClient from './client/middleware.client';
|
|
45
|
+
import { getContactMethodEntry } from './utils';
|
|
45
46
|
var getKnowledgeBotEndpoint = function (container, component /*: ComponentNodeController */
|
|
46
47
|
// ComponentNodeController type differs from component passed into registerProvider
|
|
47
48
|
) {
|
|
@@ -83,7 +84,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
83
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
84
85
|
// executes to decide on what to do on first load
|
|
85
86
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
86
|
-
|
|
87
|
+
var firstLoader = conversation.loading();
|
|
88
|
+
httpClient.firstHit().then(firstLoader);
|
|
87
89
|
component.actions.create('evaluate', function (input) {
|
|
88
90
|
var cmClient = new ContactMethodClient(container);
|
|
89
91
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
@@ -93,6 +95,12 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
93
95
|
cmClient.validate(input.form);
|
|
94
96
|
});
|
|
95
97
|
component.actions.create('submit', function (input) {
|
|
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
|
+
}
|
|
96
104
|
var cmClient = new ContactMethodClient(container);
|
|
97
105
|
cmClient.validate(input.form);
|
|
98
106
|
});
|
|
@@ -101,7 +109,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
101
109
|
});
|
|
102
110
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
103
111
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
104
|
-
|
|
112
|
+
var loader = conversation.loading();
|
|
113
|
+
httpClient.handlePhrase(input.text).then(loader);
|
|
105
114
|
return next(input);
|
|
106
115
|
});
|
|
107
116
|
component.actions.watch('conversation.form', function (input, next) {
|
|
@@ -114,20 +123,25 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
114
123
|
// cmClient.handleContactMethod(input);
|
|
115
124
|
// return next(input);
|
|
116
125
|
// }
|
|
126
|
+
var loader = conversation.loading();
|
|
117
127
|
if (input.split('/').length > 1) {
|
|
118
|
-
cmClient.handleContactMethod(input);
|
|
128
|
+
cmClient.handleContactMethod(input).then(loader);
|
|
119
129
|
return next(input);
|
|
120
130
|
}
|
|
121
|
-
var middlewareClient = new MiddlewareClient(container);
|
|
122
131
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
132
|
+
if (input == 'burger-clicked') {
|
|
133
|
+
httpClient.handleCategories().then(loader);
|
|
134
|
+
return next(input);
|
|
135
|
+
}
|
|
136
|
+
var middlewareClient = new MiddlewareClient(container);
|
|
123
137
|
// this is an update check, as it requires
|
|
124
138
|
// a lot different logic and no user message
|
|
125
139
|
if (middlewareClient.checkForUpdate(input)) {
|
|
126
|
-
httpClient.handleUpdate(input);
|
|
140
|
+
httpClient.handleUpdate(input).then(loader);
|
|
127
141
|
return next(input);
|
|
128
142
|
}
|
|
129
143
|
chatClient.printUserMessageAndStoreIt(input);
|
|
130
|
-
httpClient.handleInput(input);
|
|
144
|
+
httpClient.handleInput(input).then(loader);
|
|
131
145
|
return next(input);
|
|
132
146
|
});
|
|
133
147
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getContactMethodEntry: (contactMethodId: string) => import("./contract/model/http/server-entry.model").ServerEntry | undefined;
|
package/lib-esm/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/knowledge-widget-bot-provider",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.40",
|
|
4
4
|
"description": "Bot Provider Plugin ACE Knowledge Widgets.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"author": "Telia Company AB",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"typings": "lib/index.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@telia-ace/knowledge-widget-adapters": "^1.0.
|
|
29
|
-
"@telia-ace/knowledge-widget-types-grid": "^1.0.
|
|
28
|
+
"@telia-ace/knowledge-widget-adapters": "^1.0.9",
|
|
29
|
+
"@telia-ace/knowledge-widget-types-grid": "^1.0.9",
|
|
30
30
|
"@telia-ace/knowledge-widget-ui": "^1.0.7",
|
|
31
|
-
"@telia-ace/widget-conversation": "^1.0.
|
|
31
|
+
"@telia-ace/widget-conversation": "^1.0.8",
|
|
32
32
|
"@telia-ace/widget-forms": "^1.0.6",
|
|
33
33
|
"@telia-ace/widget-services": "^1.0.4",
|
|
34
34
|
"@webprovisions/bootstrapping": "^1.0.12",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/uuid": "^8.3.4"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "d6b4f95adbfce4da6dfc5365a3abbc5624bc4ffa"
|
|
45
45
|
}
|