@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.
@@ -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,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 ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
63
- var 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
- case 0: return [4 /*yield*/, ConversationPlatform.getInstance(container)];
67
- case 1:
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 4:
77
- compPlatform = _a.sent();
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 compPlatform, _a, component;
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
- compPlatform = _d.sent();
88
- _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];
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 (conversationComp) { return __awaiter(void 0, void 0, void 0, function () {
99
- var endpoint;
100
- var _a, _b, _c, _d;
101
- return __generator(this, function (_e) {
102
- endpoint = '';
103
- console.log('getting endpoint', conversationComp, (_b = (_a = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.knowledgeBotEndpoint);
104
- // setTimeout(() => {
105
- if ((_d = (_c = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.knowledgeBotEndpoint) {
106
- endpoint = conversationComp.attributes.properties.knowledgeBotEndpoint;
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
- console.log('execute on first');
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', 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) {
180
184
  var _a, _b;
181
- console.log('data components:node-mounted', data); // TODO: remove
182
- 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)) {
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
- console.log('conversation component property change', data);
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 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,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 ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
63
- var 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
- case 0: return [4 /*yield*/, ConversationPlatform.getInstance(container)];
67
- case 1:
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 4:
77
- compPlatform = _a.sent();
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 compPlatform, _a, component;
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
- compPlatform = _d.sent();
88
- _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];
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 (conversationComp) { return __awaiter(void 0, void 0, void 0, function () {
99
- var endpoint;
100
- var _a, _b, _c, _d;
101
- return __generator(this, function (_e) {
102
- endpoint = '';
103
- console.log('getting endpoint', conversationComp, (_b = (_a = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.knowledgeBotEndpoint);
104
- // setTimeout(() => {
105
- if ((_d = (_c = conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.knowledgeBotEndpoint) {
106
- endpoint = conversationComp.attributes.properties.knowledgeBotEndpoint;
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
- console.log('execute on first');
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', 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) {
180
184
  var _a, _b;
181
- console.log('data components:node-mounted', data); // TODO: remove
182
- 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)) {
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
- console.log('conversation component property change', data);
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 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.16",
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",