@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.18 → 0.0.1-alpha.19
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/contract/custom-component/contact-method.d.ts +1 -1
- package/lib/contract/custom-component/contact-method.js +29 -30
- package/lib/plugin.d.ts +2 -2
- package/lib/plugin.js +95 -111
- package/lib-esm/contract/custom-component/contact-method.d.ts +1 -1
- package/lib-esm/contract/custom-component/contact-method.js +29 -30
- package/lib-esm/plugin.d.ts +2 -2
- package/lib-esm/plugin.js +95 -111
- package/package.json +1 -1
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
|
-
import { DataType } from '@humany/widget-types-grid';
|
|
1
|
+
// import { DataType } from '@humany/widget-types-grid';
|
|
6
2
|
import React from 'react';
|
|
7
|
-
import styled from 'styled-components';
|
|
8
|
-
import ContactMethodItem from './contact-method-item';
|
|
9
|
-
import ContactMethodList from './contact-method-list';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
// import styled from 'styled-components';
|
|
4
|
+
// import ContactMethodItem from './contact-method-item';
|
|
5
|
+
// import ContactMethodList from './contact-method-list';
|
|
6
|
+
// const ContactMethod: React.FC = (props: any) => {
|
|
7
|
+
// let type;
|
|
8
|
+
// let methodList;
|
|
9
|
+
// if (props.contactMethods && props.contactMethods.contactMethods?.length > 0) {
|
|
10
|
+
// type = DataType.ContactMethods;
|
|
11
|
+
// methodList = props.contactMethods.contactMethods;
|
|
12
|
+
// } else if (props.contactMethods.categories && props.contactMethods.categories?.length > 0) {
|
|
13
|
+
// type = DataType.ContactMethodCategories;
|
|
14
|
+
// methodList = props.contactMethods.categories.filter((o: any) => o.matches > 0);
|
|
15
|
+
// } else {
|
|
16
|
+
// type = DataType.ContactMethod;
|
|
17
|
+
// methodList = props.contactMethods;
|
|
18
|
+
// }
|
|
19
|
+
// if (!methodList.length) {
|
|
20
|
+
// return <StyledContactMethodItem type={type} contactMethod={methodList} />;
|
|
21
|
+
// }
|
|
22
|
+
// return <ContactMethodList type={type} contactMethodList={methodList} />;
|
|
23
|
+
// };
|
|
24
|
+
// const StyledContactMethodItem = styled(ContactMethodItem)`
|
|
25
|
+
// padding: ${(p) => p.theme.sizes?.medium};
|
|
26
|
+
// `;
|
|
27
|
+
// export default ContactMethod;
|
|
28
|
+
var ContactMethod = function () {
|
|
29
|
+
console.log('rendering contact method xxx');
|
|
30
|
+
return React.createElement("div", null, "Contact Method test");
|
|
30
31
|
};
|
|
31
|
-
var StyledContactMethodItem = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: ", ";\n"], ["\n padding: ", ";\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
|
|
32
32
|
export default ContactMethod;
|
|
33
|
-
var templateObject_1;
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Container } from '@webprovisions/platform';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const KnowledgeBotProviderPlugin: (container: Container) => Promise<void>;
|
|
3
|
+
export default KnowledgeBotProviderPlugin;
|
package/lib/plugin.js
CHANGED
|
@@ -59,149 +59,133 @@ import ChatClient from './client/chat.client';
|
|
|
59
59
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
60
60
|
import { HttpClient } from './client/http.client';
|
|
61
61
|
import MiddlewareClient from './client/middleware.client';
|
|
62
|
-
var
|
|
63
|
-
var providerRegistered,
|
|
62
|
+
var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
+
var providerRegistered, componentPlatform, events, getConversationComponent, execute;
|
|
64
64
|
return __generator(this, function (_a) {
|
|
65
65
|
switch (_a.label) {
|
|
66
66
|
case 0:
|
|
67
67
|
providerRegistered = false;
|
|
68
|
-
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
69
|
-
case 1:
|
|
70
|
-
platform = _a.sent();
|
|
71
|
-
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
72
|
-
case 2:
|
|
73
|
-
contactMethodPlatform = _a.sent();
|
|
74
|
-
return [4 /*yield*/, DataClient.getInstance(container)];
|
|
75
|
-
case 3:
|
|
76
|
-
dataClient = _a.sent();
|
|
77
68
|
return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
78
|
-
case
|
|
79
|
-
|
|
80
|
-
console.log('platform', platform, contactMethodPlatform, dataClient, compPlatform);
|
|
69
|
+
case 1:
|
|
70
|
+
componentPlatform = _a.sent();
|
|
81
71
|
events = container.get('$widget').events;
|
|
82
72
|
getConversationComponent = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
|
-
var
|
|
73
|
+
var platform, _a, component;
|
|
84
74
|
var _b, _c;
|
|
85
75
|
return __generator(this, function (_d) {
|
|
86
76
|
switch (_d.label) {
|
|
87
77
|
case 0: return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
88
78
|
case 1:
|
|
89
|
-
|
|
90
|
-
_a = __read(
|
|
79
|
+
platform = _d.sent();
|
|
80
|
+
_a = __read(platform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
91
81
|
if (!component || !((_c = (_b = component === null || component === void 0 ? void 0 : component.attributes) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.knowledgeBotEndpoint)) {
|
|
92
|
-
console.log('no component');
|
|
93
82
|
return [2 /*return*/];
|
|
94
83
|
}
|
|
95
|
-
console.log('got component', component);
|
|
96
84
|
return [2 /*return*/, component];
|
|
97
85
|
}
|
|
98
86
|
});
|
|
99
87
|
}); };
|
|
100
88
|
execute = function (endpoint) { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
+
var dataClient, platform, contactMethodPlatform;
|
|
101
90
|
return __generator(this, function (_a) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
return [2 /*return*/];
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
providerRegistered = true;
|
|
94
|
+
return [4 /*yield*/, DataClient.getInstance(container)];
|
|
95
|
+
case 1:
|
|
96
|
+
dataClient = _a.sent();
|
|
97
|
+
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
98
|
+
case 2:
|
|
99
|
+
platform = _a.sent();
|
|
100
|
+
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
101
|
+
case 3:
|
|
102
|
+
contactMethodPlatform = _a.sent();
|
|
103
|
+
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
104
|
+
var clientId = v4();
|
|
105
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
106
|
+
var agent = conversation.createAgent({
|
|
107
|
+
// TODO: needs to be fixed asap
|
|
108
|
+
name: 'John Doe',
|
|
109
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
110
|
+
});
|
|
111
|
+
// passes the user and the agent to the Chat Helper
|
|
112
|
+
ChatClient.initialize(conversation.user, agent);
|
|
113
|
+
// passes the conversation provider to the Contact Method Client
|
|
114
|
+
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
115
|
+
// passes the container and the widget to the Middleware Store
|
|
116
|
+
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
117
|
+
// executes to decide on what to do on first load
|
|
118
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
119
|
+
httpClient.firstHit();
|
|
120
|
+
component.actions.create('evaluate', function (input) {
|
|
121
|
+
var cmClient = new ContactMethodClient();
|
|
122
|
+
cmClient.handleNewForm(input.form, input.form.id);
|
|
123
|
+
});
|
|
124
|
+
component.actions.create('validate', function (input) {
|
|
125
|
+
var cmClient = new ContactMethodClient();
|
|
126
|
+
cmClient.validate(input.form);
|
|
127
|
+
});
|
|
128
|
+
component.actions.create('submit', function (input) {
|
|
129
|
+
var cmClient = new ContactMethodClient();
|
|
130
|
+
cmClient.validate(input.form);
|
|
131
|
+
});
|
|
132
|
+
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
133
|
+
return next(input);
|
|
134
|
+
});
|
|
135
|
+
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
136
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
137
|
+
httpClient.handlePhrase(input.text);
|
|
138
|
+
return next(input);
|
|
139
|
+
});
|
|
140
|
+
component.actions.watch('conversation.form', function (input, next) {
|
|
141
|
+
return next(input);
|
|
142
|
+
});
|
|
143
|
+
component.actions.watch('conversation.action', function (input, next) {
|
|
144
|
+
var chatClient = new ChatClient();
|
|
145
|
+
var cmClient = new ContactMethodClient();
|
|
146
|
+
if (input === 'contact' || input.split('/').length > 1) {
|
|
147
|
+
cmClient.handleContactMethod(input);
|
|
148
|
+
return next(input);
|
|
149
|
+
}
|
|
150
|
+
var middlewareClient = new MiddlewareClient();
|
|
151
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
152
|
+
// this is an update check, as it requires
|
|
153
|
+
// a lot different logic and no user message
|
|
154
|
+
if (middlewareClient.checkForUpdate(input)) {
|
|
155
|
+
httpClient.handleUpdate(input);
|
|
156
|
+
return next(input);
|
|
157
|
+
}
|
|
158
|
+
chatClient.printUserMessageAndStoreIt(input);
|
|
159
|
+
httpClient.handleInput(input);
|
|
160
|
+
return next(input);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
177
165
|
});
|
|
178
166
|
}); };
|
|
179
167
|
getConversationComponent().then(function (conversationComp) {
|
|
180
168
|
if (conversationComp && (conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint)) {
|
|
181
|
-
console.log('execute on first');
|
|
182
169
|
execute(conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint);
|
|
183
170
|
}
|
|
184
171
|
else {
|
|
185
|
-
events.subscribe('components:node-mounted',
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
compPlatform.events.subscribe('components:properties-changed', function (event, data) {
|
|
172
|
+
// events.subscribe('components:node-mounted', (event, data) => {
|
|
173
|
+
// if (providerRegistered) {
|
|
174
|
+
// return;
|
|
175
|
+
// }
|
|
176
|
+
// if (
|
|
177
|
+
// data.node?.type === 'conversation' &&
|
|
178
|
+
// data.node?.attributes.properties.knowledgeBotEndpoint
|
|
179
|
+
// ) {
|
|
180
|
+
// execute(data.node.attributes.properties.knowledgeBotEndpoint);
|
|
181
|
+
// }
|
|
182
|
+
// });
|
|
183
|
+
componentPlatform.events.subscribe('components:properties-changed', function (event, data) {
|
|
198
184
|
var _a, _b;
|
|
199
185
|
if (providerRegistered) {
|
|
200
186
|
return;
|
|
201
187
|
}
|
|
202
|
-
console.log('component properties changed', data);
|
|
203
188
|
if (((_a = data.node) === null || _a === void 0 ? void 0 : _a.type) === 'conversation' && ((_b = data.node) === null || _b === void 0 ? void 0 : _b.attributes.properties.knowledgeBotEndpoint)) {
|
|
204
|
-
console.log('conversation component property change', data);
|
|
205
189
|
execute(data.node.attributes.properties.knowledgeBotEndpoint);
|
|
206
190
|
}
|
|
207
191
|
});
|
|
@@ -211,4 +195,4 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
211
195
|
}
|
|
212
196
|
});
|
|
213
197
|
}); };
|
|
214
|
-
export default
|
|
198
|
+
export default KnowledgeBotProviderPlugin;
|
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
|
-
import { DataType } from '@humany/widget-types-grid';
|
|
1
|
+
// import { DataType } from '@humany/widget-types-grid';
|
|
6
2
|
import React from 'react';
|
|
7
|
-
import styled from 'styled-components';
|
|
8
|
-
import ContactMethodItem from './contact-method-item';
|
|
9
|
-
import ContactMethodList from './contact-method-list';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
// import styled from 'styled-components';
|
|
4
|
+
// import ContactMethodItem from './contact-method-item';
|
|
5
|
+
// import ContactMethodList from './contact-method-list';
|
|
6
|
+
// const ContactMethod: React.FC = (props: any) => {
|
|
7
|
+
// let type;
|
|
8
|
+
// let methodList;
|
|
9
|
+
// if (props.contactMethods && props.contactMethods.contactMethods?.length > 0) {
|
|
10
|
+
// type = DataType.ContactMethods;
|
|
11
|
+
// methodList = props.contactMethods.contactMethods;
|
|
12
|
+
// } else if (props.contactMethods.categories && props.contactMethods.categories?.length > 0) {
|
|
13
|
+
// type = DataType.ContactMethodCategories;
|
|
14
|
+
// methodList = props.contactMethods.categories.filter((o: any) => o.matches > 0);
|
|
15
|
+
// } else {
|
|
16
|
+
// type = DataType.ContactMethod;
|
|
17
|
+
// methodList = props.contactMethods;
|
|
18
|
+
// }
|
|
19
|
+
// if (!methodList.length) {
|
|
20
|
+
// return <StyledContactMethodItem type={type} contactMethod={methodList} />;
|
|
21
|
+
// }
|
|
22
|
+
// return <ContactMethodList type={type} contactMethodList={methodList} />;
|
|
23
|
+
// };
|
|
24
|
+
// const StyledContactMethodItem = styled(ContactMethodItem)`
|
|
25
|
+
// padding: ${(p) => p.theme.sizes?.medium};
|
|
26
|
+
// `;
|
|
27
|
+
// export default ContactMethod;
|
|
28
|
+
var ContactMethod = function () {
|
|
29
|
+
console.log('rendering contact method xxx');
|
|
30
|
+
return React.createElement("div", null, "Contact Method test");
|
|
30
31
|
};
|
|
31
|
-
var StyledContactMethodItem = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: ", ";\n"], ["\n padding: ", ";\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
|
|
32
32
|
export default ContactMethod;
|
|
33
|
-
var templateObject_1;
|
package/lib-esm/plugin.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Container } from '@webprovisions/platform';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const KnowledgeBotProviderPlugin: (container: Container) => Promise<void>;
|
|
3
|
+
export default KnowledgeBotProviderPlugin;
|
package/lib-esm/plugin.js
CHANGED
|
@@ -59,149 +59,133 @@ import ChatClient from './client/chat.client';
|
|
|
59
59
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
60
60
|
import { HttpClient } from './client/http.client';
|
|
61
61
|
import MiddlewareClient from './client/middleware.client';
|
|
62
|
-
var
|
|
63
|
-
var providerRegistered,
|
|
62
|
+
var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
+
var providerRegistered, componentPlatform, events, getConversationComponent, execute;
|
|
64
64
|
return __generator(this, function (_a) {
|
|
65
65
|
switch (_a.label) {
|
|
66
66
|
case 0:
|
|
67
67
|
providerRegistered = false;
|
|
68
|
-
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
69
|
-
case 1:
|
|
70
|
-
platform = _a.sent();
|
|
71
|
-
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
72
|
-
case 2:
|
|
73
|
-
contactMethodPlatform = _a.sent();
|
|
74
|
-
return [4 /*yield*/, DataClient.getInstance(container)];
|
|
75
|
-
case 3:
|
|
76
|
-
dataClient = _a.sent();
|
|
77
68
|
return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
78
|
-
case
|
|
79
|
-
|
|
80
|
-
console.log('platform', platform, contactMethodPlatform, dataClient, compPlatform);
|
|
69
|
+
case 1:
|
|
70
|
+
componentPlatform = _a.sent();
|
|
81
71
|
events = container.get('$widget').events;
|
|
82
72
|
getConversationComponent = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
|
-
var
|
|
73
|
+
var platform, _a, component;
|
|
84
74
|
var _b, _c;
|
|
85
75
|
return __generator(this, function (_d) {
|
|
86
76
|
switch (_d.label) {
|
|
87
77
|
case 0: return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
88
78
|
case 1:
|
|
89
|
-
|
|
90
|
-
_a = __read(
|
|
79
|
+
platform = _d.sent();
|
|
80
|
+
_a = __read(platform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
91
81
|
if (!component || !((_c = (_b = component === null || component === void 0 ? void 0 : component.attributes) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.knowledgeBotEndpoint)) {
|
|
92
|
-
console.log('no component');
|
|
93
82
|
return [2 /*return*/];
|
|
94
83
|
}
|
|
95
|
-
console.log('got component', component);
|
|
96
84
|
return [2 /*return*/, component];
|
|
97
85
|
}
|
|
98
86
|
});
|
|
99
87
|
}); };
|
|
100
88
|
execute = function (endpoint) { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
+
var dataClient, platform, contactMethodPlatform;
|
|
101
90
|
return __generator(this, function (_a) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
return [2 /*return*/];
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
providerRegistered = true;
|
|
94
|
+
return [4 /*yield*/, DataClient.getInstance(container)];
|
|
95
|
+
case 1:
|
|
96
|
+
dataClient = _a.sent();
|
|
97
|
+
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
98
|
+
case 2:
|
|
99
|
+
platform = _a.sent();
|
|
100
|
+
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
101
|
+
case 3:
|
|
102
|
+
contactMethodPlatform = _a.sent();
|
|
103
|
+
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
104
|
+
var clientId = v4();
|
|
105
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
106
|
+
var agent = conversation.createAgent({
|
|
107
|
+
// TODO: needs to be fixed asap
|
|
108
|
+
name: 'John Doe',
|
|
109
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
110
|
+
});
|
|
111
|
+
// passes the user and the agent to the Chat Helper
|
|
112
|
+
ChatClient.initialize(conversation.user, agent);
|
|
113
|
+
// passes the conversation provider to the Contact Method Client
|
|
114
|
+
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
115
|
+
// passes the container and the widget to the Middleware Store
|
|
116
|
+
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
117
|
+
// executes to decide on what to do on first load
|
|
118
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
119
|
+
httpClient.firstHit();
|
|
120
|
+
component.actions.create('evaluate', function (input) {
|
|
121
|
+
var cmClient = new ContactMethodClient();
|
|
122
|
+
cmClient.handleNewForm(input.form, input.form.id);
|
|
123
|
+
});
|
|
124
|
+
component.actions.create('validate', function (input) {
|
|
125
|
+
var cmClient = new ContactMethodClient();
|
|
126
|
+
cmClient.validate(input.form);
|
|
127
|
+
});
|
|
128
|
+
component.actions.create('submit', function (input) {
|
|
129
|
+
var cmClient = new ContactMethodClient();
|
|
130
|
+
cmClient.validate(input.form);
|
|
131
|
+
});
|
|
132
|
+
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
133
|
+
return next(input);
|
|
134
|
+
});
|
|
135
|
+
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
136
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
137
|
+
httpClient.handlePhrase(input.text);
|
|
138
|
+
return next(input);
|
|
139
|
+
});
|
|
140
|
+
component.actions.watch('conversation.form', function (input, next) {
|
|
141
|
+
return next(input);
|
|
142
|
+
});
|
|
143
|
+
component.actions.watch('conversation.action', function (input, next) {
|
|
144
|
+
var chatClient = new ChatClient();
|
|
145
|
+
var cmClient = new ContactMethodClient();
|
|
146
|
+
if (input === 'contact' || input.split('/').length > 1) {
|
|
147
|
+
cmClient.handleContactMethod(input);
|
|
148
|
+
return next(input);
|
|
149
|
+
}
|
|
150
|
+
var middlewareClient = new MiddlewareClient();
|
|
151
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
152
|
+
// this is an update check, as it requires
|
|
153
|
+
// a lot different logic and no user message
|
|
154
|
+
if (middlewareClient.checkForUpdate(input)) {
|
|
155
|
+
httpClient.handleUpdate(input);
|
|
156
|
+
return next(input);
|
|
157
|
+
}
|
|
158
|
+
chatClient.printUserMessageAndStoreIt(input);
|
|
159
|
+
httpClient.handleInput(input);
|
|
160
|
+
return next(input);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
177
165
|
});
|
|
178
166
|
}); };
|
|
179
167
|
getConversationComponent().then(function (conversationComp) {
|
|
180
168
|
if (conversationComp && (conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint)) {
|
|
181
|
-
console.log('execute on first');
|
|
182
169
|
execute(conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint);
|
|
183
170
|
}
|
|
184
171
|
else {
|
|
185
|
-
events.subscribe('components:node-mounted',
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
compPlatform.events.subscribe('components:properties-changed', function (event, data) {
|
|
172
|
+
// events.subscribe('components:node-mounted', (event, data) => {
|
|
173
|
+
// if (providerRegistered) {
|
|
174
|
+
// return;
|
|
175
|
+
// }
|
|
176
|
+
// if (
|
|
177
|
+
// data.node?.type === 'conversation' &&
|
|
178
|
+
// data.node?.attributes.properties.knowledgeBotEndpoint
|
|
179
|
+
// ) {
|
|
180
|
+
// execute(data.node.attributes.properties.knowledgeBotEndpoint);
|
|
181
|
+
// }
|
|
182
|
+
// });
|
|
183
|
+
componentPlatform.events.subscribe('components:properties-changed', function (event, data) {
|
|
198
184
|
var _a, _b;
|
|
199
185
|
if (providerRegistered) {
|
|
200
186
|
return;
|
|
201
187
|
}
|
|
202
|
-
console.log('component properties changed', data);
|
|
203
188
|
if (((_a = data.node) === null || _a === void 0 ? void 0 : _a.type) === 'conversation' && ((_b = data.node) === null || _b === void 0 ? void 0 : _b.attributes.properties.knowledgeBotEndpoint)) {
|
|
204
|
-
console.log('conversation component property change', data);
|
|
205
189
|
execute(data.node.attributes.properties.knowledgeBotEndpoint);
|
|
206
190
|
}
|
|
207
191
|
});
|
|
@@ -211,4 +195,4 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
211
195
|
}
|
|
212
196
|
});
|
|
213
197
|
}); };
|
|
214
|
-
export default
|
|
198
|
+
export default KnowledgeBotProviderPlugin;
|
package/package.json
CHANGED