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