@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.38 → 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.
@@ -5,7 +5,7 @@ export default class ChatClient {
5
5
  entryInterface: EntryInterface;
6
6
  constructor(container: Container);
7
7
  static initialize(user: any, agent: any): void;
8
- processMessageArrayAndStoreIt(messages: Message[]): void;
8
+ processMessageArrayAndStoreIt(messages: Message[]): Promise<void>;
9
9
  updateMessageArrayAndStoreIt(messages: Message[]): void;
10
10
  printUserMessageAndStoreIt(action: string): void;
11
11
  private postUserMessage;
@@ -1,3 +1,50 @@
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
+ };
1
48
  import { v4 as newGuid } from 'uuid';
2
49
  import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
3
50
  import { ChatHelper } from '../helper/chat.helper';
@@ -14,16 +61,35 @@ var ChatClient = /** @class */ (function () {
14
61
  };
15
62
  // function for posting the messages
16
63
  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);
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var _a, _b, message;
66
+ var e_1, _c;
67
+ return __generator(this, function (_d) {
68
+ switch (_d.label) {
69
+ case 0:
70
+ try {
71
+ for (_a = __values(messages.filter(function (o) { return o && o != null; })), _b = _a.next(); !_b.done; _b = _a.next()) {
72
+ message = _b.value;
73
+ if (message.isUser)
74
+ this.postUserMessage(message);
75
+ else
76
+ this.postAgentMessage(message);
77
+ }
78
+ }
79
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
80
+ finally {
81
+ try {
82
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
83
+ }
84
+ finally { if (e_1) throw e_1.error; }
85
+ }
86
+ return [4 /*yield*/, StoreHelper.insertOrUpdateMessageArrayStore(messages)];
87
+ case 1:
88
+ _d.sent();
89
+ return [2 /*return*/];
90
+ }
91
+ });
25
92
  });
26
- StoreHelper.insertOrUpdateMessageArrayStore(messages);
27
93
  };
28
94
  // function for updating current messages
29
95
  ChatClient.prototype.updateMessageArrayAndStoreIt = function (messages) {
@@ -15,6 +15,11 @@ export declare class ContactMethodClient {
15
15
  validate(form: any): void;
16
16
  private handleContactCategoryList;
17
17
  private handleForm;
18
+ addContactMethod(contactMethod: any): {
19
+ contactMethods: any;
20
+ type: string;
21
+ noPadding: boolean;
22
+ };
18
23
  private handleContactMethodList;
19
24
  private handleSingleContactMethod;
20
25
  private submit;
@@ -162,6 +162,14 @@ var ContactMethodClient = /** @class */ (function () {
162
162
  });
163
163
  this.printMessage(contactMethods.id, contactMethods, title);
164
164
  };
165
+ ContactMethodClient.prototype.addContactMethod = function (contactMethod) {
166
+ contactMethod.expanded = true;
167
+ this.updateForm(contactMethod, {
168
+ submit: 'Submit',
169
+ errors: undefined,
170
+ });
171
+ return this.printMessage(contactMethod.id, contactMethod);
172
+ };
165
173
  ContactMethodClient.prototype.handleContactMethodList = function (input, contactMethods) {
166
174
  var title = input.split('/')[2];
167
175
  var newGuid = uuidv4();
@@ -214,6 +222,7 @@ var ContactMethodClient = /** @class */ (function () {
214
222
  isUser: false,
215
223
  },
216
224
  ]);
225
+ return message;
217
226
  }
218
227
  else {
219
228
  if (title)
@@ -236,6 +245,7 @@ var ContactMethodClient = /** @class */ (function () {
236
245
  contactMethods: contactMethods,
237
246
  entry: entry,
238
247
  });
248
+ return message;
239
249
  }
240
250
  };
