@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.12 → 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 -65
- package/lib-esm/plugin.js +112 -65
- package/package.json +1 -1
package/lib/plugin.js
CHANGED
|
@@ -60,83 +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
|
-
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
95
|
-
// executes to decide on what to do on first load
|
|
96
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
97
|
-
httpClient.firstHit();
|
|
98
|
-
component.actions.create('evaluate', function (input) {
|
|
99
|
-
var cmClient = new ContactMethodClient();
|
|
100
|
-
cmClient.handleNewForm(input.form, input.form.id);
|
|
101
|
-
});
|
|
102
|
-
component.actions.create('validate', function (input) {
|
|
103
|
-
var cmClient = new ContactMethodClient();
|
|
104
|
-
cmClient.validate(input.form);
|
|
105
|
-
});
|
|
106
|
-
component.actions.create('submit', function (input) {
|
|
107
|
-
var cmClient = new ContactMethodClient();
|
|
108
|
-
cmClient.validate(input.form);
|
|
109
|
-
});
|
|
110
|
-
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
111
|
-
return next(input);
|
|
112
|
-
});
|
|
113
|
-
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
114
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
115
|
-
httpClient.handlePhrase(input.text);
|
|
116
|
-
return next(input);
|
|
117
|
-
});
|
|
118
|
-
component.actions.watch('conversation.form', function (input, next) {
|
|
119
|
-
return next(input);
|
|
120
|
-
});
|
|
121
|
-
component.actions.watch('conversation.action', function (input, next) {
|
|
122
|
-
var chatClient = new ChatClient();
|
|
123
|
-
var cmClient = new ContactMethodClient();
|
|
124
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
125
|
-
cmClient.handleContactMethod(input);
|
|
126
|
-
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];
|
|
127
94
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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;
|
|
135
106
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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*/];
|
|
139
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
|
+
}
|
|
140
187
|
});
|
|
141
188
|
return [2 /*return*/];
|
|
142
189
|
}
|
package/lib-esm/plugin.js
CHANGED
|
@@ -60,83 +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
|
-
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
95
|
-
// executes to decide on what to do on first load
|
|
96
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
97
|
-
httpClient.firstHit();
|
|
98
|
-
component.actions.create('evaluate', function (input) {
|
|
99
|
-
var cmClient = new ContactMethodClient();
|
|
100
|
-
cmClient.handleNewForm(input.form, input.form.id);
|
|
101
|
-
});
|
|
102
|
-
component.actions.create('validate', function (input) {
|
|
103
|
-
var cmClient = new ContactMethodClient();
|
|
104
|
-
cmClient.validate(input.form);
|
|
105
|
-
});
|
|
106
|
-
component.actions.create('submit', function (input) {
|
|
107
|
-
var cmClient = new ContactMethodClient();
|
|
108
|
-
cmClient.validate(input.form);
|
|
109
|
-
});
|
|
110
|
-
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
111
|
-
return next(input);
|
|
112
|
-
});
|
|
113
|
-
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
114
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
115
|
-
httpClient.handlePhrase(input.text);
|
|
116
|
-
return next(input);
|
|
117
|
-
});
|
|
118
|
-
component.actions.watch('conversation.form', function (input, next) {
|
|
119
|
-
return next(input);
|
|
120
|
-
});
|
|
121
|
-
component.actions.watch('conversation.action', function (input, next) {
|
|
122
|
-
var chatClient = new ChatClient();
|
|
123
|
-
var cmClient = new ContactMethodClient();
|
|
124
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
125
|
-
cmClient.handleContactMethod(input);
|
|
126
|
-
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];
|
|
127
94
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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;
|
|
135
106
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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*/];
|
|
139
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
|
+
}
|
|
140
187
|
});
|
|
141
188
|
return [2 /*return*/];
|
|
142
189
|
}
|
package/package.json
CHANGED