@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.2 → 0.0.1-alpha.22

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 (119) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +12 -12
  3. package/lib/client/chat.client.d.ts +15 -0
  4. package/lib/client/chat.client.js +79 -0
  5. package/lib/client/contact-method.client.d.ts +22 -0
  6. package/lib/client/contact-method.client.js +273 -0
  7. package/lib/client/http.client.d.ts +22 -0
  8. package/lib/client/http.client.js +113 -0
  9. package/lib/client/middleware.client.d.ts +13 -0
  10. package/lib/client/middleware.client.js +46 -0
  11. package/lib/contract/custom-component/contact-method-item.d.ts +8 -0
  12. package/lib/contract/custom-component/contact-method-item.js +51 -0
  13. package/lib/contract/custom-component/contact-method-list.d.ts +7 -0
  14. package/lib/contract/custom-component/contact-method-list.js +13 -0
  15. package/lib/contract/custom-component/contact-method.d.ts +3 -0
  16. package/lib/contract/custom-component/contact-method.js +33 -0
  17. package/lib/contract/enum/server-entry-type.enum.d.ts +6 -0
  18. package/lib/contract/enum/server-entry-type.enum.js +7 -0
  19. package/lib/contract/model/conversation-api-model/list.model.d.ts +5 -0
  20. package/lib/contract/model/conversation-api-model/list.model.js +0 -0
  21. package/lib/contract/model/conversation-api-model/message.model.d.ts +7 -0
  22. package/lib/contract/model/conversation-api-model/message.model.js +0 -0
  23. package/lib/contract/model/http/action.model.d.ts +3 -0
  24. package/lib/contract/model/http/action.model.js +0 -0
  25. package/lib/contract/model/http/client-action.model.d.ts +4 -0
  26. package/lib/contract/model/http/client-action.model.js +1 -0
  27. package/lib/contract/model/http/client-envelope.model.d.ts +9 -0
  28. package/lib/contract/model/http/client-envelope.model.js +0 -0
  29. package/lib/contract/model/http/connect-options.model.d.ts +5 -0
  30. package/lib/contract/model/http/connect-options.model.js +0 -0
  31. package/lib/contract/model/http/global-state.model.d.ts +8 -0
  32. package/lib/contract/model/http/global-state.model.js +0 -0
  33. package/lib/contract/model/http/http-client-options.model.d.ts +5 -0
  34. package/lib/contract/model/http/http-client-options.model.js +0 -0
  35. package/lib/contract/model/http/server-entry.model.d.ts +11 -0
  36. package/lib/contract/model/http/server-entry.model.js +0 -0
  37. package/lib/contract/model/http/server-envelope.model.d.ts +10 -0
  38. package/lib/contract/model/http/server-envelope.model.js +0 -0
  39. package/lib/contract/model/middleware/aggregator-state.model.d.ts +4 -0
  40. package/lib/contract/model/middleware/aggregator-state.model.js +1 -0
  41. package/lib/contract/model/shared/loose-object.model.d.ts +3 -0
  42. package/lib/contract/model/shared/loose-object.model.js +0 -0
  43. package/lib/helper/chat.helper.d.ts +8 -0
  44. package/lib/helper/chat.helper.js +18 -0
  45. package/lib/helper/http.helper.d.ts +13 -0
  46. package/lib/helper/http.helper.js +28 -0
  47. package/lib/helper/middleware.helper.d.ts +12 -0
  48. package/lib/helper/middleware.helper.js +67 -0
  49. package/lib/helper/store.helper.d.ts +22 -0
  50. package/lib/helper/store.helper.js +77 -0
  51. package/lib/index.d.ts +2 -0
  52. package/lib/index.js +2 -0
  53. package/lib/interface/entry.interface.d.ts +17 -0
  54. package/lib/interface/entry.interface.js +133 -0
  55. package/lib/interface/middleware/paging.interface.d.ts +4 -0
  56. package/lib/interface/middleware/paging.interface.js +53 -0
  57. package/lib/interface/middleware/processor.interface.d.ts +10 -0
  58. package/lib/interface/middleware/processor.interface.js +118 -0
  59. package/lib/plugin.d.ts +3 -0
  60. package/lib/plugin.js +198 -0
  61. package/lib-esm/client/chat.client.d.ts +15 -0
  62. package/lib-esm/client/chat.client.js +79 -0
  63. package/lib-esm/client/contact-method.client.d.ts +22 -0
  64. package/lib-esm/client/contact-method.client.js +273 -0
  65. package/lib-esm/client/http.client.d.ts +22 -0
  66. package/lib-esm/client/http.client.js +113 -0
  67. package/lib-esm/client/middleware.client.d.ts +13 -0
  68. package/lib-esm/client/middleware.client.js +46 -0
  69. package/lib-esm/contract/custom-component/contact-method-item.d.ts +8 -0
  70. package/lib-esm/contract/custom-component/contact-method-item.js +51 -0
  71. package/lib-esm/contract/custom-component/contact-method-list.d.ts +7 -0
  72. package/lib-esm/contract/custom-component/contact-method-list.js +13 -0
  73. package/lib-esm/contract/custom-component/contact-method.d.ts +3 -0
  74. package/lib-esm/contract/custom-component/contact-method.js +33 -0
  75. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +6 -0
  76. package/lib-esm/contract/enum/server-entry-type.enum.js +7 -0
  77. package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +5 -0
  78. package/lib-esm/contract/model/conversation-api-model/list.model.js +0 -0
  79. package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +7 -0
  80. package/lib-esm/contract/model/conversation-api-model/message.model.js +0 -0
  81. package/lib-esm/contract/model/http/action.model.d.ts +3 -0
  82. package/lib-esm/contract/model/http/action.model.js +0 -0
  83. package/lib-esm/contract/model/http/client-action.model.d.ts +4 -0
  84. package/lib-esm/contract/model/http/client-action.model.js +1 -0
  85. package/lib-esm/contract/model/http/client-envelope.model.d.ts +9 -0
  86. package/lib-esm/contract/model/http/client-envelope.model.js +0 -0
  87. package/lib-esm/contract/model/http/connect-options.model.d.ts +5 -0
  88. package/lib-esm/contract/model/http/connect-options.model.js +0 -0
  89. package/lib-esm/contract/model/http/global-state.model.d.ts +8 -0
  90. package/lib-esm/contract/model/http/global-state.model.js +0 -0
  91. package/lib-esm/contract/model/http/http-client-options.model.d.ts +5 -0
  92. package/lib-esm/contract/model/http/http-client-options.model.js +0 -0
  93. package/lib-esm/contract/model/http/server-entry.model.d.ts +11 -0
  94. package/lib-esm/contract/model/http/server-entry.model.js +0 -0
  95. package/lib-esm/contract/model/http/server-envelope.model.d.ts +10 -0
  96. package/lib-esm/contract/model/http/server-envelope.model.js +0 -0
  97. package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +4 -0
  98. package/lib-esm/contract/model/middleware/aggregator-state.model.js +1 -0
  99. package/lib-esm/contract/model/shared/loose-object.model.d.ts +3 -0
  100. package/lib-esm/contract/model/shared/loose-object.model.js +0 -0
  101. package/lib-esm/helper/chat.helper.d.ts +8 -0
  102. package/lib-esm/helper/chat.helper.js +18 -0
  103. package/lib-esm/helper/http.helper.d.ts +13 -0
  104. package/lib-esm/helper/http.helper.js +28 -0
  105. package/lib-esm/helper/middleware.helper.d.ts +12 -0
  106. package/lib-esm/helper/middleware.helper.js +67 -0
  107. package/lib-esm/helper/store.helper.d.ts +22 -0
  108. package/lib-esm/helper/store.helper.js +77 -0
  109. package/lib-esm/index.d.ts +2 -0
  110. package/lib-esm/index.js +2 -0
  111. package/lib-esm/interface/entry.interface.d.ts +17 -0
  112. package/lib-esm/interface/entry.interface.js +133 -0
  113. package/lib-esm/interface/middleware/paging.interface.d.ts +4 -0
  114. package/lib-esm/interface/middleware/paging.interface.js +53 -0
  115. package/lib-esm/interface/middleware/processor.interface.d.ts +10 -0
  116. package/lib-esm/interface/middleware/processor.interface.js +118 -0
  117. package/lib-esm/plugin.d.ts +3 -0
  118. package/lib-esm/plugin.js +198 -0
  119. package/package.json +52 -45
