@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.40 → 0.0.1-alpha.43

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.
Files changed (31) hide show
  1. package/lib/client/chat.client.js +1 -1
  2. package/lib/client/contact-method.client.d.ts +4 -0
  3. package/lib/client/contact-method.client.js +45 -0
  4. package/lib/contract/custom-component/contact-method-item.d.ts +1 -0
  5. package/lib/contract/custom-component/contact-method-item.js +19 -39
  6. package/lib/contract/custom-component/contact-method-list.js +1 -1
  7. package/lib/contract/custom-component/contact-method.js +3 -1
  8. package/lib/contract/custom-component/entry-context.d.ts +5 -0
  9. package/lib/contract/custom-component/entry-context.js +4 -0
  10. package/lib/interface/entry.interface.d.ts +1 -1
  11. package/lib/interface/entry.interface.js +71 -38
  12. package/lib/interface/middleware/processor.interface.js +1 -1
  13. package/lib/plugin.js +4 -2
  14. package/lib/utils.d.ts +1 -0
  15. package/lib/utils.js +74 -0
  16. package/lib-esm/client/chat.client.js +1 -1
  17. package/lib-esm/client/contact-method.client.d.ts +4 -0
  18. package/lib-esm/client/contact-method.client.js +45 -0
  19. package/lib-esm/contract/custom-component/contact-method-item.d.ts +1 -0
  20. package/lib-esm/contract/custom-component/contact-method-item.js +19 -39
  21. package/lib-esm/contract/custom-component/contact-method-list.js +1 -1
  22. package/lib-esm/contract/custom-component/contact-method.js +3 -1
  23. package/lib-esm/contract/custom-component/entry-context.d.ts +5 -0
  24. package/lib-esm/contract/custom-component/entry-context.js +4 -0
  25. package/lib-esm/interface/entry.interface.d.ts +1 -1
  26. package/lib-esm/interface/entry.interface.js +71 -38
  27. package/lib-esm/interface/middleware/processor.interface.js +1 -1
  28. package/lib-esm/plugin.js +4 -2
  29. package/lib-esm/utils.d.ts +1 -0
  30. package/lib-esm/utils.js +74 -0
  31. package/package.json +5 -5
@@ -68,7 +68,7 @@ var ChatClient = /** @class */ (function () {
68
68
  switch (_d.label) {
69
69
  case 0:
70
70
  try {
71
- for (_a = __values(messages.filter(function (o) { return o && o != null; })), _b = _a.next(); !_b.done; _b = _a.next()) {
71
+ for (_a = __values(messages.filter(function (o) { return o && o != null && !!o.message; })), _b = _a.next(); !_b.done; _b = _a.next()) {
72
72
  message = _b.value;
73
73
  if (message.isUser)
74
74
  this.postUserMessage(message);
@@ -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();
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  interface PropsType {
3
3
  contactMethod: any;
4
4
  type: any;
5
+ expanded?: boolean;
5
6
  className?: any;
6
7
  }
7
8
  declare const ContactMethodItem: React.FC<PropsType>;
@@ -9,46 +9,26 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
12
  import { ContactMethod as GenericContactMethod } from '@telia-ace/knowledge-widget-adapters';
29
- import { useContainer, useDispatch } from '@telia-ace/knowledge-widget-ui';
30
- import React, { useEffect, useState } from 'react';
31
- var ContactMethodItem = function (props) {
13
+ import { useDispatch } from '@telia-ace/knowledge-widget-ui';
14
+ import React, { useContext } from 'react';
15
+ import { EntryContext } from './entry-context';
16
+ var ContactMethodItem = function (_a) {
17
+ var contactMethod = _a.contactMethod, className = _a.className;
32
18
  var dispatch = useDispatch();
33
- var container = useContainer();
34
- var _a = __read(useState(props.contactMethod.body), 2), body = _a[0], setBody = _a[1];
35
- useEffect(function () {
36
- if (!container || !container.get('$widget')) {
37
- return;
38
- }
39
- var events = container.get('$widget').events;
40
- events.subscribe('form:validated', function (_event, _data) {
41
- // TODO: this is a due to props not being updated when props.contactMethod.body changes
42
- // perhaps there is a cleaner way of doing this
43
- setBody(props.contactMethod.body);
44
- });
45
- }, [container]);
46
- return (React.createElement(GenericContactMethod, __assign({ className: props.className, onClick: function () {
47
- dispatch('action', "".concat(props.contactMethod.id, "/").concat(props.type.toString(), "/").concat(props.contactMethod.title));
48
- // dispatch(
49
- // "expand",
50
- // `${props.contactMethod.id}/${props.type.toString()}`
51
- // );
52
- }, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
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)));
53
33
  };
54
34
  export default ContactMethodItem;
@@ -6,7 +6,7 @@ import React, { Fragment } from 'react';
6
6
  import styled from 'styled-components';
7
7
  import ContactMethodItem from './contact-method-item';
8
8
  var ContactMethodList = function (props) {
9
- return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod })); })));
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
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; });
12
12
  export default ContactMethodList;
