@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.
- package/lib/client/chat.client.d.ts +1 -1
- package/lib/client/chat.client.js +75 -9
- package/lib/client/contact-method.client.d.ts +5 -0
- package/lib/client/contact-method.client.js +10 -0
- package/lib/client/http.client.d.ts +7 -4
- package/lib/client/http.client.js +116 -18
- 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.js +8 -14
- package/lib/plugin.js +21 -7
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +5 -0
- package/lib-esm/client/chat.client.d.ts +1 -1
- package/lib-esm/client/chat.client.js +75 -9
- package/lib-esm/client/contact-method.client.d.ts +5 -0
- package/lib-esm/client/contact-method.client.js +10 -0
- package/lib-esm/client/http.client.d.ts +7 -4
- package/lib-esm/client/http.client.js +116 -18
- 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.js +8 -14
- package/lib-esm/plugin.js +21 -7
- package/lib-esm/utils.d.ts +1 -0
- package/lib-esm/utils.js +5 -0
- package/package.json +5 -5
package/lib/plugin.js
CHANGED
|
@@ -36,12 +36,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import { ContactMethodPlatform } from '@telia-ace/knowledge-widget-adapters';
|
|
38
38
|
import { DataClient } from '@telia-ace/knowledge-widget-types-grid';
|
|
39
|
-
import { ConversationPlatform, registerCustomMessageComponent } from '@telia-ace/widget-conversation';
|
|
39
|
+
import { ConversationPlatform, registerCustomMessageComponent, } from '@telia-ace/widget-conversation';
|
|
40
40
|
import { v4 } from 'uuid';
|
|
41
41
|
import ChatClient from './client/chat.client';
|
|
42
42
|
import { ContactMethodClient } from './client/contact-method.client';
|
|
43
43
|
import { HttpClient } from './client/http.client';
|
|
44
44
|
import MiddlewareClient from './client/middleware.client';
|
|
45
|
+
import { getContactMethodEntry } from './utils';
|
|
45
46
|
var getKnowledgeBotEndpoint = function (container, component /*: ComponentNodeController */
|
|
46
47
|
// ComponentNodeController type differs from component passed into registerProvider
|
|
47
48
|
) {
|
|
@@ -83,7 +84,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
83
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
84
85
|
// executes to decide on what to do on first load
|
|
85
86
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
86
|
-
|
|
87
|
+
var firstLoader = conversation.loading();
|
|
88
|
+
httpClient.firstHit().then(firstLoader);
|
|
87
89
|
component.actions.create('evaluate', function (input) {
|
|
88
90
|
var cmClient = new ContactMethodClient(container);
|
|
89
91
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
@@ -93,6 +95,12 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
93
95
|
cmClient.validate(input.form);
|
|
94
96
|
});
|
|
95
97
|
component.actions.create('submit', function (input) {
|
|
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
|
+
}
|
|
96
104
|
var cmClient = new ContactMethodClient(container);
|
|
97
105
|
cmClient.validate(input.form);
|
|
98
106
|
});
|
|
@@ -101,7 +109,8 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
101
109
|
});
|
|
102
110
|
component.actions.watch('conversation.user-submit', function (input, next) {
|
|
103
111
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
104
|
-
|
|
112
|
+
var loader = conversation.loading();
|
|
113
|
+
httpClient.handlePhrase(input.text).then(loader);
|
|
105
114
|
return next(input);
|
|
106
115
|
});
|
|
107
116
|
component.actions.watch('conversation.form', function (input, next) {
|
|
@@ -114,20 +123,25 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
114
123
|
// cmClient.handleContactMethod(input);
|
|
115
124
|
// return next(input);
|
|
116
125
|
// }
|
|
126
|
+
var loader = conversation.loading();
|
|
117
127
|
if (input.split('/').length > 1) {
|
|
118
|
-
cmClient.handleContactMethod(input);
|
|
128
|
+
cmClient.handleContactMethod(input).then(loader);
|
|
119
129
|
return next(input);
|
|
120
130
|
}
|
|
121
|
-
var middlewareClient = new MiddlewareClient(container);
|
|
122
131
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
132
|
+
if (input == 'burger-clicked') {
|
|
133
|
+
httpClient.handleCategories().then(loader);
|
|
134
|
+
return next(input);
|
|
135
|
+
}
|
|
136
|
+
var middlewareClient = new MiddlewareClient(container);
|
|
123
137
|
// this is an update check, as it requires
|
|
124
138
|
// a lot different logic and no user message
|
|
125
139
|
if (middlewareClient.checkForUpdate(input)) {
|
|
126
|
-
httpClient.handleUpdate(input);
|
|
140
|
+
httpClient.handleUpdate(input).then(loader);
|
|
127
141
|
return next(input);
|
|
128
142
|
}
|
|
129
143
|
chatClient.printUserMessageAndStoreIt(input);
|
|
130
|
-
httpClient.handleInput(input);
|
|
144
|
+
httpClient.handleInput(input).then(loader);
|
|
131
145
|
return next(input);
|
|
132
146
|
});
|
|
133
147
|
});
|
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
|
@@ -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; })), _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):
|
|
13
|
-
handleInput(action: string): void
|
|
14
|
-
|
|
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
|
-
|
|
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);
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|