@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.39 → 0.0.1-alpha.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client/chat.client.d.ts +1 -1
- package/lib/client/chat.client.js +75 -9
- package/lib/client/http.client.d.ts +6 -5
- package/lib/client/http.client.js +100 -19
- package/lib/client/middleware.client.js +21 -11
- package/lib/contract/custom-component/contact-method.js +0 -1
- package/lib/helper/middleware.helper.js +3 -4
- package/lib/helper/store.helper.d.ts +4 -3
- package/lib/helper/store.helper.js +103 -11
- package/lib/interface/entry.interface.d.ts +1 -1
- package/lib/interface/entry.interface.js +36 -37
- package/lib/interface/middleware/processor.interface.js +1 -1
- package/lib/plugin.js +9 -6
- package/lib-esm/client/chat.client.d.ts +1 -1
- package/lib-esm/client/chat.client.js +75 -9
- package/lib-esm/client/http.client.d.ts +6 -5
- package/lib-esm/client/http.client.js +100 -19
- package/lib-esm/client/middleware.client.js +21 -11
- package/lib-esm/contract/custom-component/contact-method.js +0 -1
- package/lib-esm/helper/middleware.helper.js +3 -4
- package/lib-esm/helper/store.helper.d.ts +4 -3
- package/lib-esm/helper/store.helper.js +103 -11
- package/lib-esm/interface/entry.interface.d.ts +1 -1
- package/lib-esm/interface/entry.interface.js +36 -37
- package/lib-esm/interface/middleware/processor.interface.js +1 -1
- package/lib-esm/plugin.js +9 -6
- package/package.json +5 -5
|
@@ -57,7 +57,7 @@ var EntryInterface = /** @class */ (function () {
|
|
|
57
57
|
this.nextActionKey = 'next';
|
|
58
58
|
}
|
|
59
59
|
// transform the entry based on its type
|
|
60
|
-
EntryInterface.prototype.transform = function (entry) {
|
|
60
|
+
EntryInterface.prototype.transform = function (entry, feedbackEntry) {
|
|
61
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
62
|
var entryType, _a;
|
|
63
63
|
var _b;
|
|
@@ -69,38 +69,31 @@ var EntryInterface = /** @class */ (function () {
|
|
|
69
69
|
switch (_a) {
|
|
70
70
|
case ServerEntryTypeEnum.List: return [3 /*break*/, 1];
|
|
71
71
|
case ServerEntryTypeEnum.Text: return [3 /*break*/, 2];
|
|
72
|
-
case ServerEntryTypeEnum.
|
|
73
|
-
case ServerEntryTypeEnum.Contact: return [3 /*break*/, 4];
|
|
72
|
+
case ServerEntryTypeEnum.Contact: return [3 /*break*/, 3];
|
|
74
73
|
}
|
|
75
|
-
return [3 /*break*/,
|
|
74
|
+
return [3 /*break*/, 5];
|
|
76
75
|
case 1: return [2 /*return*/, {
|
|
77
76
|
id: entry.id,
|
|
78
|
-
message: this.listTransform(entry),
|
|
77
|
+
message: this.listTransform(entry, feedbackEntry),
|
|
79
78
|
entry: entry,
|
|
80
79
|
isUser: false,
|
|
81
80
|
}];
|
|
82
81
|
case 2: return [2 /*return*/, {
|
|
83
82
|
id: entry.id,
|
|
84
|
-
message: this.textTransform(entry),
|
|
83
|
+
message: this.textTransform(entry, feedbackEntry),
|
|
85
84
|
entry: entry,
|
|
86
85
|
isUser: false,
|
|
87
86
|
}];
|
|
88
|
-
case 3:
|
|
89
|
-
id: entry.id,
|
|
90
|
-
message: this.listTransform(entry),
|
|
91
|
-
entry: entry,
|
|
92
|
-
isUser: false,
|
|
93
|
-
}];
|
|
94
|
-
case 4:
|
|
87
|
+
case 3:
|
|
95
88
|
_b = {
|
|
96
89
|
id: entry.id
|
|
97
90
|
};
|
|
98
91
|
return [4 /*yield*/, this.transformContactMethod(entry)];
|
|
99
|
-
case
|
|
92
|
+
case 4: return [2 /*return*/, (_b.message = _c.sent(),
|
|
100
93
|
_b.entry = entry,
|
|
101
94
|
_b.isUser = false,
|
|
102
95
|
_b)];
|
|
103
|
-
case
|
|
96
|
+
case 5: return [2 /*return*/];
|
|
104
97
|
}
|
|
105
98
|
});
|
|
106
99
|
});
|
|
@@ -128,37 +121,40 @@ var EntryInterface = /** @class */ (function () {
|
|
|
128
121
|
// transform an array of entries
|
|
129
122
|
EntryInterface.prototype.transformArray = function (entryArray) {
|
|
130
123
|
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
-
var returnArray,
|
|
132
|
-
var e_1,
|
|
133
|
-
return __generator(this, function (
|
|
134
|
-
switch (
|
|
124
|
+
var feedbackEntry, returnArray, _a, _b, o, x, e_1_1;
|
|
125
|
+
var e_1, _c;
|
|
126
|
+
return __generator(this, function (_d) {
|
|
127
|
+
switch (_d.label) {
|
|
135
128
|
case 0:
|
|
129
|
+
feedbackEntry = entryArray.find(function (o) {
|
|
130
|
+
return o.tags.find(function (t) { return t == 'gentle' || t == 'feedback'; });
|
|
131
|
+
});
|
|
136
132
|
returnArray = [];
|
|
137
|
-
|
|
133
|
+
_d.label = 1;
|
|
138
134
|
case 1:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
136
|
+
_a = __values(entryArray.filter(function (t) { return t !== feedbackEntry; })), _b = _a.next();
|
|
137
|
+
_d.label = 2;
|
|
142
138
|
case 2:
|
|
143
|
-
if (!!
|
|
144
|
-
o =
|
|
145
|
-
return [4 /*yield*/, this.transform(o)];
|
|
139
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
140
|
+
o = _b.value;
|
|
141
|
+
return [4 /*yield*/, this.transform(o, feedbackEntry)];
|
|
146
142
|
case 3:
|
|
147
|
-
x =
|
|
143
|
+
x = _d.sent();
|
|
148
144
|
if (!!x)
|
|
149
145
|
returnArray.push(x);
|
|
150
|
-
|
|
146
|
+
_d.label = 4;
|
|
151
147
|
case 4:
|
|
152
|
-
|
|
148
|
+
_b = _a.next();
|
|
153
149
|
return [3 /*break*/, 2];
|
|
154
150
|
case 5: return [3 /*break*/, 8];
|
|
155
151
|
case 6:
|
|
156
|
-
e_1_1 =
|
|
152
|
+
e_1_1 = _d.sent();
|
|
157
153
|
e_1 = { error: e_1_1 };
|
|
158
154
|
return [3 /*break*/, 8];
|
|
159
155
|
case 7:
|
|
160
156
|
try {
|
|
161
|
-
if (
|
|
157
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
162
158
|
}
|
|
163
159
|
finally { if (e_1) throw e_1.error; }
|
|
164
160
|
return [7 /*endfinally*/];
|
|
@@ -172,14 +168,17 @@ var EntryInterface = /** @class */ (function () {
|
|
|
172
168
|
var entry = StoreHelper.getEntry(action);
|
|
173
169
|
return this.getTitleFromEntry(entry, action);
|
|
174
170
|
};
|
|
175
|
-
EntryInterface.prototype.listTransform = function (entry) {
|
|
171
|
+
EntryInterface.prototype.listTransform = function (entry, feedbackEntry) {
|
|
176
172
|
if (entry.type === 'Contact') {
|
|
177
|
-
|
|
178
|
-
return undefined;
|
|
173
|
+
return;
|
|
179
174
|
}
|
|
180
175
|
if (!entry.content)
|
|
181
|
-
return
|
|
176
|
+
return;
|
|
182
177
|
var object = this.getListActions(entry.content.items, this.getContentText(entry), entry.actions, entry.localState);
|
|
178
|
+
if (!!feedbackEntry) {
|
|
179
|
+
var feedbackObject = this.getListActions(feedbackEntry.content.items, this.getContentText(feedbackEntry), feedbackEntry.actions, feedbackEntry.localState);
|
|
180
|
+
return object.concat(feedbackObject);
|
|
181
|
+
}
|
|
183
182
|
return object;
|
|
184
183
|
};
|
|
185
184
|
EntryInterface.prototype.getContentText = function (entry) {
|
|
@@ -188,9 +187,9 @@ var EntryInterface = /** @class */ (function () {
|
|
|
188
187
|
if (entry.content.header)
|
|
189
188
|
return { title: entry.content.header };
|
|
190
189
|
};
|
|
191
|
-
EntryInterface.prototype.textTransform = function (entry) {
|
|
190
|
+
EntryInterface.prototype.textTransform = function (entry, feedbackEntry) {
|
|
192
191
|
if (!!entry.content.items)
|
|
193
|
-
return this.listTransform(entry);
|
|
192
|
+
return this.listTransform(entry, feedbackEntry);
|
|
194
193
|
return [
|
|
195
194
|
ConversationMessageListItemType.HTML,
|
|
196
195
|
{ body: entry.content.html.replace('\n', '') },
|
|
@@ -85,7 +85,7 @@ var ProcessorInterface = /** @class */ (function () {
|
|
|
85
85
|
return target.localState;
|
|
86
86
|
};
|
|
87
87
|
entries.forEach(function (entry) {
|
|
88
|
-
if (entry.relation) {
|
|
88
|
+
if (entry.relation && !entry.tags.find(function (o) { return o == 'gentle' || o == 'feedback'; })) {
|
|
89
89
|
var existingEntry = entries.find(function (o) { return o.id == entry.relation; });
|
|
90
90
|
if (existingEntry) {
|
|
91
91
|
var existingIndex = output.indexOf(existingEntry);
|
package/lib/plugin.js
CHANGED
|
@@ -84,7 +84,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
84
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
85
85
|
// executes to decide on what to do on first load
|
|
86
86
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
87
|
-
|
|
87
|
+
var firstLoader = conversation.loading();
|
|
88
|
+
httpClient.firstHit().then(firstLoader);
|
|
88
89
|
component.actions.create('evaluate', function (input) {
|
|
89
90
|
var cmClient = new ContactMethodClient(container);
|
|
90
91
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
@@ -108,7 +109,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
108
109
|
});
|
|
109
110
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
110
111
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
111
|
-
|
|
112
|
+
var loader = conversation.loading();
|
|
113
|
+
httpClient.handlePhrase(input.text).then(loader);
|
|
112
114
|
return next(input);
|
|
113
115
|
});
|
|
114
116
|
component.actions.watch('conversation.form', function (input, next) {
|
|
@@ -121,24 +123,25 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
121
123
|
// cmClient.handleContactMethod(input);
|
|
122
124
|
// return next(input);
|
|
123
125
|
// }
|
|
126
|
+
var loader = conversation.loading();
|
|
124
127
|
if (input.split('/').length > 1) {
|
|
125
|
-
cmClient.handleContactMethod(input);
|
|
128
|
+
cmClient.handleContactMethod(input).then(loader);
|
|
126
129
|
return next(input);
|
|
127
130
|
}
|
|
128
131
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
129
132
|
if (input == 'burger-clicked') {
|
|
130
|
-
httpClient.handleCategories();
|
|
133
|
+
httpClient.handleCategories().then(loader);
|
|
131
134
|
return next(input);
|
|
132
135
|
}
|
|
133
136
|
var middlewareClient = new MiddlewareClient(container);
|
|
134
137
|
// this is an update check, as it requires
|
|
135
138
|
// a lot different logic and no user message
|
|
136
139
|
if (middlewareClient.checkForUpdate(input)) {
|
|
137
|
-
httpClient.handleUpdate(input);
|
|
140
|
+
httpClient.handleUpdate(input).then(loader);
|
|
138
141
|
return next(input);
|
|
139
142
|
}
|
|
140
143
|
chatClient.printUserMessageAndStoreIt(input);
|
|
141
|
-
httpClient.handleInput(input);
|
|
144
|
+
httpClient.handleInput(input).then(loader);
|
|
142
145
|
return next(input);
|
|
143
146
|
});
|
|
144
147
|
});
|
|
@@ -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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 && !!o.message; })), _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) {
|
|
@@ -7,12 +7,13 @@ 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):
|
|
13
|
-
handleInput(action: string): void
|
|
14
|
-
handleCategories(): void
|
|
15
|
-
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>;
|
|
16
17
|
private postAndHandleTheData;
|
|
17
18
|
private postAndHandleTheUpdateData;
|
|
18
19
|
private getHttpOptions;
|
|
@@ -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,42 +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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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);
|
|
44
105
|
};
|
|
45
106
|
// for category burger
|
|
46
107
|
HttpClient.prototype.handleCategories = function () {
|
|
47
108
|
var envelope = this.constructCategoriesEnvelope();
|
|
48
|
-
this.postAndHandleTheData(envelope);
|
|
109
|
+
return this.postAndHandleTheData(envelope);
|
|
49
110
|
};
|
|
50
111
|
// for text entries by user
|
|
51
112
|
HttpClient.prototype.handlePhrase = function (phrase) {
|
|
52
113
|
var envelope = this.constructPhraseEnvelope(phrase);
|
|
53
|
-
|
|
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);
|
|
54
135
|
};
|
|
55
136
|
HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
|
|
56
137
|
var _this = this;
|
|
@@ -120,10 +201,10 @@ var HttpClient = /** @class */ (function () {
|
|
|
120
201
|
};
|
|
121
202
|
HttpClient.prototype.handleResponseData = function (envelope, action) {
|
|
122
203
|
StoreHelper.setGlobalState(envelope.globalState);
|
|
123
|
-
this.middlewareClient.handleEntries(envelope.entries, action);
|
|
204
|
+
return this.middlewareClient.handleEntries(envelope.entries, action);
|
|
124
205
|
};
|
|
125
206
|
HttpClient.prototype.handleUpdateResponseData = function (envelope, action) {
|
|
126
|
-
this.middlewareClient.handleUpdate(envelope.entries, action);
|
|
207
|
+
return this.middlewareClient.handleUpdate(envelope.entries, action);
|
|
127
208
|
};
|
|
128
209
|
return HttpClient;
|
|
129
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|