@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.42 → 0.0.1-alpha.45

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.
@@ -20,6 +20,10 @@ export declare class ContactMethodClient {
20
20
  type: string;
21
21
  noPadding: boolean;
22
22
  };
23
+ expandContactMethod(input: {
24
+ entryId: string;
25
+ contactMethodId: string;
26
+ }): void;
23
27
  private handleContactMethodList;
24
28
  private handleSingleContactMethod;
25
29
  private submit;
@@ -45,6 +45,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __read = (this && this.__read) || function (o, n) {
49
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
50
+ if (!m) return o;
51
+ var i = m.call(o), r, ar = [], e;
52
+ try {
53
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
+ }
55
+ catch (error) { e = { error: error }; }
56
+ finally {
57
+ try {
58
+ if (r && !r.done && (m = i["return"])) m.call(i);
59
+ }
60
+ finally { if (e) throw e.error; }
61
+ }
62
+ return ar;
63
+ };
64
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
65
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
+ if (ar || !(i in from)) {
67
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
+ ar[i] = from[i];
69
+ }
70
+ }
71
+ return to.concat(ar || Array.prototype.slice.call(from));
72
+ };
48
73
  import { DataType } from '@telia-ace/knowledge-widget-types-grid';
49
74
  import { FormBuilder, submitButton } from '@telia-ace/widget-forms';
50
75
  import { v4 as uuidv4 } from 'uuid';
@@ -170,6 +195,26 @@ var ContactMethodClient = /** @class */ (function () {
170
195
  });
171
196
  return this.printMessage(contactMethod.id, contactMethod);
172
197
  };
198
+ ContactMethodClient.prototype.expandContactMethod = function (input) {
199
+ var message = StoreHelper.getMessage(input.entryId);
200
+ if ((message === null || message === void 0 ? void 0 : message.conversationEntry) && Array.isArray(message.message)) {
201
+ var messageItemIndex = message.message.findIndex(function (_a) {
202
+ var _b = __read(_a, 1), listType = _b[0];
203
+ return listType === 'ace-knowledge-contact-method';
204
+ });
205
+ if (messageItemIndex > -1) {
206
+ var _a = __read(message.message[messageItemIndex], 2), messageItemType = _a[0], messageItemContent = _a[1];
207
+ var updatedMessageItemContent = __assign(__assign({}, messageItemContent), { contactMethods: messageItemContent.contactMethods.map(function (cm) {
208
+ cm.expanded = true;
209
+ return cm;
210
+ }) });
211
+ var updatedMessageItems = __spreadArray(__spreadArray(__spreadArray([], __read(message.message.slice(0, messageItemIndex)), false), [
212
+ [messageItemType, updatedMessageItemContent]
213
+ ], false), __read(message.message.slice(messageItemIndex + 1)), false);
214
+ message.conversationEntry.writer({ items: updatedMessageItems });
215
+ }
216
+ }
217
+ };
173
218
  ContactMethodClient.prototype.handleContactMethodList = function (input, contactMethods) {
174
219
  var title = input.split('/')[2];
175
220
  var newGuid = uuidv4();
@@ -11,12 +11,24 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { ContactMethod as GenericContactMethod } from '@telia-ace/knowledge-widget-adapters';
13
13
  import { useDispatch } from '@telia-ace/knowledge-widget-ui';
14
- import React from 'react';
14
+ import React, { useContext } from 'react';
15
+ import { EntryContext } from './entry-context';
15
16
  var ContactMethodItem = function (_a) {
16
17
  var contactMethod = _a.contactMethod, className = _a.className;
17
18
  var dispatch = useDispatch();
18
- return (React.createElement(GenericContactMethod, __assign({ className: className, onClick: function () {
19
- dispatch('action', "".concat(contactMethod.id, "/contact-methods/").concat(contactMethod.title));
20
- }, dispatch: dispatch }, contactMethod)));
19
+ var entryId = useContext(EntryContext).entryId;
20
+ return (React.createElement(GenericContactMethod, __assign({ className: className, onClick: function (event) {
21
+ if (contactMethod.inline) {
22
+ // preventing default to use a custom expand action
23
+ event.preventDefault();
24
+ dispatch('expand', {
25
+ entryId: entryId,
26
+ contactMethodId: contactMethod.id,
27
+ });
28
+ }
29
+ else {
30
+ dispatch('action', "".concat(contactMethod.id, "/contact-methods/").concat(contactMethod.title));
31
+ }
32
+ }, dispatch: dispatch }, contactMethod, { inline: true })));
21
33
  };
22
34
  export default ContactMethodItem;
@@ -8,6 +8,6 @@ import ContactMethodItem from './contact-method-item';
8
8
  var ContactMethodList = function (props) {
9
9
  return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod, expanded: !!contactMethod.executeImmediately || undefined })); })));
