@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.6 → 0.0.1-alpha.7
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.js +4 -0
- package/lib/client/contact-method.client.js +3 -0
- package/lib/client/http.client.d.ts +4 -4
- package/lib/client/http.client.js +12 -7
- package/lib/client/middleware.client.d.ts +1 -1
- package/lib/client/middleware.client.js +4 -13
- package/lib/plugin.js +7 -5
- package/lib-esm/client/chat.client.js +4 -0
- package/lib-esm/client/contact-method.client.js +3 -0
- package/lib-esm/client/http.client.d.ts +4 -4
- package/lib-esm/client/http.client.js +12 -7
- package/lib-esm/client/middleware.client.d.ts +1 -1
- package/lib-esm/client/middleware.client.js +4 -13
- package/lib-esm/plugin.js +7 -5
- package/package.json +1 -1
|
@@ -12,10 +12,12 @@ var ChatClient = /** @class */ (function () {
|
|
|
12
12
|
function ChatClient() {
|
|
13
13
|
this.entryInterface = new entry_interface_1.default();
|
|
14
14
|
}
|
|
15
|
+
// Initialize from setting the user and agent for the Helper
|
|
15
16
|
ChatClient.initialize = function (user, agent) {
|
|
16
17
|
chat_helper_1.ChatHelper.setUser(user);
|
|
17
18
|
chat_helper_1.ChatHelper.setAgent(agent);
|
|
18
19
|
};
|
|
20
|
+
// function for posting the messages
|
|
19
21
|
ChatClient.prototype.processMessageArrayAndStoreIt = function (messages) {
|
|
20
22
|
var _this = this;
|
|
21
23
|
messages
|
|
@@ -28,6 +30,7 @@ var ChatClient = /** @class */ (function () {
|
|
|
28
30
|
});
|
|
29
31
|
store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore(messages);
|
|
30
32
|
};
|
|
33
|
+
// function for updating current messages
|
|
31
34
|
ChatClient.prototype.updateMessageArrayAndStoreIt = function (messages) {
|
|
32
35
|
var conversationEntry = undefined;
|
|
33
36
|
messages.forEach(function (o) {
|
|
@@ -37,6 +40,7 @@ var ChatClient = /** @class */ (function () {
|
|
|
37
40
|
});
|
|
38
41
|
store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore(messages, conversationEntry);
|
|
39
42
|
};
|
|
43
|
+
// function for posting a message for the user actions, such as button clicks
|
|
40
44
|
ChatClient.prototype.printUserMessageAndStoreIt = function (action) {
|
|
41
45
|
if (action == 'next' || action == 'help')
|
|
42
46
|
return;
|
|
@@ -60,6 +60,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
60
60
|
function ContactMethodClient() {
|
|
61
61
|
var _this = this;
|
|
62
62
|
this.chatClient = new chat_client_1.default();
|
|
63
|
+
// function for handling forms as contact methods
|
|
63
64
|
this.handleNewForm = function (errors, entry) { return __awaiter(_this, void 0, void 0, function () {
|
|
64
65
|
return __generator(this, function (_a) {
|
|
65
66
|
this.updateForm(entry.contactMethods, {
|
|
@@ -74,6 +75,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
74
75
|
return [2 /*return*/];
|
|
75
76
|
});
|
|
76
77
|
}); };
|
|
78
|
+
// function for receiving the contact method based on the input
|
|
77
79
|
this.handleContactMethod = function (input) {
|
|
78
80
|
if (input === void 0) { input = ''; }
|
|
79
81
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -144,6 +146,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
144
146
|
this.contactMethodPlatform = contactMethodPlatform;
|
|
145
147
|
this.agent = agent;
|
|
146
148
|
};
|
|
149
|
+
// validation of the form provided
|
|
147
150
|
ContactMethodClient.prototype.validate = function (form) {
|
|
148
151
|
var _this = this;
|
|
149
152
|
var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == form.schema.id; });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
2
1
|
export declare class HttpClient {
|
|
3
2
|
private endpointUrl;
|
|
4
3
|
private clientId;
|
|
@@ -7,16 +6,17 @@ export declare class HttpClient {
|
|
|
7
6
|
private options;
|
|
8
7
|
private middlewareClient;
|
|
9
8
|
private chatClient;
|
|
10
|
-
constructor(endpoint: string);
|
|
9
|
+
constructor(endpoint: string, clientId: string);
|
|
11
10
|
firstHit(): void;
|
|
12
|
-
handleUpdate(action: string):
|
|
11
|
+
handleUpdate(action: string): void;
|
|
13
12
|
handleInput(action: string): void;
|
|
14
13
|
handlePhrase(phrase: string): void;
|
|
15
14
|
private postAndHandleTheData;
|
|
16
|
-
private
|
|
15
|
+
private postAndHandleTheUpdateData;
|
|
17
16
|
private getHttpOptions;
|
|
18
17
|
private constructInputEnvelope;
|
|
19
18
|
private constructPhraseEnvelope;
|
|
20
19
|
private constructFirstHitEnvelope;
|
|
21
20
|
private handleResponseData;
|
|
21
|
+
private handleUpdateResponseData;
|
|
22
22
|
}
|
|
@@ -10,10 +10,10 @@ var store_helper_1 = require("../helper/store.helper");
|
|
|
10
10
|
var chat_client_1 = __importDefault(require("./chat.client"));
|
|
11
11
|
var middleware_client_1 = __importDefault(require("./middleware.client"));
|
|
12
12
|
var HttpClient = /** @class */ (function () {
|
|
13
|
-
function HttpClient(endpoint) {
|
|
13
|
+
function HttpClient(endpoint, clientId) {
|
|
14
14
|
this.options = {
|
|
15
15
|
credentials: http_helper_1.HttpHelper.getCredentials(),
|
|
16
|
-
clientId:
|
|
16
|
+
clientId: clientId,
|
|
17
17
|
};
|
|
18
18
|
this.apiEndpoint = endpoint;
|
|
19
19
|
this.projectionPath = window.location.href;
|
|
@@ -38,9 +38,10 @@ var HttpClient = /** @class */ (function () {
|
|
|
38
38
|
// for updates, such as paging changes
|
|
39
39
|
HttpClient.prototype.handleUpdate = function (action) {
|
|
40
40
|
var envelope = this.constructInputEnvelope(action);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
this.postAndHandleTheUpdateData(envelope, action);
|
|
42
|
+
// return this.postAndReturnTheData(envelope, action).then((o) => {
|
|
43
|
+
// return o.entries;
|
|
44
|
+
// });
|
|
44
45
|
};
|
|
45
46
|
// for action clicks
|
|
46
47
|
HttpClient.prototype.handleInput = function (action) {
|
|
@@ -65,7 +66,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
65
66
|
})
|
|
66
67
|
.catch(function (err) { return console.log(err); });
|
|
67
68
|
};
|
|
68
|
-
HttpClient.prototype.
|
|
69
|
+
HttpClient.prototype.postAndHandleTheUpdateData = function (envelope, action) {
|
|
70
|
+
var _this = this;
|
|
69
71
|
return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
|
|
70
72
|
.then(function (response) {
|
|
71
73
|
if (response.ok)
|
|
@@ -73,7 +75,7 @@ var HttpClient = /** @class */ (function () {
|
|
|
73
75
|
throw response;
|
|
74
76
|
})
|
|
75
77
|
.then(function (data) {
|
|
76
|
-
|
|
78
|
+
_this.handleUpdateResponseData(data, action);
|
|
77
79
|
})
|
|
78
80
|
.catch(function (err) { return console.log(err); });
|
|
79
81
|
};
|
|
@@ -109,6 +111,9 @@ var HttpClient = /** @class */ (function () {
|
|
|
109
111
|
store_helper_1.StoreHelper.setGlobalState(envelope.globalState);
|
|
110
112
|
this.middlewareClient.handleEntries(envelope.entries, action);
|
|
111
113
|
};
|
|
114
|
+
HttpClient.prototype.handleUpdateResponseData = function (envelope, action) {
|
|
115
|
+
this.middlewareClient.handleUpdate(envelope.entries, action);
|
|
116
|
+
};
|
|
112
117
|
return HttpClient;
|
|
113
118
|
}());
|
|
114
119
|
exports.HttpClient = HttpClient;
|
|
@@ -7,7 +7,7 @@ export default class MiddlewareClient {
|
|
|
7
7
|
constructor();
|
|
8
8
|
static initialize(container: any, widget: any): void;
|
|
9
9
|
handleEntries(entries: ServerEntry[], action?: string): void;
|
|
10
|
-
handleUpdate(
|
|
10
|
+
handleUpdate(entries: ServerEntry[], action?: string): void;
|
|
11
11
|
checkForUpdate(input: string): boolean;
|
|
12
12
|
private executeMiddlewares;
|
|
13
13
|
}
|
|
@@ -6,16 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
var middleware_helper_1 = require("../helper/middleware.helper");
|
|
7
7
|
var store_helper_1 = require("../helper/store.helper");
|
|
8
8
|
var entry_interface_1 = __importDefault(require("../interface/entry.interface"));
|
|
9
|
-
// import ContactExpandedInterface from "../interface/middleware/contact-expanded.interface";
|
|
10
|
-
// import ContactInterface from "../interface/middleware/legacy-contact-methods.interface";
|
|
11
9
|
var paging_interface_1 = __importDefault(require("../interface/middleware/paging.interface"));
|
|
12
10
|
var processor_interface_1 = __importDefault(require("../interface/middleware/processor.interface"));
|
|
13
11
|
var chat_client_1 = __importDefault(require("./chat.client"));
|
|
14
|
-
var http_client_1 = require("./http.client");
|
|
15
12
|
var MiddlewareClient = /** @class */ (function () {
|
|
16
13
|
function MiddlewareClient() {
|
|
17
|
-
// this.contactExpanded = new ContactExpandedInterface();
|
|
18
|
-
// this.legacyContact = new ContactInterface();
|
|
19
14
|
this.paging = new paging_interface_1.default();
|
|
20
15
|
this.processor = new processor_interface_1.default();
|
|
21
16
|
this.entryInterface = new entry_interface_1.default();
|
|
@@ -33,14 +28,10 @@ var MiddlewareClient = /** @class */ (function () {
|
|
|
33
28
|
};
|
|
34
29
|
// called on situations such as paging changes
|
|
35
30
|
// when no new entries will be printed
|
|
36
|
-
MiddlewareClient.prototype.handleUpdate = function (
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
var o = _this.executeMiddlewares(entries, true, input);
|
|
41
|
-
var messageArray = _this.entryInterface.transformArray(o);
|
|
42
|
-
_this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
43
|
-
});
|
|
31
|
+
MiddlewareClient.prototype.handleUpdate = function (entries, action) {
|
|
32
|
+
var o = this.executeMiddlewares(entries, true, action);
|
|
33
|
+
var messageArray = this.entryInterface.transformArray(o);
|
|
34
|
+
this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
44
35
|
};
|
|
45
36
|
// checks whether the action was of an update type
|
|
46
37
|
MiddlewareClient.prototype.checkForUpdate = function (input) {
|
package/lib/plugin.js
CHANGED
|
@@ -81,12 +81,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
81
81
|
var knowledge_widget_core_1 = require("@telia-ace/knowledge-widget-core");
|
|
82
82
|
var knowledge_widget_types_grid_1 = require("@telia-ace/knowledge-widget-types-grid");
|
|
83
83
|
var widget_conversation_1 = require("@telia-ace/widget-conversation");
|
|
84
|
+
var uuid_1 = require("uuid");
|
|
84
85
|
var chat_client_1 = __importDefault(require("./client/chat.client"));
|
|
85
86
|
var contact_method_client_1 = require("./client/contact-method.client");
|
|
86
87
|
var http_client_1 = require("./client/http.client");
|
|
87
88
|
var middleware_client_1 = __importDefault(require("./client/middleware.client"));
|
|
88
89
|
var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
-
var platform, contactMethodPlatform, dataClient, compPlatform, _a, component, endpoint;
|
|
90
|
+
var platform, contactMethodPlatform, dataClient, compPlatform, clientId, _a, component, endpoint;
|
|
90
91
|
return __generator(this, function (_b) {
|
|
91
92
|
switch (_b.label) {
|
|
92
93
|
case 0: return [4 /*yield*/, widget_conversation_1.ConversationPlatform.getInstance(container)];
|
|
@@ -101,6 +102,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
101
102
|
return [4 /*yield*/, knowledge_widget_core_1.ComponentPlatform.getInstance(container)];
|
|
102
103
|
case 4:
|
|
103
104
|
compPlatform = _b.sent();
|
|
105
|
+
clientId = (0, uuid_1.v4)();
|
|
104
106
|
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
105
107
|
endpoint = '';
|
|
106
108
|
setTimeout(function () {
|
|
@@ -119,7 +121,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
119
121
|
// passes the container and the widget to the Middleware Store
|
|
120
122
|
middleware_client_1.default.initialize(container, container.get('$widget'));
|
|
121
123
|
// executes to decide on what to do on first load
|
|
122
|
-
var httpClient = new http_client_1.HttpClient(endpoint);
|
|
124
|
+
var httpClient = new http_client_1.HttpClient(endpoint, clientId);
|
|
123
125
|
httpClient.firstHit();
|
|
124
126
|
component.actions.create('evaluate', function (input) {
|
|
125
127
|
var cmClient = new contact_method_client_1.ContactMethodClient();
|
|
@@ -137,7 +139,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
137
139
|
return next(input);
|
|
138
140
|
});
|
|
139
141
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
140
|
-
var httpClient = new http_client_1.HttpClient(endpoint);
|
|
142
|
+
var httpClient = new http_client_1.HttpClient(endpoint, clientId);
|
|
141
143
|
httpClient.handlePhrase(input.text);
|
|
142
144
|
return next(input);
|
|
143
145
|
});
|
|
@@ -152,14 +154,14 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
152
154
|
return next(input);
|
|
153
155
|
}
|
|
154
156
|
var middlewareClient = new middleware_client_1.default();
|
|
157
|
+
var httpClient = new http_client_1.HttpClient(endpoint, clientId);
|
|
155
158
|
// this is an update check, as it requires
|
|
156
159
|
// a lot different logic and no user message
|
|
157
160
|
if (middlewareClient.checkForUpdate(input)) {
|
|
158
|
-
|
|
161
|
+
httpClient.handleUpdate(input);
|
|
159
162
|
return next(input);
|
|
160
163
|
}
|
|
161
164
|
chatClient.printUserMessageAndStoreIt(input);
|
|
162
|
-
var httpClient = new http_client_1.HttpClient(endpoint);
|
|
163
165
|
httpClient.handleInput(input);
|
|
164
166
|
return next(input);
|
|
165
167
|
});
|
|
@@ -7,10 +7,12 @@ var ChatClient = /** @class */ (function () {
|
|
|
7
7
|
function ChatClient() {
|
|
8
8
|
this.entryInterface = new EntryInterface();
|
|
9
9
|
}
|
|
10
|
+
// Initialize from setting the user and agent for the Helper
|
|
10
11
|
ChatClient.initialize = function (user, agent) {
|
|
11
12
|
ChatHelper.setUser(user);
|
|
12
13
|
ChatHelper.setAgent(agent);
|
|
13
14
|
};
|
|
15
|
+
// function for posting the messages
|
|
14
16
|
ChatClient.prototype.processMessageArrayAndStoreIt = function (messages) {
|
|
15
17
|
var _this = this;
|
|
16
18
|
messages
|
|
@@ -23,6 +25,7 @@ var ChatClient = /** @class */ (function () {
|
|
|
23
25
|
});
|
|
24
26
|
StoreHelper.insertOrUpdateMessageArrayStore(messages);
|
|
25
27
|
};
|
|
28
|
+
// function for updating current messages
|
|
26
29
|
ChatClient.prototype.updateMessageArrayAndStoreIt = function (messages) {
|
|
27
30
|
var conversationEntry = undefined;
|
|
28
31
|
messages.forEach(function (o) {
|
|
@@ -32,6 +35,7 @@ var ChatClient = /** @class */ (function () {
|
|
|
32
35
|
});
|
|
33
36
|
StoreHelper.insertOrUpdateMessageArrayStore(messages, conversationEntry);
|
|
34
37
|
};
|
|
38
|
+
// function for posting a message for the user actions, such as button clicks
|
|
35
39
|
ChatClient.prototype.printUserMessageAndStoreIt = function (action) {
|
|
36
40
|
if (action == 'next' || action == 'help')
|
|
37
41
|
return;
|
|
@@ -54,6 +54,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
54
54
|
function ContactMethodClient() {
|
|
55
55
|
var _this = this;
|
|
56
56
|
this.chatClient = new ChatClient();
|
|
57
|
+
// function for handling forms as contact methods
|
|
57
58
|
this.handleNewForm = function (errors, entry) { return __awaiter(_this, void 0, void 0, function () {
|
|
58
59
|
return __generator(this, function (_a) {
|
|
59
60
|
this.updateForm(entry.contactMethods, {
|
|
@@ -68,6 +69,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
68
69
|
return [2 /*return*/];
|
|
69
70
|
});
|
|
70
71
|
}); };
|
|
72
|
+
// function for receiving the contact method based on the input
|
|
71
73
|
this.handleContactMethod = function (input) {
|
|
72
74
|
if (input === void 0) { input = ''; }
|
|
73
75
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -138,6 +140,7 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
138
140
|
this.contactMethodPlatform = contactMethodPlatform;
|
|
139
141
|
this.agent = agent;
|
|
140
142
|
};
|
|
143
|
+
// validation of the form provided
|
|
141
144
|
ContactMethodClient.prototype.validate = function (form) {
|
|
142
145
|
var _this = this;
|
|
143
146
|
var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == form.schema.id; });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
2
1
|
export declare class HttpClient {
|
|
3
2
|
private endpointUrl;
|
|
4
3
|
private clientId;
|
|
@@ -7,16 +6,17 @@ export declare class HttpClient {
|
|
|
7
6
|
private options;
|
|
8
7
|
private middlewareClient;
|
|
9
8
|
private chatClient;
|
|
10
|
-
constructor(endpoint: string);
|
|
9
|
+
constructor(endpoint: string, clientId: string);
|
|
11
10
|
firstHit(): void;
|
|
12
|
-
handleUpdate(action: string):
|
|
11
|
+
handleUpdate(action: string): void;
|
|
13
12
|
handleInput(action: string): void;
|
|
14
13
|
handlePhrase(phrase: string): void;
|
|
15
14
|
private postAndHandleTheData;
|
|
16
|
-
private
|
|
15
|
+
private postAndHandleTheUpdateData;
|
|
17
16
|
private getHttpOptions;
|
|
18
17
|
private constructInputEnvelope;
|
|
19
18
|
private constructPhraseEnvelope;
|
|
20
19
|
private constructFirstHitEnvelope;
|
|
21
20
|
private handleResponseData;
|
|
21
|
+
private handleUpdateResponseData;
|
|
22
22
|
}
|
|
@@ -4,10 +4,10 @@ import { StoreHelper } from '../helper/store.helper';
|
|
|
4
4
|
import ChatClient from './chat.client';
|
|
5
5
|
import MiddlewareClient from './middleware.client';
|
|
6
6
|
var HttpClient = /** @class */ (function () {
|
|
7
|
-
function HttpClient(endpoint) {
|
|
7
|
+
function HttpClient(endpoint, clientId) {
|
|
8
8
|
this.options = {
|
|
9
9
|
credentials: HttpHelper.getCredentials(),
|
|
10
|
-
clientId:
|
|
10
|
+
clientId: clientId,
|
|
11
11
|
};
|
|
12
12
|
this.apiEndpoint = endpoint;
|
|
13
13
|
this.projectionPath = window.location.href;
|
|
@@ -32,9 +32,10 @@ var HttpClient = /** @class */ (function () {
|
|
|
32
32
|
// for updates, such as paging changes
|
|
33
33
|
HttpClient.prototype.handleUpdate = function (action) {
|
|
34
34
|
var envelope = this.constructInputEnvelope(action);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
this.postAndHandleTheUpdateData(envelope, action);
|
|
36
|
+
// return this.postAndReturnTheData(envelope, action).then((o) => {
|
|
37
|
+
// return o.entries;
|
|
38
|
+
// });
|
|
38
39
|
};
|
|
39
40
|
// for action clicks
|
|
40
41
|
HttpClient.prototype.handleInput = function (action) {
|
|
@@ -59,7 +60,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
59
60
|
})
|
|
60
61
|
.catch(function (err) { return console.log(err); });
|
|
61
62
|
};
|
|
62
|
-
HttpClient.prototype.
|
|
63
|
+
HttpClient.prototype.postAndHandleTheUpdateData = function (envelope, action) {
|
|
64
|
+
var _this = this;
|
|
63
65
|
return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
|
|
64
66
|
.then(function (response) {
|
|
65
67
|
if (response.ok)
|
|
@@ -67,7 +69,7 @@ var HttpClient = /** @class */ (function () {
|
|
|
67
69
|
throw response;
|
|
68
70
|
})
|
|
69
71
|
.then(function (data) {
|
|
70
|
-
|
|
72
|
+
_this.handleUpdateResponseData(data, action);
|
|
71
73
|
})
|
|
72
74
|
.catch(function (err) { return console.log(err); });
|
|
73
75
|
};
|
|
@@ -103,6 +105,9 @@ var HttpClient = /** @class */ (function () {
|
|
|
103
105
|
StoreHelper.setGlobalState(envelope.globalState);
|
|
104
106
|
this.middlewareClient.handleEntries(envelope.entries, action);
|
|
105
107
|
};
|
|
108
|
+
HttpClient.prototype.handleUpdateResponseData = function (envelope, action) {
|
|
109
|
+
this.middlewareClient.handleUpdate(envelope.entries, action);
|
|
110
|
+
};
|
|
106
111
|
return HttpClient;
|
|
107
112
|
}());
|
|
108
113
|
export { HttpClient };
|
|
@@ -7,7 +7,7 @@ export default class MiddlewareClient {
|
|
|
7
7
|
constructor();
|
|
8
8
|
static initialize(container: any, widget: any): void;
|
|
9
9
|
handleEntries(entries: ServerEntry[], action?: string): void;
|
|
10
|
-
handleUpdate(
|
|
10
|
+
handleUpdate(entries: ServerEntry[], action?: string): void;
|
|
11
11
|
checkForUpdate(input: string): boolean;
|
|
12
12
|
private executeMiddlewares;
|
|
13
13
|
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
2
2
|
import { StoreHelper } from '../helper/store.helper';
|
|
3
3
|
import EntryInterface from '../interface/entry.interface';
|
|
4
|
-
// import ContactExpandedInterface from "../interface/middleware/contact-expanded.interface";
|
|
5
|
-
// import ContactInterface from "../interface/middleware/legacy-contact-methods.interface";
|
|
6
4
|
import PagingInterface from '../interface/middleware/paging.interface';
|
|
7
5
|
import ProcessorInterface from '../interface/middleware/processor.interface';
|
|
8
6
|
import ChatClient from './chat.client';
|
|
9
|
-
import { HttpClient } from './http.client';
|
|
10
7
|
var MiddlewareClient = /** @class */ (function () {
|
|
11
8
|
function MiddlewareClient() {
|
|
12
|
-
// this.contactExpanded = new ContactExpandedInterface();
|
|
13
|
-
// this.legacyContact = new ContactInterface();
|
|
14
9
|
this.paging = new PagingInterface();
|
|
15
10
|
this.processor = new ProcessorInterface();
|
|
16
11
|
this.entryInterface = new EntryInterface();
|
|
@@ -28,14 +23,10 @@ var MiddlewareClient = /** @class */ (function () {
|
|
|
28
23
|
};
|
|
29
24
|
// called on situations such as paging changes
|
|
30
25
|
// when no new entries will be printed
|
|
31
|
-
MiddlewareClient.prototype.handleUpdate = function (
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
var o = _this.executeMiddlewares(entries, true, input);
|
|
36
|
-
var messageArray = _this.entryInterface.transformArray(o);
|
|
37
|
-
_this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
38
|
-
});
|
|
26
|
+
MiddlewareClient.prototype.handleUpdate = function (entries, action) {
|
|
27
|
+
var o = this.executeMiddlewares(entries, true, action);
|
|
28
|
+
var messageArray = this.entryInterface.transformArray(o);
|
|
29
|
+
this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
39
30
|
};
|
|
40
31
|
// checks whether the action was of an update type
|
|
41
32
|
MiddlewareClient.prototype.checkForUpdate = function (input) {
|
package/lib-esm/plugin.js
CHANGED
|
@@ -53,12 +53,13 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
53
53
|
import { ComponentPlatform } from '@telia-ace/knowledge-widget-core';
|
|
54
54
|
import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
|
|
55
55
|
import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
|
|
56
|
+
import { v4 } from 'uuid';
|
|
56
57
|
import ChatClient from './client/chat.client';
|
|
57
58
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
58
59
|
import { HttpClient } from './client/http.client';
|
|
59
60
|
import MiddlewareClient from './client/middleware.client';
|
|
60
61
|
var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
61
|
-
var platform, contactMethodPlatform, dataClient, compPlatform, _a, component, endpoint;
|
|
62
|
+
var platform, contactMethodPlatform, dataClient, compPlatform, clientId, _a, component, endpoint;
|
|
62
63
|
return __generator(this, function (_b) {
|
|
63
64
|
switch (_b.label) {
|
|
64
65
|
case 0: return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
@@ -73,6 +74,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
73
74
|
return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
74
75
|
case 4:
|
|
75
76
|
compPlatform = _b.sent();
|
|
77
|
+
clientId = v4();
|
|
76
78
|
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
77
79
|
endpoint = '';
|
|
78
80
|
setTimeout(function () {
|
|
@@ -91,7 +93,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
91
93
|
// passes the container and the widget to the Middleware Store
|
|
92
94
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
93
95
|
// executes to decide on what to do on first load
|
|
94
|
-
var httpClient = new HttpClient(endpoint);
|
|
96
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
95
97
|
httpClient.firstHit();
|
|
96
98
|
component.actions.create('evaluate', function (input) {
|
|
97
99
|
var cmClient = new ContactMethodClient();
|
|
@@ -109,7 +111,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
109
111
|
return next(input);
|
|
110
112
|
});
|
|
111
113
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
112
|
-
var httpClient = new HttpClient(endpoint);
|
|
114
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
113
115
|
httpClient.handlePhrase(input.text);
|
|
114
116
|
return next(input);
|
|
115
117
|
});
|
|
@@ -124,14 +126,14 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
124
126
|
return next(input);
|
|
125
127
|
}
|
|
126
128
|
var middlewareClient = new MiddlewareClient();
|
|
129
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
127
130
|
// this is an update check, as it requires
|
|
128
131
|
// a lot different logic and no user message
|
|
129
132
|
if (middlewareClient.checkForUpdate(input)) {
|
|
130
|
-
|
|
133
|
+
httpClient.handleUpdate(input);
|
|
131
134
|
return next(input);
|
|
132
135
|
}
|
|
133
136
|
chatClient.printUserMessageAndStoreIt(input);
|
|
134
|
-
var httpClient = new HttpClient(endpoint);
|
|
135
137
|
httpClient.handleInput(input);
|
|
136
138
|
return next(input);
|
|
137
139
|
});
|
package/package.json
CHANGED