@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.41 → 0.0.1-alpha.44

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();
@@ -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
+ });
@@ -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;
@@ -190,16 +202,31 @@ var EntryInterface = /** @class */ (function () {
190
202
  EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
191
203
  if (!!entry.content.items)
192
204
  return this.listTransform(entry, feedbackEntry);
193
- return [
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
  };
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
+ };
@@ -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
+ });
@@ -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;
@@ -190,16 +202,31 @@ var EntryInterface = /** @class */ (function () {
190
202
  EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
191
203
  if (!!entry.content.items)
192
204
  return this.listTransform(entry, feedbackEntry);
193
- return [
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
  };
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.41",
3
+ "version": "0.0.1-alpha.44",
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.11",
29
+ "@telia-ace/knowledge-widget-types-grid": "^1.0.11",
30
+ "@telia-ace/knowledge-widget-ui": "^1.0.8",
31
+ "@telia-ace/widget-conversation": "^1.0.11",
32
+ "@telia-ace/widget-forms": "^1.0.7",
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": "733b97495cbc823d594ae31e687aeb05a660f195"
44
+ "gitHead": "5c7beb5d15b048dfc70489486ae597f891f1d691"
45
45
  }