10
10
  };
11
- var StyledContactMethod = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"], ["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
11
+ var StyledContactMethod = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n\n &:last-child {\n border-bottom: none;\n }\n"], ["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n\n &:last-child {\n border-bottom: none;\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
12
12
  export default ContactMethodList;
13
13
  var templateObject_1;
@@ -7,6 +7,7 @@ import React from 'react';
7
7
  import styled from 'styled-components';
8
8
  import ContactMethodItem from './contact-method-item';
9
9
  import ContactMethodList from './contact-method-list';
10
+ import { EntryContext } from './entry-context';
10
11
  var ContactMethod = function (props) {
11
12
  var _a, _b;
12
13
  var type;
@@ -26,7 +27,8 @@ var ContactMethod = function (props) {
26
27
  if (!methodList.length) {
27
28
  return React.createElement(StyledContactMethodItem, { type: type, contactMethod: methodList });
28
29
  }
29
- return React.createElement(ContactMethodList, { type: type, contactMethodList: methodList });
30
+ return (React.createElement(EntryContext.Provider, { value: props.entry },
31
+ React.createElement(ContactMethodList, { type: type, contactMethodList: methodList })));
30
32
  };
31
33
  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
34
  export default ContactMethod;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export declare type IEntryContext = {
3
+ entryId: string | null;
4
+ };
5
+ export declare const EntryContext: import("react").Context<IEntryContext>;
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+ export var EntryContext = createContext({
3
+ entryId: null,
4
+ });
@@ -202,10 +202,16 @@ var EntryInterface = /** @class */ (function () {
202
202
  EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
203
203
  if (!!entry.content.items)
204
204
  return this.listTransform(entry, feedbackEntry);
205
- return [
205
+ var returnObj = [
206
206
  ConversationMessageListItemType.HTML,
207
207
  { body: entry.content.html.replace('\n', '') },
208
208
  ];
209
+ if (!!feedbackEntry) {
210
+ var feedbackObject = this.getListActions(feedbackEntry.content.items, this.getContentText(feedbackEntry), feedbackEntry.actions, feedbackEntry.localState);
211
+ feedbackObject.unshift(returnObj);
212
+ return feedbackObject;
213
+ }
214
+ return returnObj;
209
215
  };
210
216
  EntryInterface.prototype.getListActions = function (items, text, actions, state) {
211
217
  var _this = this;
@@ -217,7 +223,9 @@ var EntryInterface = /** @class */ (function () {
217
223
  mainList[1] = __assign(__assign({}, mainList[1]), { contactMethods: items.map(function (item) {
218
224
  var formatted = contactMethodFromLegacy(item.data);
219
225
  return formatted;
220
- }) });
226
+ }), entry: {
227
+ entryId: state.entryId,
228
+ } });
221
229
  }
222
230
  if (text && text.title) {
223
231
  list.push([ConversationMessageListItemType.Header, text.title]);
package/lib/plugin.js CHANGED
@@ -86,6 +86,10 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
86
86
  var httpClient = new HttpClient(endpoint, clientId, container);
87
87
  var firstLoader = conversation.loading();
88
88
  httpClient.firstHit().then(firstLoader);
89
+ component.actions.create('expand', function (input) {
90
+ var cmClient = new ContactMethodClient(container);
91
+ cmClient.expandContactMethod(input);
92
+ });
89
93
  component.actions.create('evaluate', function (input) {
90
94
  var cmClient = new ContactMethodClient(container);
91
95
  cmClient.handleNewForm(input.form, input.form.id);
@@ -98,8 +102,6 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
98
102
  var _a;
99
103
  if ((_a = input === null || input === void 0 ? void 0 : input.form) === null || _a === void 0 ? void 0 : _a.schema.id) {
100
104
  var contactMethodEntry = getContactMethodEntry(input.form.schema.id);
101
- if (contactMethodEntry) {
102
- }
103
105
  }
104
106
  var cmClient = new ContactMethodClient(container);
105
107
  cmClient.validate(input.form);
@@ -20,6 +20,10 @@ export declare class ContactMethodClient {
20
20
  type: string;
21
21
  noPadding: boolean;
22
22
  };
23
+ expandContactMethod(input: {
24
+ entryId: string;
25
+ contactMethodId: string;
26
+ }): void;
23
27
  private handleContactMethodList;
24
28
  private handleSingleContactMethod;
25
29
  private submit;
@@ -45,6 +45,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __read = (this && this.__read) || function (o, n) {
49
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
50
+ if (!m) return o;
51
+ var i = m.call(o), r, ar = [], e;
52
+ try {
53
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
+ }
55
+ catch (error) { e = { error: error }; }
56
+ finally {
57
+ try {
58
+ if (r && !r.done && (m = i["return"])) m.call(i);
59
+ }
60
+ finally { if (e) throw e.error; }
61
+ }
62
+ return ar;
63
+ };
64
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
65
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
+ if (ar || !(i in from)) {
67
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
+ ar[i] = from[i];
69
+ }
70
+ }
71
+ return to.concat(ar || Array.prototype.slice.call(from));
72
+ };
48
73
  import { DataType } from '@telia-ace/knowledge-widget-types-grid';
49
74
  import { FormBuilder, submitButton } from '@telia-ace/widget-forms';
50
75
  import { v4 as uuidv4 } from 'uuid';
@@ -170,6 +195,26 @@ var ContactMethodClient = /** @class */ (function () {
170
195
  });
171
196
  return this.printMessage(contactMethod.id, contactMethod);
172
197
  };
198
+ ContactMethodClient.prototype.expandContactMethod = function (input) {
199
+ var message = StoreHelper.getMessage(input.entryId);
200
+ if ((message === null || message === void 0 ? void 0 : message.conversationEntry) && Array.isArray(message.message)) {
201
+ var messageItemIndex = message.message.findIndex(function (_a) {
202
+ var _b = __read(_a, 1), listType = _b[0];
203
+ return listType === 'ace-knowledge-contact-method';
204
+ });
205
+ if (messageItemIndex > -1) {
206
+ var _a = __read(message.message[messageItemIndex], 2), messageItemType = _a[0], messageItemContent = _a[1];
207
+ var updatedMessageItemContent = __assign(__assign({}, messageItemContent), { contactMethods: messageItemContent.contactMethods.map(function (cm) {
208
+ cm.expanded = true;
209
+ return cm;
210
+ }) });
211
+ var updatedMessageItems = __spreadArray(__spreadArray(__spreadArray([], __read(message.message.slice(0, messageItemIndex)), false), [
212
+ [messageItemType, updatedMessageItemContent]
213
+ ], false), __read(message.message.slice(messageItemIndex + 1)), false);
214
+ message.conversationEntry.writer({ items: updatedMessageItems });
215
+ }
216
+ }
217
+ };
173
218
  ContactMethodClient.prototype.handleContactMethodList = function (input, contactMethods) {
174
219
  var title = input.split('/')[2];
175
220
  var newGuid = uuidv4();
@@ -11,12 +11,24 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { ContactMethod as GenericContactMethod } from '@telia-ace/knowledge-widget-adapters';
13
13
  import { useDispatch } from '@telia-ace/knowledge-widget-ui';
14
- import React from 'react';
14
+ import React, { useContext } from 'react';
15
+ import { EntryContext } from './entry-context';
15
16
  var ContactMethodItem = function (_a) {
16
17
  var contactMethod = _a.contactMethod, className = _a.className;
17
18
  var dispatch = useDispatch();
18
- return (React.createElement(GenericContactMethod, __assign({ className: className, onClick: function () {
19
- dispatch('action', "".concat(contactMethod.id, "/contact-methods/").concat(contactMethod.title));
20
- }, dispatch: dispatch }, contactMethod)));
19
+ var entryId = useContext(EntryContext).entryId;
20
+ return (React.createElement(GenericContactMethod, __assign({ className: className, onClick: function (event) {
21
+ if (contactMethod.inline) {
22
+ // preventing default to use a custom expand action
23
+ event.preventDefault();
24
+ dispatch('expand', {
25
+ entryId: entryId,
26
+ contactMethodId: contactMethod.id,
27
+ });
28
+ }
29
+ else {
30
+ dispatch('action', "".concat(contactMethod.id, "/contact-methods/").concat(contactMethod.title));
31
+ }
32
+ }, dispatch: dispatch }, contactMethod, { inline: true })));
21
33
  };
22
34
  export default ContactMethodItem;
@@ -8,6 +8,6 @@ import ContactMethodItem from './contact-method-item';
8
8
  var ContactMethodList = function (props) {
9
9
  return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod, expanded: !!contactMethod.executeImmediately || undefined })); })));
