@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.22 → 0.0.1-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client/contact-method.client.d.ts +2 -1
- package/lib/client/contact-method.client.js +14 -4
- package/lib/contract/custom-component/contact-method-item.js +3 -0
- package/lib/contract/custom-component/contact-method.js +1 -0
- package/lib/contract/enum/server-entry-type.enum.d.ts +3 -2
- package/lib/contract/enum/server-entry-type.enum.js +3 -2
- package/lib/interface/_mocked-contact-method.json +375 -0
- package/lib/interface/convert.d.ts +1 -0
- package/lib/interface/convert.js +68 -0
- package/lib/interface/entry.interface.d.ts +1 -0
- package/lib/interface/entry.interface.js +20 -2
- package/lib/plugin.js +82 -141
- package/lib-esm/client/contact-method.client.d.ts +2 -1
- package/lib-esm/client/contact-method.client.js +14 -4
- package/lib-esm/contract/custom-component/contact-method-item.js +3 -0
- package/lib-esm/contract/custom-component/contact-method.js +1 -0
- package/lib-esm/contract/enum/server-entry-type.enum.d.ts +3 -2
- package/lib-esm/contract/enum/server-entry-type.enum.js +3 -2
- package/lib-esm/interface/_mocked-contact-method.json +375 -0
- package/lib-esm/interface/convert.d.ts +1 -0
- package/lib-esm/interface/convert.js +68 -0
- package/lib-esm/interface/entry.interface.d.ts +1 -0
- package/lib-esm/interface/entry.interface.js +20 -2
- package/lib-esm/plugin.js +82 -141
- package/package.json +11 -9
package/lib/plugin.js
CHANGED
|
@@ -34,162 +34,103 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
38
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
-
if (!m) return o;
|
|
40
|
-
var i = m.call(o), r, ar = [], e;
|
|
41
|
-
try {
|
|
42
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
-
}
|
|
44
|
-
catch (error) { e = { error: error }; }
|
|
45
|
-
finally {
|
|
46
|
-
try {
|
|
47
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
-
}
|
|
49
|
-
finally { if (e) throw e.error; }
|
|
50
|
-
}
|
|
51
|
-
return ar;
|
|
52
|
-
};
|
|
53
37
|
import { ContactMethodPlatform } from '@humany/widget-adapters';
|
|
54
38
|
import { ConversationPlatform, registerCustomMessageComponent } from '@humany/widget-conversation';
|
|
55
|
-
import { ComponentPlatform } from '@humany/widget-core';
|
|
56
39
|
import { DataClient } from '@humany/widget-types-grid';
|
|
57
40
|
import { v4 } from 'uuid';
|
|
58
41
|
import ChatClient from './client/chat.client';
|
|
59
42
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
60
43
|
import { HttpClient } from './client/http.client';
|
|
61
44
|
import MiddlewareClient from './client/middleware.client';
|
|
45
|
+
var getKnowledgeBotEndpoint = function (container, component /*: ComponentNodeController */
|
|
46
|
+
// ComponentNodeController type differs from component passed into registerProvider
|
|
47
|
+
) {
|
|
48
|
+
var knowledgeBotEndpoint = component.properties().knowledgeBotEndpoint;
|
|
49
|
+
if (knowledgeBotEndpoint) {
|
|
50
|
+
return knowledgeBotEndpoint + "/conversations";
|
|
51
|
+
}
|
|
52
|
+
var data = container.get('$settings').data;
|
|
53
|
+
if (!data || !data.projection)
|
|
54
|
+
throw new Error('Missing Knowledge Bot endpoint');
|
|
55
|
+
return data.projection + "/conversations";
|
|
56
|
+
};
|
|
62
57
|
var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
-
var
|
|
58
|
+
var dataClient, platform, contactMethodPlatform;
|
|
64
59
|
return __generator(this, function (_a) {
|
|
65
60
|
switch (_a.label) {
|
|
66
|
-
case 0:
|
|
67
|
-
providerRegistered = false;
|
|
68
|
-
return [4 /*yield*/, ComponentPlatform.getInstance(container)];
|
|
61
|
+
case 0: return [4 /*yield*/, DataClient.getInstance(container)];
|
|
69
62
|
case 1:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
63
|
+
dataClient = _a.sent();
|
|
64
|
+
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
65
|
+
case 2:
|
|
66
|
+
platform = _a.sent();
|
|
67
|
+
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
68
|
+
case 3:
|
|
69
|
+
contactMethodPlatform = _a.sent();
|
|
70
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
71
|
+
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
72
|
+
var endpoint = getKnowledgeBotEndpoint(container, component);
|
|
73
|
+
var clientId = v4();
|
|
74
|
+
var agent = conversation.createAgent({
|
|
75
|
+
// TODO: needs to be fixed asap
|
|
76
|
+
name: 'John Doe',
|
|
77
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
85
78
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
httpClient.handlePhrase(input.text);
|
|
137
|
-
return next(input);
|
|
138
|
-
});
|
|
139
|
-
component.actions.watch('conversation.form', function (input, next) {
|
|
140
|
-
return next(input);
|
|
141
|
-
});
|
|
142
|
-
component.actions.watch('conversation.action', function (input, next) {
|
|
143
|
-
var chatClient = new ChatClient();
|
|
144
|
-
var cmClient = new ContactMethodClient();
|
|
145
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
146
|
-
cmClient.handleContactMethod(input);
|
|
147
|
-
return next(input);
|
|
148
|
-
}
|
|
149
|
-
var middlewareClient = new MiddlewareClient();
|
|
150
|
-
var httpClient = new HttpClient(endpoint, clientId);
|
|
151
|
-
// this is an update check, as it requires
|
|
152
|
-
// a lot different logic and no user message
|
|
153
|
-
if (middlewareClient.checkForUpdate(input)) {
|
|
154
|
-
httpClient.handleUpdate(input);
|
|
155
|
-
return next(input);
|
|
156
|
-
}
|
|
157
|
-
chatClient.printUserMessageAndStoreIt(input);
|
|
158
|
-
httpClient.handleInput(input);
|
|
159
|
-
return next(input);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
return [2 /*return*/];
|
|
79
|
+
// passes the user and the agent to the Chat Helper
|
|
80
|
+
ChatClient.initialize(conversation.user, agent);
|
|
81
|
+
// passes the conversation provider to the Contact Method Client
|
|
82
|
+
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
83
|
+
// passes the container and the widget to the Middleware Store
|
|
84
|
+
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
85
|
+
// executes to decide on what to do on first load
|
|
86
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
87
|
+
httpClient.firstHit();
|
|
88
|
+
component.actions.create('evaluate', function (input) {
|
|
89
|
+
var cmClient = new ContactMethodClient();
|
|
90
|
+
cmClient.handleNewForm(input.form, input.form.id);
|
|
91
|
+
});
|
|
92
|
+
component.actions.create('validate', function (input) {
|
|
93
|
+
var cmClient = new ContactMethodClient();
|
|
94
|
+
cmClient.validate(input.form);
|
|
95
|
+
});
|
|
96
|
+
component.actions.create('submit', function (input) {
|
|
97
|
+
var cmClient = new ContactMethodClient();
|
|
98
|
+
cmClient.validate(input.form);
|
|
99
|
+
});
|
|
100
|
+
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
101
|
+
return next(input);
|
|
102
|
+
});
|
|
103
|
+
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
104
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
105
|
+
httpClient.handlePhrase(input.text);
|
|
106
|
+
return next(input);
|
|
107
|
+
});
|
|
108
|
+
component.actions.watch('conversation.form', function (input, next) {
|
|
109
|
+
return next(input);
|
|
110
|
+
});
|
|
111
|
+
component.actions.watch('conversation.action', function (input, next) {
|
|
112
|
+
var chatClient = new ChatClient();
|
|
113
|
+
var cmClient = new ContactMethodClient();
|
|
114
|
+
// if (input === 'contact' || input.split('/').length > 1) {
|
|
115
|
+
// cmClient.handleContactMethod(input);
|
|
116
|
+
// return next(input);
|
|
117
|
+
// }
|
|
118
|
+
if (input.split('/').length > 1) {
|
|
119
|
+
cmClient.handleContactMethod(input);
|
|
120
|
+
return next(input);
|
|
121
|
+
}
|
|
122
|
+
var middlewareClient = new MiddlewareClient();
|
|
123
|
+
var httpClient = new HttpClient(endpoint, clientId);
|
|
124
|
+
// this is an update check, as it requires
|
|
125
|
+
// a lot different logic and no user message
|
|
126
|
+
if (middlewareClient.checkForUpdate(input)) {
|
|
127
|
+
httpClient.handleUpdate(input);
|
|
128
|
+
return next(input);
|
|
163
129
|
}
|
|
130
|
+
chatClient.printUserMessageAndStoreIt(input);
|
|
131
|
+
httpClient.handleInput(input);
|
|
132
|
+
return next(input);
|
|
164
133
|
});
|
|
165
|
-
}); };
|
|
166
|
-
getConversationComponent().then(function (conversationComp) {
|
|
167
|
-
if (conversationComp && (conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint)) {
|
|
168
|
-
execute(conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
// const { events } = container.get('$widget') as Widget;
|
|
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) {
|
|
184
|
-
var _a, _b;
|
|
185
|
-
if (providerRegistered) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
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)) {
|
|
189
|
-
execute(data.node.attributes.properties.knowledgeBotEndpoint);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
134
|
});
|
|
194
135
|
return [2 /*return*/];
|
|
195
136
|
}
|
|
@@ -6,7 +6,8 @@ export declare class ContactMethodClient {
|
|
|
6
6
|
private static contactMessageEntryArray;
|
|
7
7
|
private static agent;
|
|
8
8
|
private chatClient;
|
|
9
|
-
static
|
|
9
|
+
private static container;
|
|
10
|
+
static initialize(container: any, dataClient: DataClient, contactMethodPlatform: ContactMethodPlatform, agent: any): void;
|
|
10
11
|
handleNewForm: (errors: any, entry: any) => Promise<void>;
|
|
11
12
|
handleContactMethod: (input?: string) => Promise<void>;
|
|
12
13
|
validate(form: any): void;
|
|
@@ -135,10 +135,11 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
135
135
|
return (contactMethod === null || contactMethod === void 0 ? void 0 : contactMethod.body) || {};
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
ContactMethodClient.initialize = function (dataClient, contactMethodPlatform, agent) {
|
|
138
|
+
ContactMethodClient.initialize = function (container, dataClient, contactMethodPlatform, agent) {
|
|
139
139
|
this.dataClient = dataClient;
|
|
140
140
|
this.contactMethodPlatform = contactMethodPlatform;
|
|
141
141
|
this.agent = agent;
|
|
142
|
+
this.container = container;
|
|
142
143
|
};
|
|
143
144
|
// validation of the form provided
|
|
144
145
|
ContactMethodClient.prototype.validate = function (form) {
|
|
@@ -241,9 +242,18 @@ var ContactMethodClient = /** @class */ (function () {
|
|
|
241
242
|
if (id === void 0) { id = undefined; }
|
|
242
243
|
switch (dataType) {
|
|
243
244
|
case DataType.ContactMethodCategories: {
|
|
244
|
-
return ContactMethodClient.
|
|
245
|
-
.
|
|
246
|
-
.then(function (
|
|
245
|
+
return ContactMethodClient.container
|
|
246
|
+
.getAsync('matchingClient')
|
|
247
|
+
.then(function (matchingClient) {
|
|
248
|
+
return matchingClient.customRequest('/contactmethods', 'GET', {});
|
|
249
|
+
})
|
|
250
|
+
.then(function (contactMethods) {
|
|
251
|
+
console.log('contactmethodsxxx', contactMethods);
|
|
252
|
+
return contactMethods;
|
|
253
|
+
});
|
|
254
|
+
// return ContactMethodClient.dataClient
|
|
255
|
+
// .fetch(DataType.ContactMethods, { contactMethodCategoryId: id })
|
|
256
|
+
// .then((contactMethods) => contactMethods);
|
|
247
257
|
}
|
|
248
258
|
case DataType.ContactMethods: {
|
|
249
259
|
if (!!id) {
|
|
@@ -33,6 +33,9 @@ var ContactMethodItem = function (props) {
|
|
|
33
33
|
var container = useContainer();
|
|
34
34
|
var _a = __read(useState(props.contactMethod.body), 2), body = _a[0], setBody = _a[1];
|
|
35
35
|
useEffect(function () {
|
|
36
|
+
if (!container || !container.get('$widget')) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
36
39
|
var events = container.get('$widget').events;
|
|
37
40
|
events.subscribe('form:validated', function (_event, _data) {
|
|
38
41
|
// TODO: this is a due to props not being updated when props.contactMethod.body changes
|
|
@@ -23,6 +23,7 @@ var ContactMethod = function (props) {
|
|
|
23
23
|
type = DataType.ContactMethod;
|
|
24
24
|
methodList = props.contactMethods;
|
|
25
25
|
}
|
|
26
|
+
// TODO: ContactMethodItem should not be passed a list as contact method?
|
|
26
27
|
if (!methodList.length) {
|
|
27
28
|
return React.createElement(StyledContactMethodItem, { type: type, contactMethod: methodList });
|
|
28
29
|
}
|
|
@@ -2,6 +2,7 @@ export var ServerEntryTypeEnum;
|
|
|
2
2
|
(function (ServerEntryTypeEnum) {
|
|
3
3
|
ServerEntryTypeEnum[ServerEntryTypeEnum["Widget"] = 0] = "Widget";
|
|
4
4
|
ServerEntryTypeEnum[ServerEntryTypeEnum["Text"] = 1] = "Text";
|
|
5
|
-
ServerEntryTypeEnum[ServerEntryTypeEnum["
|
|
6
|
-
ServerEntryTypeEnum[ServerEntryTypeEnum["
|
|
5
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["Contact"] = 2] = "Contact";
|
|
6
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["List"] = 3] = "List";
|
|
7
|
+
ServerEntryTypeEnum[ServerEntryTypeEnum["Error"] = 4] = "Error";
|
|
7
8
|
})(ServerEntryTypeEnum || (ServerEntryTypeEnum = {}));
|