@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.4 → 0.0.1-alpha.40
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/chat.client.d.ts +3 -2
- package/lib/client/chat.client.js +98 -33
- package/lib/client/contact-method.client.d.ts +9 -1
- package/lib/client/contact-method.client.js +48 -32
- package/lib/client/http.client.d.ts +11 -7
- package/lib/client/http.client.js +138 -41
- package/lib/client/middleware.client.d.ts +4 -3
- package/lib/client/middleware.client.js +100 -35
- package/lib/contract/custom-component/contact-method-item.js +12 -34
- package/lib/contract/custom-component/contact-method-list.js +6 -34
- package/lib/contract/custom-component/contact-method.js +12 -17
- package/lib/contract/enum/server-entry-type.enum.d.ts +3 -2
- package/lib/contract/enum/server-entry-type.enum.js +5 -7
- package/lib/contract/model/conversation-api-model/list.model.js +1 -2
- package/lib/contract/model/conversation-api-model/message.model.js +1 -2
- package/lib/contract/model/http/action.model.js +1 -2
- package/lib/contract/model/http/client-action.model.js +1 -2
- package/lib/contract/model/http/client-envelope.model.js +1 -2
- package/lib/contract/model/http/connect-options.model.js +1 -2
- package/lib/contract/model/http/global-state.model.js +1 -2
- package/lib/contract/model/http/http-client-options.model.js +1 -2
- package/lib/contract/model/http/server-entry.model.js +1 -2
- package/lib/contract/model/http/server-envelope.model.js +1 -2
- package/lib/contract/model/middleware/aggregator-state.model.js +1 -2
- package/lib/contract/model/shared/loose-object.model.js +1 -2
- package/lib/helper/chat.helper.js +1 -4
- package/lib/helper/http.helper.d.ts +1 -1
- package/lib/helper/http.helper.js +8 -13
- package/lib/helper/middleware.helper.d.ts +1 -1
- package/lib/helper/middleware.helper.js +7 -11
- package/lib/helper/store.helper.d.ts +4 -3
- package/lib/helper/store.helper.js +105 -16
- package/lib/index.js +2 -8
- package/lib/interface/entry.interface.d.ts +6 -3
- package/lib/interface/entry.interface.js +176 -57
- package/lib/interface/middleware/paging.interface.js +3 -5
- package/lib/interface/middleware/processor.interface.js +1 -3
- package/lib/plugin.d.ts +2 -2
- package/lib/plugin.js +73 -90
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +5 -0
- package/lib-esm/client/chat.client.d.ts +3 -2
- package/lib-esm/client/chat.client.js +81 -11
- package/lib-esm/client/contact-method.client.d.ts +9 -1
- package/lib-esm/client/contact-method.client.js +28 -6
- package/lib-esm/client/http.client.d.ts +11 -7
- package/lib-esm/client/http.client.js +125 -22
- package/lib-esm/client/middleware.client.d.ts +4 -3
- package/lib-esm/client/middleware.client.js +89 -19
- package/lib-esm/contract/custom-component/contact-method-item.js +4 -1
- 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/helper/http.helper.d.ts +1 -1
- package/lib-esm/helper/http.helper.js +7 -9
- package/lib-esm/helper/middleware.helper.d.ts +1 -1
- package/lib-esm/helper/middleware.helper.js +5 -6
- package/lib-esm/helper/store.helper.d.ts +4 -3
- package/lib-esm/helper/store.helper.js +103 -11
- package/lib-esm/interface/entry.interface.d.ts +6 -3
- package/lib-esm/interface/entry.interface.js +160 -39
- package/lib-esm/plugin.d.ts +2 -2
- package/lib-esm/plugin.js +66 -55
- package/lib-esm/utils.d.ts +1 -0
- package/lib-esm/utils.js +5 -0
- package/package.json +45 -45
- package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
- package/lib/interface/middleware/contact-expanded.interface.js +0 -50
- package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
- package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
package/lib-esm/plugin.js
CHANGED
|
@@ -34,103 +34,114 @@ 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 '@telia-ace/knowledge-widget-adapters';
|
|
54
|
-
import { ComponentPlatform } from '@telia-ace/knowledge-widget-core';
|
|
55
38
|
import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
|
|
56
39
|
import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
|
|
40
|
+
import { v4 } from 'uuid';
|
|
57
41
|
import ChatClient from './client/chat.client';
|
|
58
42
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
59
43
|
import { HttpClient } from './client/http.client';
|
|
60
44
|
import MiddlewareClient from './client/middleware.client';
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
import { getContactMethodEntry } from './utils';
|
|
46
|
+
var getKnowledgeBotEndpoint = function (container, component /*: ComponentNodeController */
|
|
47
|
+
// ComponentNodeController type differs from component passed into registerProvider
|
|
48
|
+
) {
|
|
49
|
+
var knowledgeBotEndpoint = component.properties().knowledgeBotEndpoint;
|
|
50
|
+
if (knowledgeBotEndpoint) {
|
|
51
|
+
return "".concat(knowledgeBotEndpoint, "/conversations");
|
|
52
|
+
}
|
|
53
|
+
var data = container.get('$settings').data;
|
|
54
|
+
if (!data || !data.projection)
|
|
55
|
+
throw new Error('Missing Knowledge Bot endpoint');
|
|
56
|
+
return "".concat(data.projection, "/conversations");
|
|
57
|
+
};
|
|
58
|
+
var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
+
var dataClient, platform, contactMethodPlatform;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0: return [4 /*yield*/, DataClient.getInstance(container)];
|
|
66
63
|
case 1:
|
|
67
|
-
|
|
68
|
-
return [4 /*yield*/,
|
|
64
|
+
dataClient = _a.sent();
|
|
65
|
+
return [4 /*yield*/, ConversationPlatform.getInstance(container)];
|
|
69
66
|
case 2:
|
|
70
|
-
|
|
71
|
-
return [4 /*yield*/,
|
|
67
|
+
platform = _a.sent();
|
|
68
|
+
return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
|
|
72
69
|
case 3:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
case 4:
|
|
76
|
-
compPlatform = _b.sent();
|
|
77
|
-
_a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
|
|
78
|
-
endpoint = '';
|
|
79
|
-
setTimeout(function () {
|
|
80
|
-
endpoint = component.attributes.properties.knowledgeBotEndpoint;
|
|
81
|
-
});
|
|
70
|
+
contactMethodPlatform = _a.sent();
|
|
71
|
+
registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
|
|
82
72
|
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
|
|
73
|
+
var endpoint = getKnowledgeBotEndpoint(container, component);
|
|
74
|
+
var clientId = v4();
|
|
75
|
+
var agent = conversation.createAgent({
|
|
76
|
+
name: '',
|
|
77
|
+
avatar: undefined,
|
|
78
|
+
});
|
|
79
|
+
// passes the user and the agent to the Chat Helper
|
|
86
80
|
ChatClient.initialize(conversation.user, agent);
|
|
87
81
|
// passes the conversation provider to the Contact Method Client
|
|
88
|
-
ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
|
|
82
|
+
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
89
83
|
// passes the container and the widget to the Middleware Store
|
|
90
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
91
85
|
// executes to decide on what to do on first load
|
|
92
|
-
var httpClient = new HttpClient(endpoint);
|
|
93
|
-
|
|
86
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
87
|
+
var firstLoader = conversation.loading();
|
|
88
|
+
httpClient.firstHit().then(firstLoader);
|
|
94
89
|
component.actions.create('evaluate', function (input) {
|
|
95
|
-
var cmClient = new ContactMethodClient();
|
|
90
|
+
var cmClient = new ContactMethodClient(container);
|
|
96
91
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
97
92
|
});
|
|
98
93
|
component.actions.create('validate', function (input) {
|
|
99
|
-
var cmClient = new ContactMethodClient();
|
|
94
|
+
var cmClient = new ContactMethodClient(container);
|
|
100
95
|
cmClient.validate(input.form);
|
|
101
96
|
});
|
|
102
97
|
component.actions.create('submit', function (input) {
|
|
103
|
-
var
|
|
98
|
+
var _a;
|
|
99
|
+
if ((_a = input === null || input === void 0 ? void 0 : input.form) === null || _a === void 0 ? void 0 : _a.schema.id) {
|
|
100
|
+
var contactMethodEntry = getContactMethodEntry(input.form.schema.id);
|
|
101
|
+
if (contactMethodEntry) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
var cmClient = new ContactMethodClient(container);
|
|
104
105
|
cmClient.validate(input.form);
|
|
105
106
|
});
|
|
106
107
|
component.actions.watch('conversation.user-typing', function (input, next) {
|
|
107
108
|
return next(input);
|
|
108
109
|
});
|
|
109
110
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
110
|
-
var httpClient = new HttpClient(endpoint);
|
|
111
|
-
|
|
111
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
112
|
+
var loader = conversation.loading();
|
|
113
|
+
httpClient.handlePhrase(input.text).then(loader);
|
|
112
114
|
return next(input);
|
|
113
115
|
});
|
|
114
116
|
component.actions.watch('conversation.form', function (input, next) {
|
|
115
117
|
return next(input);
|
|
116
118
|
});
|
|
117
119
|
component.actions.watch('conversation.action', function (input, next) {
|
|
118
|
-
var chatClient = new ChatClient();
|
|
119
|
-
var cmClient = new ContactMethodClient();
|
|
120
|
-
if (input === 'contact' || input.split('/').length > 1) {
|
|
121
|
-
|
|
120
|
+
var chatClient = new ChatClient(container);
|
|
121
|
+
var cmClient = new ContactMethodClient(container);
|
|
122
|
+
// if (input === 'contact' || input.split('/').length > 1) {
|
|
123
|
+
// cmClient.handleContactMethod(input);
|
|
124
|
+
// return next(input);
|
|
125
|
+
// }
|
|
126
|
+
var loader = conversation.loading();
|
|
127
|
+
if (input.split('/').length > 1) {
|
|
128
|
+
cmClient.handleContactMethod(input).then(loader);
|
|
129
|
+
return next(input);
|
|
130
|
+
}
|
|
131
|
+
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
132
|
+
if (input == 'burger-clicked') {
|
|
133
|
+
httpClient.handleCategories().then(loader);
|
|
122
134
|
return next(input);
|
|
123
135
|
}
|
|
124
|
-
var middlewareClient = new MiddlewareClient();
|
|
136
|
+
var middlewareClient = new MiddlewareClient(container);
|
|
125
137
|
// this is an update check, as it requires
|
|
126
138
|
// a lot different logic and no user message
|
|
127
139
|
if (middlewareClient.checkForUpdate(input)) {
|
|
128
|
-
|
|
140
|
+
httpClient.handleUpdate(input).then(loader);
|
|
129
141
|
return next(input);
|
|
130
142
|
}
|
|
131
143
|
chatClient.printUserMessageAndStoreIt(input);
|
|
132
|
-
|
|
133
|
-
httpClient.handleInput(input);
|
|
144
|
+
httpClient.handleInput(input).then(loader);
|
|
134
145
|
return next(input);
|
|
135
146
|
});
|
|
136
147
|
});
|
|
@@ -138,4 +149,4 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
|
|
|
138
149
|
}
|
|
139
150
|
});
|
|
140
151
|
}); };
|
|
141
|
-
export default
|
|
152
|
+
export default KnowledgeBotProviderPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getContactMethodEntry: (contactMethodId: string) => import("./contract/model/http/server-entry.model").ServerEntry | undefined;
|
package/lib-esm/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@telia-ace/knowledge-widget-bot-provider",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
4
|
-
"description": "Bot Provider Plugin ACE Knowledge Widgets.",
|
|
5
|
-
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
-
"author": "Telia Company AB",
|
|
7
|
-
"keywords": [
|
|
8
|
-
"telia"
|
|
9
|
-
],
|
|
10
|
-
"main": "lib/index.js",
|
|
11
|
-
"module": "lib-esm/index.js",
|
|
12
|
-
"files": [
|
|
13
|
-
"LICENSE.txt",
|
|
14
|
-
"README.md",
|
|
15
|
-
"lib/",
|
|
16
|
-
"lib-esm/"
|
|
17
|
-
],
|
|
18
|
-
"publishConfig": {
|
|
19
|
-
"access": "public"
|
|
20
|
-
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"clean": "cleandir lib && cleandir lib-esm",
|
|
23
|
-
"compile": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json"
|
|
24
|
-
},
|
|
25
|
-
"sideEffects": false,
|
|
26
|
-
"typings": "lib/index.d.ts",
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"@telia-ace/knowledge-widget-adapters": "^1.0.
|
|
29
|
-
"@telia-ace/knowledge-widget-
|
|
30
|
-
"@telia-ace/knowledge-widget-
|
|
31
|
-
"@telia-ace/widget-
|
|
32
|
-
"@telia-ace/widget-
|
|
33
|
-
"@telia-ace/widget-
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@telia-ace/knowledge-widget-bot-provider",
|
|
3
|
+
"version": "0.0.1-alpha.40",
|
|
4
|
+
"description": "Bot Provider Plugin ACE Knowledge Widgets.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"author": "Telia Company AB",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"telia"
|
|
9
|
+
],
|
|
10
|
+
"main": "lib/index.js",
|
|
11
|
+
"module": "lib-esm/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"LICENSE.txt",
|
|
14
|
+
"README.md",
|
|
15
|
+
"lib/",
|
|
16
|
+
"lib-esm/"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "cleandir lib && cleandir lib-esm",
|
|
23
|
+
"compile": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"typings": "lib/index.d.ts",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@telia-ace/knowledge-widget-adapters": "^1.0.9",
|
|
29
|
+
"@telia-ace/knowledge-widget-types-grid": "^1.0.9",
|
|
30
|
+
"@telia-ace/knowledge-widget-ui": "^1.0.7",
|
|
31
|
+
"@telia-ace/widget-conversation": "^1.0.8",
|
|
32
|
+
"@telia-ace/widget-forms": "^1.0.6",
|
|
33
|
+
"@telia-ace/widget-services": "^1.0.4",
|
|
34
|
+
"@webprovisions/bootstrapping": "^1.0.12",
|
|
35
|
+
"uuid": "^8.3.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^16.8.0",
|
|
39
|
+
"styled-components": "^4.3.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/uuid": "^8.3.4"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "d6b4f95adbfce4da6dfc5365a3abbc5624bc4ffa"
|
|
45
|
+
}
|
|
File without changes
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { convertToStringAttributes } from "@humany/widget-ui";
|
|
3
|
-
// import { ServerEntry } from "../../contract/model/http/server-entry.model";
|
|
4
|
-
// import { StoreHelper } from "../../helper/store.helper";
|
|
5
|
-
// export default class ContactExpandedInterface {
|
|
6
|
-
// name = "contact-expanded-handler";
|
|
7
|
-
// constructor() {}
|
|
8
|
-
// process(entries: ServerEntry[], action?: string): ServerEntry[] {
|
|
9
|
-
// let didSelect = false;
|
|
10
|
-
// let didCategorySelect = false;
|
|
11
|
-
// if (!action) return entries;
|
|
12
|
-
// const entry = StoreHelper.getEntry(action);
|
|
13
|
-
// if (
|
|
14
|
-
// entry.actions &&
|
|
15
|
-
// entry.actions[action] &&
|
|
16
|
-
// entry.actions[action].$type.indexOf("SelectContactMethod") !== -1
|
|
17
|
-
// ) {
|
|
18
|
-
// didSelect = true;
|
|
19
|
-
// }
|
|
20
|
-
// if (
|
|
21
|
-
// entry.actions &&
|
|
22
|
-
// entry.actions[action] &&
|
|
23
|
-
// entry.actions[action].$type.indexOf("SelectContactCategory") !== -1
|
|
24
|
-
// ) {
|
|
25
|
-
// didCategorySelect = true;
|
|
26
|
-
// }
|
|
27
|
-
// entries
|
|
28
|
-
// .filter(
|
|
29
|
-
// (e) =>
|
|
30
|
-
// e.type === "Contact" ||
|
|
31
|
-
// (e.type === "List" &&
|
|
32
|
-
// e.tags.indexOf("contact") > -1 &&
|
|
33
|
-
// e.tags.indexOf("category") === -1)
|
|
34
|
-
// ).forEach((e) => {
|
|
35
|
-
// if (e.type === "List") {
|
|
36
|
-
// if (e.content && e.content.items && e.content.items.length === 1) {
|
|
37
|
-
// const item = e.content.items[0];
|
|
38
|
-
// const hasForm = !!item && !!item.body && !!item.body.form;
|
|
39
|
-
// if (hasForm) {
|
|
40
|
-
// e.content.items[0].inline = !didCategorySelect;
|
|
41
|
-
// if (didSelect) {
|
|
42
|
-
// e.content.items[0].expanded = true;
|
|
43
|
-
// }
|
|
44
|
-
// }
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// });
|
|
48
|
-
// return entries;
|
|
49
|
-
// }
|
|
50
|
-
// }
|
|
File without changes
|