@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.
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
- declare const ContactMethod: React.FC;
2
+ declare const ContactMethod: React.FC<any>;
3
3
  export default ContactMethod;
@@ -1,33 +1,32 @@
1
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
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
- var ContactMethod = function (props) {
11
- var _a, _b;
12
- var type;
13
- var methodList;
14
- if (props.contactMethods && ((_a = props.contactMethods.contactMethods) === null || _a === void 0 ? void 0 : _a.length) > 0) {
15
- type = DataType.ContactMethods;
16
- methodList = props.contactMethods.contactMethods;
17
- }
18
- else if (props.contactMethods.categories && ((_b = props.contactMethods.categories) === null || _b === void 0 ? void 0 : _b.length) > 0) {
19
- type = DataType.ContactMethodCategories;
20
- methodList = props.contactMethods.categories.filter(function (o) { return o.matches > 0; });
21
- }
22
- else {
23
- type = DataType.ContactMethod;
24
- methodList = props.contactMethods;
25
- }
26
- if (!methodList.length) {
27
- return React.createElement(StyledContactMethodItem, { type: type, contactMethod: methodList });
28
- }
29
- return React.createElement(ContactMethodList, { type: type, contactMethodList: methodList });
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 ConversationPlugin: (container: Container) => Promise<void>;
3
- export default ConversationPlugin;
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 ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
63
- var providerRegistered, platform, contactMethodPlatform, dataClient, compPlatform, events, getConversationComponent, execute;
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 4:
79
- compPlatform = _a.sent();
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 compPlatform, _a, component;
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
- compPlatform = _d.sent();
90
- _a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
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
- // let endpoint = '';
103
- // console.log(
104
- // 'getting endpoint',
105
- // conversationComp,
106
- // conversationComp?.attributes?.properties?.knowledgeBotEndpoint
107
- // );
108
- // // setTimeout(() => {
109
- // if (conversationComp?.attributes?.properties?.knowledgeBotEndpoint) {
110
- // endpoint = conversationComp.attributes.properties.knowledgeBotEndpoint;
111
- // }
112
- // });
113
- providerRegistered = true;
114
- console.log('executing with endpoint', endpoint);
115
- platform.registerProvider('chat.bot', function (conversation, component) {
116
- var clientId = v4();
117
- registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
118
- var agent = conversation.createAgent({
119
- // TODO: needs to be fixed asap
120
- name: 'John Doe',
121
- avatar: 'https://www.site.com/avatar.jpg',
122
- });
123
- console.log('initailizing');
124
- // passes the user and the agent to the Chat Helper
125
- ChatClient.initialize(conversation.user, agent);
126
- // passes the conversation provider to the Contact Method Client
127
- ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
128
- // passes the container and the widget to the Middleware Store
129
- MiddlewareClient.initialize(container, container.get('$widget'));
130
- // executes to decide on what to do on first load
131
- var httpClient = new HttpClient(endpoint, clientId);
132
- httpClient.firstHit();
133
- component.actions.create('evaluate', function (input) {
134
- var cmClient = new ContactMethodClient();
135
- cmClient.handleNewForm(input.form, input.form.id);
136
- });
137
- component.actions.create('validate', function (input) {
138
- var cmClient = new ContactMethodClient();
139
- cmClient.validate(input.form);
140
- });
141
- component.actions.create('submit', function (input) {
142
- var cmClient = new ContactMethodClient();
143
- cmClient.validate(input.form);
144
- });
145
- component.actions.watch('conversation.user-typing', function (input, next) {
146
- return next(input);
147
- });
148
- component.actions.watch('conversation.user-submit', function (input, next) {
149
- var httpClient = new HttpClient(endpoint, clientId);
150
- httpClient.handlePhrase(input.text);
151
- return next(input);
152
- });
153
- component.actions.watch('conversation.form', function (input, next) {
154
- return next(input);
155
- });
156
- component.actions.watch('conversation.action', function (input, next) {
157
- var chatClient = new ChatClient();
158
- var cmClient = new ContactMethodClient();
159
- if (input === 'contact' || input.split('/').length > 1) {
160
- cmClient.handleContactMethod(input);
161
- return next(input);
162
- }
163
- var middlewareClient = new MiddlewareClient();
164
- var httpClient = new HttpClient(endpoint, clientId);
165
- // this is an update check, as it requires
166
- // a lot different logic and no user message
167
- if (middlewareClient.checkForUpdate(input)) {
168
- httpClient.handleUpdate(input);
169
- return next(input);
170
- }
171
- chatClient.printUserMessageAndStoreIt(input);
172
- httpClient.handleInput(input);
173
- return next(input);
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', function (event, data) {
186
- var _a, _b;
187
- if (providerRegistered) {
188
- return;
189
- }
190
- console.log('data components:node-mounted', data); // TODO: remove
191
- 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
- // const component = getConversationComponent();
193
- console.log('execute on event');
194
- execute(data.node.attributes.properties.knowledgeBotEndpoint);
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 ConversationPlugin;
198
+ export default KnowledgeBotProviderPlugin;
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
- declare const ContactMethod: React.FC;
2
+ declare const ContactMethod: React.FC<any>;
3
3
  export default ContactMethod;
@@ -1,33 +1,32 @@
1
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
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
- var ContactMethod = function (props) {
11
- var _a, _b;
12
- var type;
13
- var methodList;
14
- if (props.contactMethods && ((_a = props.contactMethods.contactMethods) === null || _a === void 0 ? void 0 : _a.length) > 0) {
15
- type = DataType.ContactMethods;
16
- methodList = props.contactMethods.contactMethods;
17
- }
18
- else if (props.contactMethods.categories && ((_b = props.contactMethods.categories) === null || _b === void 0 ? void 0 : _b.length) > 0) {
19
- type = DataType.ContactMethodCategories;
20
- methodList = props.contactMethods.categories.filter(function (o) { return o.matches > 0; });
21
- }
22
- else {
23
- type = DataType.ContactMethod;
24
- methodList = props.contactMethods;
25
- }
26
- if (!methodList.length) {
27
- return React.createElement(StyledContactMethodItem, { type: type, contactMethod: methodList });
28
- }
29
- return React.createElement(ContactMethodList, { type: type, contactMethodList: methodList });
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;
@@ -1,3 +1,3 @@
1
1
  import { Container } from '@webprovisions/platform';
2
- declare const ConversationPlugin: (container: Container) => Promise<void>;
3
- export default ConversationPlugin;
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 ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
63
- var providerRegistered, platform, contactMethodPlatform, dataClient, compPlatform, events, getConversationComponent, execute;
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 4:
79
- compPlatform = _a.sent();
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 compPlatform, _a, component;
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
- compPlatform = _d.sent();
90
- _a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
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
- // let endpoint = '';
103
- // console.log(
104
- // 'getting endpoint',
105
- // conversationComp,
106
- // conversationComp?.attributes?.properties?.knowledgeBotEndpoint
107
- // );
108
- // // setTimeout(() => {
109
- // if (conversationComp?.attributes?.properties?.knowledgeBotEndpoint) {
110
- // endpoint = conversationComp.attributes.properties.knowledgeBotEndpoint;
111
- // }
112
- // });
113
- providerRegistered = true;
114
- console.log('executing with endpoint', endpoint);
115
- platform.registerProvider('chat.bot', function (conversation, component) {
116
- var clientId = v4();
117
- registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
118
- var agent = conversation.createAgent({
119
- // TODO: needs to be fixed asap
120
- name: 'John Doe',
121
- avatar: 'https://www.site.com/avatar.jpg',
122
- });
123
- console.log('initailizing');
124
- // passes the user and the agent to the Chat Helper
125
- ChatClient.initialize(conversation.user, agent);
126
- // passes the conversation provider to the Contact Method Client
127
- ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
128
- // passes the container and the widget to the Middleware Store
129
- MiddlewareClient.initialize(container, container.get('$widget'));
130
- // executes to decide on what to do on first load
131
- var httpClient = new HttpClient(endpoint, clientId);
132
- httpClient.firstHit();
133
- component.actions.create('evaluate', function (input) {
134
- var cmClient = new ContactMethodClient();
135
- cmClient.handleNewForm(input.form, input.form.id);
136
- });
137
- component.actions.create('validate', function (input) {
138
- var cmClient = new ContactMethodClient();
139
- cmClient.validate(input.form);
140
- });
141
- component.actions.create('submit', function (input) {
142
- var cmClient = new ContactMethodClient();
143
- cmClient.validate(input.form);
144
- });
145
- component.actions.watch('conversation.user-typing', function (input, next) {
146
- return next(input);
147
- });
148
- component.actions.watch('conversation.user-submit', function (input, next) {
149
- var httpClient = new HttpClient(endpoint, clientId);
150
- httpClient.handlePhrase(input.text);
151
- return next(input);
152
- });
153
- component.actions.watch('conversation.form', function (input, next) {
154
- return next(input);
155
- });
156
- component.actions.watch('conversation.action', function (input, next) {
157
- var chatClient = new ChatClient();
158
- var cmClient = new ContactMethodClient();
159
- if (input === 'contact' || input.split('/').length > 1) {
160
- cmClient.handleContactMethod(input);
161
- return next(input);
162
- }
163
- var middlewareClient = new MiddlewareClient();
164
- var httpClient = new HttpClient(endpoint, clientId);
165
- // this is an update check, as it requires
166
- // a lot different logic and no user message
167
- if (middlewareClient.checkForUpdate(input)) {
168
- httpClient.handleUpdate(input);
169
- return next(input);
170
- }
171
- chatClient.printUserMessageAndStoreIt(input);
172
- httpClient.handleInput(input);
173
- return next(input);
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', function (event, data) {
186
- var _a, _b;
187
- if (providerRegistered) {
188
- return;
189
- }
190
- console.log('data components:node-mounted', data); // TODO: remove
191
- 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
- // const component = getConversationComponent();
193
- console.log('execute on event');
194
- execute(data.node.attributes.properties.knowledgeBotEndpoint);
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 ConversationPlugin;
198
+ export default KnowledgeBotProviderPlugin;
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.18",
3
+ "version": "0.0.1-alpha.19",
4
4
  "description": "Bot Provider Plugin ACE Knowledge Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",