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

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 (69) hide show
  1. package/lib/client/chat.client.d.ts +3 -2
  2. package/lib/client/chat.client.js +98 -33
  3. package/lib/client/contact-method.client.d.ts +9 -1
  4. package/lib/client/contact-method.client.js +48 -32
  5. package/lib/client/http.client.d.ts +11 -7
  6. package/lib/client/http.client.js +138 -41
  7. package/lib/client/middleware.client.d.ts +4 -3
  8. package/lib/client/middleware.client.js +100 -35
  9. package/lib/contract/custom-component/contact-method-item.js +12 -34
  10. package/lib/contract/custom-component/contact-method-list.js +6 -34
  11. package/lib/contract/custom-component/contact-method.js +12 -17
  12. package/lib/contract/enum/server-entry-type.enum.d.ts +3 -2
  13. package/lib/contract/enum/server-entry-type.enum.js +5 -7
  14. package/lib/contract/model/conversation-api-model/list.model.js +1 -2
  15. package/lib/contract/model/conversation-api-model/message.model.js +1 -2
  16. package/lib/contract/model/http/action.model.js +1 -2
  17. package/lib/contract/model/http/client-action.model.js +1 -2
  18. package/lib/contract/model/http/client-envelope.model.js +1 -2
  19. package/lib/contract/model/http/connect-options.model.js +1 -2
  20. package/lib/contract/model/http/global-state.model.js +1 -2
  21. package/lib/contract/model/http/http-client-options.model.js +1 -2
  22. package/lib/contract/model/http/server-entry.model.js +1 -2
  23. package/lib/contract/model/http/server-envelope.model.js +1 -2
  24. package/lib/contract/model/middleware/aggregator-state.model.js +1 -2
  25. package/lib/contract/model/shared/loose-object.model.js +1 -2
  26. package/lib/helper/chat.helper.js +1 -4
  27. package/lib/helper/http.helper.d.ts +1 -1
  28. package/lib/helper/http.helper.js +8 -13
  29. package/lib/helper/middleware.helper.d.ts +1 -1
  30. package/lib/helper/middleware.helper.js +7 -11
  31. package/lib/helper/store.helper.d.ts +4 -3
  32. package/lib/helper/store.helper.js +105 -16
  33. package/lib/index.js +2 -8
  34. package/lib/interface/entry.interface.d.ts +6 -3
  35. package/lib/interface/entry.interface.js +176 -57
  36. package/lib/interface/middleware/paging.interface.js +3 -5
  37. package/lib/interface/middleware/processor.interface.js +1 -3
  38. package/lib/plugin.d.ts +2 -2
  39. package/lib/plugin.js +73 -90
  40. package/lib/utils.d.ts +1 -0
  41. package/lib/utils.js +5 -0
  42. package/lib-esm/client/chat.client.d.ts +3 -2
  43. package/lib-esm/client/chat.client.js +81 -11
  44. package/lib-esm/client/contact-method.client.d.ts +9 -1
  45. package/lib-esm/client/contact-method.client.js +28 -6
  46. package/lib-esm/client/http.client.d.ts +11 -7
  47. package/lib-esm/client/http.client.js +125 -22
  48. package/lib-esm/client/middleware.client.d.ts +4 -3
  49. package/lib-esm/client/middleware.client.js +89 -19
  50. package/lib-esm/contract/custom-component/contact-method-item.js +4 -1
  51. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +3 -2
  52. package/lib-esm/contract/enum/server-entry-type.enum.js +3 -2
  53. package/lib-esm/helper/http.helper.d.ts +1 -1
  54. package/lib-esm/helper/http.helper.js +7 -9
  55. package/lib-esm/helper/middleware.helper.d.ts +1 -1
  56. package/lib-esm/helper/middleware.helper.js +5 -6
  57. package/lib-esm/helper/store.helper.d.ts +4 -3
  58. package/lib-esm/helper/store.helper.js +103 -11
  59. package/lib-esm/interface/entry.interface.d.ts +6 -3
  60. package/lib-esm/interface/entry.interface.js +160 -39
  61. package/lib-esm/plugin.d.ts +2 -2
  62. package/lib-esm/plugin.js +66 -55
  63. package/lib-esm/utils.d.ts +1 -0
  64. package/lib-esm/utils.js +5 -0
  65. package/package.json +45 -45
  66. package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
  67. package/lib/interface/middleware/contact-expanded.interface.js +0 -50
  68. package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
  69. package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