241
251
  ContactMethodClient.prototype.loadContactMethods = function (dataType, id) {
@@ -7,15 +7,18 @@ export declare class HttpClient {
7
7
  private options;
8
8
  private middlewareClient;
9
9
  private chatClient;
10
+ private container;
10
11
  constructor(endpoint: string, clientId: string, container: Container);
11
- firstHit(): void;
12
- handleUpdate(action: string): void;
13
- handleInput(action: string): void;
14
- handlePhrase(phrase: string): void;
12
+ firstHit(): Promise<void>;
13
+ handleUpdate(action: string): Promise<any>;
14
+ handleInput(action: string): Promise<void>;
15
+ handleCategories(): Promise<void>;
16
+ handlePhrase(phrase: string): Promise<void>;
15
17
  private postAndHandleTheData;
16
18
  private postAndHandleTheUpdateData;
17
19
  private getHttpOptions;
18
20
  private constructInputEnvelope;
21
+ private constructCategoriesEnvelope;
19
22
  private constructPhraseEnvelope;
20
23
  private constructFirstHitEnvelope;
21
24
  private handleResponseData;
@@ -1,3 +1,42 @@
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
+ import { readStorage } from '@telia-ace/widget-services';
38
+ import { v4 as newGuid } from 'uuid';
39
+ import { ChatHelper } from '../helper/chat.helper';
1
40
  import { HttpHelper } from '../helper/http.helper';
2
41
  import { MiddlewareHelper } from '../helper/middleware.helper';
3
42
  import { StoreHelper } from '../helper/store.helper';
@@ -15,37 +54,84 @@ var HttpClient = /** @class */ (function () {
15
54
  this.clientId = this.options.clientId;
16
55
  this.middlewareClient = new MiddlewareClient(container);
17
56
  this.chatClient = new ChatClient(container);
57
+ this.container = container;
18
58
  }
19
59
  HttpClient.prototype.firstHit = function () {
20
- var _this = this;
21
- // On first hit if there are entries stored in the storage, use them
22
- // Otherwise start a new session
23
- MiddlewareHelper.getEntrySessionStorage().then(function (o) {
24
- if (o && o.length > 0)
25
- _this.chatClient.processMessageArrayAndStoreIt(o);
26
- else {
27
- var envelope = _this.constructFirstHitEnvelope();
28
- _this.postAndHandleTheData(envelope);
29
- }
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var entries, meta, agent, envelope;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0: return [4 /*yield*/, MiddlewareHelper.getEntrySessionStorage()];
65
+ case 1:
66
+ entries = (_a.sent());
67
+ if (!(entries && entries.length > 0)) return [3 /*break*/, 5];
68
+ return [4 /*yield*/, StoreHelper.rehydrateState()];
69
+ case 2:
70
+ _a.sent();
71
+ return [4 /*yield*/, readStorage(this.container, 'bot-provider-conversation-meta')];
72
+ case 3:
73
+ meta = _a.sent();
74
+ if (meta === null || meta === void 0 ? void 0 : meta.agent) {
75
+ agent = ChatHelper.getAgent();
76
+ agent.update({
77
+ name: meta.agent.name,
78
+ avatar: meta.agent.avatar,
79
+ });
80
+ }
81
+ return [4 /*yield*/, this.chatClient.processMessageArrayAndStoreIt(entries)];
82
+ case 4:
83
+ _a.sent();
84
+ return [3 /*break*/, 7];
85
+ case 5:
86
+ envelope = this.constructFirstHitEnvelope();
87
+ return [4 /*yield*/, this.postAndHandleTheData(envelope)];
88
+ case 6:
89
+ _a.sent();
90
+ _a.label = 7;
91
+ case 7: return [2 /*return*/];
92
+ }
93
+ });
30
94
  });
31
95
  };
32
96
  // for updates, such as paging changes
33
97
  HttpClient.prototype.handleUpdate = function (action) {
34
98
  var envelope = this.constructInputEnvelope(action);
35
- this.postAndHandleTheUpdateData(envelope, action);
36
- // return this.postAndReturnTheData(envelope, action).then((o) => {
37
- // return o.entries;
38
- // });
99
+ return this.postAndHandleTheUpdateData(envelope, action);
39
100
  };
40
101
  // for action clicks
41
102
  HttpClient.prototype.handleInput = function (action) {
42
103
  var envelope = this.constructInputEnvelope(action);
43
- this.postAndHandleTheData(envelope, action);
104
+ return this.postAndHandleTheData(envelope, action);
105
+ };
106
+ // for category burger
107
+ HttpClient.prototype.handleCategories = function () {
108
+ var envelope = this.constructCategoriesEnvelope();
109
+ return this.postAndHandleTheData(envelope);
44
110
  };
45
111
  // for text entries by user