@@ -0,0 +1,133 @@
1
+ import { ConversationMessageListItemType, } from '@humany/widget-conversation';
2
+ import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
3
+ import { StoreHelper } from '../helper/store.helper';
4
+ var EntryInterface = /** @class */ (function () {
5
+ function EntryInterface() {
6
+ this.helpActionKey = 'help';
7
+ this.nextActionKey = 'next';
8
+ }
9
+ // transform the entry based on its type
10
+ EntryInterface.prototype.transform = function (entry) {
11
+ var entryType = ServerEntryTypeEnum[entry.type];
12
+ switch (entryType) {
13
+ case ServerEntryTypeEnum.List:
14
+ return {
15
+ id: entry.id,
16
+ message: this.listTransform(entry),
17
+ entry: entry,
18
+ isUser: false,
19
+ };
20
+ case ServerEntryTypeEnum.Text:
21
+ return {
22
+ id: entry.id,
23
+ message: this.textTransform(entry),
24
+ entry: entry,
25
+ isUser: false,
26
+ };
27
+ case ServerEntryTypeEnum.Text:
28
+ return {
29
+ id: entry.id,
30
+ message: this.listTransform(entry),
31
+ entry: entry,
32
+ isUser: false,
33
+ };
34
+ }
35
+ };
36
+ // transform an array of entries
37
+ EntryInterface.prototype.transformArray = function (entryArray) {
38
+ var _this = this;
39
+ var returnArray = [];
40
+ entryArray.forEach(function (o) {
41
+ var x = _this.transform(o);
42
+ if (!!x)
43
+ returnArray.push(x);
44
+ });
45
+ return returnArray;
46
+ };
47
+ // gets the text that should be printed as a user message on action
48
+ EntryInterface.prototype.getUserMessage = function (action) {
49
+ var entry = StoreHelper.getEntry(action);
50
+ return this.getTitleFromEntry(entry, action);
51
+ };
52
+ EntryInterface.prototype.listTransform = function (entry) {
53
+ if (!entry.content)
54
+ return undefined;
55
+ var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
56
+ return object;
57
+ };
58
+ EntryInterface.prototype.getContentText = function (entry) {
59
+ if (entry.content.html)
60
+ return { body: entry.content.html };
61
+ if (entry.content.header)
62
+ return { title: entry.content.header };
63
+ };
64
+ EntryInterface.prototype.textTransform = function (entry) {
65
+ if (!!entry.content.items)
66
+ return this.listTransform(entry);
67
+ return [
68
+ ConversationMessageListItemType.HTML,
69
+ { body: entry.content.html.replace('\n', '') },
70
+ ];
71
+ };
72
+ EntryInterface.prototype.getListActions = function (items, text, actions, state) {
73
+ var _this = this;
74
+ var list = [];
75
+ var mainListContent = {};
76
+ var mainList = [this.getListType(state), { actions: mainListContent }];
77
+ if (text && text.title) {
78
+ list.push([ConversationMessageListItemType.Header, text.title]);
79
+ }
80
+ if (text && text.body) {
81
+ list.push([ConversationMessageListItemType.HTML, { body: text.body }]);
82
+ }
83
+ list.push(mainList);
84
+ items.forEach(function (o) {
85
+ switch (o.actionKey) {
86
+ case _this.helpActionKey: {
87
+ list.push([ConversationMessageListItemType.Separator, undefined]);
88
+ list.push([
89
+ ConversationMessageListItemType.NoGoodAlternative,
90
+ { body: o.title },
91
+ ]);
92
+ break;
93
+ }
94
+ case _this.nextActionKey: {
95
+ if (!!actions['next'] && actions['next'].take === items.length + 1)
96
+ mainListContent[o.actionKey] = o.title;
97
+ // console.log(actions['next'], actions['next'].take, items.length, items.length - 2)
98
+ break;
99
+ }
100
+ default: {
101
+ mainListContent[o.actionKey] = o.title;
102
+ // mainListContent.push(this.getItemObject(o))
103
+ }
104
+ }
105
+ });
106
+ return list;
107
+ };
108
+ EntryInterface.prototype.getListType = function (state) {
109
+ if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
110
+ return ConversationMessageListItemType.LinkList;
111
+ else if ((state === null || state === void 0 ? void 0 : state.$type) ===
112
+ 'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
113
+ return ConversationMessageListItemType.FeedbackList;
114
+ else
115
+ return ConversationMessageListItemType.ButtonList;
116
+ };
117
+ EntryInterface.prototype.getTitleFromEntry = function (entry, action) {
118
+ if (!!entry) {
119
+ var entryType = ServerEntryTypeEnum[entry.type];
120
+ switch (entryType) {
121
+ case ServerEntryTypeEnum.List:
122
+ return this.getTitleFromList(entry, action);
123
+ case ServerEntryTypeEnum.Text:
124
+ return this.textTransform(entry);
125
+ }
126
+ }
127
+ };
128
+ EntryInterface.prototype.getTitleFromList = function (entry, action) {
129
+ return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
130
+ };
131
+ return EntryInterface;
132
+ }());
133
+ export default EntryInterface;
@@ -0,0 +1,4 @@
1
+ import { ServerEntry } from "../../contract/model/http/server-entry.model";
2
+ export default class PagingInterface {
3
+ process(entries: ServerEntry[]): ServerEntry[];
4
+ }
@@ -0,0 +1,53 @@
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
+ };
12
+ import { StoreHelper } from "../../helper/store.helper";
13
+ var PagingInterface = /** @class */ (function () {
14
+ function PagingInterface() {
15
+ }
16
+ PagingInterface.prototype.process = function (entries) {
17
+ var pagingEntry = entries.find(function (e) { return e.tags.indexOf("paging") > -1; });
18
+ if (pagingEntry) {
19
+ var stream = StoreHelper.getEntryStore().filter(function (e) { return e.tags.indexOf("paging") > -1 && e.id === pagingEntry.id; });
20
+ if (stream.length > 0) {
21
+ // Get the paging entry with the highest take count
22
+ var last_1 = stream.reduce(function (acc, entry) {
23
+ if (entry.actions.next &&
24
+ entry.actions.next.take >= acc.actions.next.take) {
25
+ return entry;
26
+ }
27
+ return acc;
28
+ }, stream[0]); // tslint:disable-line:align
29
+ // If there is a paging entry with higher take count than the entry to be written,
30
+ // it should be updated to use the paging data from the highest take count entry
31
+ if (last_1.actions.next.take > pagingEntry.actions.next.take) {
32
+ entries.forEach(function (entry) {
33
+ if (entry.id === pagingEntry.id) {
34
+ entry.actions.next = __assign(__assign({}, entry.actions.next), { take: last_1.actions.next.take, skip: last_1.actions.next.skip });
35
+ }
36
+ });
37
+ }
38
+ }
39
+ // if items is null or undefined it should
40
+ // overwrite with an empty array
41
+ entries.forEach(function (entry) {
42
+ if (entry.id === pagingEntry.id &&
43
+ entry.content &&
44
+ entry.content.timestamp) {
45
+ entry.content = __assign(__assign({}, entry.content), { items: (entry.content && entry.content.items) || [] });
46
+ }
47
+ });
48
+ }
49
+ return entries;
50
+ };
51
+ return PagingInterface;
52
+ }());
53
+ export 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
+ }
@@ -0,0 +1,118 @@
1
+ var ProcessorInterface = /** @class */ (function () {
2
+ function ProcessorInterface() {
3
+ }
4
+ ProcessorInterface.prototype.process = function (entries) {
5
+ var processedEntries = entries;
6
+ processedEntries = this.deletePaging(processedEntries);
7
+ processedEntries = this.delete(processedEntries);
8
+ processedEntries = this.merge(processedEntries);
9
+ processedEntries = this.moveLoader(processedEntries);
10
+ return processedEntries;
11
+ };
12
+ ProcessorInterface.prototype.processUpdate = function (entry, updateEntryArray) {
13
+ var _this = this;
14
+ updateEntryArray
15
+ .filter(function (t) { return t.type == 'List'; })
16
+ .forEach(function (o) {
17
+ var _a;
18
+ (_a = o.content) === null || _a === void 0 ? void 0 : _a.items.forEach(function (t) {
19
+ if (!(entry === null || entry === void 0 ? void 0 : entry.content.items.find(function (p) { return p.actionKey == t.actionKey; })))
20
+ entry === null || entry === void 0 ? void 0 : entry.content.items.push(t);
21
+ });
22
+ Object.keys(o.actions).forEach(function (t) {
23
+ _this.handleActionUpdateOrInsert(entry === null || entry === void 0 ? void 0 : entry.actions, t, o.actions);
24
+ });
25
+ });
26
+ //moves the show more and if it helped to the end if it is needed
27
+ var itemArray = entry === null || entry === void 0 ? void 0 : entry.content.items;
28
+ if (itemArray.find(function (o) { return o.actionKey == 'next'; })) {
29
+ itemArray.push(itemArray.splice(itemArray.indexOf(itemArray.find(function (o) { return o.actionKey == 'next'; })), 1)[0]);
30
+ }
31
+ if (itemArray.find(function (o) { return o.actionKey == 'help'; })) {
32
+ itemArray.push(itemArray.splice(itemArray.indexOf(itemArray.find(function (o) { return o.actionKey == 'help'; })), 1)[0]);
33
+ }
34
+ return entry ? [entry] : [];
35
+ };
36
+ ProcessorInterface.prototype.handleActionUpdateOrInsert = function (currentArray, actionKey, action) {
37
+ if (!!currentArray)
38
+ currentArray[actionKey] = action[actionKey];
39
+ };
40
+ ProcessorInterface.prototype.deletePaging = function (entries) {
41
+ return entries.filter(function (entry) {
42
+ var isEmptyPaging = entry.type === 'List' &&
43
+ entry.tags &&
44
+ entry.tags.indexOf('paging') > -1 &&
45
+ typeof entry.content === 'undefined';
46
+ return !isEmptyPaging;
47
+ });
48
+ };
49
+ ProcessorInterface.prototype.delete = function (entries) {
50
+ return entries.filter(function (entry) { return entry.content !== null; });
51
+ };
52
+ ProcessorInterface.prototype.merge = function (entries) {
53
+ var output = [];
54
+ var merge = function (source, target) {
55
+ if (target === void 0) { target = {}; }
56
+ var content = {};
57
+ if (source == null) {
58
+ return null;
59
+ }
60
+ if (target) {
61
+ Object.keys(target).forEach(function (key) {
62
+ content[key] = target[key];
63
+ });
64
+ }
65
+ Object.keys(source).forEach(function (key) {
66
+ if (key == 'items') {
67
+ if (!content[key])
68
+ content[key] = [];
69
+ content[key] = content[key].concat(source[key]);
70
+ }
71
+ else if (key == 'html')
72
+ content[key] = content[key] + source[key];
73
+ else
74
+ content[key] = source[key];
75
+ });
76
+ return content;
77
+ };
78
+ var mergeLocalState = function (source, target) {
79
+ if (source == null)
80
+ return null;
81
+ if (Object.keys(source.actions).length === 0)
82
+ return target.localState;
83
+ if (Object.keys(target.actions).length === 0)
84
+ return source.localState;
85
+ return target.localState;
86
+ };
87
+ entries.forEach(function (entry) {
88
+ if (entry.relation) {
89
+ var existingEntry = entries.find(function (o) { return o.id == entry.relation; });
90
+ if (existingEntry) {
91
+ var existingIndex = output.indexOf(existingEntry);
92
+ existingEntry.localState = mergeLocalState(entry, existingEntry);
93
+ existingEntry.content = merge(entry.content, existingEntry.content);
94
+ existingEntry.actions = merge(entry.actions, existingEntry.actions);
95
+ output[existingIndex] = existingEntry;
96
+ }
97
+ }
98
+ else {
99
+ output.push(entry);
100
+ }
101
+ });
102
+ return output;
103
+ };
104
+ ProcessorInterface.prototype.moveLoader = function (entries) {
105
+ // Moves the loader component to last position in stream
106
+ var loaderEntry = entries.find(function (e) { return e.id === 'loader'; });
107
+ if (!loaderEntry) {
108
+ return entries;
109
+ }
110
+ var loaderIndex = entries.indexOf(loaderEntry);
111
+ if (loaderIndex > -1) {
112
+ entries.splice(entries.length - 1, 0, entries.splice(loaderIndex, 1)[0]);
113
+ }
114
+ return entries;
115
+ };
116
+ return ProcessorInterface;
117
+ }());
118
+ export default ProcessorInterface;
@@ -0,0 +1,3 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ declare const KnowledgeBotProviderPlugin: (container: Container) => Promise<void>;
3
+ export default KnowledgeBotProviderPlugin;
package/lib/plugin.js ADDED
@@ -0,0 +1,198 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __read = (this && this.__read) || function (o, n) {
38
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
39
+ if (!m) return o;
40
+ var i = m.call(o), r, ar = [], e;
41
+ try {
42
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
43
+ }
44
+ catch (error) { e = { error: error }; }
45
+ finally {
46
+ try {
47
+ if (r && !r.done && (m = i["return"])) m.call(i);
48
+ }
49
+ finally { if (e) throw e.error; }
50
+ }
51
+ return ar;
52
+ };
53
+ import { ContactMethodPlatform } from '@humany/widget-adapters';
54
+ import { ConversationPlatform, registerCustomMessageComponent } from '@humany/widget-conversation';
55
+ import { ComponentPlatform } from '@humany/widget-core';
56
+ import { DataClient } from '@humany/widget-types-grid';
57
+ import { v4 } from 'uuid';
58
+ import ChatClient from './client/chat.client';
59
+ import { ContactMethodClient } from './client/contact-method.client';
60
+ import { HttpClient } from './client/http.client';
61
+ import MiddlewareClient from './client/middleware.client';
62
+ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
63
+ var providerRegistered, componentPlatform, getConversationComponent, execute;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ providerRegistered = false;
68
+ return [4 /*yield*/, ComponentPlatform.getInstance(container)];
69
+ case 1:
70
+ componentPlatform = _a.sent();
71
+ getConversationComponent = function () { return __awaiter(void 0, void 0, void 0, function () {
72
+ var platform, _a, component;
73
+ var _b, _c;
74
+ return __generator(this, function (_d) {
75
+ switch (_d.label) {
76
+ case 0: return [4 /*yield*/, ComponentPlatform.getInstance(container)];
77
+ case 1:
78
+ platform = _d.sent();
79
+ _a = __read(platform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
80
+ if (!component || !((_c = (_b = component === null || component === void 0 ? void 0 : component.attributes) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.knowledgeBotEndpoint)) {
81
+ return [2 /*return*/];
82
+ }
83
+ return [2 /*return*/, component];
84
+ }
85
+ });
86
+ }); };
87
+ execute = function (endpoint) { return __awaiter(void 0, void 0, void 0, function () {
88
+ var dataClient, platform, contactMethodPlatform;
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0:
92
+ providerRegistered = true;
93
+ return [4 /*yield*/, DataClient.getInstance(container)];
94
+ case 1:
95
+ dataClient = _a.sent();
96
+ return [4 /*yield*/, ConversationPlatform.getInstance(container)];
97
+ case 2:
98
+ platform = _a.sent();
99
+ return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
100
+ case 3:
101
+ contactMethodPlatform = _a.sent();
102
+ platform.registerProvider('chat.bot', function (conversation, component) {
103
+ var clientId = v4();
104
+ registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
105
+ var agent = conversation.createAgent({
106
+ // TODO: needs to be fixed asap
107
+ name: 'John Doe',
108
+ avatar: 'https://www.site.com/avatar.jpg',
109
+ });
110
+ // passes the user and the agent to the Chat Helper
111
+ ChatClient.initialize(conversation.user, agent);
112
+ // passes the conversation provider to the Contact Method Client
113
+ ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
114
+ // passes the container and the widget to the Middleware Store
115
+ MiddlewareClient.initialize(container, container.get('$widget'));
116
+ // executes to decide on what to do on first load
117
+ var httpClient = new HttpClient(endpoint, clientId);
118
+ httpClient.firstHit();
119
+ component.actions.create('evaluate', function (input) {
120
+ var cmClient = new ContactMethodClient();
121
+ cmClient.handleNewForm(input.form, input.form.id);
122
+ });
123
+ component.actions.create('validate', function (input) {
124
+ var cmClient = new ContactMethodClient();
125
+ cmClient.validate(input.form);
126
+ });
127
+ component.actions.create('submit', function (input) {
128
+ var cmClient = new ContactMethodClient();
129
+ cmClient.validate(input.form);
130
+ });
131
+ component.actions.watch('conversation.user-typing', function (input, next) {
132
+ return next(input);
133
+ });
134
+ component.actions.watch('conversation.user-submit', function (input, next) {
135
+ var httpClient = new HttpClient(endpoint, clientId);
136
+ httpClient.handlePhrase(input.text);
137
+ return next(input);
138
+ });
139
+ component.actions.watch('conversation.form', function (input, next) {
140
+ return next(input);
141
+ });
142
+ component.actions.watch('conversation.action', function (input, next) {
143
+ var chatClient = new ChatClient();
144
+ var cmClient = new ContactMethodClient();
145
+ if (input === 'contact' || input.split('/').length > 1) {
146
+ cmClient.handleContactMethod(input);
147
+ return next(input);
148
+ }
149
+ var middlewareClient = new MiddlewareClient();
150
+ var httpClient = new HttpClient(endpoint, clientId);
151
+ // this is an update check, as it requires
152
+ // a lot different logic and no user message
153
+ if (middlewareClient.checkForUpdate(input)) {
154
+ httpClient.handleUpdate(input);
155
+ return next(input);
156
+ }
157
+ chatClient.printUserMessageAndStoreIt(input);
158
+ httpClient.handleInput(input);
159
+ return next(input);
160
+ });
161
+ });
162
+ return [2 /*return*/];
163
+ }
164
+ });
165
+ }); };
166
+ getConversationComponent().then(function (conversationComp) {
167
+ if (conversationComp && (conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint)) {
168
+ execute(conversationComp === null || conversationComp === void 0 ? void 0 : conversationComp.attributes.properties.knowledgeBotEndpoint);
169
+ }
170
+ else {
171
+ // const { events } = container.get('$widget') as Widget;
172
+ // events.subscribe('components:node-mounted', (event, data) => {
173
+ // if (providerRegistered) {
174
+ // return;
175
+ // }
176
+ // if (
177
+ // data.node?.type === 'conversation' &&
178
+ // data.node?.attributes.properties.knowledgeBotEndpoint
179
+ // ) {
180
+ // execute(data.node.attributes.properties.knowledgeBotEndpoint);
181
+ // }
182
+ // });
183
+ componentPlatform.events.subscribe('components:properties-changed', function (event, data) {
184
+ var _a, _b;
185
+ if (providerRegistered) {
186
+ return;
187
+ }
188
+ if (((_a = data.node) === null || _a === void 0 ? void 0 : _a.type) === 'conversation' && ((_b = data.node) === null || _b === void 0 ? void 0 : _b.attributes.properties.knowledgeBotEndpoint)) {
189
+ execute(data.node.attributes.properties.knowledgeBotEndpoint);
190
+ }
191
+ });
192
+ }
193
+ });
194
+ return [2 /*return*/];
195
+ }
196
+ });
197
+ }); };
198
+ export default KnowledgeBotProviderPlugin;
@@ -0,0 +1,15 @@
1
+ import { Message } from '../contract/model/conversation-api-model/message.model';
2
+ import EntryInterface from '../interface/entry.interface';
3
+ export default class ChatClient {
4
+ entryInterface: EntryInterface;
5
+ constructor();
6
+ static initialize(user: any, agent: any): void;
7
+ processMessageArrayAndStoreIt(messages: Message[]): void;
8
+ updateMessageArrayAndStoreIt(messages: Message[]): void;
9
+ printUserMessageAndStoreIt(action: string): void;
10
+ private postUserMessage;
11
+ private postAgentMessage;
12
+ private getTitleFromEntry;
13
+ private getTitleFromText;
14
+ private getTitleFromList;
15
+ }
@@ -0,0 +1,79 @@
1
+ import { v4 as newGuid } from 'uuid';
2
+ import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
3
+ import { ChatHelper } from '../helper/chat.helper';
4
+ import { StoreHelper } from '../helper/store.helper';
5
+ import EntryInterface from '../interface/entry.interface';
6
+ var ChatClient = /** @class */ (function () {
7
+ function ChatClient() {
8
+ this.entryInterface = new EntryInterface();
9
+ }
10
+ // Initialize from setting the user and agent for the Helper
11
+ ChatClient.initialize = function (user, agent) {
12
+ ChatHelper.setUser(user);
13
+ ChatHelper.setAgent(agent);
14
+ };
15
+ // function for posting the messages
16
+ ChatClient.prototype.processMessageArrayAndStoreIt = function (messages) {
17
+ var _this = this;
18
+ messages
19
+ .filter(function (o) { return o && o != null; })
20
+ .forEach(function (o) {
21
+ if (o.isUser)
22
+ _this.postUserMessage(o);
23
+ else
24
+ _this.postAgentMessage(o);
25
+ });
26
+ StoreHelper.insertOrUpdateMessageArrayStore(messages);
27
+ };
28
+ // function for updating current messages
29
+ ChatClient.prototype.updateMessageArrayAndStoreIt = function (messages) {
30
+ var conversationEntry = undefined;
31
+ messages.forEach(function (o) {
32
+ var message = StoreHelper.getMessage(o.id);
33
+ message === null || message === void 0 ? void 0 : message.conversationEntry.update(o.message);
34
+ conversationEntry = message === null || message === void 0 ? void 0 : message.conversationEntry;
35
+ });
36
+ StoreHelper.insertOrUpdateMessageArrayStore(messages, conversationEntry);
37
+ };
38
+ // function for posting a message for the user actions, such as button clicks
39
+ ChatClient.prototype.printUserMessageAndStoreIt = function (action) {
40
+ if (action == 'next' || action == 'help')
41
+ return;
42
+ var entry = StoreHelper.getEntry(action);
43
+ var message = {
44
+ id: newGuid(),
45
+ message: !entry ? action : this.getTitleFromEntry(entry, action),
46
+ isUser: true,
47
+ };
48
+ this.postUserMessage(message);
49
+ StoreHelper.insertOrUpdateMessageArrayStore([message]);
50
+ };
51
+ ChatClient.prototype.postUserMessage = function (message) {
52
+ ChatHelper.getUser().print(message.message);
53
+ };
54
+ ChatClient.prototype.postAgentMessage = function (message) {
55
+ message.conversationEntry = ChatHelper.getAgent().print(message.message);
56
+ };
57
+ ChatClient.prototype.getTitleFromEntry = function (entry, action) {
58
+ var entryType = ServerEntryTypeEnum[entry.type];
59
+ switch (entryType) {
60
+ case ServerEntryTypeEnum.List:
61
+ return this.getTitleFromList(entry, action);
62
+ case ServerEntryTypeEnum.Text:
63
+ return this.getTitleFromText(entry, action);
64
+ default:
65
+ return '';
66
+ }
67
+ };
68
+ ChatClient.prototype.getTitleFromText = function (entry, action) {
69
+ if (!!entry.content.items)
70
+ return this.getTitleFromList(entry, action);
71
+ else
72
+ return entry.content.html;
73
+ };
74
+ ChatClient.prototype.getTitleFromList = function (entry, action) {
75
+ return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
76
+ };
77
+ return ChatClient;
78
+ }());
79
+ export default ChatClient;
@@ -0,0 +1,22 @@
1
+ import { ContactMethodPlatform } from '@humany/widget-adapters';
2
+ import { DataClient } from '@humany/widget-types-grid';
3
+ export declare class ContactMethodClient {
4
+ private static dataClient;
5
+ private static contactMethodPlatform;
6
+ private static contactMessageEntryArray;
7
+ private static agent;
8
+ private chatClient;
9
+ static initialize(dataClient: DataClient, contactMethodPlatform: ContactMethodPlatform, agent: any): void;
10
+ handleNewForm: (errors: any, entry: any) => Promise<void>;
11
+ handleContactMethod: (input?: string) => Promise<void>;
12
+ validate(form: any): void;
13
+ private handleContactCategoryList;
14
+ private handleForm;
15
+ private handleContactMethodList;
16
+ private handleSingleContactMethod;
17
+ private submit;
18
+ private removeForm;
19
+ private printMessage;
20
+ private loadContactMethods;
21
+ private updateForm;
22
+ }