@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.31 → 0.0.1-alpha.34
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/http.client.d.ts +1 -1
- package/lib/client/http.client.js +8 -55
- package/lib/plugin.js +10 -18
- package/lib-esm/client/http.client.d.ts +1 -1
- package/lib-esm/client/http.client.js +8 -55
- package/lib-esm/plugin.js +10 -18
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ export declare class HttpClient {
|
|
|
8
8
|
private middlewareClient;
|
|
9
9
|
private chatClient;
|
|
10
10
|
constructor(endpoint: string, clientId: string, container: Container);
|
|
11
|
-
firstHit():
|
|
11
|
+
firstHit(): void;
|
|
12
12
|
handleUpdate(action: string): void;
|
|
13
13
|
handleInput(action: string): void;
|
|
14
14
|
handlePhrase(phrase: string): void;
|
|
@@ -1,39 +1,3 @@
|
|
|
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
1
|
import { HttpHelper } from '../helper/http.helper';
|
|
38
2
|
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
39
3
|
import { StoreHelper } from '../helper/store.helper';
|
|
@@ -56,24 +20,14 @@ var HttpClient = /** @class */ (function () {
|
|
|
56
20
|
var _this = this;
|
|
57
21
|
// On first hit if there are entries stored in the storage, use them
|
|
58
22
|
// Otherwise start a new session
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
case 1:
|
|
68
|
-
envelope = this.constructFirstHitEnvelope();
|
|
69
|
-
return [4 /*yield*/, this.postAndHandleTheData(envelope)];
|
|
70
|
-
case 2:
|
|
71
|
-
response = _a.sent();
|
|
72
|
-
return [2 /*return*/, response];
|
|
73
|
-
case 3: return [2 /*return*/];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}); });
|
|
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
|
+
}
|
|
30
|
+
});
|
|
77
31
|
};
|
|
78
32
|
// for updates, such as paging changes
|
|
79
33
|
HttpClient.prototype.handleUpdate = function (action) {
|
|
@@ -103,7 +57,6 @@ var HttpClient = /** @class */ (function () {
|
|
|
103
57
|
})
|
|
104
58
|
.then(function (data) {
|
|
105
59
|
_this.handleResponseData(data, action);
|
|
106
|
-
return data;
|
|
107
60
|
})
|
|
108
61
|
.catch(function (err) { return console.log(err); });
|
|
109
62
|
};
|
package/lib/plugin.js
CHANGED
|
@@ -71,28 +71,20 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
71
71
|
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
72
72
|
var endpoint = getKnowledgeBotEndpoint(container, component);
|
|
73
73
|
var clientId = v4();
|
|
74
|
+
var agent = conversation.createAgent({
|
|
75
|
+
// TODO: needs to be fixed asap
|
|
76
|
+
name: 'John Doe',
|
|
77
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
78
|
+
});
|
|
79
|
+
// passes the user and the agent to the Chat Helper
|
|
80
|
+
ChatClient.initialize(conversation.user, agent);
|
|
81
|
+
// passes the conversation provider to the Contact Method Client
|
|
82
|
+
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
74
83
|
// passes the container and the widget to the Middleware Store
|
|
75
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
76
85
|
// executes to decide on what to do on first load
|
|
77
86
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
78
|
-
httpClient.firstHit()
|
|
79
|
-
if (response) {
|
|
80
|
-
console.log('response from first hit', response);
|
|
81
|
-
var widgetEntry = ((response === null || response === void 0 ? void 0 : response.entries) || []).find(function (e) { return e.type === 'Widget'; });
|
|
82
|
-
if (widgetEntry) {
|
|
83
|
-
var agent = conversation.createAgent({
|
|
84
|
-
// TODO: needs to be fixed asap
|
|
85
|
-
name: 'John Doe',
|
|
86
|
-
avatar: 'https://www.site.com/avatar.jpg',
|
|
87
|
-
});
|
|
88
|
-
console.log('widget entry', widgetEntry);
|
|
89
|
-
// passes the user and the agent to the Chat Helper
|
|
90
|
-
ChatClient.initialize(conversation.user, agent);
|
|
91
|
-
// passes the conversation provider to the Contact Method Client
|
|
92
|
-
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
87
|
+
httpClient.firstHit();
|
|
96
88
|
component.actions.create('evaluate', function (input) {
|
|
97
89
|
var cmClient = new ContactMethodClient(container);
|
|
98
90
|
cmClient.handleNewForm(input.form, input.form.id);
|
|
@@ -8,7 +8,7 @@ export declare class HttpClient {
|
|
|
8
8
|
private middlewareClient;
|
|
9
9
|
private chatClient;
|
|
10
10
|
constructor(endpoint: string, clientId: string, container: Container);
|
|
11
|
-
firstHit():
|
|
11
|
+
firstHit(): void;
|
|
12
12
|
handleUpdate(action: string): void;
|
|
13
13
|
handleInput(action: string): void;
|
|
14
14
|
handlePhrase(phrase: string): void;
|
|
@@ -1,39 +1,3 @@
|
|
|
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
1
|
import { HttpHelper } from '../helper/http.helper';
|
|
38
2
|
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
39
3
|
import { StoreHelper } from '../helper/store.helper';
|
|
@@ -56,24 +20,14 @@ var HttpClient = /** @class */ (function () {
|
|
|
56
20
|
var _this = this;
|
|
57
21
|
// On first hit if there are entries stored in the storage, use them
|
|
58
22
|
// Otherwise start a new session
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
case 1:
|
|
68
|
-
envelope = this.constructFirstHitEnvelope();
|
|
69
|
-
return [4 /*yield*/, this.postAndHandleTheData(envelope)];
|
|
70
|
-
case 2:
|
|
71
|
-
response = _a.sent();
|
|
72
|
-
return [2 /*return*/, response];
|
|
73
|
-
case 3: return [2 /*return*/];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}); });
|
|
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
|
+
}
|
|
30
|
+
});
|
|
77
31
|
};
|
|
78
32
|
// for updates, such as paging changes
|
|
79
33
|
HttpClient.prototype.handleUpdate = function (action) {
|
|
@@ -103,7 +57,6 @@ var HttpClient = /** @class */ (function () {
|
|
|
103
57
|
})
|
|
104
58
|
.then(function (data) {
|
|
105
59
|
_this.handleResponseData(data, action);
|
|
106
|
-
return data;
|
|
107
60
|
})
|
|
108
61
|
.catch(function (err) { return console.log(err); });
|
|
109
62
|
};
|
package/lib-esm/plugin.js
CHANGED
|
@@ -71,28 +71,20 @@ var KnowledgeBotProviderPlugin = function (container) { return __awaiter(void 0,
|
|
|
71
71
|
platform.registerProvider('chat.bot', function (conversation, component) {
|
|
72
72
|
var endpoint = getKnowledgeBotEndpoint(container, component);
|
|
73
73
|
var clientId = v4();
|
|
74
|
+
var agent = conversation.createAgent({
|
|
75
|
+
// TODO: needs to be fixed asap
|
|
76
|
+
name: 'John Doe',
|
|
77
|
+
avatar: 'https://www.site.com/avatar.jpg',
|
|
78
|
+
});
|
|
79
|
+
// passes the user and the agent to the Chat Helper
|
|
80
|
+
ChatClient.initialize(conversation.user, agent);
|
|
81
|
+
// passes the conversation provider to the Contact Method Client
|
|
82
|
+
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
74
83
|
// passes the container and the widget to the Middleware Store
|
|
75
84
|
MiddlewareClient.initialize(container, container.get('$widget'));
|
|
76
85
|
// executes to decide on what to do on first load
|
|
77
86
|
var httpClient = new HttpClient(endpoint, clientId, container);
|
|
78
|
-
httpClient.firstHit()
|
|
79
|
-
if (response) {
|
|
80
|
-
console.log('response from first hit', response);
|
|
81
|
-
var widgetEntry = ((response === null || response === void 0 ? void 0 : response.entries) || []).find(function (e) { return e.type === 'Widget'; });
|
|
82
|
-
if (widgetEntry) {
|
|
83
|
-
var agent = conversation.createAgent({
|
|
84
|
-
// TODO: needs to be fixed asap
|
|
85
|
-
name: 'John Doe',
|
|
86
|
-
avatar: 'https://www.site.com/avatar.jpg',
|
|
87
|
-
});
|
|
88
|
-
console.log('widget entry', widgetEntry);
|
|
89
|
-
// passes the user and the agent to the Chat Helper
|
|
90
|
-
ChatClient.initialize(conversation.user, agent);
|
|
91
|
-
// passes the conversation provider to the Contact Method Client
|
|
92
|
-
ContactMethodClient.initialize(container, dataClient, contactMethodPlatform, agent);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
87
|
+
httpClient.firstHit();
|
|
96
88
|
component.actions.create('evaluate', function (input) {
|
|
97
89
|
var cmClient = new ContactMethodClient(container);
|
|
98
90
|
cmClient.handleNewForm(input.form, input.form.id);
|
package/package.json
CHANGED