10
10
  };
11
- var StyledContactMethod = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"], ["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
11
+ var StyledContactMethod = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n\n &:last-child {\n border-bottom: none;\n }\n"], ["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n\n &:last-child {\n border-bottom: none;\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
12
12
  export default ContactMethodList;
13
13
  var templateObject_1;
@@ -7,6 +7,7 @@ import React from 'react';
7
7
  import styled from 'styled-components';
8
8
  import ContactMethodItem from './contact-method-item';
9
9
  import ContactMethodList from './contact-method-list';
10
+ import { EntryContext } from './entry-context';
10
11
  var ContactMethod = function (props) {
11
12
  var _a, _b;
12
13
  var type;
@@ -26,7 +27,8 @@ var ContactMethod = function (props) {
26
27
  if (!methodList.length) {
27
28
  return React.createElement(StyledContactMethodItem, { type: type, contactMethod: methodList });
28
29
  }
29
- return React.createElement(ContactMethodList, { type: type, contactMethodList: methodList });
30
+ return (React.createElement(EntryContext.Provider, { value: props.entry },
31
+ React.createElement(ContactMethodList, { type: type, contactMethodList: methodList })));
30
32
  };
31
33
  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
34
  export default ContactMethod;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export declare type IEntryContext = {
3
+ entryId: string | null;
4
+ };
5
+ export declare const EntryContext: import("react").Context<IEntryContext>;
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+ export var EntryContext = createContext({
3
+ entryId: null,
4
+ });
@@ -202,10 +202,16 @@ var EntryInterface = /** @class */ (function () {
202
202
  EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
203
203
  if (!!entry.content.items)
204
204
  return this.listTransform(entry, feedbackEntry);
205
- return [
205
+ var returnObj = [
206
206
  ConversationMessageListItemType.HTML,
207
207
  { body: entry.content.html.replace('\n', '') },
208
208
  ];
209
+ if (!!feedbackEntry) {
210
+ var feedbackObject = this.getListActions(feedbackEntry.content.items, this.getContentText(feedbackEntry), feedbackEntry.actions, feedbackEntry.localState);
211
+ feedbackObject.unshift(returnObj);
212
+ return feedbackObject;
213
+ }
214
+ return returnObj;
209
215
  };
210
216
  EntryInterface.prototype.getListActions = function (items, text, actions, state) {
211
217
  var _this = this;
@@ -217,7 +223,9 @@ var EntryInterface = /** @class */ (function () {
217
223
  mainList[1] = __assign(__assign({}, mainList[1]), { contactMethods: items.map(function (item) {
218
224
  var formatted = contactMethodFromLegacy(item.data);
219
225
  return formatted;
220
- }) });
226
+ }), entry: {
227
+ entryId: state.entryId,
228
+ } });
221
229
  }
222
230
  if (text && text.title) {
223
231
  list.push([ConversationMessageListItemType.Header, text.title]);
package/lib-esm/plugin.js CHANGED
@@ -86,6 +86,10 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
86
86
  var httpClient = new HttpClient(endpoint, clientId, container);
87
87
  var firstLoader = conversation.loading();
88
88
  httpClient.firstHit().then(firstLoader);
89
+ component.actions.create('expand', function (input) {
90
+ var cmClient = new ContactMethodClient(container);
91
+ cmClient.expandContactMethod(input);
92
+ });
89
93
  component.actions.create('evaluate', function (input) {
90
94
  var cmClient = new ContactMethodClient(container);
91
95
  cmClient.handleNewForm(input.form, input.form.id);
@@ -98,8 +102,6 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
98
102
  var _a;
99
103
  if ((_a = input === null || input === void 0 ? void 0 : input.form) === null || _a === void 0 ? void 0 : _a.schema.id) {
100
104
  var contactMethodEntry = getContactMethodEntry(input.form.schema.id);
101
- if (contactMethodEntry) {
102
- }
103
105
  }
104
106
  var cmClient = new ContactMethodClient(container);
105
107
  cmClient.validate(input.form);
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.42",
3
+ "version": "0.0.1-alpha.45",
4
4
  "description": "Bot Provider Plugin ACE Knowledge Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",
@@ -25,11 +25,11 @@
25
25
  "sideEffects": false,
26
26
  "typings": "lib/index.d.ts",
27
27
  "dependencies": {
28
- "@telia-ace/knowledge-widget-adapters": "^1.0.10",
29
- "@telia-ace/knowledge-widget-types-grid": "^1.0.10",
30
- "@telia-ace/knowledge-widget-ui": "^1.0.7",
31
- "@telia-ace/widget-conversation": "^1.0.9",
32
- "@telia-ace/widget-forms": "^1.0.6",
28
+ "@telia-ace/knowledge-widget-adapters": "^1.0.12",
29
+ "@telia-ace/knowledge-widget-types-grid": "^1.0.12",
30
+ "@telia-ace/knowledge-widget-ui": "^1.0.9",
31
+ "@telia-ace/widget-conversation": "^1.0.12",
32
+ "@telia-ace/widget-forms": "^1.0.8",
33
33
  "@telia-ace/widget-services": "^1.0.4",
34
34
  "@webprovisions/bootstrapping": "^1.0.12",
35
35
  "uuid": "^8.3.2"
@@ -41,5 +41,5 @@
41
41
  "devDependencies": {
42
42
  "@types/uuid": "^8.3.4"
43
43
  },
44
- "gitHead": "7cffe3a572ab9968a9d9f4d9e2035accdf79e608"
44
+ "gitHead": "367472dfe2a286f0ac8d4073b31ac07c74fe0b18"
45
45
  }