@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.35 → 0.0.1-alpha.39

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 (129) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +12 -12
  3. package/lib/client/chat.client.d.ts +16 -16
  4. package/lib/client/chat.client.js +79 -79
  5. package/lib/client/contact-method.client.d.ts +30 -25
  6. package/lib/client/contact-method.client.js +292 -282
  7. package/lib/client/http.client.d.ts +25 -23
  8. package/lib/client/http.client.js +130 -113
  9. package/lib/client/middleware.client.d.ts +14 -14
  10. package/lib/client/middleware.client.js +115 -118
  11. package/lib/contract/custom-component/contact-method-item.d.ts +8 -8
  12. package/lib/contract/custom-component/contact-method-item.js +54 -54
  13. package/lib/contract/custom-component/contact-method-list.d.ts +7 -7
  14. package/lib/contract/custom-component/contact-method-list.js +13 -13
  15. package/lib/contract/custom-component/contact-method.d.ts +3 -3
  16. package/lib/contract/custom-component/contact-method.js +34 -34
  17. package/lib/contract/enum/server-entry-type.enum.d.ts +7 -7
  18. package/lib/contract/enum/server-entry-type.enum.js +8 -8
  19. package/lib/contract/model/conversation-api-model/list.model.d.ts +5 -5
  20. package/lib/contract/model/conversation-api-model/list.model.js +1 -0
  21. package/lib/contract/model/conversation-api-model/message.model.d.ts +7 -7
  22. package/lib/contract/model/conversation-api-model/message.model.js +1 -0
  23. package/lib/contract/model/http/action.model.d.ts +3 -3
  24. package/lib/contract/model/http/action.model.js +1 -0
  25. package/lib/contract/model/http/client-action.model.d.ts +4 -4
  26. package/lib/contract/model/http/client-action.model.js +2 -1
  27. package/lib/contract/model/http/client-envelope.model.d.ts +9 -9
  28. package/lib/contract/model/http/client-envelope.model.js +1 -0
  29. package/lib/contract/model/http/connect-options.model.d.ts +5 -5
  30. package/lib/contract/model/http/connect-options.model.js +1 -0
  31. package/lib/contract/model/http/global-state.model.d.ts +8 -8
  32. package/lib/contract/model/http/global-state.model.js +1 -0
  33. package/lib/contract/model/http/http-client-options.model.d.ts +5 -5
  34. package/lib/contract/model/http/http-client-options.model.js +1 -0
  35. package/lib/contract/model/http/server-entry.model.d.ts +11 -11
  36. package/lib/contract/model/http/server-entry.model.js +1 -0
  37. package/lib/contract/model/http/server-envelope.model.d.ts +10 -10
  38. package/lib/contract/model/http/server-envelope.model.js +1 -0
  39. package/lib/contract/model/middleware/aggregator-state.model.d.ts +4 -4
  40. package/lib/contract/model/middleware/aggregator-state.model.js +2 -1
  41. package/lib/contract/model/shared/loose-object.model.d.ts +3 -3
  42. package/lib/contract/model/shared/loose-object.model.js +1 -0
  43. package/lib/helper/chat.helper.d.ts +8 -8
  44. package/lib/helper/chat.helper.js +18 -18
  45. package/lib/helper/http.helper.d.ts +13 -13
  46. package/lib/helper/http.helper.js +28 -28
  47. package/lib/helper/middleware.helper.d.ts +12 -12
  48. package/lib/helper/middleware.helper.js +69 -67
  49. package/lib/helper/store.helper.d.ts +22 -22
  50. package/lib/helper/store.helper.js +77 -77
  51. package/lib/index.d.ts +2 -2
  52. package/lib/index.js +2 -2
  53. package/lib/interface/entry.interface.d.ts +20 -20
  54. package/lib/interface/entry.interface.js +258 -262
  55. package/lib/interface/middleware/paging.interface.d.ts +4 -4
  56. package/lib/interface/middleware/paging.interface.js +53 -53
  57. package/lib/interface/middleware/processor.interface.d.ts +10 -10
  58. package/lib/interface/middleware/processor.interface.js +118 -118
  59. package/lib/plugin.d.ts +3 -3
  60. package/lib/plugin.js +149 -139
  61. package/lib/utils.d.ts +1 -0
  62. package/lib/utils.js +5 -0
  63. package/lib-esm/client/chat.client.d.ts +16 -16
  64. package/lib-esm/client/chat.client.js +79 -79
  65. package/lib-esm/client/contact-method.client.d.ts +30 -25
  66. package/lib-esm/client/contact-method.client.js +292 -282
  67. package/lib-esm/client/http.client.d.ts +25 -23
  68. package/lib-esm/client/http.client.js +130 -113
  69. package/lib-esm/client/middleware.client.d.ts +14 -14
  70. package/lib-esm/client/middleware.client.js +115 -118
  71. package/lib-esm/contract/custom-component/contact-method-item.d.ts +8 -8
  72. package/lib-esm/contract/custom-component/contact-method-item.js +54 -54
  73. package/lib-esm/contract/custom-component/contact-method-list.d.ts +7 -7
  74. package/lib-esm/contract/custom-component/contact-method-list.js +13 -13
  75. package/lib-esm/contract/custom-component/contact-method.d.ts +3 -3
  76. package/lib-esm/contract/custom-component/contact-method.js +34 -34
  77. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +7 -7
  78. package/lib-esm/contract/enum/server-entry-type.enum.js +8 -8
  79. package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +5 -5
  80. package/lib-esm/contract/model/conversation-api-model/list.model.js +1 -0
  81. package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +7 -7
  82. package/lib-esm/contract/model/conversation-api-model/message.model.js +1 -0
  83. package/lib-esm/contract/model/http/action.model.d.ts +3 -3
  84. package/lib-esm/contract/model/http/action.model.js +1 -0
  85. package/lib-esm/contract/model/http/client-action.model.d.ts +4 -4
  86. package/lib-esm/contract/model/http/client-action.model.js +2 -1
  87. package/lib-esm/contract/model/http/client-envelope.model.d.ts +9 -9
  88. package/lib-esm/contract/model/http/client-envelope.model.js +1 -0
  89. package/lib-esm/contract/model/http/connect-options.model.d.ts +5 -5
  90. package/lib-esm/contract/model/http/connect-options.model.js +1 -0
  91. package/lib-esm/contract/model/http/global-state.model.d.ts +8 -8
  92. package/lib-esm/contract/model/http/global-state.model.js +1 -0
  93. package/lib-esm/contract/model/http/http-client-options.model.d.ts +5 -5
  94. package/lib-esm/contract/model/http/http-client-options.model.js +1 -0
  95. package/lib-esm/contract/model/http/server-entry.model.d.ts +11 -11
  96. package/lib-esm/contract/model/http/server-entry.model.js +1 -0
  97. package/lib-esm/contract/model/http/server-envelope.model.d.ts +10 -10
  98. package/lib-esm/contract/model/http/server-envelope.model.js +1 -0
  99. package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +4 -4
  100. package/lib-esm/contract/model/middleware/aggregator-state.model.js +2 -1
  101. package/lib-esm/contract/model/shared/loose-object.model.d.ts +3 -3
  102. package/lib-esm/contract/model/shared/loose-object.model.js +1 -0
  103. package/lib-esm/helper/chat.helper.d.ts +8 -8
  104. package/lib-esm/helper/chat.helper.js +18 -18
  105. package/lib-esm/helper/http.helper.d.ts +13 -13
  106. package/lib-esm/helper/http.helper.js +28 -28
  107. package/lib-esm/helper/middleware.helper.d.ts +12 -12
  108. package/lib-esm/helper/middleware.helper.js +69 -67
  109. package/lib-esm/helper/store.helper.d.ts +22 -22
  110. package/lib-esm/helper/store.helper.js +77 -77
  111. package/lib-esm/index.d.ts +2 -2
  112. package/lib-esm/index.js +2 -2
  113. package/lib-esm/interface/entry.interface.d.ts +20 -20
  114. package/lib-esm/interface/entry.interface.js +258 -262
  115. package/lib-esm/interface/middleware/paging.interface.d.ts +4 -4
  116. package/lib-esm/interface/middleware/paging.interface.js +53 -53
  117. package/lib-esm/interface/middleware/processor.interface.d.ts +10 -10
  118. package/lib-esm/interface/middleware/processor.interface.js +118 -118
  119. package/lib-esm/plugin.d.ts +3 -3
  120. package/lib-esm/plugin.js +149 -139
  121. package/lib-esm/utils.d.ts +1 -0
  122. package/lib-esm/utils.js +5 -0
  123. package/package.json +15 -24
  124. package/lib/interface/_mocked-contact-method.json +0 -375
  125. package/lib/interface/convert.d.ts +0 -1
  126. package/lib/interface/convert.js +0 -68
  127. package/lib-esm/interface/_mocked-contact-method.json +0 -375
  128. package/lib-esm/interface/convert.d.ts +0 -1
  129. package/lib-esm/interface/convert.js +0 -68