46
112
  HttpClient.prototype.handlePhrase = function (phrase) {
47
113
  var envelope = this.constructPhraseEnvelope(phrase);
48
- this.postAndHandleTheData(envelope);
114
+ var id = newGuid();
115
+ var entry = {
116
+ id: id,
117
+ type: 'Text',
118
+ timestamp: new Date(),
119
+ content: {
120
+ $type: 'Humany.Matching.Bots.Conversations.Content.Text, Humany.Matching',
121
+ html: "".concat(phrase),
122
+ },
123
+ actions: {},
124
+ tags: {},
125
+ };
126
+ var message = {
127
+ id: id,
128
+ message: ['html', { body: "<p>".concat(phrase, "</p>") }],
129
+ entry: entry,
130
+ isUser: true,
131
+ conversationEntry: {},
132
+ };
133
+ StoreHelper.insertMessageToStore(message);
134
+ return this.postAndHandleTheData(envelope);
49
135
  };
50
136
  HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
51
137
  var _this = this;
@@ -87,6 +173,18 @@ var HttpClient = /** @class */ (function () {
87
173
  clientId: this.clientId,
88
174
  };
89
175
  };
176
+ HttpClient.prototype.constructCategoriesEnvelope = function () {
177
+ return {
178
+ action: {
179
+ content: {
180
+ $type: 'Humany.Matching.Bots.Conversations.Actions.BrowseCategories, Humany.Matching',
181
+ },
182
+ key: 'browseCategories',
183
+ },
184
+ globalState: StoreHelper.getGlobalState(),
185
+ clientId: this.clientId,
186
+ };
187
+ };
90
188
  HttpClient.prototype.constructPhraseEnvelope = function (phrase) {
91
189
  return {
92
190
  command: { phrase: phrase },
@@ -103,10 +201,10 @@ var HttpClient = /** @class */ (function () {
103
201
  };
104
202
  HttpClient.prototype.handleResponseData = function (envelope, action) {
105
203
  StoreHelper.setGlobalState(envelope.globalState);
106
- this.middlewareClient.handleEntries(envelope.entries, action);
204
+ return this.middlewareClient.handleEntries(envelope.entries, action);
107
205
  };
108
206
  HttpClient.prototype.handleUpdateResponseData = function (envelope, action) {
109
- this.middlewareClient.handleUpdate(envelope.entries, action);
207
+ return this.middlewareClient.handleUpdate(envelope.entries, action);
110
208
  };
111
209
  return HttpClient;
112
210
  }());
@@ -34,6 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ import { createStorageWriter, StorageCategory } from '@telia-ace/widget-services';
37
38
  import { ChatHelper } from '../helper/chat.helper';
38
39
  import { MiddlewareHelper } from '../helper/middleware.helper';
39
40
  import { StoreHelper } from '../helper/store.helper';
@@ -55,23 +56,32 @@ var MiddlewareClient = /** @class */ (function () {
55
56
  // called on all standard scenarios like actions and user messages
56
57
  MiddlewareClient.prototype.handleEntries = function (entries, action) {
57
58
  return __awaiter(this, void 0, void 0, function () {
58
- var widgetEntry, agent, o, messageArray;
59
+ var widgetEntry, agent, write, o, messageArray;
59
60
  return __generator(this, function (_a) {
60
61
  switch (_a.label) {
61
62
  case 0:
62
63
  widgetEntry = (entries || []).find(function (e) { return e.type === 'Widget'; });
63
- if (widgetEntry) {
64
- agent = ChatHelper.getAgent();
65
- if (agent) {
66
- agent.update({
67
- name: widgetEntry.content.agent.name,
68
- avatar: widgetEntry.content.agent.avatar,
69
- });
70
- }
71
- }
64
+ if (!widgetEntry) return [3 /*break*/, 2];
65
+ agent = ChatHelper.getAgent();
66
+ if (!agent) return [3 /*break*/, 2];
67
+ agent.update({
68
+ name: widgetEntry.content.agent.name,
69
+ avatar: widgetEntry.content.agent.avatar,
70
+ });
71
+ return [4 /*yield*/, createStorageWriter(MiddlewareHelper.getContainer(), 'bot-provider-conversation-meta', StorageCategory.Necessary)];
72
+ case 1:
73
+ write = _a.sent();
74
+ write({
75
+ agent: {
76
+ name: widgetEntry.content.agent.name,
77
+ avatar: widgetEntry.content.agent.avatar,
78
+ },
79
+ });
80
+ _a.label = 2;
81
+ case 2:
72
82
  o = this.executeMiddlewares(entries, false, action);
73
83
  return [4 /*yield*/, this.entryInterface.transformArray(o)];
74
- case 1:
84
+ case 3:
75
85
  messageArray = _a.sent();
76
86
  this.chatClient.processMessageArrayAndStoreIt(messageArray);
77
87
  return [2 /*return*/];
@@ -23,7 +23,6 @@ var ContactMethod = function (props) {
23
23
  type = DataType.ContactMethod;
24
24
  methodList = props.contactMethods;
25
25
  }
26
- // TODO: ContactMethodItem should not be passed a list as contact method?
27
26
  if (!methodList.length) {
28
27
  return React.createElement(StyledContactMethodItem, { type: type, contactMethod: methodList });
29
28
  }
@@ -58,10 +58,9 @@ var MiddlewareHelper = /** @class */ (function () {
58
58
  MiddlewareHelper.sessionMessageStorageVariable = 'conversation-plugin-messages';
59
59
  MiddlewareHelper.setEntrySessionStorage = function (messages) { return __awaiter(void 0, void 0, void 0, function () {
60
60
  return __generator(_a, function (_b) {
61
- createStorageWriter(MiddlewareHelper.container, MiddlewareHelper.sessionMessageStorageVariable, StorageCategory.Necessary).then(function (write) {
62
- return write(messages);
63
- });
64
- return [2 /*return*/];
61
+ return [2 /*return*/, createStorageWriter(MiddlewareHelper.container, MiddlewareHelper.sessionMessageStorageVariable, StorageCategory.Necessary).then(function (write) {
62
+ return write(messages);
63
+ })];
65
64
  });
66
65
  }); };
67
66
  return MiddlewareHelper;
@@ -7,16 +7,17 @@ export declare class StoreHelper {
7
7
  private static messageStore;
8
8
  private static globalState;
9
9
  constructor();
10
- static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): void;
11
- private static insertMessageToStore;
10
+ static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): Promise<void>;
11
+ static insertMessageToStore(message: Message): void;
12
12
  private static updateMessageInStore;
13
13
  static checkIdInMessageStore(id: string): boolean;
14
14
  static getLocalState(action: string): LooseObject | undefined;
15
15
  static getGlobalState(): GlobalState;
16
- static setGlobalState(state: GlobalState): void;
16
+ static setGlobalState(state: GlobalState): Promise<void>;
17
17
  static getAction(action: string): ClientAction;
18
18
  static getCommand(text: string): LooseObject;
19
19
  static getEntry(action: string): ServerEntry | undefined;
20
20
  static getMessage(id: string): Message | undefined;
21
21
  static getEntryStore(): ServerEntry[];
22
+ static rehydrateState(): Promise<void>;
22
23
  }
@@ -1,25 +1,98 @@
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 { createStorageWriter, readStorage, StorageCategory } from '@telia-ace/widget-services';
1
49
  import { MiddlewareHelper } from './middleware.helper';
50
+ var botProviderGlobalStateSessionKey = 'bot-provider-global-state';
2
51
  var StoreHelper = /** @class */ (function () {
3
52
  function StoreHelper() {
4
53
  StoreHelper.globalState = {
5
54
  completedInteractionsCount: 0,
6
55
  lastBotGuide: 0,
7
- site: 'https://localhost:8080/',
56
+ site: '',
8
57
  invincibleParameters: {},
9
58
  };
10
59
  }
11
60
  StoreHelper.insertOrUpdateMessageArrayStore = function (messageArray, entry) {
12
- var _this = this;
13
- messageArray
14
- .filter(function (o) { return !!o; })
15
- .forEach(function (t) {
16
- if (!_this.messageStore.find(function (o) { return o.id == t.id; }))
17
- _this.insertMessageToStore(t);
18
- else {
19
- _this.updateMessageInStore(t, entry);
20
- }
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var _loop_1, this_1, _a, _b, message;
63
+ var e_1, _c;
64
+ return __generator(this, function (_d) {
65
+ switch (_d.label) {
66
+ case 0:
67
+ _loop_1 = function (message) {
68
+ if (!this_1.messageStore.find(function (o) { return o.id == message.id; })) {
69
+ this_1.insertMessageToStore(message);
70
+ }
71
+ else {
72
+ this_1.updateMessageInStore(message, entry);
73
+ }
74
+ };
75
+ this_1 = this;
76
+ try {
77
+ for (_a = __values(messageArray.filter(function (o) { return !!o; })), _b = _a.next(); !_b.done; _b = _a.next()) {
78
+ message = _b.value;
79
+ _loop_1(message);
80
+ }
81
+ }
82
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
83
+ finally {
84
+ try {
85
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
86
+ }
87
+ finally { if (e_1) throw e_1.error; }
88
+ }
89
+ return [4 /*yield*/, MiddlewareHelper.setEntrySessionStorage(this.messageStore)];
90
+ case 1:
91
+ _d.sent();
92
+ return [2 /*return*/];
93
+ }
94
+ });
21
95
  });
22
- MiddlewareHelper.setEntrySessionStorage(this.messageStore);
23
96
  };
24
97
  StoreHelper.insertMessageToStore = function (message) {
25
98
  this.messageStore.push(message);
@@ -41,6 +114,9 @@ var StoreHelper = /** @class */ (function () {
41
114
  };
42
115
  StoreHelper.setGlobalState = function (state) {
43
116
  StoreHelper.globalState = state;
117
+ return createStorageWriter(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey, StorageCategory.Necessary).then(function (write) {
118
+ return write(state);
119
+ });
44
120
  };
45
121
  StoreHelper.getAction = function (action) {
46
122
  var entry = this.getEntry(action);
@@ -71,6 +147,22 @@ var StoreHelper = /** @class */ (function () {
71
147
  return o.entry;
72
148
  });
73
149
  };
150
+ StoreHelper.rehydrateState = function () {
151
+ return __awaiter(this, void 0, void 0, function () {
152
+ var state;
153
+ return __generator(this, function (_a) {
154
+ switch (_a.label) {
155
+ case 0: return [4 /*yield*/, readStorage(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey)];
156
+ case 1:
157
+ state = _a.sent();
158
+ if (state) {
159
+ this.setGlobalState(state);
160
+ }
161
+ return [2 /*return*/];
162
+ }
163
+ });
164
+ });
165
+ };
74
166
  StoreHelper.messageStore = [];
75
167
  return StoreHelper;
76
168
  }());
@@ -46,7 +46,8 @@ var __values = (this && this.__values) || function(o) {
46
46
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
47
  };
48
48
  import { DataType } from '@telia-ace/knowledge-widget-types-grid';
49
- import { ConversationMessageListItemType } from '@telia-ace/widget-conversation';
49
+ import { ConversationMessageListItemType, } from '@telia-ace/widget-conversation';
50
+ import { ContactMethodClient } from '../client/contact-method.client';
50
51
  import { ServerEntryTypeEnum } from '../contract/enum/server-entry-type.enum';
51
52
  import { StoreHelper } from '../helper/store.helper';
52
53
  var EntryInterface = /** @class */ (function () {
@@ -106,26 +107,20 @@ var EntryInterface = /** @class */ (function () {
106
107
  };
107
108
  EntryInterface.prototype.transformContactMethod = function (entry) {
108
109
  return __awaiter(this, void 0, void 0, function () {
109
- var dataClient, contactMethods, contactMethod;
110
+ var dataClient, contactMethod, cmClient;
110
111
  return __generator(this, function (_a) {
111
112
  switch (_a.label) {
112
113
  case 0: return [4 /*yield*/, this.container.getAsync('dataClient')];
113
114
  case 1:
114
115
  dataClient = _a.sent();
115
- contactMethods = [];
116
116
  return [4 /*yield*/, dataClient.fetch(DataType.ContactMethod, {
117
117
  contactMethodId: entry.content.id,
118
118
  })];
119
119
  case 2:
120
120
  contactMethod = _a.sent();
121
- if (contactMethod) {
122
- contactMethod.expanded = true;
123
- contactMethods.push(contactMethod);
124
- }
125
- return [2 /*return*/, {
126
- type: 'ace-knowledge-contact-method',
127
- contactMethods: contactMethods,
128
- }];
121
+ cmClient = new ContactMethodClient(this.container);
122
+ cmClient.addContactMethod(contactMethod);
123
+ return [2 /*return*/];
129
124
  }
130
125
  });
131
126
  });
@@ -179,11 +174,10 @@ var EntryInterface = /** @class */ (function () {
179
174
  };
180
175
  EntryInterface.prototype.listTransform = function (entry) {
181
176
  if (entry.type === 'Contact') {
182
- // TODO: is this needed
183
- return undefined;
177
+ return;
184
178
  }
185
179
  if (!entry.content)
186
- return undefined;
180
+ return;
187
181
  var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
188
182
  return object;
189
183
  };