@@ -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
+ });
@@ -6,7 +6,7 @@ export default class EntryInterface {
6
6
  private helpActionKey;
7
7
  private nextActionKey;
8
8
  constructor(container: Container);
9
- transform(entry: ServerEntry): Promise<Message | undefined>;
9
+ transform(entry: ServerEntry, feedbackEntry?: ServerEntry): Promise<Message | undefined>;
10
10
  transformContactMethod(entry: ServerEntry): Promise<any>;
11
11
  transformArray(entryArray: ServerEntry[]): Promise<Message[]>;
12
12
  getUserMessage(action: string): string | undefined;
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -50,6 +61,7 @@ import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation
50
61
  import { ContactMethodClient } from '../client/contact-method.client';
51
62
  import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
52
63
  import { StoreHelper } from '../helper/store.helper';
64
+ import { contactMethodFromLegacy } from '../utils';
53
65
  var EntryInterface = /** @class */ (function () {
54
66
  function EntryInterface(container) {
55
67
  this.container = container;
@@ -57,7 +69,7 @@ var EntryInterface = /** @class */ (function () {
57
69
  this.nextActionKey = 'next';
58
70
  }
59
71
  // transform the entry based on its type
60
- EntryInterface.prototype.transform = function (entry) {
72
+ EntryInterface.prototype.transform = function (entry, feedbackEntry) {
61
73
  return __awaiter(this, void 0, void 0, function () {
62
74
  var entryType, _a;
63
75
  var _b;
@@ -69,38 +81,31 @@ var EntryInterface = /** @class */ (function () {
69
81
  switch (_a) {
70
82
  case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
71
83
  case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
72
- case ServerEntryTypeEnum.Text: return [3 /*break*/, 3];
73
- case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
84
+ case ServerEntryTypeEnum.Contact: return [3 /*break*/, 3];
74
85
  }
75
- return [3 /*break*/, 6];
86
+ return [3 /*break*/, 5];
76
87
  case 1: return [2 /*return*/, {
77
88
  id: entry.id,
78
- message: this.listTransform(entry),
89
+ message: this.listTransform(entry, feedbackEntry),
79
90
  entry: entry,
80
91
  isUser: false,
81
92
  }];
82
93
  case 2: return [2 /*return*/, {
83
94
  id: entry.id,
84
- message: this.textTransform(entry),
85
- entry: entry,
86
- isUser: false,
87
- }];
88
- case 3: return [2 /*return*/, {
89
- id: entry.id,
90
- message: this.listTransform(entry),
95
+ message: this.textTransform(entry, feedbackEntry),
91
96
  entry: entry,
92
97
  isUser: false,
93
98
  }];
94
- case 4:
99
+ case 3:
95
100
  _b = {
96
101
  id: entry.id
97
102
  };
98
103
  return [4 /*yield*/, this.transformContactMethod(entry)];
99
- case 5: return [2 /*return*/, (_b.message = _c.sent(),
104
+ case 4: return [2 /*return*/, (_b.message = _c.sent(),
100
105
  _b.entry = entry,
101
106
  _b.isUser = false,
102
107
  _b)];
103
- case 6: return [2 /*return*/];
108
+ case 5: return [2 /*return*/];
104
109
  }
105
110
  });
106
111
  });
@@ -128,37 +133,40 @@ var EntryInterface = /** @class */ (function () {
128
133
  // transform an array of entries
129
134
  EntryInterface.prototype.transformArray = function (entryArray) {
130
135
  return __awaiter(this, void 0, void 0, function () {
131
- var returnArray, entryArray_1, entryArray_1_1, o, x, e_1_1;
132
- var e_1, _a;
133
- return __generator(this, function (_b) {
134
- switch (_b.label) {
136
+ var feedbackEntry, returnArray, _a, _b, o, x, e_1_1;
137
+ var e_1, _c;
138
+ return __generator(this, function (_d) {
139
+ switch (_d.label) {
135
140
  case 0:
141
+ feedbackEntry = entryArray.find(function (o) {
142
+ return o.tags.find(function (t) { return t == 'gentle' || t == 'feedback'; });
143
+ });
136
144
  returnArray = [];
137
- _b.label = 1;
145
+ _d.label = 1;
138
146
  case 1:
139
- _b.trys.push([1, 6, 7, 8]);
140
- entryArray_1 = __values(entryArray), entryArray_1_1 = entryArray_1.next();
141
- _b.label = 2;
147
+ _d.trys.push([1, 6, 7, 8]);
148
+ _a = __values(entryArray.filter(function (t) { return t !== feedbackEntry; })), _b = _a.next();
149
+ _d.label = 2;
142
150
  case 2:
143
- if (!!entryArray_1_1.done) return [3 /*break*/, 5];
144
- o = entryArray_1_1.value;
145
- return [4 /*yield*/, this.transform(o)];
151
+ if (!!_b.done) return [3 /*break*/, 5];
152
+ o = _b.value;
153
+ return [4 /*yield*/, this.transform(o, feedbackEntry)];
146
154
  case 3:
147
- x = _b.sent();
155
+ x = _d.sent();
148
156
  if (!!x)
149
157
  returnArray.push(x);
150
- _b.label = 4;
158
+ _d.label = 4;
151
159
  case 4:
152
- entryArray_1_1 = entryArray_1.next();
160
+ _b = _a.next();
153
161
  return [3 /*break*/, 2];
154
162
  case 5: return [3 /*break*/, 8];
155
163
  case 6:
156
- e_1_1 = _b.sent();
164
+ e_1_1 = _d.sent();
157
165
  e_1 = { error: e_1_1 };
158
166
  return [3 /*break*/, 8];
159
167
  case 7:
160
168
  try {
161
- if (entryArray_1_1 && !entryArray_1_1.done && (_a = entryArray_1.return)) _a.call(entryArray_1);
169
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
162
170
  }
163
171
  finally { if (e_1) throw e_1.error; }
164
172
  return [7 /*endfinally*/];
@@ -172,13 +180,17 @@ var EntryInterface = /** @class */ (function () {
172
180
  var entry = StoreHelper.getEntry(action);
173
181
  return this.getTitleFromEntry(entry, action);
174
182
  };
175
- EntryInterface.prototype.listTransform = function (entry) {
183
+ EntryInterface.prototype.listTransform = function (entry, feedbackEntry) {
176
184
  if (entry.type === 'Contact') {
177
185
  return;
178
186
  }
179
187
  if (!entry.content)
180
188
  return;
181
189
  var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
190
+ if (!!feedbackEntry) {
191
+ var feedbackObject = this.getListActions(feedbackEntry.content.items, this.getContentText(feedbackEntry), feedbackEntry.actions, feedbackEntry.localState);
192
+ return object.concat(feedbackObject);
193
+ }
182
194
  return object;
183
195
  };
184
196
  EntryInterface.prototype.getContentText = function (entry) {
@@ -187,19 +199,34 @@ var EntryInterface = /** @class */ (function () {
187
199
  if (entry.content.header)
188
200
  return { title: entry.content.header };
189
201
  };
190
- EntryInterface.prototype.textTransform = function (entry) {
202
+ EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
191
203
  if (!!entry.content.items)
192
- return this.listTransform(entry);
193
- return [
204
+ return this.listTransform(entry, feedbackEntry);
205
+ var returnObj = [
194
206
  ConversationMessageListItemType.HTML,
195
207
  { body: entry.content.html.replace('\n', '') },
196
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;
197
215
  };
198
216
  EntryInterface.prototype.getListActions = function (items, text, actions, state) {
199
217
  var _this = this;
200
218
  var list = [];
201
219
  var mainListContent = {};
202
- var mainList = [this.getListType(state), { actions: mainListContent }];
220
+ var mainListType = this.getListType(state);
221
+ var mainList = [mainListType, { actions: mainListContent }];
222
+ if (mainListType === 'ace-knowledge-contact-method') {
223
+ mainList[1] = __assign(__assign({}, mainList[1]), { contactMethods: items.map(function (item) {
224
+ var formatted = contactMethodFromLegacy(item.data);
225
+ return formatted;
226
+ }), entry: {
227
+ entryId: state.entryId,
228
+ } });
229
+ }
203
230
  if (text && text.title) {
204
231
  list.push([ConversationMessageListItemType.Header, text.title]);
205
232
  }
@@ -230,11 +257,17 @@ var EntryInterface = /** @class */ (function () {
230
257
  return list;
231
258
  };
232
259
  EntryInterface.prototype.getListType = function (state) {
233
- if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
260
+ if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching') {
234
261
  return ConversationMessageListItemType.LinkList;
262
+ }
235
263
  else if ((state === null || state === void 0 ? void 0 : state.$type) ===
236
- 'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
264
+ 'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching') {
237
265
  return ConversationMessageListItemType.FeedbackList;
266
+ }
267
+ else if ((state === null || state === void 0 ? void 0 : state.$type) ===
268
+ 'Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching') {
269
+ return 'ace-knowledge-contact-method';
270
+ }
238
271
  else
239
272
  return ConversationMessageListItemType.ButtonList;
240
273
  };
@@ -85,7 +85,7 @@ var ProcessorInterface = /** @class */ (function () {
85
85
  return target.localState;
86
86
  };
87
87
  entries.forEach(function (entry) {
88
- if (entry.relation) {
88
+ if (entry.relation && !entry.tags.find(function (o) { return o == 'gentle' || o == 'feedback'; })) {
89
89
  var existingEntry = entries.find(function (o) { return o.id == entry.relation; });
90
90
  if (existingEntry) {
91
91
  var existingIndex = output.indexOf(existingEntry);
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);
package/lib/utils.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare const getContactMethodEntry: (contactMethodId: string) => import("./contract/model/http/server-entry.model").ServerEntry | undefined;
2
+ export declare const contactMethodFromLegacy: ({ id, title, defaultIcon, exits: [exit], exitType, confirmationText, expandFormAutomatically, form, description, }: any, validation?: any) => any;
package/lib/utils.js CHANGED
@@ -1,5 +1,79 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ import { FormBuilder } from '@telia-ace/widget-forms';
1
18
  import { StoreHelper } from './helper/store.helper';
2
19
  export var getContactMethodEntry = function (contactMethodId) {
3
20
  var entries = StoreHelper.getEntryStore();
4
21
  return entries.find(function (e) { return e.content.id === +contactMethodId; });
5
22
  };
23
+ var convertLegacySymbol = function (symbol) {
24
+ if (symbol) {
25
+ var type = symbol.type, content = symbol.content;
26
+ if (type && content) {
27
+ return { type: type, content: content };
28
+ }
29
+ }
30
+ };
31
+ export var contactMethodFromLegacy = function (_a, validation) {
32
+ var id = _a.id, title = _a.title, defaultIcon = _a.defaultIcon, _b = __read(_a.exits, 1), exit = _b[0], exitType = _a.exitType, confirmationText = _a.confirmationText, expandFormAutomatically = _a.expandFormAutomatically, form = _a.form, description = _a.description;
33
+ var adapter = (exit || { Adapter: {} }).adapter;
34
+ var _c = adapter.clientName, clientName = _c === void 0 ? '' : _c, _d = adapter.settings, adapterSettings = _d === void 0 ? {} : _d, _e = adapter.customClientName, customClientName = _e === void 0 ? '' : _e;
35
+ var settings = {
36
+ id: id.toString(),
37
+ title: title,
38
+ description: description,
39
+ symbol: convertLegacySymbol(defaultIcon),
40
+ clientName: clientName === 'custom.adapter' ? customClientName : clientName,
41
+ expanded: true,
42
+ inline: true,
43
+ body: {},
44
+ };
45
+ if (clientName.indexOf('phone') > -1 || clientName.indexOf('freetext') > -1) {
46
+ var displayTextBeforeClick = adapterSettings.displayTextBeforeClick, textBeforeClick = adapterSettings.textBeforeClick;
47
+ if (displayTextBeforeClick === 'true') {
48
+ settings.expanded = false;
49
+ settings.title = textBeforeClick;
50
+ }
51
+ if (clientName.indexOf('phone.text') > -1) {
52
+ settings.body.phoneNumber = adapterSettings.phoneNumber;
53
+ }
54
+ else {
55
+ settings.body.freetext = adapterSettings.freetext;
56
+ }
57
+ }
58
+ if (clientName.indexOf('chat.popup') > -1 ||
59
+ clientName.indexOf('link') > -1 ||
60
+ (clientName === 'custom.adapter' && exitType === 'custom')) {
61
+ settings.body = adapterSettings;
62
+ settings.body.confirmationFallback = confirmationText;
63
+ }
64
+ if (clientName.indexOf('ace') > -1) {
65
+ settings.body = adapterSettings;
66
+ }
67
+ if (form && form.hasValueComponents) {
68
+ if (validation) {
69
+ settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form, validation).get();
70
+ }
71
+ else {
72
+ settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form).get();
73
+ }
74
+ if (!expandFormAutomatically) {
75
+ settings.expanded = settings.inline = false;
76
+ }
77
+ }
78
+ return settings;
79
+ };
@@ -68,7 +68,7 @@ var ChatClient = /** @class */ (function () {
68
68
  switch (_d.label) {
69
69
  case 0:
70
70
  try {
71
- for (_a = __values(messages.filter(function (o) { return o && o != null; })), _b = _a.next(); !_b.done; _b = _a.next()) {
71
+ for (_a = __values(messages.filter(function (o) { return o && o != null && !!o.message; })), _b = _a.next(); !_b.done; _b = _a.next()) {
72
72
  message = _b.value;
73
73
  if (message.isUser)
74
74
  this.postUserMessage(message);
@@ -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();
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  interface PropsType {
3
3
  contactMethod: any;
4
4
  type: any;
5
+ expanded?: boolean;
5
6
  className?: any;
6
7
  }
7
8
  declare const ContactMethodItem: React.FC<PropsType>;
@@ -9,46 +9,26 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
12
  import { ContactMethod as GenericContactMethod } from '@telia-ace/knowledge-widget-adapters';
29
- import { useContainer, useDispatch } from '@telia-ace/knowledge-widget-ui';
30
- import React, { useEffect, useState } from 'react';
31
- var ContactMethodItem = function (props) {
13
+ import { useDispatch } from '@telia-ace/knowledge-widget-ui';
14
+ import React, { useContext } from 'react';
15
+ import { EntryContext } from './entry-context';
16
+ var ContactMethodItem = function (_a) {
17
+ var contactMethod = _a.contactMethod, className = _a.className;
32
18
  var dispatch = useDispatch();
33
- var container = useContainer();
34
- var _a = __read(useState(props.contactMethod.body), 2), body = _a[0], setBody = _a[1];
35
- useEffect(function () {
36
- if (!container || !container.get('$widget')) {
37
- return;
38
- }
39
- var events = container.get('$widget').events;
40
- events.subscribe('form:validated', function (_event, _data) {
41
- // TODO: this is a due to props not being updated when props.contactMethod.body changes
42
- // perhaps there is a cleaner way of doing this
43
- setBody(props.contactMethod.body);
44
- });
45
- }, [container]);
46
- return (React.createElement(GenericContactMethod, __assign({ className: props.className, onClick: function () {
47
- dispatch('action', "".concat(props.contactMethod.id, "/").concat(props.type.toString(), "/").concat(props.contactMethod.title));
48
- // dispatch(
49
- // "expand",
50
- // `${props.contactMethod.id}/${props.type.toString()}`
51
- // );
52
- }, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
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)));
53
33
  };
54
34
  export default ContactMethodItem;
@@ -6,7 +6,7 @@ import React, { Fragment } from 'react';
6
6
  import styled from 'styled-components';
7
7
  import ContactMethodItem from './contact-method-item';
8
8
  var ContactMethodList = function (props) {
9
- return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod })); })));
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
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; });
12
12
  export default ContactMethodList;
@@ -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
+ });
@@ -6,7 +6,7 @@ export default class EntryInterface {
6
6
  private helpActionKey;
7
7
  private nextActionKey;
8
8
  constructor(container: Container);
9
- transform(entry: ServerEntry): Promise<Message | undefined>;
9
+ transform(entry: ServerEntry, feedbackEntry?: ServerEntry): Promise<Message | undefined>;
10
10
  transformContactMethod(entry: ServerEntry): Promise<any>;
11
11
  transformArray(entryArray: ServerEntry[]): Promise<Message[]>;
12
12
  getUserMessage(action: string): string | undefined;
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -50,6 +61,7 @@ import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation
50
61
  import { ContactMethodClient } from '../client/contact-method.client';
51
62
  import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
52
63
  import { StoreHelper } from '../helper/store.helper';
64
+ import { contactMethodFromLegacy } from '../utils';
53
65
  var EntryInterface = /** @class */ (function () {
54
66
  function EntryInterface(container) {
55
67
  this.container = container;
@@ -57,7 +69,7 @@ var EntryInterface = /** @class */ (function () {
57
69
  this.nextActionKey = 'next';
58
70
  }
59
71
  // transform the entry based on its type
60
- EntryInterface.prototype.transform = function (entry) {
72
+ EntryInterface.prototype.transform = function (entry, feedbackEntry) {
61
73
  return __awaiter(this, void 0, void 0, function () {
62
74
  var entryType, _a;
63
75
  var _b;
@@ -69,38 +81,31 @@ var EntryInterface = /** @class */ (function () {
69
81
  switch (_a) {
70
82
  case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
71
83
  case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
72
- case ServerEntryTypeEnum.Text: return [3 /*break*/, 3];
73
- case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
84
+ case ServerEntryTypeEnum.Contact: return [3 /*break*/, 3];
74
85
  }
75
- return [3 /*break*/, 6];
86
+ return [3 /*break*/, 5];
76
87
  case 1: return [2 /*return*/, {
77
88
  id: entry.id,
78
- message: this.listTransform(entry),
89
+ message: this.listTransform(entry, feedbackEntry),
79
90
  entry: entry,
80
91
  isUser: false,
81
92
  }];
82
93
  case 2: return [2 /*return*/, {
83
94
  id: entry.id,
84
- message: this.textTransform(entry),
85
- entry: entry,
86
- isUser: false,
87
- }];
88
- case 3: return [2 /*return*/, {
89
- id: entry.id,
90
- message: this.listTransform(entry),
95
+ message: this.textTransform(entry, feedbackEntry),
91
96
  entry: entry,
92
97
  isUser: false,
93
98
  }];
94
- case 4:
99
+ case 3:
95
100
  _b = {
96
101
  id: entry.id
97
102
  };
98
103
  return [4 /*yield*/, this.transformContactMethod(entry)];
99
- case 5: return [2 /*return*/, (_b.message = _c.sent(),
104
+ case 4: return [2 /*return*/, (_b.message = _c.sent(),
100
105
  _b.entry = entry,
101
106
  _b.isUser = false,
102
107
  _b)];
103
- case 6: return [2 /*return*/];
108
+ case 5: return [2 /*return*/];
104
109
  }
105
110
  });
106
111
  });
@@ -128,37 +133,40 @@ var EntryInterface = /** @class */ (function () {
128
133
  // transform an array of entries
129
134
  EntryInterface.prototype.transformArray = function (entryArray) {
130
135
  return __awaiter(this, void 0, void 0, function () {
131
- var returnArray, entryArray_1, entryArray_1_1, o, x, e_1_1;
132
- var e_1, _a;
133
- return __generator(this, function (_b) {
134
- switch (_b.label) {
136
+ var feedbackEntry, returnArray, _a, _b, o, x, e_1_1;
137
+ var e_1, _c;
138
+ return __generator(this, function (_d) {
139
+ switch (_d.label) {
135
140
  case 0:
141
+ feedbackEntry = entryArray.find(function (o) {
142
+ return o.tags.find(function (t) { return t == 'gentle' || t == 'feedback'; });
143
+ });
136
144
  returnArray = [];
137
- _b.label = 1;
145
+ _d.label = 1;
138
146
  case 1:
139
- _b.trys.push([1, 6, 7, 8]);
140
- entryArray_1 = __values(entryArray), entryArray_1_1 = entryArray_1.next();
141
- _b.label = 2;
147
+ _d.trys.push([1, 6, 7, 8]);
148
+ _a = __values(entryArray.filter(function (t) { return t !== feedbackEntry; })), _b = _a.next();
149
+ _d.label = 2;
142
150
  case 2:
143
- if (!!entryArray_1_1.done) return [3 /*break*/, 5];
144
- o = entryArray_1_1.value;
145
- return [4 /*yield*/, this.transform(o)];
151
+ if (!!_b.done) return [3 /*break*/, 5];
152
+ o = _b.value;
153
+ return [4 /*yield*/, this.transform(o, feedbackEntry)];
146
154
  case 3:
147
- x = _b.sent();
155
+ x = _d.sent();
148
156
  if (!!x)
149
157
  returnArray.push(x);
150
- _b.label = 4;
158
+ _d.label = 4;
151
159
  case 4:
152
- entryArray_1_1 = entryArray_1.next();
160
+ _b = _a.next();
153
161
  return [3 /*break*/, 2];
154
162
  case 5: return [3 /*break*/, 8];
155
163
  case 6:
156
- e_1_1 = _b.sent();
164
+ e_1_1 = _d.sent();
157
165
  e_1 = { error: e_1_1 };
158
166
  return [3 /*break*/, 8];
159
167
  case 7:
160
168
  try {
161
- if (entryArray_1_1 && !entryArray_1_1.done && (_a = entryArray_1.return)) _a.call(entryArray_1);
169
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
162
170
  }
163
171
  finally { if (e_1) throw e_1.error; }
164
172
  return [7 /*endfinally*/];
@@ -172,13 +180,17 @@ var EntryInterface = /** @class */ (function () {
172
180
  var entry = StoreHelper.getEntry(action);
173
181
  return this.getTitleFromEntry(entry, action);
174
182
  };
175
- EntryInterface.prototype.listTransform = function (entry) {
183
+ EntryInterface.prototype.listTransform = function (entry, feedbackEntry) {
176
184
  if (entry.type === 'Contact') {
177
185
  return;
178
186
  }
179
187
  if (!entry.content)
180
188
  return;
181
189
  var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
190
+ if (!!feedbackEntry) {
191
+ var feedbackObject = this.getListActions(feedbackEntry.content.items, this.getContentText(feedbackEntry), feedbackEntry.actions, feedbackEntry.localState);
192
+ return object.concat(feedbackObject);
193
+ }
182
194
  return object;
183
195
  };
184
196
  EntryInterface.prototype.getContentText = function (entry) {
@@ -187,19 +199,34 @@ var EntryInterface = /** @class */ (function () {
187
199
  if (entry.content.header)
188
200
  return { title: entry.content.header };
189
201
  };
190
- EntryInterface.prototype.textTransform = function (entry) {
202
+ EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
191
203
  if (!!entry.content.items)
192
- return this.listTransform(entry);
193
- return [
204
+ return this.listTransform(entry, feedbackEntry);
205
+ var returnObj = [
194
206
  ConversationMessageListItemType.HTML,
195
207
  { body: entry.content.html.replace('\n', '') },
196
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;
197
215
  };
198
216
  EntryInterface.prototype.getListActions = function (items, text, actions, state) {
199
217
  var _this = this;
200
218
  var list = [];
201
219
  var mainListContent = {};
202
- var mainList = [this.getListType(state), { actions: mainListContent }];
220
+ var mainListType = this.getListType(state);
221
+ var mainList = [mainListType, { actions: mainListContent }];
222
+ if (mainListType === 'ace-knowledge-contact-method') {
223
+ mainList[1] = __assign(__assign({}, mainList[1]), { contactMethods: items.map(function (item) {
224
+ var formatted = contactMethodFromLegacy(item.data);
225
+ return formatted;
226
+ }), entry: {
227
+ entryId: state.entryId,
228
+ } });
229
+ }
203
230
  if (text && text.title) {
204
231
  list.push([ConversationMessageListItemType.Header, text.title]);
205
232
  }
@@ -230,11 +257,17 @@ var EntryInterface = /** @class */ (function () {
230
257
  return list;
231
258
  };
232
259
  EntryInterface.prototype.getListType = function (state) {
233
- if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
260
+ if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching') {
234
261
  return ConversationMessageListItemType.LinkList;
262
+ }
235
263
  else if ((state === null || state === void 0 ? void 0 : state.$type) ===
236
- 'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
264
+ 'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching') {
237
265
  return ConversationMessageListItemType.FeedbackList;
266
+ }
267
+ else if ((state === null || state === void 0 ? void 0 : state.$type) ===
268
+ 'Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching') {
269
+ return 'ace-knowledge-contact-method';
270
+ }
238
271
  else
239
272
  return ConversationMessageListItemType.ButtonList;
240
273
  };
@@ -85,7 +85,7 @@ var ProcessorInterface = /** @class */ (function () {
85
85
  return target.localState;
86
86
  };
87
87
  entries.forEach(function (entry) {
88
- if (entry.relation) {
88
+ if (entry.relation && !entry.tags.find(function (o) { return o == 'gentle' || o == 'feedback'; })) {
89
89
  var existingEntry = entries.find(function (o) { return o.id == entry.relation; });
90
90
  if (existingEntry) {
91
91
  var existingIndex = output.indexOf(existingEntry);
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);
@@ -1 +1,2 @@
1
1
  export declare const getContactMethodEntry: (contactMethodId: string) => import("./contract/model/http/server-entry.model").ServerEntry | undefined;
2
+ export declare const contactMethodFromLegacy: ({ id, title, defaultIcon, exits: [exit], exitType, confirmationText, expandFormAutomatically, form, description, }: any, validation?: any) => any;
package/lib-esm/utils.js CHANGED
@@ -1,5 +1,79 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ import { FormBuilder } from '@telia-ace/widget-forms';
1
18
  import { StoreHelper } from './helper/store.helper';
2
19
  export var getContactMethodEntry = function (contactMethodId) {
3
20
  var entries = StoreHelper.getEntryStore();
4
21
  return entries.find(function (e) { return e.content.id === +contactMethodId; });
5
22
  };
23
+ var convertLegacySymbol = function (symbol) {
24
+ if (symbol) {
25
+ var type = symbol.type, content = symbol.content;
26
+ if (type && content) {
27
+ return { type: type, content: content };
28
+ }
29
+ }
30
+ };
31
+ export var contactMethodFromLegacy = function (_a, validation) {
32
+ var id = _a.id, title = _a.title, defaultIcon = _a.defaultIcon, _b = __read(_a.exits, 1), exit = _b[0], exitType = _a.exitType, confirmationText = _a.confirmationText, expandFormAutomatically = _a.expandFormAutomatically, form = _a.form, description = _a.description;
33
+ var adapter = (exit || { Adapter: {} }).adapter;
34
+ var _c = adapter.clientName, clientName = _c === void 0 ? '' : _c, _d = adapter.settings, adapterSettings = _d === void 0 ? {} : _d, _e = adapter.customClientName, customClientName = _e === void 0 ? '' : _e;
35
+ var settings = {
36
+ id: id.toString(),
37
+ title: title,
38
+ description: description,
39
+ symbol: convertLegacySymbol(defaultIcon),
40
+ clientName: clientName === 'custom.adapter' ? customClientName : clientName,
41
+ expanded: true,
42
+ inline: true,
43
+ body: {},
44
+ };
45
+ if (clientName.indexOf('phone') > -1 || clientName.indexOf('freetext') > -1) {
46
+ var displayTextBeforeClick = adapterSettings.displayTextBeforeClick, textBeforeClick = adapterSettings.textBeforeClick;
47
+ if (displayTextBeforeClick === 'true') {
48
+ settings.expanded = false;
49
+ settings.title = textBeforeClick;
50
+ }
51
+ if (clientName.indexOf('phone.text') > -1) {
52
+ settings.body.phoneNumber = adapterSettings.phoneNumber;
53
+ }
54
+ else {
55
+ settings.body.freetext = adapterSettings.freetext;
56
+ }
57
+ }
58
+ if (clientName.indexOf('chat.popup') > -1 ||
59
+ clientName.indexOf('link') > -1 ||
60
+ (clientName === 'custom.adapter' && exitType === 'custom')) {
61
+ settings.body = adapterSettings;
62
+ settings.body.confirmationFallback = confirmationText;
63
+ }
64
+ if (clientName.indexOf('ace') > -1) {
65
+ settings.body = adapterSettings;
66
+ }
67
+ if (form && form.hasValueComponents) {
68
+ if (validation) {
69
+ settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form, validation).get();
70
+ }
71
+ else {
72
+ settings.body.form = FormBuilder.fromLegacyForm(id.toString(), form).get();
73
+ }
74
+ if (!expandFormAutomatically) {
75
+ settings.expanded = settings.inline = false;
76
+ }
77
+ }
78
+ return settings;
79
+ };
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.40",
3
+ "version": "0.0.1-alpha.43",
4
4
  "description": "Bot Provider Plugin ACE Knowledge Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",
@@ -25,10 +25,10 @@
25
25
  "sideEffects": false,
26
26
  "typings": "lib/index.d.ts",
27
27
  "dependencies": {
28
- "@telia-ace/knowledge-widget-adapters": "^1.0.9",
29
- "@telia-ace/knowledge-widget-types-grid": "^1.0.9",
28
+ "@telia-ace/knowledge-widget-adapters": "^1.0.10",
29
+ "@telia-ace/knowledge-widget-types-grid": "^1.0.10",
30
30
  "@telia-ace/knowledge-widget-ui": "^1.0.7",
31
- "@telia-ace/widget-conversation": "^1.0.8",
31
+ "@telia-ace/widget-conversation": "^1.0.10",
32
32
  "@telia-ace/widget-forms": "^1.0.6",
33
33
  "@telia-ace/widget-services": "^1.0.4",
34
34
  "@webprovisions/bootstrapping": "^1.0.12",
@@ -41,5 +41,5 @@
41
41
  "devDependencies": {
42
42
  "@types/uuid": "^8.3.4"
43
43
  },
44
- "gitHead": "d6b4f95adbfce4da6dfc5365a3abbc5624bc4ffa"
44
+ "gitHead": "2571dff48af6805e89ce409697982a51effd7488"
45
45
  }