@@ -1,262 +1,258 @@
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 __values = (this && this.__values) || function(o) {
38
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
- if (m) return m.call(o);
40
- if (o && typeof o.length === "number") return {
41
- next: function () {
42
- if (o && i >= o.length) o = void 0;
43
- return { value: o && o[i++], done: !o };
44
- }
45
- };
46
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
- };
48
- import { ConversationMessageListItemType, } from '@humany/widget-conversation';
49
- import { DataType } from '@humany/widget-types-grid';
50
- import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
51
- import { StoreHelper } from '../helper/store.helper';
52
- var EntryInterface = /** @class */ (function () {
53
- function EntryInterface(container) {
54
- this.container = container;
55
- this.helpActionKey = 'help';
56
- this.nextActionKey = 'next';
57
- }
58
- // transform the entry based on its type
59
- EntryInterface.prototype.transform = function (entry) {
60
- return __awaiter(this, void 0, void 0, function () {
61
- var entryType, _a, _b;
62
- return __generator(this, function (_c) {
63
- switch (_c.label) {
64
- case 0:
65
- entryType = ServerEntryTypeEnum[entry.type];
66
- _a = entryType;
67
- switch (_a) {
68
- case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
69
- case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
70
- case ServerEntryTypeEnum.Text: return [3 /*break*/, 3];
71
- case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
72
- }
73
- return [3 /*break*/, 6];
74
- case 1: return [2 /*return*/, {
75
- id: entry.id,
76
- message: this.listTransform(entry),
77
- entry: entry,
78
- isUser: false,
79
- }];
80
- case 2: return [2 /*return*/, {
81
- id: entry.id,
82
- message: this.textTransform(entry),
83
- entry: entry,
84
- isUser: false,
85
- }];
86
- case 3: return [2 /*return*/, {
87
- id: entry.id,
88
- message: this.listTransform(entry),
89
- entry: entry,
90
- isUser: false,
91
- }];
92
- case 4:
93
- _b = {
94
- id: entry.id
95
- };
96
- return [4 /*yield*/, this.transformContactMethod(entry)];
97
- case 5: return [2 /*return*/, (_b.message = _c.sent(),
98
- _b.entry = entry,
99
- _b.isUser = false,
100
- _b)];
101
- case 6: return [2 /*return*/];
102
- }
103
- });
104
- });
105
- };
106
- EntryInterface.prototype.transformContactMethod = function (entry) {
107
- return __awaiter(this, void 0, void 0, function () {
108
- var dataClient, contactMethods, contactMethod;
109
- return __generator(this, function (_a) {
110
- switch (_a.label) {
111
- case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
112
- case 1:
113
- dataClient = _a.sent();
114
- contactMethods = [];
115
- return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
116
- contactMethodId: entry.content.id,
117
- })];
118
- case 2:
119
- contactMethod = _a.sent();
120
- if (contactMethod) {
121
- contactMethod.expanded = true;
122
- contactMethods.push(contactMethod);
123
- }
124
- return [2 /*return*/, {
125
- type: 'ace-knowledge-contact-method',
126
- contactMethods: contactMethods,
127
- }];
128
- }
129
- });
130
- });
131
- };
132
- // transform an array of entries
133
- EntryInterface.prototype.transformArray = function (entryArray) {
134
- return __awaiter(this, void 0, void 0, function () {
135
- var returnArray, entryArray_1, entryArray_1_1, o, x, e_1_1;
136
- var e_1, _a;
137
- return __generator(this, function (_b) {
138
- switch (_b.label) {
139
- case 0:
140
- returnArray = [];
141
- _b.label = 1;
142
- case 1:
143
- _b.trys.push([1, 6, 7, 8]);
144
- entryArray_1 = __values(entryArray), entryArray_1_1 = entryArray_1.next();
145
- _b.label = 2;
146
- case 2:
147
- if (!!entryArray_1_1.done) return [3 /*break*/, 5];
148
- o = entryArray_1_1.value;
149
- return [4 /*yield*/, this.transform(o)];
150
- case 3:
151
- x = _b.sent();
152
- if (!!x)
153
- returnArray.push(x);
154
- _b.label = 4;
155
- case 4:
156
- entryArray_1_1 = entryArray_1.next();
157
- return [3 /*break*/, 2];
158
- case 5: return [3 /*break*/, 8];
159
- case 6:
160
- e_1_1 = _b.sent();
161
- e_1 = { error: e_1_1 };
162
- return [3 /*break*/, 8];
163
- case 7:
164
- try {
165
- if (entryArray_1_1 && !entryArray_1_1.done && (_a = entryArray_1.return)) _a.call(entryArray_1);
166
- }
167
- finally { if (e_1) throw e_1.error; }
168
- return [7 /*endfinally*/];
169
- case 8: return [2 /*return*/, returnArray];
170
- }
171
- });
172
- });
173
- };
174
- // gets the text that should be printed as a user message on action
175
- EntryInterface.prototype.getUserMessage = function (action) {
176
- var entry = StoreHelper.getEntry(action);
177
- return this.getTitleFromEntry(entry, action);
178
- };
179
- EntryInterface.prototype.listTransform = function (entry) {
180
- if (entry.type === 'Contact') {
181
- // TODO: is this needed
182
- return undefined;
183
- }
184
- if (!entry.content)
185
- return undefined;
186
- var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
187
- return object;
188
- };
189
- EntryInterface.prototype.getContentText = function (entry) {
190
- if (entry.content.html)
191
- return { body: entry.content.html };
192
- if (entry.content.header)
193
- return { title: entry.content.header };
194
- };
195
- EntryInterface.prototype.textTransform = function (entry) {
196
- if (!!entry.content.items)
197
- return this.listTransform(entry);
198
- return [
199
- ConversationMessageListItemType.HTML,
200
- { body: entry.content.html.replace('\n', '') },
201
- ];
202
- };
203
- EntryInterface.prototype.getListActions = function (items, text, actions, state) {
204
- var _this = this;
205
- var list = [];
206
- var mainListContent = {};
207
- var mainList = [this.getListType(state), { actions: mainListContent }];
208
- if (text && text.title) {
209
- list.push([ConversationMessageListItemType.Header, text.title]);
210
- }
211
- if (text && text.body) {
212
- list.push([ConversationMessageListItemType.HTML, { body: text.body }]);
213
- }
214
- list.push(mainList);
215
- items.forEach(function (o) {
216
- switch (o.actionKey) {
217
- case _this.helpActionKey: {
218
- list.push([ConversationMessageListItemType.Separator, undefined]);
219
- list.push([
220
- ConversationMessageListItemType.NoGoodAlternative,
221
- { body: o.title },
222
- ]);
223
- break;
224
- }
225
- case _this.nextActionKey: {
226
- if (!!actions['next'] && actions['next'].take === items.length + 1)
227
- mainListContent[o.actionKey] = o.title;
228
- break;
229
- }
230
- default: {
231
- mainListContent[o.actionKey] = o.title;
232
- }
233
- }
234
- });
235
- return list;
236
- };
237
- EntryInterface.prototype.getListType = function (state) {
238
- if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
239
- return ConversationMessageListItemType.LinkList;
240
- else if ((state === null || state === void 0 ? void 0 : state.$type) ===
241
- 'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
242
- return ConversationMessageListItemType.FeedbackList;
243
- else
244
- return ConversationMessageListItemType.ButtonList;
245
- };
246
- EntryInterface.prototype.getTitleFromEntry = function (entry, action) {
247
- if (!!entry) {
248
- var entryType = ServerEntryTypeEnum[entry.type];
249
- switch (entryType) {
250
- case ServerEntryTypeEnum.List:
251
- return this.getTitleFromList(entry, action);
252
- case ServerEntryTypeEnum.Text:
253
- return this.textTransform(entry);
254
- }
255
- }
256
- };
257
- EntryInterface.prototype.getTitleFromList = function (entry, action) {
258
- return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
259
- };
260
- return EntryInterface;
261
- }());
262
- export default EntryInterface;
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 __values = (this && this.__values) || function(o) {
38
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
+ if (m) return m.call(o);
40
+ if (o && typeof o.length === "number") return {
41
+ next: function () {
42
+ if (o && i >= o.length) o = void 0;
43
+ return { value: o && o[i++], done: !o };
44
+ }
45
+ };
46
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
+ };
48
+ import { DataType } from '@telia-ace/knowledge-widget-types-grid';
49
+ import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation';
50
+ import { ContactMethodClient } from '../client/contact-method.client';
51
+ import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
52
+ import { StoreHelper } from '../helper/store.helper';
53
+ var EntryInterface = /** @class */ (function () {
54
+ function EntryInterface(container) {
55
+ this.container = container;
56
+ this.helpActionKey = 'help';
57
+ this.nextActionKey = 'next';
58
+ }
59
+ // transform the entry based on its type
60
+ EntryInterface.prototype.transform = function (entry) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var entryType, _a;
63
+ var _b;
64
+ return __generator(this, function (_c) {
65
+ switch (_c.label) {
66
+ case 0:
67
+ entryType = ServerEntryTypeEnum[entry.type];
68
+ _a = entryType;
69
+ switch (_a) {
70
+ case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
71
+ case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
72
+ case ServerEntryTypeEnum.Text: return [3 /*break*/, 3];
73
+ case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
74
+ }
75
+ return [3 /*break*/, 6];
76
+ case 1: return [2 /*return*/, {
77
+ id: entry.id,
78
+ message: this.listTransform(entry),
79
+ entry: entry,
80
+ isUser: false,
81
+ }];
82
+ case 2: return [2 /*return*/, {
83
+ id: entry.id,
84
+ message: this.textTransform(entry),
85
+ entry: entry,
86
+ isUser: false,
87
+ }];
88
+ case 3: return [2 /*return*/, {
89
+ id: entry.id,
90
+ message: this.listTransform(entry),
91
+ entry: entry,
92
+ isUser: false,
93
+ }];
94
+ case 4:
95
+ _b = {
96
+ id: entry.id
97
+ };
98
+ return [4 /*yield*/, this.transformContactMethod(entry)];
99
+ case 5: return [2 /*return*/, (_b.message = _c.sent(),
100
+ _b.entry = entry,
101
+ _b.isUser = false,
102
+ _b)];
103
+ case 6: return [2 /*return*/];
104
+ }
105
+ });
106
+ });
107
+ };
108
+ EntryInterface.prototype.transformContactMethod = function (entry) {
109
+ return __awaiter(this, void 0, void 0, function () {
110
+ var dataClient, contactMethod, cmClient;
111
+ return __generator(this, function (_a) {
112
+ switch (_a.label) {
113
+ case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
114
+ case 1:
115
+ dataClient = _a.sent();
116
+ return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
117
+ contactMethodId: entry.content.id,
118
+ })];
119
+ case 2:
120
+ contactMethod = _a.sent();
121
+ cmClient = new ContactMethodClient(this.container);
122
+ cmClient.addContactMethod(contactMethod);
123
+ return [2 /*return*/];
124
+ }
125
+ });
126
+ });
127
+ };
128
+ // transform an array of entries
129
+ EntryInterface.prototype.transformArray = function (entryArray) {
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ var returnArray, entryArray_1, entryArray_1_1, o, x, e_1_1;
132
+ var e_1, _a;
133
+ return __generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0:
136
+ returnArray = [];
137
+ _b.label = 1;
138
+ case 1:
139
+ _b.trys.push([1, 6, 7, 8]);
140
+ entryArray_1 = __values(entryArray), entryArray_1_1 = entryArray_1.next();
141
+ _b.label = 2;
142
+ case 2:
143
+ if (!!entryArray_1_1.done) return [3 /*break*/, 5];
144
+ o = entryArray_1_1.value;
145
+ return [4 /*yield*/, this.transform(o)];
146
+ case 3:
147
+ x = _b.sent();
148
+ if (!!x)
149
+ returnArray.push(x);
150
+ _b.label = 4;
151
+ case 4:
152
+ entryArray_1_1 = entryArray_1.next();
153
+ return [3 /*break*/, 2];
154
+ case 5: return [3 /*break*/, 8];
155
+ case 6:
156
+ e_1_1 = _b.sent();
157
+ e_1 = { error: e_1_1 };
158
+ return [3 /*break*/, 8];
159
+ case 7:
160
+ try {
161
+ if (entryArray_1_1 && !entryArray_1_1.done && (_a = entryArray_1.return)) _a.call(entryArray_1);
162
+ }
163
+ finally { if (e_1) throw e_1.error; }
164
+ return [7 /*endfinally*/];
165
+ case 8: return [2 /*return*/, returnArray];
166
+ }
167
+ });
168
+ });
169
+ };
170
+ // gets the text that should be printed as a user message on action
171
+ EntryInterface.prototype.getUserMessage = function (action) {
172
+ var entry = StoreHelper.getEntry(action);
173
+ return this.getTitleFromEntry(entry, action);
174
+ };
175
+ EntryInterface.prototype.listTransform = function (entry) {
176
+ if (entry.type === 'Contact') {
177
+ // TODO: is this needed
178
+ return undefined;
179
+ }
180
+ if (!entry.content)
181
+ return undefined;
182
+ var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
183
+ return object;
184
+ };
185
+ EntryInterface.prototype.getContentText = function (entry) {
186
+ if (entry.content.html)
187
+ return { body: entry.content.html };
188
+ if (entry.content.header)
189
+ return { title: entry.content.header };
190
+ };
191
+ EntryInterface.prototype.textTransform = function (entry) {
192
+ if (!!entry.content.items)
193
+ return this.listTransform(entry);
194
+ return [
195
+ ConversationMessageListItemType.HTML,
196
+ { body: entry.content.html.replace('\n', '') },
197
+ ];
198
+ };
199
+ EntryInterface.prototype.getListActions = function (items, text, actions, state) {
200
+ var _this = this;
201
+ var list = [];
202
+ var mainListContent = {};
203
+ var mainList = [this.getListType(state), { actions: mainListContent }];
204
+ if (text && text.title) {
205
+ list.push([ConversationMessageListItemType.Header, text.title]);
206
+ }
207
+ if (text && text.body) {
208
+ list.push([ConversationMessageListItemType.HTML, { body: text.body }]);
209
+ }
210
+ list.push(mainList);
211
+ items.forEach(function (o) {
212
+ switch (o.actionKey) {
213
+ case _this.helpActionKey: {
214
+ list.push([ConversationMessageListItemType.Separator, undefined]);
215
+ list.push([
216
+ ConversationMessageListItemType.NoGoodAlternative,
217
+ { body: o.title },
218
+ ]);
219
+ break;
220
+ }
221
+ case _this.nextActionKey: {
222
+ if (!!actions['next'] && actions['next'].take === items.length + 1)
223
+ mainListContent[o.actionKey] = o.title;
224
+ break;
225
+ }
226
+ default: {
227
+ mainListContent[o.actionKey] = o.title;
228
+ }
229
+ }
230
+ });
231
+ return list;
232
+ };
233
+ EntryInterface.prototype.getListType = function (state) {
234
+ if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
235
+ return ConversationMessageListItemType.LinkList;
236
+ else if ((state === null || state === void 0 ? void 0 : state.$type) ===
237
+ 'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
238
+ return ConversationMessageListItemType.FeedbackList;
239
+ else
240
+ return ConversationMessageListItemType.ButtonList;
241
+ };
242
+ EntryInterface.prototype.getTitleFromEntry = function (entry, action) {
243
+ if (!!entry) {
244
+ var entryType = ServerEntryTypeEnum[entry.type];
245
+ switch (entryType) {
246
+ case ServerEntryTypeEnum.List:
247
+ return this.getTitleFromList(entry, action);
248
+ case ServerEntryTypeEnum.Text:
249
+ return this.textTransform(entry);
250
+ }
251
+ }
252
+ };
253
+ EntryInterface.prototype.getTitleFromList = function (entry, action) {
254
+ return entry.content.items.find(function (o) { return o.actionKey == action; }).title;
255
+ };
256
+ return EntryInterface;
257
+ }());
258
+ export default EntryInterface;
@@ -1,4 +1,4 @@
1
- import { ServerEntry } from "../../contract/model/http/server-entry.model";
2
- export default class PagingInterface {
3
- process(entries: ServerEntry[]): ServerEntry[];
4
- }
1
+ import { ServerEntry } from "../../contract/model/http/server-entry.model";
2
+ export default class PagingInterface {
3
+ process(entries: ServerEntry[]): ServerEntry[];
4
+ }