@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.10 → 0.0.1-alpha.13
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/plugin.js +112 -71
- package/lib-esm/plugin.js +112 -71
- package/package.json +1 -1
package/lib/plugin.js
CHANGED
|
@@ -60,89 +60,130 @@ import { ContactMethodClient } from './client/contact-method.client';
|
|
|
60
60
|
import { HttpClient } from './client/http.client';
|
|
61
61
|
import MiddlewareClient from './client/middleware.client';
|
|
62
62
|
var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
-
var platform, contactMethodPlatform, dataClient, compPlatform,
|
|
64
|
-
return __generator(this, function (
|
|
65
|
-
switch (
|
|
63
|
+
var platform, contactMethodPlatform, dataClient, compPlatform, events, getConversationComponent, execute;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
66
|
case 0: return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
67
67
|
case 1:
|
|
68
|
-
platform =
|
|
68
|
+
platform = _a.sent();
|
|
69
69
|
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
70
70
|
case 2:
|
|
71
|
-
contactMethodPlatform =
|
|
71
|
+
contactMethodPlatform = _a.sent();
|
|
72
72
|
return [4 /*yield*/, DataClient.getInstance(container)];
|
|
73
73
|
case 3:
|
|
74
|
-
dataClient =
|
|
74
|
+
dataClient = _a.sent();
|
|
75
75
|
return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
76
76
|
case 4:
|
|
77
|
-
compPlatform =
|
|
77
|
+
compPlatform = _a.sent();
|
|
78
78
|
console.log('platform', platform, contactMethodPlatform, dataClient, compPlatform);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
console.log('initailizing');
|
|
95
|
-
// passes the user and the agent to the Chat Helper
|
|
96
|
-
ChatClient.initialize(conversation.user, agent);
|
|
97
|
-
// passes the conversation provider to the Contact Method Client
|
|
98
|
-
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
99
|
-
// passes the container and the widget to the Middleware Store
|
|
100
|
-
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
101
|
-
// executes to decide on what to do on first load
|
|
102
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
103
|
-
httpClient.firstHit();
|
|
104
|
-
component.actions.create('evaluate', function (input) {
|
|
105
|
-
var cmClient = new ContactMethodClient();
|
|
106
|
-
cmClient.handleNewForm(input.form, input.form.id);
|
|
107
|
-
});
|
|
108
|
-
component.actions.create('validate', function (input) {
|
|
109
|
-
var cmClient = new ContactMethodClient();
|
|
110
|
-
cmClient.validate(input.form);
|
|
111
|
-
});
|
|
112
|
-
component.actions.create('submit', function (input) {
|
|
113
|
-
var cmClient = new ContactMethodClient();
|
|
114
|
-
cmClient.validate(input.form);
|
|
115
|
-
});
|
|
116
|
-
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
117
|
-
return next(input);
|
|
118
|
-
});
|
|
119
|
-
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
120
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
121
|
-
httpClient.handlePhrase(input.text);
|
|
122
|
-
return next(input);
|
|
123
|
-
});
|
|
124
|
-
component.actions.watch('conversation.form', function (input, next) {
|
|
125
|
-
return next(input);
|
|
126
|
-
});
|
|
127
|
-
component.actions.watch('conversation.action', function (input, next) {
|
|
128
|
-
var chatClient = new ChatClient();
|
|
129
|
-
var cmClient = new ContactMethodClient();
|
|
130
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
131
|
-
cmClient.handleContactMethod(input);
|
|
132
|
-
return next(input);
|
|
79
|
+
events = container.get('$widget').events;
|
|
80
|
+
getConversationComponent = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
var compPlatform, _a, component;
|
|
82
|
+
return __generator(this, function (_b) {
|
|
83
|
+
switch (_b.label) {
|
|
84
|
+
case 0: return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
85
|
+
case 1:
|
|
86
|
+
compPlatform = _b.sent();
|
|
87
|
+
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
88
|
+
if (!component) {
|
|
89
|
+
console.log('no component');
|
|
90
|
+
return [2 /*return*/];
|
|
91
|
+
}
|
|
92
|
+
console.log('got component', component);
|
|
93
|
+
return [2 /*return*/, component];
|
|
133
94
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
95
|
+
});
|
|
96
|
+
}); };
|
|
97
|
+
execute = function (conversationComp) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var endpoint;
|
|
99
|
+
var _a, _b, _c, _d;
|
|
100
|
+
return __generator(this, function (_e) {
|
|
101
|
+
endpoint = '';
|
|
102
|
+
console.log('getting endpoint', conversationComp, (_b = (_a = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.knowledgeBotEndpoint);
|
|
103
|
+
// setTimeout(() => {
|
|
104
|
+
if ((_d = (_c = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.knowledgeBotEndpoint) {
|
|
105
|
+
endpoint = conversationComp.attributes.properties.knowledgeBotEndpoint;
|
|
141
106
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
107
|
+
// });
|
|
108
|
+
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
109
|
+
var clientId = v4();
|
|
110
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
111
|
+
var agent = conversation.createAgent({
|
|
112
|
+
name: 'John Doe',
|
|
113
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
114
|
+
});
|
|
115
|
+
console.log('initailizing');
|
|
116
|
+
// passes the user and the agent to the Chat Helper
|
|
117
|
+
ChatClient.initialize(conversation.user, agent);
|
|
118
|
+
// passes the conversation provider to the Contact Method Client
|
|
119
|
+
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
120
|
+
// passes the container and the widget to the Middleware Store
|
|
121
|
+
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
122
|
+
// executes to decide on what to do on first load
|
|
123
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
124
|
+
httpClient.firstHit();
|
|
125
|
+
component.actions.create('evaluate', function (input) {
|
|
126
|
+
var cmClient = new ContactMethodClient();
|
|
127
|
+
cmClient.handleNewForm(input.form, input.form.id);
|
|
128
|
+
});
|
|
129
|
+
component.actions.create('validate', function (input) {
|
|
130
|
+
var cmClient = new ContactMethodClient();
|
|
131
|
+
cmClient.validate(input.form);
|
|
132
|
+
});
|
|
133
|
+
component.actions.create('submit', function (input) {
|
|
134
|
+
var cmClient = new ContactMethodClient();
|
|
135
|
+
cmClient.validate(input.form);
|
|
136
|
+
});
|
|
137
|
+
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
138
|
+
return next(input);
|
|
139
|
+
});
|
|
140
|
+
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
141
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
142
|
+
httpClient.handlePhrase(input.text);
|
|
143
|
+
return next(input);
|
|
144
|
+
});
|
|
145
|
+
component.actions.watch('conversation.form', function (input, next) {
|
|
146
|
+
return next(input);
|
|
147
|
+
});
|
|
148
|
+
component.actions.watch('conversation.action', function (input, next) {
|
|
149
|
+
var chatClient = new ChatClient();
|
|
150
|
+
var cmClient = new ContactMethodClient();
|
|
151
|
+
if (input === 'contact' || input.split('/').length > 1) {
|
|
152
|
+
cmClient.handleContactMethod(input);
|
|
153
|
+
return next(input);
|
|
154
|
+
}
|
|
155
|
+
var middlewareClient = new MiddlewareClient();
|
|
156
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
157
|
+
// this is an update check, as it requires
|
|
158
|
+
// a lot different logic and no user message
|
|
159
|
+
if (middlewareClient.checkForUpdate(input)) {
|
|
160
|
+
httpClient.handleUpdate(input);
|
|
161
|
+
return next(input);
|
|
162
|
+
}
|
|
163
|
+
chatClient.printUserMessageAndStoreIt(input);
|
|
164
|
+
httpClient.handleInput(input);
|
|
165
|
+
return next(input);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
return [2 /*return*/];
|
|
145
169
|
});
|
|
170
|
+
}); };
|
|
171
|
+
getConversationComponent().then(function (conversationComp) {
|
|
172
|
+
if (conversationComp) {
|
|
173
|
+
console.log('execute on first');
|
|
174
|
+
execute(conversationComp);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
events.subscribe('components:node-mounted', function (event, data) {
|
|
178
|
+
var _a;
|
|
179
|
+
console.log('data components:node-mounted', data); // TODO: remove
|
|
180
|
+
if (((_a = data.node) === null || _a === void 0 ? void 0 : _a.type) === 'conversation') {
|
|
181
|
+
var component = getConversationComponent();
|
|
182
|
+
console.log('execute on event');
|
|
183
|
+
execute(component);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
146
187
|
});
|
|
147
188
|
return [2 /*return*/];
|
|
148
189
|
}
|
package/lib-esm/plugin.js
CHANGED
|
@@ -60,89 +60,130 @@ import { ContactMethodClient } from './client/contact-method.client';
|
|
|
60
60
|
import { HttpClient } from './client/http.client';
|
|
61
61
|
import MiddlewareClient from './client/middleware.client';
|
|
62
62
|
var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
-
var platform, contactMethodPlatform, dataClient, compPlatform,
|
|
64
|
-
return __generator(this, function (
|
|
65
|
-
switch (
|
|
63
|
+
var platform, contactMethodPlatform, dataClient, compPlatform, events, getConversationComponent, execute;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
66
|
case 0: return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
67
67
|
case 1:
|
|
68
|
-
platform =
|
|
68
|
+
platform = _a.sent();
|
|
69
69
|
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
70
70
|
case 2:
|
|
71
|
-
contactMethodPlatform =
|
|
71
|
+
contactMethodPlatform = _a.sent();
|
|
72
72
|
return [4 /*yield*/, DataClient.getInstance(container)];
|
|
73
73
|
case 3:
|
|
74
|
-
dataClient =
|
|
74
|
+
dataClient = _a.sent();
|
|
75
75
|
return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
76
76
|
case 4:
|
|
77
|
-
compPlatform =
|
|
77
|
+
compPlatform = _a.sent();
|
|
78
78
|
console.log('platform', platform, contactMethodPlatform, dataClient, compPlatform);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
console.log('initailizing');
|
|
95
|
-
// passes the user and the agent to the Chat Helper
|
|
96
|
-
ChatClient.initialize(conversation.user, agent);
|
|
97
|
-
// passes the conversation provider to the Contact Method Client
|
|
98
|
-
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
99
|
-
// passes the container and the widget to the Middleware Store
|
|
100
|
-
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
101
|
-
// executes to decide on what to do on first load
|
|
102
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
103
|
-
httpClient.firstHit();
|
|
104
|
-
component.actions.create('evaluate', function (input) {
|
|
105
|
-
var cmClient = new ContactMethodClient();
|
|
106
|
-
cmClient.handleNewForm(input.form, input.form.id);
|
|
107
|
-
});
|
|
108
|
-
component.actions.create('validate', function (input) {
|
|
109
|
-
var cmClient = new ContactMethodClient();
|
|
110
|
-
cmClient.validate(input.form);
|
|
111
|
-
});
|
|
112
|
-
component.actions.create('submit', function (input) {
|
|
113
|
-
var cmClient = new ContactMethodClient();
|
|
114
|
-
cmClient.validate(input.form);
|
|
115
|
-
});
|
|
116
|
-
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
117
|
-
return next(input);
|
|
118
|
-
});
|
|
119
|
-
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
120
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
121
|
-
httpClient.handlePhrase(input.text);
|
|
122
|
-
return next(input);
|
|
123
|
-
});
|
|
124
|
-
component.actions.watch('conversation.form', function (input, next) {
|
|
125
|
-
return next(input);
|
|
126
|
-
});
|
|
127
|
-
component.actions.watch('conversation.action', function (input, next) {
|
|
128
|
-
var chatClient = new ChatClient();
|
|
129
|
-
var cmClient = new ContactMethodClient();
|
|
130
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
131
|
-
cmClient.handleContactMethod(input);
|
|
132
|
-
return next(input);
|
|
79
|
+
events = container.get('$widget').events;
|
|
80
|
+
getConversationComponent = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
var compPlatform, _a, component;
|
|
82
|
+
return __generator(this, function (_b) {
|
|
83
|
+
switch (_b.label) {
|
|
84
|
+
case 0: return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
85
|
+
case 1:
|
|
86
|
+
compPlatform = _b.sent();
|
|
87
|
+
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
88
|
+
if (!component) {
|
|
89
|
+
console.log('no component');
|
|
90
|
+
return [2 /*return*/];
|
|
91
|
+
}
|
|
92
|
+
console.log('got component', component);
|
|
93
|
+
return [2 /*return*/, component];
|
|
133
94
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
95
|
+
});
|
|
96
|
+
}); };
|
|
97
|
+
execute = function (conversationComp) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var endpoint;
|
|
99
|
+
var _a, _b, _c, _d;
|
|
100
|
+
return __generator(this, function (_e) {
|
|
101
|
+
endpoint = '';
|
|
102
|
+
console.log('getting endpoint', conversationComp, (_b = (_a = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.knowledgeBotEndpoint);
|
|
103
|
+
// setTimeout(() => {
|
|
104
|
+
if ((_d = (_c = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.knowledgeBotEndpoint) {
|
|
105
|
+
endpoint = conversationComp.attributes.properties.knowledgeBotEndpoint;
|
|
141
106
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
107
|
+
// });
|
|
108
|
+
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
109
|
+
var clientId = v4();
|
|
110
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
111
|
+
var agent = conversation.createAgent({
|
|
112
|
+
name: 'John Doe',
|
|
113
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
114
|
+
});
|
|
115
|
+
console.log('initailizing');
|
|
116
|
+
// passes the user and the agent to the Chat Helper
|
|
117
|
+
ChatClient.initialize(conversation.user, agent);
|
|
118
|
+
// passes the conversation provider to the Contact Method Client
|
|
119
|
+
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
120
|
+
// passes the container and the widget to the Middleware Store
|
|
121
|
+
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
122
|
+
// executes to decide on what to do on first load
|
|
123
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
124
|
+
httpClient.firstHit();
|
|
125
|
+
component.actions.create('evaluate', function (input) {
|
|
126
|
+
var cmClient = new ContactMethodClient();
|
|
127
|
+
cmClient.handleNewForm(input.form, input.form.id);
|
|
128
|
+
});
|
|
129
|
+
component.actions.create('validate', function (input) {
|
|
130
|
+
var cmClient = new ContactMethodClient();
|
|
131
|
+
cmClient.validate(input.form);
|
|
132
|
+
});
|
|
133
|
+
component.actions.create('submit', function (input) {
|
|
134
|
+
var cmClient = new ContactMethodClient();
|
|
135
|
+
cmClient.validate(input.form);
|
|
136
|
+
});
|
|
137
|
+
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
138
|
+
return next(input);
|
|
139
|
+
});
|
|
140
|
+
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
141
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
142
|
+
httpClient.handlePhrase(input.text);
|
|
143
|
+
return next(input);
|
|
144
|
+
});
|
|
145
|
+
component.actions.watch('conversation.form', function (input, next) {
|
|
146
|
+
return next(input);
|
|
147
|
+
});
|
|
148
|
+
component.actions.watch('conversation.action', function (input, next) {
|
|
149
|
+
var chatClient = new ChatClient();
|
|
150
|
+
var cmClient = new ContactMethodClient();
|
|
151
|
+
if (input === 'contact' || input.split('/').length > 1) {
|
|
152
|
+
cmClient.handleContactMethod(input);
|
|
153
|
+
return next(input);
|
|
154
|
+
}
|
|
155
|
+
var middlewareClient = new MiddlewareClient();
|
|
156
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
157
|
+
// this is an update check, as it requires
|
|
158
|
+
// a lot different logic and no user message
|
|
159
|
+
if (middlewareClient.checkForUpdate(input)) {
|
|
160
|
+
httpClient.handleUpdate(input);
|
|
161
|
+
return next(input);
|
|
162
|
+
}
|
|
163
|
+
chatClient.printUserMessageAndStoreIt(input);
|
|
164
|
+
httpClient.handleInput(input);
|
|
165
|
+
return next(input);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
return [2 /*return*/];
|
|
145
169
|
});
|
|
170
|
+
}); };
|
|
171
|
+
getConversationComponent().then(function (conversationComp) {
|
|
172
|
+
if (conversationComp) {
|
|
173
|
+
console.log('execute on first');
|
|
174
|
+
execute(conversationComp);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
events.subscribe('components:node-mounted', function (event, data) {
|
|
178
|
+
var _a;
|
|
179
|
+
console.log('data components:node-mounted', data); // TODO: remove
|
|
180
|
+
if (((_a = data.node) === null || _a === void 0 ? void 0 : _a.type) === 'conversation') {
|
|
181
|
+
var component = getConversationComponent();
|
|
182
|
+
console.log('execute on event');
|
|
183
|
+
execute(component);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
146
187
|
});
|
|
147
188
|
return [2 /*return*/];
|
|
148
189
|
}
|
package/package.json
CHANGED