@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.22 → 0.0.1-alpha.23

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.
@@ -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
  }
package/lib/plugin.js CHANGED
@@ -34,162 +34,99 @@ 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 providerRegistered, componentPlatform, getConversationComponent, execute;
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
- componentPlatform = _a.sent();
71
- getConversationComponent = function () { return __awaiter(void 0, void 0, void 0, function () {
72
- var platform, _a, component;
73
- var _b, _c;
74
- return __generator(this, function (_d) {
75
- switch (_d.label) {
76
- case 0: return [4 /*yield*/, ComponentPlatform.getInstance(container)];
77
- case 1:
78
- platform = _d.sent();
79
- _a = __read(platform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
80
- 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)) {
81
- return [2 /*return*/];
82
- }
83
- return [2 /*return*/, component];
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
- execute = function (endpoint) { return __awaiter(void 0, void 0, void 0, function () {
88
- var dataClient, platform, contactMethodPlatform;
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0:
92
- providerRegistered = true;
93
- return [4 /*yield*/, DataClient.getInstance(container)];
94
- case 1:
95
- dataClient = _a.sent();
96
- return [4 /*yield*/, ConversationPlatform.getInstance(container)];
97
- case 2:
98
- platform = _a.sent();
99
- return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
100
- case 3:
101
- contactMethodPlatform = _a.sent();
102
- platform.registerProvider('chat.bot', function (conversation, component) {
103
- var clientId = v4();
104
- registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
105
- var agent = conversation.createAgent({
106
- // TODO: needs to be fixed asap
107
- name: 'John Doe',
108
- avatar: 'https://www.site.com/avatar.jpg',
109
- });
110
- // passes the user and the agent to the Chat Helper
111
- ChatClient.initialize(conversation.user, agent);
112
- // passes the conversation provider to the Contact Method Client
113
- ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
114
- // passes the container and the widget to the Middleware Store
115
- MiddlewareClient.initialize(container, container.get('$widget'));
116
- // executes to decide on what to do on first load
117
- var httpClient = new HttpClient(endpoint, clientId);
118
- httpClient.firstHit();
119
- component.actions.create('evaluate', function (input) {
120
- var cmClient = new ContactMethodClient();
121
- cmClient.handleNewForm(input.form, input.form.id);
122
- });
123
- component.actions.create('validate', function (input) {
124
- var cmClient = new ContactMethodClient();
125
- cmClient.validate(input.form);
126
- });
127
- component.actions.create('submit', function (input) {
128
- var cmClient = new ContactMethodClient();
129
- cmClient.validate(input.form);
130
- });
131
- component.actions.watch('conversation.user-typing', function (input, next) {
132
- return next(input);
133
- });
134
- component.actions.watch('conversation.user-submit', function (input, next) {
135
- var httpClient = new HttpClient(endpoint, clientId);
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(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
+ var middlewareClient = new MiddlewareClient();
119
+ var httpClient = new HttpClient(endpoint, clientId);
120
+ // this is an update check, as it requires
121
+ // a lot different logic and no user message
122
+ if (middlewareClient.checkForUpdate(input)) {
123
+ httpClient.handleUpdate(input);
124
+ return next(input);
163
125
  }
126
+ chatClient.printUserMessageAndStoreIt(input);
127
+ httpClient.handleInput(input);
128
+ return next(input);
164
129
  });
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
130
  });
194
131
  return [2 /*return*/];
195
132
  }
@@ -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
  }
package/lib-esm/plugin.js CHANGED
@@ -34,162 +34,99 @@ 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 providerRegistered, componentPlatform, getConversationComponent, execute;
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
- componentPlatform = _a.sent();
71
- getConversationComponent = function () { return __awaiter(void 0, void 0, void 0, function () {
72
- var platform, _a, component;
73
- var _b, _c;
74
- return __generator(this, function (_d) {
75
- switch (_d.label) {
76
- case 0: return [4 /*yield*/, ComponentPlatform.getInstance(container)];
77
- case 1:
78
- platform = _d.sent();
79
- _a = __read(platform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
80
- 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)) {
81
- return [2 /*return*/];
82
- }
83
- return [2 /*return*/, component];
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
- execute = function (endpoint) { return __awaiter(void 0, void 0, void 0, function () {
88
- var dataClient, platform, contactMethodPlatform;
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0:
92
- providerRegistered = true;
93
- return [4 /*yield*/, DataClient.getInstance(container)];
94
- case 1:
95
- dataClient = _a.sent();
96
- return [4 /*yield*/, ConversationPlatform.getInstance(container)];
97
- case 2:
98
- platform = _a.sent();
99
- return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
100
- case 3:
101
- contactMethodPlatform = _a.sent();
102
- platform.registerProvider('chat.bot', function (conversation, component) {
103
- var clientId = v4();
104
- registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
105
- var agent = conversation.createAgent({
106
- // TODO: needs to be fixed asap
107
- name: 'John Doe',
108
- avatar: 'https://www.site.com/avatar.jpg',
109
- });
110
- // passes the user and the agent to the Chat Helper
111
- ChatClient.initialize(conversation.user, agent);
112
- // passes the conversation provider to the Contact Method Client
113
- ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
114
- // passes the container and the widget to the Middleware Store
115
- MiddlewareClient.initialize(container, container.get('$widget'));
116
- // executes to decide on what to do on first load
117
- var httpClient = new HttpClient(endpoint, clientId);
118
- httpClient.firstHit();
119
- component.actions.create('evaluate', function (input) {
120
- var cmClient = new ContactMethodClient();
121
- cmClient.handleNewForm(input.form, input.form.id);
122
- });
123
- component.actions.create('validate', function (input) {
124
- var cmClient = new ContactMethodClient();
125
- cmClient.validate(input.form);
126
- });
127
- component.actions.create('submit', function (input) {
128
- var cmClient = new ContactMethodClient();
129
- cmClient.validate(input.form);
130
- });
131
- component.actions.watch('conversation.user-typing', function (input, next) {
132
- return next(input);
133
- });
134
- component.actions.watch('conversation.user-submit', function (input, next) {
135
- var httpClient = new HttpClient(endpoint, clientId);
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(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
+ var middlewareClient = new MiddlewareClient();
119
+ var httpClient = new HttpClient(endpoint, clientId);
120
+ // this is an update check, as it requires
121
+ // a lot different logic and no user message
122
+ if (middlewareClient.checkForUpdate(input)) {
123
+ httpClient.handleUpdate(input);
124
+ return next(input);
163
125
  }
126
+ chatClient.printUserMessageAndStoreIt(input);
127
+ httpClient.handleInput(input);
128
+ return next(input);
164
129
  });
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
130
  });
194
131
  return [2 /*return*/];
195
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/knowledge-widget-bot-provider",
3
- "version": "0.0.1-alpha.22",
3
+ "version": "0.0.1-alpha.23",
4
4
  "description": "Bot Provider Plugin ACE Knowledge Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",