@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.1 → 0.0.1-alpha.4
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.
- package/lib/client/chat.client.d.ts +15 -0
- package/lib/client/chat.client.js +80 -0
- package/lib/client/contact-method.client.d.ts +22 -0
- package/lib/client/contact-method.client.js +276 -0
- package/lib/client/http.client.d.ts +22 -0
- package/lib/client/http.client.js +114 -0
- package/lib/client/middleware.client.d.ts +13 -0
- package/lib/client/middleware.client.js +60 -0
- package/lib/contract/custom-component/contact-method-item.d.ts +8 -0
- package/lib/contract/custom-component/contact-method-item.js +76 -0
- package/lib/contract/custom-component/contact-method-list.d.ts +7 -0
- package/lib/contract/custom-component/contact-method-list.js +41 -0
- package/lib/contract/custom-component/contact-method.d.ts +3 -0
- package/lib/contract/custom-component/contact-method.js +38 -0
- package/lib/contract/enum/server-entry-type.enum.d.ts +6 -0
- package/lib/contract/enum/server-entry-type.enum.js +10 -0
- package/lib/contract/model/conversation-api-model/list.model.d.ts +5 -0
- package/lib/contract/model/conversation-api-model/list.model.js +2 -0
- package/lib/contract/model/conversation-api-model/message.model.d.ts +7 -0
- package/lib/contract/model/conversation-api-model/message.model.js +2 -0
- package/lib/contract/model/http/action.model.d.ts +3 -0
- package/lib/contract/model/http/action.model.js +2 -0
- package/lib/contract/model/http/client-action.model.d.ts +4 -0
- package/lib/contract/model/http/client-action.model.js +3 -0
- package/lib/contract/model/http/client-envelope.model.d.ts +9 -0
- package/lib/contract/model/http/client-envelope.model.js +2 -0
- package/lib/contract/model/http/connect-options.model.d.ts +5 -0
- package/lib/contract/model/http/connect-options.model.js +2 -0
- package/lib/contract/model/http/global-state.model.d.ts +8 -0
- package/lib/contract/model/http/global-state.model.js +2 -0
- package/lib/contract/model/http/http-client-options.model.d.ts +5 -0
- package/lib/contract/model/http/http-client-options.model.js +2 -0
- package/lib/contract/model/http/server-entry.model.d.ts +11 -0
- package/lib/contract/model/http/server-entry.model.js +2 -0
- package/lib/contract/model/http/server-envelope.model.d.ts +10 -0
- package/lib/contract/model/http/server-envelope.model.js +2 -0
- package/lib/contract/model/middleware/aggregator-state.model.d.ts +4 -0
- package/lib/contract/model/middleware/aggregator-state.model.js +3 -0
- package/lib/contract/model/shared/loose-object.model.d.ts +3 -0
- package/lib/contract/model/shared/loose-object.model.js +2 -0
- package/lib/helper/chat.helper.d.ts +8 -0
- package/lib/helper/chat.helper.js +21 -0
- package/lib/helper/http.helper.d.ts +13 -0
- package/lib/helper/http.helper.js +33 -0
- package/lib/helper/middleware.helper.d.ts +12 -0
- package/lib/helper/middleware.helper.js +72 -0
- package/lib/helper/store.helper.d.ts +22 -0
- package/lib/helper/store.helper.js +80 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib/interface/entry.interface.d.ts +17 -0
- package/lib/interface/entry.interface.js +138 -0
- package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
- package/lib/interface/middleware/contact-expanded.interface.js +50 -0
- package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
- package/lib/interface/middleware/legacy-contact-methods.interface.js +394 -0
- package/lib/interface/middleware/paging.interface.d.ts +4 -0
- package/lib/interface/middleware/paging.interface.js +55 -0
- package/lib/interface/middleware/processor.interface.d.ts +10 -0
- package/lib/interface/middleware/processor.interface.js +120 -0
- package/lib/plugin.d.ts +3 -0
- package/lib/plugin.js +169 -0
- package/lib-esm/client/chat.client.d.ts +15 -0
- package/lib-esm/client/chat.client.js +75 -0
- package/lib-esm/client/contact-method.client.d.ts +22 -0
- package/lib-esm/client/contact-method.client.js +270 -0
- package/lib-esm/client/http.client.d.ts +22 -0
- package/lib-esm/client/http.client.js +108 -0
- package/lib-esm/client/middleware.client.d.ts +13 -0
- package/lib-esm/client/middleware.client.js +55 -0
- package/lib-esm/contract/custom-component/contact-method-item.d.ts +8 -0
- package/lib-esm/contract/custom-component/contact-method-item.js +51 -0
- package/lib-esm/contract/custom-component/contact-method-list.d.ts +7 -0
- package/lib-esm/contract/custom-component/contact-method-list.js +13 -0
- package/lib-esm/contract/custom-component/contact-method.d.ts +3 -0
- package/lib-esm/contract/custom-component/contact-method.js +33 -0
- package/lib-esm/contract/enum/server-entry-type.enum.d.ts +6 -0
- package/lib-esm/contract/enum/server-entry-type.enum.js +7 -0
- package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +5 -0
- package/lib-esm/contract/model/conversation-api-model/list.model.js +1 -0
- package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +7 -0
- package/lib-esm/contract/model/conversation-api-model/message.model.js +1 -0
- package/lib-esm/contract/model/http/action.model.d.ts +3 -0
- package/lib-esm/contract/model/http/action.model.js +1 -0
- package/lib-esm/contract/model/http/client-action.model.d.ts +4 -0
- package/lib-esm/contract/model/http/client-action.model.js +2 -0
- package/lib-esm/contract/model/http/client-envelope.model.d.ts +9 -0
- package/lib-esm/contract/model/http/client-envelope.model.js +1 -0
- package/lib-esm/contract/model/http/connect-options.model.d.ts +5 -0
- package/lib-esm/contract/model/http/connect-options.model.js +1 -0
- package/lib-esm/contract/model/http/global-state.model.d.ts +8 -0
- package/lib-esm/contract/model/http/global-state.model.js +1 -0
- package/lib-esm/contract/model/http/http-client-options.model.d.ts +5 -0
- package/lib-esm/contract/model/http/http-client-options.model.js +1 -0
- package/lib-esm/contract/model/http/server-entry.model.d.ts +11 -0
- package/lib-esm/contract/model/http/server-entry.model.js +1 -0
- package/lib-esm/contract/model/http/server-envelope.model.d.ts +10 -0
- package/lib-esm/contract/model/http/server-envelope.model.js +1 -0
- package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +4 -0
- package/lib-esm/contract/model/middleware/aggregator-state.model.js +2 -0
- package/lib-esm/contract/model/shared/loose-object.model.d.ts +3 -0
- package/lib-esm/contract/model/shared/loose-object.model.js +1 -0
- package/lib-esm/helper/chat.helper.d.ts +8 -0
- package/lib-esm/helper/chat.helper.js +18 -0
- package/lib-esm/helper/http.helper.d.ts +13 -0
- package/lib-esm/helper/http.helper.js +30 -0
- package/lib-esm/helper/middleware.helper.d.ts +12 -0
- package/lib-esm/helper/middleware.helper.js +69 -0
- package/lib-esm/helper/store.helper.d.ts +22 -0
- package/lib-esm/helper/store.helper.js +77 -0
- package/lib-esm/index.d.ts +2 -0
- package/lib-esm/index.js +2 -0
- package/lib-esm/interface/entry.interface.d.ts +17 -0
- package/lib-esm/interface/entry.interface.js +136 -0
- package/lib-esm/interface/middleware/paging.interface.d.ts +4 -0
- package/lib-esm/interface/middleware/paging.interface.js +53 -0
- package/lib-esm/interface/middleware/processor.interface.d.ts +10 -0
- package/lib-esm/interface/middleware/processor.interface.js +118 -0
- package/lib-esm/plugin.d.ts +3 -0
- package/lib-esm/plugin.js +141 -0
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var widget_conversation_1 = require("@telia-ace/widget-conversation");
|
|
4
|
+
var server_entry_type_enum_1 = require("../contract/enum/server-entry-type.enum");
|
|
5
|
+
var store_helper_1 = require("../helper/store.helper");
|
|
6
|
+
var EntryInterface = /** @class */ (function () {
|
|
7
|
+
function EntryInterface() {
|
|
8
|
+
this.helpActionKey = 'help';
|
|
9
|
+
this.nextActionKey = 'next';
|
|
10
|
+
}
|
|
11
|
+
// transform the entry based on its type
|
|
12
|
+
EntryInterface.prototype.transform = function (entry) {
|
|
13
|
+
var entryType = server_entry_type_enum_1.ServerEntryTypeEnum[entry.type];
|
|
14
|
+
switch (entryType) {
|
|
15
|
+
case server_entry_type_enum_1.ServerEntryTypeEnum.List:
|
|
16
|
+
return {
|
|
17
|
+
id: entry.id,
|
|
18
|
+
message: this.listTransform(entry),
|
|
19
|
+
entry: entry,
|
|
20
|
+
isUser: false,
|
|
21
|
+
};
|
|
22
|
+
case server_entry_type_enum_1.ServerEntryTypeEnum.Text:
|
|
23
|
+
return {
|
|
24
|
+
id: entry.id,
|
|
25
|
+
message: this.textTransform(entry),
|
|
26
|
+
entry: entry,
|
|
27
|
+
isUser: false,
|
|
28
|
+
};
|
|
29
|
+
case server_entry_type_enum_1.ServerEntryTypeEnum.Text:
|
|
30
|
+
return {
|
|
31
|
+
id: entry.id,
|
|
32
|
+
message: this.listTransform(entry),
|
|
33
|
+
entry: entry,
|
|
34
|
+
isUser: false,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// transform an array of entries
|
|
39
|
+
EntryInterface.prototype.transformArray = function (entryArray) {
|
|
40
|
+
var _this = this;
|
|
41
|
+
var returnArray = [];
|
|
42
|
+
entryArray.forEach(function (o) {
|
|
43
|
+
var x = _this.transform(o);
|
|
44
|
+
if (!!x)
|
|
45
|
+
returnArray.push(x);
|
|
46
|
+
});
|
|
47
|
+
return returnArray;
|
|
48
|
+
};
|
|
49
|
+
// gets the text that should be printed as a user message on action
|
|
50
|
+
EntryInterface.prototype.getUserMessage = function (action) {
|
|
51
|
+
var entry = store_helper_1.StoreHelper.getEntry(action);
|
|
52
|
+
return this.getTitleFromEntry(entry, action);
|
|
53
|
+
};
|
|
54
|
+
EntryInterface.prototype.listTransform = function (entry) {
|
|
55
|
+
if (!entry.content)
|
|
56
|
+
return undefined;
|
|
57
|
+
var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
|
|
58
|
+
return object;
|
|
59
|
+
};
|
|
60
|
+
EntryInterface.prototype.getContentText = function (entry) {
|
|
61
|
+
if (entry.content.html)
|
|
62
|
+
return { body: entry.content.html };
|
|
63
|
+
if (entry.content.header)
|
|
64
|
+
return { title: entry.content.header };
|
|
65
|
+
};
|
|
66
|
+
EntryInterface.prototype.textTransform = function (entry) {
|
|
67
|
+
if (!!entry.content.items)
|
|
68
|
+
return this.listTransform(entry);
|
|
69
|
+
return [
|
|
70
|
+
widget_conversation_1.ConversationMessageListItemType.HTML,
|
|
71
|
+
{ body: entry.content.html.replace('\n', '') },
|
|
72
|
+
];
|
|
73
|
+
};
|
|
74
|
+
EntryInterface.prototype.getListActions = function (items, text, actions, state) {
|
|
75
|
+
var _this = this;
|
|
76
|
+
var list = [];
|
|
77
|
+
var mainListContent = {};
|
|
78
|
+
var mainList = [
|
|
79
|
+
this.getListType(state),
|
|
80
|
+
{ actions: mainListContent },
|
|
81
|
+
];
|
|
82
|
+
if (text && text.title) {
|
|
83
|
+
list.push([widget_conversation_1.ConversationMessageListItemType.Header, text.title]);
|
|
84
|
+
}
|
|
85
|
+
if (text && text.body) {
|
|
86
|
+
list.push([widget_conversation_1.ConversationMessageListItemType.HTML, { body: text.body }]);
|
|
87
|
+
}
|
|
88
|
+
list.push(mainList);
|
|
89
|
+
items.forEach(function (o) {
|
|
90
|
+
switch (o.actionKey) {
|
|
91
|
+
case _this.helpActionKey: {
|
|
92
|
+
list.push([widget_conversation_1.ConversationMessageListItemType.Separator, undefined]);
|
|
93
|
+
list.push([
|
|
94
|
+
widget_conversation_1.ConversationMessageListItemType.NoGoodAlternative,
|
|
95
|
+
{ body: o.title },
|
|
96
|
+
]);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case _this.nextActionKey: {
|
|
100
|
+
if (!!actions['next'] && actions['next'].take === items.length + 1)
|
|
101
|
+
mainListContent[o.actionKey] = o.title;
|
|
102
|
+
// console.log(actions['next'], actions['next'].take, items.length, items.length - 2)
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
default: {
|
|
106
|
+
mainListContent[o.actionKey] = o.title;
|
|
107
|
+
// mainListContent.push(this.getItemObject(o))
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return list;
|
|
112
|
+
};
|
|
113
|
+
EntryInterface.prototype.getListType = function (state) {
|
|
114
|
+
if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
|
|
115
|
+
return widget_conversation_1.ConversationMessageListItemType.LinkList;
|
|
116
|
+
else if ((state === null || state === void 0 ? void 0 : state.$type) ===
|
|
117
|
+
'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
|
|
118
|
+
return widget_conversation_1.ConversationMessageListItemType.FeedbackList;
|
|
119
|
+
else
|
|
120
|
+
return widget_conversation_1.ConversationMessageListItemType.ButtonList;
|
|
121
|
+
};
|
|
122
|
+
EntryInterface.prototype.getTitleFromEntry = function (entry, action) {
|
|
123
|
+
if (!!entry) {
|
|
124
|
+
var entryType = server_entry_type_enum_1.ServerEntryTypeEnum[entry.type];
|
|
125
|
+
switch (entryType) {
|
|
126
|
+
case server_entry_type_enum_1.ServerEntryTypeEnum.List:
|
|
127
|
+
return this.getTitleFromList(entry, action);
|
|
128
|
+
case server_entry_type_enum_1.ServerEntryTypeEnum.Text:
|
|
129
|
+
return this.textTransform(entry);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
EntryInterface.prototype.getTitleFromList = function (entry, action) {
|
|
134
|
+
return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
|
|
135
|
+
};
|
|
136
|
+
return EntryInterface;
|
|
137
|
+
}());
|
|
138
|
+
exports.default = EntryInterface;
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { convertToStringAttributes } from "@humany/widget-ui";
|
|
3
|
+
// import { ServerEntry } from "../../contract/model/http/server-entry.model";
|
|
4
|
+
// import { StoreHelper } from "../../helper/store.helper";
|
|
5
|
+
// export default class ContactExpandedInterface {
|
|
6
|
+
// name = "contact-expanded-handler";
|
|
7
|
+
// constructor() {}
|
|
8
|
+
// process(entries: ServerEntry[], action?: string): ServerEntry[] {
|
|
9
|
+
// let didSelect = false;
|
|
10
|
+
// let didCategorySelect = false;
|
|
11
|
+
// if (!action) return entries;
|
|
12
|
+
// const entry = StoreHelper.getEntry(action);
|
|
13
|
+
// if (
|
|
14
|
+
// entry.actions &&
|
|
15
|
+
// entry.actions[action] &&
|
|
16
|
+
// entry.actions[action].$type.indexOf("SelectContactMethod") !== -1
|
|
17
|
+
// ) {
|
|
18
|
+
// didSelect = true;
|
|
19
|
+
// }
|
|
20
|
+
// if (
|
|
21
|
+
// entry.actions &&
|
|
22
|
+
// entry.actions[action] &&
|
|
23
|
+
// entry.actions[action].$type.indexOf("SelectContactCategory") !== -1
|
|
24
|
+
// ) {
|
|
25
|
+
// didCategorySelect = true;
|
|
26
|
+
// }
|
|
27
|
+
// entries
|
|
28
|
+
// .filter(
|
|
29
|
+
// (e) =>
|
|
30
|
+
// e.type === "Contact" ||
|
|
31
|
+
// (e.type === "List" &&
|
|
32
|
+
// e.tags.indexOf("contact") > -1 &&
|
|
33
|
+
// e.tags.indexOf("category") === -1)
|
|
34
|
+
// ).forEach((e) => {
|
|
35
|
+
// if (e.type === "List") {
|
|
36
|
+
// if (e.content && e.content.items && e.content.items.length === 1) {
|
|
37
|
+
// const item = e.content.items[0];
|
|
38
|
+
// const hasForm = !!item && !!item.body && !!item.body.form;
|
|
39
|
+
// if (hasForm) {
|
|
40
|
+
// e.content.items[0].inline = !didCategorySelect;
|
|
41
|
+
// if (didSelect) {
|
|
42
|
+
// e.content.items[0].expanded = true;
|
|
43
|
+
// }
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
// });
|
|
48
|
+
// return entries;
|
|
49
|
+
// }
|
|
50
|
+
// }
|
|
File without changes
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { Container } from "@webprovisions/platform";
|
|
3
|
+
// import { ServerEntry } from "../../contract/model/http/server-entry.model";
|
|
4
|
+
// import { MiddlewareHelper } from "../../helper/middleware.helper";
|
|
5
|
+
// export const mapContactMethodType = (cm: any): string => {
|
|
6
|
+
// const a = cm.exitConfiguration.split(".");
|
|
7
|
+
// if (a.indexOf("phone") > -1) {
|
|
8
|
+
// return "phone";
|
|
9
|
+
// }
|
|
10
|
+
// if (a.indexOf("freetext") > -1) {
|
|
11
|
+
// return "free-text";
|
|
12
|
+
// }
|
|
13
|
+
// if (a.indexOf("email") > -1) {
|
|
14
|
+
// return "email";
|
|
15
|
+
// }
|
|
16
|
+
// if (a.indexOf("link") > -1) {
|
|
17
|
+
// return "link";
|
|
18
|
+
// }
|
|
19
|
+
// if (a.indexOf("custom") > -1 && a.indexOf("adapter") > -1) {
|
|
20
|
+
// return "custom-adapter";
|
|
21
|
+
// }
|
|
22
|
+
// if (a.indexOf("chat") > -1) {
|
|
23
|
+
// return "chat";
|
|
24
|
+
// }
|
|
25
|
+
// if (a.indexOf("callback") > -1) {
|
|
26
|
+
// return "callback";
|
|
27
|
+
// }
|
|
28
|
+
// return "";
|
|
29
|
+
// };
|
|
30
|
+
// const fetchContactMethods = (
|
|
31
|
+
// matchingServiceClient: ServiceClient,
|
|
32
|
+
// guideId: string,
|
|
33
|
+
// connectionKey: string
|
|
34
|
+
// ): any => {
|
|
35
|
+
// return new Promise((resolve) => {
|
|
36
|
+
// if (guideId) {
|
|
37
|
+
// matchingServiceClient.getGuide(
|
|
38
|
+
// guideId,
|
|
39
|
+
// connectionKey,
|
|
40
|
+
// { statisticsDisabled: true },
|
|
41
|
+
// (guide: GuideViewApiResponse) => {
|
|
42
|
+
// const contactMethods = [guide.ContactMethod].concat(
|
|
43
|
+
// guide.ContactMethods ? guide.ContactMethods : []
|
|
44
|
+
// );
|
|
45
|
+
// resolve(contactMethods);
|
|
46
|
+
// }
|
|
47
|
+
// );
|
|
48
|
+
// } else {
|
|
49
|
+
// matchingServiceClient.contactMethods((contactMethods: any) => {
|
|
50
|
+
// resolve(contactMethods.Matches);
|
|
51
|
+
// });
|
|
52
|
+
// }
|
|
53
|
+
// });
|
|
54
|
+
// };
|
|
55
|
+
// export const mapContactMethod = (
|
|
56
|
+
// match: any,
|
|
57
|
+
// contactMethods: ContactMethodPlatform,
|
|
58
|
+
// entryId?: string,
|
|
59
|
+
// actionKey?: string
|
|
60
|
+
// ) => {
|
|
61
|
+
// const adapter = match.exits[0].adapter;
|
|
62
|
+
// const clientName = adapter.customClientName || adapter.clientName;
|
|
63
|
+
// // const contactMethodType =
|
|
64
|
+
// // contactMethods.get(clientName) || <ContactMethodType>{};
|
|
65
|
+
// const contactMethod: any = {
|
|
66
|
+
// entryId,
|
|
67
|
+
// actionKey,
|
|
68
|
+
// clientName,
|
|
69
|
+
// canRender: true,
|
|
70
|
+
// id: `${match.id}`,
|
|
71
|
+
// title: match.title,
|
|
72
|
+
// body: adapter.settings,
|
|
73
|
+
// type: mapContactMethodType(match),
|
|
74
|
+
// description:
|
|
75
|
+
// match.description && match.description.length
|
|
76
|
+
// ? match.description
|
|
77
|
+
// : undefined,
|
|
78
|
+
// expanded: false,
|
|
79
|
+
// inline: true,
|
|
80
|
+
// uriName: match.uriName,
|
|
81
|
+
// };
|
|
82
|
+
// if (
|
|
83
|
+
// match.defaultIcon &&
|
|
84
|
+
// match.defaultIcon.content &&
|
|
85
|
+
// match.defaultIcon.type
|
|
86
|
+
// ) {
|
|
87
|
+
// contactMethod.symbol = {
|
|
88
|
+
// type: match.defaultIcon.type,
|
|
89
|
+
// content: match.defaultIcon.content,
|
|
90
|
+
// };
|
|
91
|
+
// }
|
|
92
|
+
// const hasForm =
|
|
93
|
+
// match.form &&
|
|
94
|
+
// (match.form.hasValueComponents || match.form.HasValueComponents);
|
|
95
|
+
// if (hasForm) {
|
|
96
|
+
// const formId = contactMethod.id || "";
|
|
97
|
+
// const builder = FormBuilder.fromLegacyForm(formId, match.form, null);
|
|
98
|
+
// // builder.createComponent(submitButton(texts.get("forms.submit"), "submit"));
|
|
99
|
+
// contactMethod.body.form = builder.get();
|
|
100
|
+
// contactMethod.inline = false;
|
|
101
|
+
// if (match.expandFormAutomatically) {
|
|
102
|
+
// contactMethod.expanded = true;
|
|
103
|
+
// contactMethod.inline = true;
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
106
|
+
// if (contactMethod.type === "free-text" || contactMethod.type === "phone") {
|
|
107
|
+
// contactMethod.expanded =
|
|
108
|
+
// contactMethod.body.displayTextBeforeClick === "false";
|
|
109
|
+
// }
|
|
110
|
+
// if (contactMethod.type === "link") {
|
|
111
|
+
// contactMethod.expanded = true;
|
|
112
|
+
// }
|
|
113
|
+
// if (match.exitConfiguration === "custom.adapter") {
|
|
114
|
+
// if (hasForm) {
|
|
115
|
+
// contactMethod.inline = false;
|
|
116
|
+
// } else {
|
|
117
|
+
// contactMethod.expanded = true;
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
// return contactMethod;
|
|
121
|
+
// };
|
|
122
|
+
// // Displays confirmation text after contact method form has been submitted
|
|
123
|
+
// // const respondContactMethodSubmitted = (
|
|
124
|
+
// // dataSource: DataSource,
|
|
125
|
+
// // data: { entryId: string; confirmationText: string; type: string },
|
|
126
|
+
// // ) => {
|
|
127
|
+
// // dataSource.respond(data.entryId, data.type, {
|
|
128
|
+
// // completedMessage: data.confirmationText,
|
|
129
|
+
// // });
|
|
130
|
+
// // };
|
|
131
|
+
// const modifyActionsForExpandedItems = (entry: ServerEntry) => {
|
|
132
|
+
// const keysToModify = entry.content.items
|
|
133
|
+
// .filter((item: any) => {
|
|
134
|
+
// if (!item.data) {
|
|
135
|
+
// return false;
|
|
136
|
+
// }
|
|
137
|
+
// return item.data.expandFormAutomatically;
|
|
138
|
+
// })
|
|
139
|
+
// .map((item: any) => item.actionKey);
|
|
140
|
+
// return Object.keys(entry.actions).reduce<any>((acc, actionKey: any) => {
|
|
141
|
+
// const action = entry.actions[actionKey];
|
|
142
|
+
// if (keysToModify.indexOf(actionKey) > -1) {
|
|
143
|
+
// acc[actionKey] = {
|
|
144
|
+
// ...action,
|
|
145
|
+
// $type:
|
|
146
|
+
// "Humany.Matching.Bots.Conversations.Actions.ContactMethodCompleted, Humany.Matching",
|
|
147
|
+
// };
|
|
148
|
+
// } else {
|
|
149
|
+
// acc[actionKey] = action;
|
|
150
|
+
// }
|
|
151
|
+
// return acc;
|
|
152
|
+
// }, {});
|
|
153
|
+
// };
|
|
154
|
+
// const storeLegacyContactMethod = (container: any, legacyContactMethod: any) => {
|
|
155
|
+
// return lock(container)(() => {
|
|
156
|
+
// return container.getAsync("storage").then((storage: StorageProvider) => {
|
|
157
|
+
// return storage.session
|
|
158
|
+
// .getItem("legacyContactMethods")
|
|
159
|
+
// .then((legacyContactMethods) => {
|
|
160
|
+
// return legacyContactMethods || container.get("legacyContactMethods");
|
|
161
|
+
// })
|
|
162
|
+
// .then((legacyContactMethods) => {
|
|
163
|
+
// let legacyContactMethodsToStore = legacyContactMethods;
|
|
164
|
+
// if (!legacyContactMethodsToStore) {
|
|
165
|
+
// legacyContactMethodsToStore = {};
|
|
166
|
+
// container.register(
|
|
167
|
+
// "legacyContactMethods",
|
|
168
|
+
// legacyContactMethodsToStore
|
|
169
|
+
// );
|
|
170
|
+
// }
|
|
171
|
+
// legacyContactMethodsToStore[legacyContactMethod.id] = {
|
|
172
|
+
// entity: legacyContactMethod,
|
|
173
|
+
// };
|
|
174
|
+
// return storage.session.setItem(
|
|
175
|
+
// "legacyContactMethods",
|
|
176
|
+
// legacyContactMethods
|
|
177
|
+
// );
|
|
178
|
+
// });
|
|
179
|
+
// });
|
|
180
|
+
// });
|
|
181
|
+
// };
|
|
182
|
+
// class ContactMethodResolver {
|
|
183
|
+
// cache: Map<string, Promise<any>> = new Map<string, Promise<any>>();
|
|
184
|
+
// constructor(
|
|
185
|
+
// private matchingClient: ServiceClient,
|
|
186
|
+
// private container: any,
|
|
187
|
+
// private contactMethods: ContactMethodPlatform
|
|
188
|
+
// ) {}
|
|
189
|
+
// add(content: any, entryId: string) {
|
|
190
|
+
// const { id, guideId, connectionKey } = content;
|
|
191
|
+
// const key = (guideId || "") + (connectionKey || "") || "all";
|
|
192
|
+
// let promise = this.cache.get(key);
|
|
193
|
+
// if (promise) {
|
|
194
|
+
// promise.then((contactMethodEntity) => {
|
|
195
|
+
// Object.assign(
|
|
196
|
+
// content,
|
|
197
|
+
// mapContactMethod(
|
|
198
|
+
// contactMethodEntity,
|
|
199
|
+
// this.contactMethods,
|
|
200
|
+
// entryId
|
|
201
|
+
// )
|
|
202
|
+
// );
|
|
203
|
+
// });
|
|
204
|
+
// } else {
|
|
205
|
+
// promise = <Promise<any>>fetchContactMethods(
|
|
206
|
+
// this.matchingClient,
|
|
207
|
+
// guideId,
|
|
208
|
+
// connectionKey
|
|
209
|
+
// )
|
|
210
|
+
// .then((contactMethodEntites: any) => {
|
|
211
|
+
// const contactMethodEntity = contactMethodEntites.find(
|
|
212
|
+
// (entity: any) => entity.Id === id
|
|
213
|
+
// );
|
|
214
|
+
// const { Form } = contactMethodEntity;
|
|
215
|
+
// return Object.assign({}, camilize(contactMethodEntity), {
|
|
216
|
+
// form: Form,
|
|
217
|
+
// });
|
|
218
|
+
// })
|
|
219
|
+
// .then((contactMethodEntity: any) => {
|
|
220
|
+
// storeLegacyContactMethod(this.container, contactMethodEntity);
|
|
221
|
+
// Object.assign(
|
|
222
|
+
// content,
|
|
223
|
+
// mapContactMethod(
|
|
224
|
+
// contactMethodEntity,
|
|
225
|
+
// this.contactMethods,
|
|
226
|
+
// entryId
|
|
227
|
+
// )
|
|
228
|
+
// );
|
|
229
|
+
// return contactMethodEntity;
|
|
230
|
+
// });
|
|
231
|
+
// this.cache.set(key, promise);
|
|
232
|
+
// }
|
|
233
|
+
// }
|
|
234
|
+
// wait(): Promise<any> {
|
|
235
|
+
// return Promise.all(Array.from(this.cache.values()));
|
|
236
|
+
// }
|
|
237
|
+
// }
|
|
238
|
+
// export default class ContactInterface {
|
|
239
|
+
// name = "contact";
|
|
240
|
+
// private container: Container;
|
|
241
|
+
// constructor() {
|
|
242
|
+
// this.initalize();
|
|
243
|
+
// this.container = <Container>MiddlewareHelper.getContainer();
|
|
244
|
+
// }
|
|
245
|
+
// process(entries: ServerEntry[]): Promise<ServerEntry[]> {
|
|
246
|
+
// return Promise.all([
|
|
247
|
+
// <Promise<ContactMethodPlatform>>this.container.getAsync("contactMethods"),
|
|
248
|
+
// <Promise<ServiceClient>>this.container.getAsync("matchingClient")
|
|
249
|
+
// ])
|
|
250
|
+
// .then(result => {
|
|
251
|
+
// let contactMethods = result[0];
|
|
252
|
+
// let matchingClient = result[1];
|
|
253
|
+
// // remove Text entries without text or html props.
|
|
254
|
+
// const updatedEntries = entries.filter(
|
|
255
|
+
// (entry) =>
|
|
256
|
+
// !(
|
|
257
|
+
// entry.type === "Text" &&
|
|
258
|
+
// entry.content &&
|
|
259
|
+
// !entry.content.text &&
|
|
260
|
+
// !entry.content.html
|
|
261
|
+
// )
|
|
262
|
+
// );
|
|
263
|
+
// const resolver = new ContactMethodResolver(
|
|
264
|
+
// matchingClient,
|
|
265
|
+
// this.container,
|
|
266
|
+
// contactMethods
|
|
267
|
+
// );
|
|
268
|
+
// // get all contact method lists
|
|
269
|
+
// const lists = updatedEntries.filter(
|
|
270
|
+
// (entry) => entry.type === "List" && entry.tags.indexOf("contact") > -1
|
|
271
|
+
// );
|
|
272
|
+
// // iterate and patch legacy items by mapping the 'data' attribute
|
|
273
|
+
// lists.forEach((entry) => {
|
|
274
|
+
// if (entry.content.items) {
|
|
275
|
+
// // if the list contains already expanded contact methods,
|
|
276
|
+
// // we do not want to use the action type ContactMethodCompleted
|
|
277
|
+
// // instead of ContactMethodSelected
|
|
278
|
+
// entry.actions = modifyActionsForExpandedItems(entry);
|
|
279
|
+
// entry.content.items.forEach((item: any) => {
|
|
280
|
+
// if (item.data) {
|
|
281
|
+
// storeLegacyContactMethod(this.container, item.data);
|
|
282
|
+
// Object.assign(
|
|
283
|
+
// item,
|
|
284
|
+
// mapContactMethod(
|
|
285
|
+
// item.data,
|
|
286
|
+
// contactMethods,
|
|
287
|
+
// entry.id,
|
|
288
|
+
// item.actionKey
|
|
289
|
+
// )
|
|
290
|
+
// );
|
|
291
|
+
// delete item.data;
|
|
292
|
+
// }
|
|
293
|
+
// });
|
|
294
|
+
// }
|
|
295
|
+
// });
|
|
296
|
+
// // get all single contact methods
|
|
297
|
+
// const singles = updatedEntries.filter(
|
|
298
|
+
// (entry) =>
|
|
299
|
+
// entry.type === "Contact" &&
|
|
300
|
+
// entry.content.id &&
|
|
301
|
+
// !entry.content.clientName
|
|
302
|
+
// );
|
|
303
|
+
// singles.forEach((entry) => resolver.add(entry.content, entry.id));
|
|
304
|
+
// return resolver.wait().then(() => {
|
|
305
|
+
// // patch with ContactMethodType
|
|
306
|
+
// updatedEntries
|
|
307
|
+
// .filter(
|
|
308
|
+
// (entry) =>
|
|
309
|
+
// entry.type === "Contact" &&
|
|
310
|
+
// entry.content &&
|
|
311
|
+
// !entry.content.contactMethodType
|
|
312
|
+
// )
|
|
313
|
+
// .forEach((entry) => {
|
|
314
|
+
// // // const contactMethodType =
|
|
315
|
+
// // // contactMethods.get(entry.content.clientName) ||
|
|
316
|
+
// // // <ContactMethodType>{};
|
|
317
|
+
// entry.content.canRender = true;
|
|
318
|
+
// });
|
|
319
|
+
// updatedEntries
|
|
320
|
+
// .filter((entry) => entry.type === "Contact")
|
|
321
|
+
// .forEach((entry) => {
|
|
322
|
+
// entry.type = "List";
|
|
323
|
+
// const { timestamp, ...content } = entry.content;
|
|
324
|
+
// entry.content = { timestamp, items: [{ ...content }] };
|
|
325
|
+
// if (entry.tags.indexOf("contact") === -1) {
|
|
326
|
+
// entry.tags.push("contact");
|
|
327
|
+
// }
|
|
328
|
+
// });
|
|
329
|
+
// return entries;
|
|
330
|
+
// });
|
|
331
|
+
// });
|
|
332
|
+
// }
|
|
333
|
+
// initalize() {
|
|
334
|
+
// // this.widget.events.subscribe(
|
|
335
|
+
// // 'contact-method:invoked',
|
|
336
|
+
// // async (event, data) => {
|
|
337
|
+
// // const { method, contactMethod, result } = data;
|
|
338
|
+
// // const { entryId } = contactMethod;
|
|
339
|
+
// // // TODO: Currently we need to look up the contact method entry in the full "unwashed"
|
|
340
|
+
// // // stream as it does not exist in the "regular" washed stream.
|
|
341
|
+
// // // This should be handled differently by perhaps storing a reference in
|
|
342
|
+
// // // the parent entity to the contact method entry in some way.
|
|
343
|
+
// // const entry = StoreHelper.getEntryStore()
|
|
344
|
+
// // .find(e => e.id === entryId);
|
|
345
|
+
// // if (method === 'submit' && result.success && !result.preventResponse) {
|
|
346
|
+
// // let actionType = 'submitted';
|
|
347
|
+
// // if (
|
|
348
|
+
// // entry &&
|
|
349
|
+
// // entry.actions &&
|
|
350
|
+
// // Object.keys(entry.actions).length >= 1 &&
|
|
351
|
+
// // !entry.actions.submitted
|
|
352
|
+
// // ) {
|
|
353
|
+
// // const item = entry.content.items
|
|
354
|
+
// // .find((item: any) => item.id === contactMethod.id);
|
|
355
|
+
// // if (item && item.actionKey && entry.actions[item.actionKey]) {
|
|
356
|
+
// // actionType = item.actionKey;
|
|
357
|
+
// // }
|
|
358
|
+
// // }
|
|
359
|
+
// // // respondContactMethodSubmitted(dataSource, {
|
|
360
|
+
// // // entryId,
|
|
361
|
+
// // // type: actionType,
|
|
362
|
+
// // // confirmationText: result.confirmationText,
|
|
363
|
+
// // // });
|
|
364
|
+
// // if (entry) {
|
|
365
|
+
// // // Disable form
|
|
366
|
+
// // const item = entry.content.items
|
|
367
|
+
// // .find((item: any) => item.id === contactMethod.id);
|
|
368
|
+
// // if (item && item.body && item.body.form) {
|
|
369
|
+
// // item.body.form.layout['ui:disabled'] = true;
|
|
370
|
+
// // }
|
|
371
|
+
// // }
|
|
372
|
+
// // }
|
|
373
|
+
// // if (entry) {
|
|
374
|
+
// // if (entry.type === 'List') {
|
|
375
|
+
// // const updatedItems = entry.content.items.map((item: any) => {
|
|
376
|
+
// // if (item.id === contactMethod.id) {
|
|
377
|
+
// // return contactMethod;
|
|
378
|
+
// // }
|
|
379
|
+
// // return item;
|
|
380
|
+
// // });
|
|
381
|
+
// // writer.update(entryId, { items: updatedItems });
|
|
382
|
+
// // writer.commit();
|
|
383
|
+
// // } else if (
|
|
384
|
+
// // entry.type === 'ContactMethod' ||
|
|
385
|
+
// // entry.type === 'Contact'
|
|
386
|
+
// // ) {
|
|
387
|
+
// // writer.update(contactMethod.entryId, contactMethod);
|
|
388
|
+
// // writer.commit();
|
|
389
|
+
// // }
|
|
390
|
+
// // }
|
|
391
|
+
// // },
|
|
392
|
+
// // );
|
|
393
|
+
// }
|
|
394
|
+
// }
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var store_helper_1 = require("../../helper/store.helper");
|
|
15
|
+
var PagingInterface = /** @class */ (function () {
|
|
16
|
+
function PagingInterface() {
|
|
17
|
+
}
|
|
18
|
+
PagingInterface.prototype.process = function (entries) {
|
|
19
|
+
var pagingEntry = entries.find(function (e) { return e.tags.indexOf("paging") > -1; });
|
|
20
|
+
if (pagingEntry) {
|
|
21
|
+
var stream = store_helper_1.StoreHelper.getEntryStore().filter(function (e) { return e.tags.indexOf("paging") > -1 && e.id === pagingEntry.id; });
|
|
22
|
+
if (stream.length > 0) {
|
|
23
|
+
// Get the paging entry with the highest take count
|
|
24
|
+
var last_1 = stream.reduce(function (acc, entry) {
|
|
25
|
+
if (entry.actions.next &&
|
|
26
|
+
entry.actions.next.take >= acc.actions.next.take) {
|
|
27
|
+
return entry;
|
|
28
|
+
}
|
|
29
|
+
return acc;
|
|
30
|
+
}, stream[0]); // tslint:disable-line:align
|
|
31
|
+
// If there is a paging entry with higher take count than the entry to be written,
|
|
32
|
+
// it should be updated to use the paging data from the highest take count entry
|
|
33
|
+
if (last_1.actions.next.take > pagingEntry.actions.next.take) {
|
|
34
|
+
entries.forEach(function (entry) {
|
|
35
|
+
if (entry.id === pagingEntry.id) {
|
|
36
|
+
entry.actions.next = __assign(__assign({}, entry.actions.next), { take: last_1.actions.next.take, skip: last_1.actions.next.skip });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// if items is null or undefined it should
|
|
42
|
+
// overwrite with an empty array
|
|
43
|
+
entries.forEach(function (entry) {
|
|
44
|
+
if (entry.id === pagingEntry.id &&
|
|
45
|
+
entry.content &&
|
|
46
|
+
entry.content.timestamp) {
|
|
47
|
+
entry.content = __assign(__assign({}, entry.content), { items: (entry.content && entry.content.items) || [] });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return entries;
|
|
52
|
+
};
|
|
53
|
+
return PagingInterface;
|
|
54
|
+
}());
|
|
55
|
+
exports.default = PagingInterface;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ServerEntry } from '../../contract/model/http/server-entry.model';
|
|
2
|
+
export default class ProcessorInterface {
|
|
3
|
+
process(entries: ServerEntry[]): ServerEntry[];
|
|
4
|
+
processUpdate(entry: ServerEntry | undefined, updateEntryArray: ServerEntry[]): ServerEntry[];
|
|
5
|
+
private handleActionUpdateOrInsert;
|
|
6
|
+
private deletePaging;
|
|
7
|
+
private delete;
|
|
8
|
+
private merge;
|
|
9
|
+
private moveLoader;
|
|
10
|
+
}
|