@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.4 → 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 +12 -8
- 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 +12 -8
- 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
|
@@ -78,22 +78,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
78
78
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
79
79
|
};
|
|
80
80
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
|
-
var knowledge_widget_adapters_1 = require("@telia-ace/knowledge-widget-adapters");
|
|
82
81
|
var knowledge_widget_core_1 = require("@telia-ace/knowledge-widget-core");
|
|
83
82
|
var knowledge_widget_types_grid_1 = require("@telia-ace/knowledge-widget-types-grid");
|
|
84
83
|
var widget_conversation_1 = require("@telia-ace/widget-conversation");
|
|
84
|
+
var uuid_1 = require("uuid");
|
|
85
85
|
var chat_client_1 = __importDefault(require("./client/chat.client"));
|
|
86
86
|
var contact_method_client_1 = require("./client/contact-method.client");
|
|
87
87
|
var http_client_1 = require("./client/http.client");
|
|
88
88
|
var middleware_client_1 = __importDefault(require("./client/middleware.client"));
|
|
89
89
|
var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var platform, contactMethodPlatform, dataClient, compPlatform, _a, component, endpoint;
|
|
90
|
+
var platform, contactMethodPlatform, dataClient, compPlatform, clientId, _a, component, endpoint;
|
|
91
91
|
return __generator(this, function (_b) {
|
|
92
92
|
switch (_b.label) {
|
|
93
93
|
case 0: return [4 /*yield*/, widget_conversation_1.ConversationPlatform.getInstance(container)];
|
|
94
94
|
case 1:
|
|
95
95
|
platform = _b.sent();
|
|
96
|
-
return [4 /*yield*/,
|
|
96
|
+
return [4 /*yield*/, container.getAsync('contactMethods')];
|
|
97
97
|
case 2:
|
|
98
98
|
contactMethodPlatform = _b.sent();
|
|
99
99
|
return [4 /*yield*/, knowledge_widget_types_grid_1.DataClient.getInstance(container)];
|
|
@@ -102,6 +102,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
102
102
|
return [4 /*yield*/, knowledge_widget_core_1.ComponentPlatform.getInstance(container)];
|
|
103
103
|
case 4:
|
|
104
104
|
compPlatform = _b.sent();
|
|
105
|
+
clientId = (0, uuid_1.v4)();
|
|
105
106
|
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
106
107
|
endpoint = '';
|
|
107
108
|
setTimeout(function () {
|
|
@@ -109,7 +110,10 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
109
110
|
});
|
|
110
111
|
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
111
112
|
(0, widget_conversation_1.registerCustomMessageComponent)(container, 'ace-knowledge-contact-method', Promise.resolve().then(function () { return __importStar(require('./contract/custom-component/contact-method')); }));
|
|
112
|
-
var agent = conversation.createAgent({
|
|
113
|
+
var agent = conversation.createAgent({
|
|
114
|
+
name: 'John Doe',
|
|
115
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
116
|
+
});
|
|
113
117
|
// pases the user and the agent to the Chat Helper
|
|
114
118
|
chat_client_1.default.initialize(conversation.user, agent);
|
|
115
119
|
// passes the conversation provider to the Contact Method Client
|
|
@@ -117,7 +121,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
117
121
|
// passes the container and the widget to the Middleware Store
|
|
118
122
|
middleware_client_1.default.initialize(container, container.get('$widget'));
|
|
119
123
|
// executes to decide on what to do on first load
|
|
120
|
-
var httpClient = new http_client_1.HttpClient(endpoint);
|
|
124
|
+
var httpClient = new http_client_1.HttpClient(endpoint, clientId);
|
|
121
125
|
httpClient.firstHit();
|
|
122
126
|
component.actions.create('evaluate', function (input) {
|
|
123
127
|
var cmClient = new contact_method_client_1.ContactMethodClient();
|
|
@@ -135,7 +139,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
135
139
|
return next(input);
|
|
136
140
|
});
|
|
137
141
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
138
|
-
var httpClient = new http_client_1.HttpClient(endpoint);
|
|
142
|
+
var httpClient = new http_client_1.HttpClient(endpoint, clientId);
|
|
139
143
|
httpClient.handlePhrase(input.text);
|
|
140
144
|
return next(input);
|
|
141
145
|
});
|
|
@@ -150,14 +154,14 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
150
154
|
return next(input);
|
|
151
155
|
}
|
|
152
156
|
var middlewareClient = new middleware_client_1.default();
|
|
157
|
+
var httpClient = new http_client_1.HttpClient(endpoint, clientId);
|
|
153
158
|
// this is an update check, as it requires
|
|
154
159
|
// a lot different logic and no user message
|
|
155
160
|
if (middlewareClient.checkForUpdate(input)) {
|
|
156
|
-
|
|
161
|
+
httpClient.handleUpdate(input);
|
|
157
162
|
return next(input);
|
|
158
163
|
}
|
|
159
164
|
chatClient.printUserMessageAndStoreIt(input);
|
|
160
|
-
var httpClient = new http_client_1.HttpClient(endpoint);
|
|
161
165
|
httpClient.handleInput(input);
|
|
162
166
|
return next(input);
|
|
163
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
|
@@ -50,22 +50,22 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
50
50
|
}
|
|
51
51
|
return ar;
|
|
52
52
|
};
|
|
53
|
-
import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
|
|
54
53
|
import { ComponentPlatform } from '@telia-ace/knowledge-widget-core';
|
|
55
54
|
import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
|
|
56
55
|
import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
|
|
56
|
+
import { v4 } from 'uuid';
|
|
57
57
|
import ChatClient from './client/chat.client';
|
|
58
58
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
59
59
|
import { HttpClient } from './client/http.client';
|
|
60
60
|
import MiddlewareClient from './client/middleware.client';
|
|
61
61
|
var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
-
var platform, contactMethodPlatform, dataClient, compPlatform, _a, component, endpoint;
|
|
62
|
+
var platform, contactMethodPlatform, dataClient, compPlatform, clientId, _a, component, endpoint;
|
|
63
63
|
return __generator(this, function (_b) {
|
|
64
64
|
switch (_b.label) {
|
|
65
65
|
case 0: return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
66
66
|
case 1:
|
|
67
67
|
platform = _b.sent();
|
|
68
|
-
return [4 /*yield*/,
|
|
68
|
+
return [4 /*yield*/, container.getAsync('contactMethods')];
|
|
69
69
|
case 2:
|
|
70
70
|
contactMethodPlatform = _b.sent();
|
|
71
71
|
return [4 /*yield*/, DataClient.getInstance(container)];
|
|
@@ -74,6 +74,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
74
74
|
return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
75
75
|
case 4:
|
|
76
76
|
compPlatform = _b.sent();
|
|
77
|
+
clientId = v4();
|
|
77
78
|
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
78
79
|
endpoint = '';
|
|
79
80
|
setTimeout(function () {
|
|
@@ -81,7 +82,10 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
81
82
|
});
|
|
82
83
|
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
83
84
|
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
84
|
-
var agent = conversation.createAgent({
|
|
85
|
+
var agent = conversation.createAgent({
|
|
86
|
+
name: 'John Doe',
|
|
87
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
88
|
+
});
|
|
85
89
|
// pases the user and the agent to the Chat Helper
|
|
86
90
|
ChatClient.initialize(conversation.user, agent);
|
|
87
91
|
// passes the conversation provider to the Contact Method Client
|
|
@@ -89,7 +93,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
89
93
|
// passes the container and the widget to the Middleware Store
|
|
90
94
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
91
95
|
// executes to decide on what to do on first load
|
|
92
|
-
var httpClient = new HttpClient(endpoint);
|
|
96
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
93
97
|
httpClient.firstHit();
|
|
94
98
|
component.actions.create('evaluate', function (input) {
|
|
95
99
|
var cmClient = new ContactMethodClient();
|
|
@@ -107,7 +111,7 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
107
111
|
return next(input);
|
|
108
112
|
});
|
|
109
113
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
110
|
-
var httpClient = new HttpClient(endpoint);
|
|
114
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
111
115
|
httpClient.handlePhrase(input.text);
|
|
112
116
|
return next(input);
|
|
113
117
|
});
|
|
@@ -122,14 +126,14 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
122
126
|
return next(input);
|
|
123
127
|
}
|
|
124
128
|
var middlewareClient = new MiddlewareClient();
|
|
129
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
125
130
|
// this is an update check, as it requires
|
|
126
131
|
// a lot different logic and no user message
|
|
127
132
|
if (middlewareClient.checkForUpdate(input)) {
|
|
128
|
-
|
|
133
|
+
httpClient.handleUpdate(input);
|
|
129
134
|
return next(input);
|
|
130
135
|
}
|
|
131
136
|
chatClient.printUserMessageAndStoreIt(input);
|
|
132
|
-
var httpClient = new HttpClient(endpoint);
|
|
133
137
|
httpClient.handleInput(input);
|
|
134
138
|
return next(input);
|
|
135
139
|
});
|
package/package.json
CHANGED