@@ -1,59 +1,183 @@
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");
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';
6
53
  var EntryInterface = /** @class */ (function () {
7
- function EntryInterface() {
54
+ function EntryInterface(container) {
55
+ this.container = container;
8
56
  this.helpActionKey = 'help';
9
57
  this.nextActionKey = 'next';
10
58
  }
11
59
  // transform the entry based on its type
12
60
  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
- }
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
+ });
37
127
  };
38
128
  // transform an array of entries
39
129
  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);
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
+ });
46
168
  });
47
- return returnArray;
48
169
  };
49
170
  // gets the text that should be printed as a user message on action
50
171
  EntryInterface.prototype.getUserMessage = function (action) {
51
- var entry = store_helper_1.StoreHelper.getEntry(action);
172
+ var entry = StoreHelper.getEntry(action);
52
173
  return this.getTitleFromEntry(entry, action);
53
174
  };
54
175
  EntryInterface.prototype.listTransform = function (entry) {
176
+ if (entry.type === 'Contact') {
177
+ return;
178
+ }
55
179
  if (!entry.content)
56
- return undefined;
180
+ return;
57
181
  var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
58
182
  return object;
59
183
  };
@@ -67,7 +191,7 @@ var EntryInterface = /** @class */ (function () {
67
191
  if (!!entry.content.items)
68
192
  return this.listTransform(entry);
69
193
  return [
70
- widget_conversation_1.ConversationMessageListItemType.HTML,
194
+ ConversationMessageListItemType.HTML,
71
195
  { body: entry.content.html.replace('\n', '') },
72
196
  ];
73
197
  };
@@ -75,23 +199,20 @@ var EntryInterface = /** @class */ (function () {
75
199
  var _this = this;
76
200
  var list = [];
77
201
  var mainListContent = {};
78
- var mainList = [
79
- this.getListType(state),
80
- { actions: mainListContent },
81
- ];
202
+ var mainList = [this.getListType(state), { actions: mainListContent }];
82
203
  if (text && text.title) {
83
- list.push([widget_conversation_1.ConversationMessageListItemType.Header, text.title]);
204
+ list.push([ConversationMessageListItemType.Header, text.title]);
84
205
  }
85
206
  if (text && text.body) {
86
- list.push([widget_conversation_1.ConversationMessageListItemType.HTML, { body: text.body }]);
207
+ list.push([ConversationMessageListItemType.HTML, { body: text.body }]);
87
208
  }
88
209
  list.push(mainList);
89
210
  items.forEach(function (o) {
90
211
  switch (o.actionKey) {
91
212
  case _this.helpActionKey: {
92
- list.push([widget_conversation_1.ConversationMessageListItemType.Separator, undefined]);
213
+ list.push([ConversationMessageListItemType.Separator, undefined]);
93
214
  list.push([
94
- widget_conversation_1.ConversationMessageListItemType.NoGoodAlternative,
215
+ ConversationMessageListItemType.NoGoodAlternative,
95
216
  { body: o.title },
96
217
  ]);
97
218
  break;
@@ -99,12 +220,10 @@ var EntryInterface = /** @class */ (function () {
99
220
  case _this.nextActionKey: {
100
221
  if (!!actions['next'] && actions['next'].take === items.length + 1)
101
222
  mainListContent[o.actionKey] = o.title;
102
- // console.log(actions['next'], actions['next'].take, items.length, items.length - 2)
103
223
  break;
104
224
  }
105
225
  default: {
106
226
  mainListContent[o.actionKey] = o.title;
107
- // mainListContent.push(this.getItemObject(o))
108
227
  }
109
228
  }
110
229
  });
@@ -112,20 +231,20 @@ var EntryInterface = /** @class */ (function () {
112
231
  };
113
232
  EntryInterface.prototype.getListType = function (state) {
114
233
  if ((state === null || state === void 0 ? void 0 : state.$type) === 'Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching')
115
- return widget_conversation_1.ConversationMessageListItemType.LinkList;
234
+ return ConversationMessageListItemType.LinkList;
116
235
  else if ((state === null || state === void 0 ? void 0 : state.$type) ===
117
236
  'Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching')
118
- return widget_conversation_1.ConversationMessageListItemType.FeedbackList;
237
+ return ConversationMessageListItemType.FeedbackList;
119
238
  else
120
- return widget_conversation_1.ConversationMessageListItemType.ButtonList;
239
+ return ConversationMessageListItemType.ButtonList;
121
240
  };
122
241
  EntryInterface.prototype.getTitleFromEntry = function (entry, action) {
123
242
  if (!!entry) {
124
- var entryType = server_entry_type_enum_1.ServerEntryTypeEnum[entry.type];
243
+ var entryType = ServerEntryTypeEnum[entry.type];
125
244
  switch (entryType) {
126
- case server_entry_type_enum_1.ServerEntryTypeEnum.List:
245
+ case ServerEntryTypeEnum.List:
127
246
  return this.getTitleFromList(entry, action);
128
- case server_entry_type_enum_1.ServerEntryTypeEnum.Text:
247
+ case ServerEntryTypeEnum.Text:
129
248
  return this.textTransform(entry);
130
249
  }
131
250
  }
@@ -135,4 +254,4 @@ var EntryInterface = /** @class */ (function () {
135
254
  };
136
255
  return EntryInterface;
137
256
  }());
138
- exports.default = EntryInterface;
257
+ export default EntryInterface;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __assign = (this && this.__assign) || function () {
3
2
  __assign = Object.assign || function(t) {
4
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -10,15 +9,14 @@ var __assign = (this && this.__assign) || function () {
10
9
  };
11
10
  return __assign.apply(this, arguments);
12
11
  };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- var store_helper_1 = require("../../helper/store.helper");
12
+ import { StoreHelper } from "../../helper/store.helper";
15
13
  var PagingInterface = /** @class */ (function () {
16
14
  function PagingInterface() {
17
15
  }
18
16
  PagingInterface.prototype.process = function (entries) {
19
17
  var pagingEntry = entries.find(function (e) { return e.tags.indexOf("paging") > -1; });
20
18
  if (pagingEntry) {
21
- var stream = store_helper_1.StoreHelper.getEntryStore().filter(function (e) { return e.tags.indexOf("paging") > -1 && e.id === pagingEntry.id; });
19
+ var stream = StoreHelper.getEntryStore().filter(function (e) { return e.tags.indexOf("paging") > -1 && e.id === pagingEntry.id; });
22
20
  if (stream.length > 0) {
23
21
  // Get the paging entry with the highest take count
24
22
  var last_1 = stream.reduce(function (acc, entry) {
@@ -52,4 +50,4 @@ var PagingInterface = /** @class */ (function () {
52
50
  };
53
51
  return PagingInterface;
54
52
  }());
55
- exports.default = PagingInterface;
53
+ export default PagingInterface;
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  var ProcessorInterface = /** @class */ (function () {
4
2
  function ProcessorInterface() {
5
3
  }
@@ -117,4 +115,4 @@ var ProcessorInterface = /** @class */ (function () {
117
115
  };
118
116
  return ProcessorInterface;
119
117
  }());
120
- exports.default = ProcessorInterface;
118
+ export default ProcessorInterface;
package/lib/plugin.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { Container } from '@webprovisions/platform';
2
- declare const ConversationPlugin: (container: Container) => Promise<void>;
3
- export default ConversationPlugin;
2
+ declare const KnowledgeBotProviderPlugin: (container: Container) => Promise<void>;
3
+ export default KnowledgeBotProviderPlugin;
package/lib/plugin.js CHANGED
@@ -1,27 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -58,107 +34,114 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
58
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
35
  }
60
36
  };
61
- var __read = (this && this.__read) || function (o, n) {
62
- var m = typeof Symbol === "function" && o[Symbol.iterator];
63
- if (!m) return o;
64
- var i = m.call(o), r, ar = [], e;
65
- try {
66
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
37
+ import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
38
+ import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
39
+ import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
40
+ import { v4 } from 'uuid';
41
+ import ChatClient from './client/chat.client';
42
+ import { ContactMethodClient } from './client/contact-method.client';
43
+ import { HttpClient } from './client/http.client';
44
+ import MiddlewareClient from './client/middleware.client';
45
+ import { getContactMethodEntry } from './utils';
46
+ var getKnowledgeBotEndpoint = function (container, component /*: ComponentNodeController */
47
+ // ComponentNodeController type differs from component passed into registerProvider
48
+ ) {
49
+ var knowledgeBotEndpoint = component.properties().knowledgeBotEndpoint;
50
+ if (knowledgeBotEndpoint) {
51
+ return "".concat(knowledgeBotEndpoint, "/conversations");
67
52
  }
68
- catch (error) { e = { error: error }; }
69
- finally {
70
- try {
71
- if (r && !r.done && (m = i["return"])) m.call(i);
72
- }
73
- finally { if (e) throw e.error; }
74
- }
75
- return ar;
76
- };
77
- var __importDefault = (this && this.__importDefault) || function (mod) {
78
- return (mod && mod.__esModule) ? mod : { "default": mod };
53
+ var data = container.get('$settings').data;
54
+ if (!data || !data.projection)
55
+ throw new Error('Missing Knowledge Bot endpoint');
56
+ return "".concat(data.projection, "/conversations");
79
57
  };
80
- Object.defineProperty(exports, "__esModule", { value: true });
81
- var knowledge_widget_adapters_1 = require("@telia-ace/knowledge-widget-adapters");
82
- var knowledge_widget_core_1 = require("@telia-ace/knowledge-widget-core");
83
- var knowledge_widget_types_grid_1 = require("@telia-ace/knowledge-widget-types-grid");
84
- var widget_conversation_1 = require("@telia-ace/widget-conversation");
85
- var chat_client_1 = __importDefault(require("./client/chat.client"));
86
- var contact_method_client_1 = require("./client/contact-method.client");
87
- var http_client_1 = require("./client/http.client");
88
- var middleware_client_1 = __importDefault(require("./client/middleware.client"));
89
- var ConversationPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
90
- var platform, contactMethodPlatform, dataClient, compPlatform, _a, component, endpoint;
91
- return __generator(this, function (_b) {
92
- switch (_b.label) {
93
- case 0: return [4 /*yield*/, widget_conversation_1.ConversationPlatform.getInstance(container)];
58
+ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0, void 0, void 0, function () {
59
+ var dataClient, platform, contactMethodPlatform;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0: return [4 /*yield*/, DataClient.getInstance(container)];
94
63
  case 1:
95
- platform = _b.sent();
96
- return [4 /*yield*/, knowledge_widget_adapters_1.ContactMethodPlatform.getInstance(container)];
64
+ dataClient = _a.sent();
65
+ return [4 /*yield*/, ConversationPlatform.getInstance(container)];
97
66
  case 2:
98
- contactMethodPlatform = _b.sent();
99
- return [4 /*yield*/, knowledge_widget_types_grid_1.DataClient.getInstance(container)];
67
+ platform = _a.sent();
68
+ return [4 /*yield*/, ContactMethodPlatform.getInstance(container)];
100
69
  case 3:
101
- dataClient = _b.sent();
102
- return [4 /*yield*/, knowledge_widget_core_1.ComponentPlatform.getInstance(container)];
103
- case 4:
104
- compPlatform = _b.sent();
105
- _a = __read(compPlatform.nodes.query({ type: 'conversation' }), 1), component = _a[0];
106
- endpoint = '';
107
- setTimeout(function () {
108
- endpoint = component.attributes.properties.knowledgeBotEndpoint;
109
- });
70
+ contactMethodPlatform = _a.sent();
71
+ registerCustomMessageComponent(container, 'ace-knowledge-contact-method', import('./contract/custom-component/contact-method'));
110
72
  platform.registerProvider('chat.bot', function (conversation, component) {
111
- (0, widget_conversation_1.registerCustomMessageComponent)(container, 'ace-knowledge-contact-method', Promise.resolve().then(function () { return __importStar(require('./contract/custom-component/contact-method')); }));
112
- var agent = conversation.createAgent({ name: 'John Doe' });
113
- // pases the user and the agent to the Chat Helper
114
- chat_client_1.default.initialize(conversation.user, agent);
73
+ var endpoint = getKnowledgeBotEndpoint(container, component);
74
+ var clientId = v4();
75
+ var agent = conversation.createAgent({
76
+ name: '',
77
+ avatar: undefined,
78
+ });
79
+ // passes the user and the agent to the Chat Helper
80
+ ChatClient.initialize(conversation.user, agent);
115
81
  // passes the conversation provider to the Contact Method Client
116
- contact_method_client_1.ContactMethodClient.initialize(dataClient, contactMethodPlatform, agent);
82
+ ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
117
83
  // passes the container and the widget to the Middleware Store
118
- middleware_client_1.default.initialize(container, container.get('$widget'));
84
+ MiddlewareClient.initialize(container, container.get('$widget'));
119
85
  // executes to decide on what to do on first load
120
- var httpClient = new http_client_1.HttpClient(endpoint);
121
- httpClient.firstHit();
86
+ var httpClient = new HttpClient(endpoint, clientId, container);
87
+ var firstLoader = conversation.loading();
88
+ httpClient.firstHit().then(firstLoader);
122
89
  component.actions.create('evaluate', function (input) {
123
- var cmClient = new contact_method_client_1.ContactMethodClient();
90
+ var cmClient = new ContactMethodClient(container);
124
91
  cmClient.handleNewForm(input.form, input.form.id);
125
92
  });
126
93
  component.actions.create('validate', function (input) {
127
- var cmClient = new contact_method_client_1.ContactMethodClient();
94
+ var cmClient = new ContactMethodClient(container);
128
95
  cmClient.validate(input.form);
129
96
  });
130
97
  component.actions.create('submit', function (input) {
131
- var cmClient = new contact_method_client_1.ContactMethodClient();
98
+ var _a;
99
+ if ((_a = input === null || input === void 0 ? void 0 : input.form) === null || _a === void 0 ? void 0 : _a.schema.id) {
100
+ var contactMethodEntry = getContactMethodEntry(input.form.schema.id);
101
+ if (contactMethodEntry) {
102
+ }
103
+ }
104
+ var cmClient = new ContactMethodClient(container);
132
105
  cmClient.validate(input.form);
133
106
  });
134
107
  component.actions.watch('conversation.user-typing', function (input, next) {
135
108
  return next(input);
136
109
  });
137
110
  component.actions.watch('conversation.user-submit', function (input, next) {
138
- var httpClient = new http_client_1.HttpClient(endpoint);
139
- httpClient.handlePhrase(input.text);
111
+ var httpClient = new HttpClient(endpoint, clientId, container);
112
+ var loader = conversation.loading();
113
+ httpClient.handlePhrase(input.text).then(loader);
140
114
  return next(input);
141
115
  });
142
116
  component.actions.watch('conversation.form', function (input, next) {
143
117
  return next(input);
144
118
  });
145
119
  component.actions.watch('conversation.action', function (input, next) {
146
- var chatClient = new chat_client_1.default();
147
- var cmClient = new contact_method_client_1.ContactMethodClient();
148
- if (input === 'contact' || input.split('/').length > 1) {
149
- cmClient.handleContactMethod(input);
120
+ var chatClient = new ChatClient(container);
121
+ var cmClient = new ContactMethodClient(container);
122
+ // if (input === 'contact' || input.split('/').length > 1) {
123
+ // cmClient.handleContactMethod(input);
124
+ // return next(input);
125
+ // }
126
+ var loader = conversation.loading();
127
+ if (input.split('/').length > 1) {
128
+ cmClient.handleContactMethod(input).then(loader);
129
+ return next(input);
130
+ }
131
+ var httpClient = new HttpClient(endpoint, clientId, container);
132
+ if (input == 'burger-clicked') {
133
+ httpClient.handleCategories().then(loader);
150
134
  return next(input);
151
135
  }
152
- var middlewareClient = new middleware_client_1.default();
136
+ var middlewareClient = new MiddlewareClient(container);
153
137
  // this is an update check, as it requires
154
138
  // a lot different logic and no user message
155
139
  if (middlewareClient.checkForUpdate(input)) {
156
- middlewareClient.handleUpdate(input, endpoint);
140
+ httpClient.handleUpdate(input).then(loader);
157
141
  return next(input);
158
142
  }
159
143
  chatClient.printUserMessageAndStoreIt(input);
160
- var httpClient = new http_client_1.HttpClient(endpoint);
161
- httpClient.handleInput(input);
144
+ httpClient.handleInput(input).then(loader);
162
145
  return next(input);
163
146
  });
164
147
  });
@@ -166,4 +149,4 @@ var ConversationPlugin = function (container) { return __awaiter(void 0, void 0,
166
149
  }
167
150
  });
168
151
  }); };
169
- exports.default = ConversationPlugin;
152
+ export default KnowledgeBotProviderPlugin;
package/lib/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const getContactMethodEntry: (contactMethodId: string) => import("./contract/model/http/server-entry.model").ServerEntry | undefined;
package/lib/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ import { StoreHelper } from './helper/store.helper';
2
+ export var getContactMethodEntry = function (contactMethodId) {
3
+ var entries = StoreHelper.getEntryStore();
4
+ return entries.find(function (e) { return e.content.id === +contactMethodId; });
5
+ };
@@ -1,10 +1,11 @@
1
+ import { Container } from '@webprovisions/platform';
1
2
  import { Message } from '../contract/model/conversation-api-model/message.model';
2
3
  import EntryInterface from '../interface/entry.interface';
3
4
  export default class ChatClient {
4
5
  entryInterface: EntryInterface;
5
- constructor();
6
+ constructor(container: Container);
6
7
  static initialize(user: any, agent: any): void;
7
- processMessageArrayAndStoreIt(messages: Message[]): void;
8
+ processMessageArrayAndStoreIt(messages: Message[]): Promise<void>;
8
9
  updateMessageArrayAndStoreIt(messages: Message[]): void;
9
10
  printUserMessageAndStoreIt(action: string): void;
10
11
  private postUserMessage;