@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.35 → 0.0.1-alpha.39
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/LICENSE.txt +5 -5
- package/README.md +12 -12
- package/lib/client/chat.client.d.ts +16 -16
- package/lib/client/chat.client.js +79 -79
- package/lib/client/contact-method.client.d.ts +30 -25
- package/lib/client/contact-method.client.js +292 -282
- package/lib/client/http.client.d.ts +25 -23
- package/lib/client/http.client.js +130 -113
- package/lib/client/middleware.client.d.ts +14 -14
- package/lib/client/middleware.client.js +115 -118
- package/lib/contract/custom-component/contact-method-item.d.ts +8 -8
- package/lib/contract/custom-component/contact-method-item.js +54 -54
- package/lib/contract/custom-component/contact-method-list.d.ts +7 -7
- package/lib/contract/custom-component/contact-method-list.js +13 -13
- package/lib/contract/custom-component/contact-method.d.ts +3 -3
- package/lib/contract/custom-component/contact-method.js +34 -34
- package/lib/contract/enum/server-entry-type.enum.d.ts +7 -7
- package/lib/contract/enum/server-entry-type.enum.js +8 -8
- package/lib/contract/model/conversation-api-model/list.model.d.ts +5 -5
- package/lib/contract/model/conversation-api-model/list.model.js +1 -0
- package/lib/contract/model/conversation-api-model/message.model.d.ts +7 -7
- package/lib/contract/model/conversation-api-model/message.model.js +1 -0
- package/lib/contract/model/http/action.model.d.ts +3 -3
- package/lib/contract/model/http/action.model.js +1 -0
- package/lib/contract/model/http/client-action.model.d.ts +4 -4
- package/lib/contract/model/http/client-action.model.js +2 -1
- package/lib/contract/model/http/client-envelope.model.d.ts +9 -9
- package/lib/contract/model/http/client-envelope.model.js +1 -0
- package/lib/contract/model/http/connect-options.model.d.ts +5 -5
- package/lib/contract/model/http/connect-options.model.js +1 -0
- package/lib/contract/model/http/global-state.model.d.ts +8 -8
- package/lib/contract/model/http/global-state.model.js +1 -0
- package/lib/contract/model/http/http-client-options.model.d.ts +5 -5
- package/lib/contract/model/http/http-client-options.model.js +1 -0
- package/lib/contract/model/http/server-entry.model.d.ts +11 -11
- package/lib/contract/model/http/server-entry.model.js +1 -0
- package/lib/contract/model/http/server-envelope.model.d.ts +10 -10
- package/lib/contract/model/http/server-envelope.model.js +1 -0
- package/lib/contract/model/middleware/aggregator-state.model.d.ts +4 -4
- package/lib/contract/model/middleware/aggregator-state.model.js +2 -1
- package/lib/contract/model/shared/loose-object.model.d.ts +3 -3
- package/lib/contract/model/shared/loose-object.model.js +1 -0
- package/lib/helper/chat.helper.d.ts +8 -8
- package/lib/helper/chat.helper.js +18 -18
- package/lib/helper/http.helper.d.ts +13 -13
- package/lib/helper/http.helper.js +28 -28
- package/lib/helper/middleware.helper.d.ts +12 -12
- package/lib/helper/middleware.helper.js +69 -67
- package/lib/helper/store.helper.d.ts +22 -22
- package/lib/helper/store.helper.js +77 -77
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/interface/entry.interface.d.ts +20 -20
- package/lib/interface/entry.interface.js +258 -262
- package/lib/interface/middleware/paging.interface.d.ts +4 -4
- package/lib/interface/middleware/paging.interface.js +53 -53
- package/lib/interface/middleware/processor.interface.d.ts +10 -10
- package/lib/interface/middleware/processor.interface.js +118 -118
- package/lib/plugin.d.ts +3 -3
- package/lib/plugin.js +149 -139
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +5 -0
- package/lib-esm/client/chat.client.d.ts +16 -16
- package/lib-esm/client/chat.client.js +79 -79
- package/lib-esm/client/contact-method.client.d.ts +30 -25
- package/lib-esm/client/contact-method.client.js +292 -282
- package/lib-esm/client/http.client.d.ts +25 -23
- package/lib-esm/client/http.client.js +130 -113
- package/lib-esm/client/middleware.client.d.ts +14 -14
- package/lib-esm/client/middleware.client.js +115 -118
- package/lib-esm/contract/custom-component/contact-method-item.d.ts +8 -8
- package/lib-esm/contract/custom-component/contact-method-item.js +54 -54
- package/lib-esm/contract/custom-component/contact-method-list.d.ts +7 -7
- package/lib-esm/contract/custom-component/contact-method-list.js +13 -13
- package/lib-esm/contract/custom-component/contact-method.d.ts +3 -3
- package/lib-esm/contract/custom-component/contact-method.js +34 -34
- package/lib-esm/contract/enum/server-entry-type.enum.d.ts +7 -7
- package/lib-esm/contract/enum/server-entry-type.enum.js +8 -8
- package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +5 -5
- package/lib-esm/contract/model/conversation-api-model/list.model.js +1 -0
- package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +7 -7
- package/lib-esm/contract/model/conversation-api-model/message.model.js +1 -0
- package/lib-esm/contract/model/http/action.model.d.ts +3 -3
- package/lib-esm/contract/model/http/action.model.js +1 -0
- package/lib-esm/contract/model/http/client-action.model.d.ts +4 -4
- package/lib-esm/contract/model/http/client-action.model.js +2 -1
- package/lib-esm/contract/model/http/client-envelope.model.d.ts +9 -9
- package/lib-esm/contract/model/http/client-envelope.model.js +1 -0
- package/lib-esm/contract/model/http/connect-options.model.d.ts +5 -5
- package/lib-esm/contract/model/http/connect-options.model.js +1 -0
- package/lib-esm/contract/model/http/global-state.model.d.ts +8 -8
- package/lib-esm/contract/model/http/global-state.model.js +1 -0
- package/lib-esm/contract/model/http/http-client-options.model.d.ts +5 -5
- package/lib-esm/contract/model/http/http-client-options.model.js +1 -0
- package/lib-esm/contract/model/http/server-entry.model.d.ts +11 -11
- package/lib-esm/contract/model/http/server-entry.model.js +1 -0
- package/lib-esm/contract/model/http/server-envelope.model.d.ts +10 -10
- package/lib-esm/contract/model/http/server-envelope.model.js +1 -0
- package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +4 -4
- package/lib-esm/contract/model/middleware/aggregator-state.model.js +2 -1
- package/lib-esm/contract/model/shared/loose-object.model.d.ts +3 -3
- package/lib-esm/contract/model/shared/loose-object.model.js +1 -0
- package/lib-esm/helper/chat.helper.d.ts +8 -8
- package/lib-esm/helper/chat.helper.js +18 -18
- package/lib-esm/helper/http.helper.d.ts +13 -13
- package/lib-esm/helper/http.helper.js +28 -28
- package/lib-esm/helper/middleware.helper.d.ts +12 -12
- package/lib-esm/helper/middleware.helper.js +69 -67
- package/lib-esm/helper/store.helper.d.ts +22 -22
- package/lib-esm/helper/store.helper.js +77 -77
- package/lib-esm/index.d.ts +2 -2
- package/lib-esm/index.js +2 -2
- package/lib-esm/interface/entry.interface.d.ts +20 -20
- package/lib-esm/interface/entry.interface.js +258 -262
- package/lib-esm/interface/middleware/paging.interface.d.ts +4 -4
- package/lib-esm/interface/middleware/paging.interface.js +53 -53
- package/lib-esm/interface/middleware/processor.interface.d.ts +10 -10
- package/lib-esm/interface/middleware/processor.interface.js +118 -118
- package/lib-esm/plugin.d.ts +3 -3
- package/lib-esm/plugin.js +149 -139
- package/lib-esm/utils.d.ts +1 -0
- package/lib-esm/utils.js +5 -0
- package/package.json +15 -24
- package/lib/interface/_mocked-contact-method.json +0 -375
- package/lib/interface/convert.d.ts +0 -1
- package/lib/interface/convert.js +0 -68
- package/lib-esm/interface/_mocked-contact-method.json +0 -375
- package/lib-esm/interface/convert.d.ts +0 -1
- package/lib-esm/interface/convert.js +0 -68
|
@@ -1,113 +1,130 @@
|
|
|
1
|
-
import { HttpHelper } from '../helper/http.helper';
|
|
2
|
-
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
3
|
-
import { StoreHelper } from '../helper/store.helper';
|
|
4
|
-
import ChatClient from './chat.client';
|
|
5
|
-
import MiddlewareClient from './middleware.client';
|
|
6
|
-
var HttpClient = /** @class */ (function () {
|
|
7
|
-
function HttpClient(endpoint, clientId, container) {
|
|
8
|
-
this.options = {
|
|
9
|
-
credentials: HttpHelper.getCredentials(),
|
|
10
|
-
clientId: clientId,
|
|
11
|
-
};
|
|
12
|
-
this.apiEndpoint = endpoint;
|
|
13
|
-
this.projectionPath = window.location.href;
|
|
14
|
-
this.endpointUrl = HttpHelper.combineUrl(this.projectionPath, 'conversations');
|
|
15
|
-
this.clientId = this.options.clientId;
|
|
16
|
-
this.middlewareClient = new MiddlewareClient(container);
|
|
17
|
-
this.chatClient = new ChatClient(container);
|
|
18
|
-
}
|
|
19
|
-
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
|
-
}
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
// for updates, such as paging changes
|
|
33
|
-
HttpClient.prototype.handleUpdate = function (action) {
|
|
34
|
-
var envelope = this.constructInputEnvelope(action);
|
|
35
|
-
this.postAndHandleTheUpdateData(envelope, action);
|
|
36
|
-
// return this.postAndReturnTheData(envelope, action).then((o) => {
|
|
37
|
-
// return o.entries;
|
|
38
|
-
// });
|
|
39
|
-
};
|
|
40
|
-
// for action clicks
|
|
41
|
-
HttpClient.prototype.handleInput = function (action) {
|
|
42
|
-
var envelope = this.constructInputEnvelope(action);
|
|
43
|
-
this.postAndHandleTheData(envelope, action);
|
|
44
|
-
};
|
|
45
|
-
// for
|
|
46
|
-
HttpClient.prototype.
|
|
47
|
-
var envelope = this.
|
|
48
|
-
this.postAndHandleTheData(envelope);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.then(function (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.then(function (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
1
|
+
import { HttpHelper } from '../helper/http.helper';
|
|
2
|
+
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
3
|
+
import { StoreHelper } from '../helper/store.helper';
|
|
4
|
+
import ChatClient from './chat.client';
|
|
5
|
+
import MiddlewareClient from './middleware.client';
|
|
6
|
+
var HttpClient = /** @class */ (function () {
|
|
7
|
+
function HttpClient(endpoint, clientId, container) {
|
|
8
|
+
this.options = {
|
|
9
|
+
credentials: HttpHelper.getCredentials(),
|
|
10
|
+
clientId: clientId,
|
|
11
|
+
};
|
|
12
|
+
this.apiEndpoint = endpoint;
|
|
13
|
+
this.projectionPath = window.location.href;
|
|
14
|
+
this.endpointUrl = HttpHelper.combineUrl(this.projectionPath, 'conversations');
|
|
15
|
+
this.clientId = this.options.clientId;
|
|
16
|
+
this.middlewareClient = new MiddlewareClient(container);
|
|
17
|
+
this.chatClient = new ChatClient(container);
|
|
18
|
+
}
|
|
19
|
+
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
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
// for updates, such as paging changes
|
|
33
|
+
HttpClient.prototype.handleUpdate = function (action) {
|
|
34
|
+
var envelope = this.constructInputEnvelope(action);
|
|
35
|
+
this.postAndHandleTheUpdateData(envelope, action);
|
|
36
|
+
// return this.postAndReturnTheData(envelope, action).then((o) => {
|
|
37
|
+
// return o.entries;
|
|
38
|
+
// });
|
|
39
|
+
};
|
|
40
|
+
// for action clicks
|
|
41
|
+
HttpClient.prototype.handleInput = function (action) {
|
|
42
|
+
var envelope = this.constructInputEnvelope(action);
|
|
43
|
+
this.postAndHandleTheData(envelope, action);
|
|
44
|
+
};
|
|
45
|
+
// for category burger
|
|
46
|
+
HttpClient.prototype.handleCategories = function () {
|
|
47
|
+
var envelope = this.constructCategoriesEnvelope();
|
|
48
|
+
this.postAndHandleTheData(envelope);
|
|
49
|
+
};
|
|
50
|
+
// for text entries by user
|
|
51
|
+
HttpClient.prototype.handlePhrase = function (phrase) {
|
|
52
|
+
var envelope = this.constructPhraseEnvelope(phrase);
|
|
53
|
+
this.postAndHandleTheData(envelope);
|
|
54
|
+
};
|
|
55
|
+
HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
|
|
56
|
+
var _this = this;
|
|
57
|
+
return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
|
|
58
|
+
.then(function (response) {
|
|
59
|
+
if (response.ok)
|
|
60
|
+
return response.json();
|
|
61
|
+
throw response;
|
|
62
|
+
})
|
|
63
|
+
.then(function (data) {
|
|
64
|
+
_this.handleResponseData(data, action);
|
|
65
|
+
})
|
|
66
|
+
.catch(function (err) { return console.log(err); });
|
|
67
|
+
};
|
|
68
|
+
HttpClient.prototype.postAndHandleTheUpdateData = function (envelope, action) {
|
|
69
|
+
var _this = this;
|
|
70
|
+
return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
|
|
71
|
+
.then(function (response) {
|
|
72
|
+
if (response.ok)
|
|
73
|
+
return response.json();
|
|
74
|
+
throw response;
|
|
75
|
+
})
|
|
76
|
+
.then(function (data) {
|
|
77
|
+
_this.handleUpdateResponseData(data, action);
|
|
78
|
+
})
|
|
79
|
+
.catch(function (err) { return console.log(err); });
|
|
80
|
+
};
|
|
81
|
+
HttpClient.prototype.getHttpOptions = function (envelope) {
|
|
82
|
+
return Object.assign({}, HttpHelper.fetchOptions, {
|
|
83
|
+
body: JSON.stringify(envelope),
|
|
84
|
+
credentials: this.options.credentials,
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
HttpClient.prototype.constructInputEnvelope = function (action) {
|
|
88
|
+
return {
|
|
89
|
+
action: StoreHelper.getAction(action),
|
|
90
|
+
localState: StoreHelper.getLocalState(action),
|
|
91
|
+
globalState: StoreHelper.getGlobalState(),
|
|
92
|
+
clientId: this.clientId,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
HttpClient.prototype.constructCategoriesEnvelope = function () {
|
|
96
|
+
return {
|
|
97
|
+
action: {
|
|
98
|
+
content: {
|
|
99
|
+
$type: 'Humany.Matching.Bots.Conversations.Actions.BrowseCategories, Humany.Matching',
|
|
100
|
+
},
|
|
101
|
+
key: 'browseCategories',
|
|
102
|
+
},
|
|
103
|
+
globalState: StoreHelper.getGlobalState(),
|
|
104
|
+
clientId: this.clientId,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
HttpClient.prototype.constructPhraseEnvelope = function (phrase) {
|
|
108
|
+
return {
|
|
109
|
+
command: { phrase: phrase },
|
|
110
|
+
globalState: StoreHelper.getGlobalState(),
|
|
111
|
+
clientId: this.clientId,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
HttpClient.prototype.constructFirstHitEnvelope = function () {
|
|
115
|
+
return {
|
|
116
|
+
command: { site: this.endpointUrl },
|
|
117
|
+
clientId: this.clientId,
|
|
118
|
+
globalState: {},
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
HttpClient.prototype.handleResponseData = function (envelope, action) {
|
|
122
|
+
StoreHelper.setGlobalState(envelope.globalState);
|
|
123
|
+
this.middlewareClient.handleEntries(envelope.entries, action);
|
|
124
|
+
};
|
|
125
|
+
HttpClient.prototype.handleUpdateResponseData = function (envelope, action) {
|
|
126
|
+
this.middlewareClient.handleUpdate(envelope.entries, action);
|
|
127
|
+
};
|
|
128
|
+
return HttpClient;
|
|
129
|
+
}());
|
|
130
|
+
export { HttpClient };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Container } from '@webprovisions/platform';
|
|
2
|
-
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
3
|
-
export default class MiddlewareClient {
|
|
4
|
-
private paging;
|
|
5
|
-
private processor;
|
|
6
|
-
private entryInterface;
|
|
7
|
-
private chatClient;
|
|
8
|
-
constructor(container: Container);
|
|
9
|
-
static initialize(container: any, widget: any): void;
|
|
10
|
-
handleEntries(entries: ServerEntry[], action?: string): Promise<void>;
|
|
11
|
-
handleUpdate(entries: ServerEntry[], action?: string): Promise<void>;
|
|
12
|
-
checkForUpdate(input: string): boolean;
|
|
13
|
-
private executeMiddlewares;
|
|
14
|
-
}
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
2
|
+
import { ServerEntry } from '../contract/model/http/server-entry.model';
|
|
3
|
+
export default class MiddlewareClient {
|
|
4
|
+
private paging;
|
|
5
|
+
private processor;
|
|
6
|
+
private entryInterface;
|
|
7
|
+
private chatClient;
|
|
8
|
+
constructor(container: Container);
|
|
9
|
+
static initialize(container: any, widget: any): void;
|
|
10
|
+
handleEntries(entries: ServerEntry[], action?: string): Promise<void>;
|
|
11
|
+
handleUpdate(entries: ServerEntry[], action?: string): Promise<void>;
|
|
12
|
+
checkForUpdate(input: string): boolean;
|
|
13
|
+
private executeMiddlewares;
|
|
14
|
+
}
|
|
@@ -1,118 +1,115 @@
|
|
|
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 { ChatHelper } from '../helper/chat.helper';
|
|
38
|
-
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
39
|
-
import { StoreHelper } from '../helper/store.helper';
|
|
40
|
-
import EntryInterface from '../interface/entry.interface';
|
|
41
|
-
import PagingInterface from '../interface/middleware/paging.interface';
|
|
42
|
-
import ProcessorInterface from '../interface/middleware/processor.interface';
|
|
43
|
-
import ChatClient from './chat.client';
|
|
44
|
-
var MiddlewareClient = /** @class */ (function () {
|
|
45
|
-
function MiddlewareClient(container) {
|
|
46
|
-
this.paging = new PagingInterface();
|
|
47
|
-
this.processor = new ProcessorInterface();
|
|
48
|
-
this.entryInterface = new EntryInterface(container);
|
|
49
|
-
this.chatClient = new ChatClient(container);
|
|
50
|
-
}
|
|
51
|
-
MiddlewareClient.initialize = function (container, widget) {
|
|
52
|
-
MiddlewareHelper.setContainer(container);
|
|
53
|
-
MiddlewareHelper.setWidget(widget);
|
|
54
|
-
};
|
|
55
|
-
// called on all standard scenarios like actions and user messages
|
|
56
|
-
MiddlewareClient.prototype.handleEntries = function (entries, action) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var widgetEntry, agent, o, messageArray;
|
|
59
|
-
return __generator(this, function (_a) {
|
|
60
|
-
switch (_a.label) {
|
|
61
|
-
case 0:
|
|
62
|
-
widgetEntry = (entries || []).find(function (e) { return e.type === 'Widget'; });
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
case
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
MiddlewareClient.prototype.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return MiddlewareClient;
|
|
117
|
-
}());
|
|
118
|
-
export default MiddlewareClient;
|
|
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 { ChatHelper } from '../helper/chat.helper';
|
|
38
|
+
import { MiddlewareHelper } from '../helper/middleware.helper';
|
|
39
|
+
import { StoreHelper } from '../helper/store.helper';
|
|
40
|
+
import EntryInterface from '../interface/entry.interface';
|
|
41
|
+
import PagingInterface from '../interface/middleware/paging.interface';
|
|
42
|
+
import ProcessorInterface from '../interface/middleware/processor.interface';
|
|
43
|
+
import ChatClient from './chat.client';
|
|
44
|
+
var MiddlewareClient = /** @class */ (function () {
|
|
45
|
+
function MiddlewareClient(container) {
|
|
46
|
+
this.paging = new PagingInterface();
|
|
47
|
+
this.processor = new ProcessorInterface();
|
|
48
|
+
this.entryInterface = new EntryInterface(container);
|
|
49
|
+
this.chatClient = new ChatClient(container);
|
|
50
|
+
}
|
|
51
|
+
MiddlewareClient.initialize = function (container, widget) {
|
|
52
|
+
MiddlewareHelper.setContainer(container);
|
|
53
|
+
MiddlewareHelper.setWidget(widget);
|
|
54
|
+
};
|
|
55
|
+
// called on all standard scenarios like actions and user messages
|
|
56
|
+
MiddlewareClient.prototype.handleEntries = function (entries, action) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var widgetEntry, agent, o, messageArray;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
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
|
+
}
|
|
72
|
+
o = this.executeMiddlewares(entries, false, action);
|
|
73
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
74
|
+
case 1:
|
|
75
|
+
messageArray = _a.sent();
|
|
76
|
+
this.chatClient.processMessageArrayAndStoreIt(messageArray);
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
// called on situations such as paging changes
|
|
83
|
+
// when no new entries will be printed
|
|
84
|
+
MiddlewareClient.prototype.handleUpdate = function (entries, action) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var o, messageArray;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
o = this.executeMiddlewares(entries, true, action);
|
|
91
|
+
return [4 /*yield*/, this.entryInterface.transformArray(o)];
|
|
92
|
+
case 1:
|
|
93
|
+
messageArray = _a.sent();
|
|
94
|
+
this.chatClient.updateMessageArrayAndStoreIt(messageArray);
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
// checks whether the action was of an update type
|
|
101
|
+
MiddlewareClient.prototype.checkForUpdate = function (input) {
|
|
102
|
+
return input === 'next';
|
|
103
|
+
};
|
|
104
|
+
MiddlewareClient.prototype.executeMiddlewares = function (entries, isUpdate, action) {
|
|
105
|
+
if (isUpdate && action)
|
|
106
|
+
entries = this.processor.processUpdate(StoreHelper.getEntry(action), entries);
|
|
107
|
+
else {
|
|
108
|
+
entries = this.processor.process(entries);
|
|
109
|
+
}
|
|
110
|
+
entries = this.paging.process(entries);
|
|
111
|
+
return entries;
|
|
112
|
+
};
|
|
113
|
+
return MiddlewareClient;
|
|
114
|
+
}());
|
|
115
|
+
export default MiddlewareClient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
interface PropsType {
|
|
3
|
-
contactMethod: any;
|
|
4
|
-
type: any;
|
|
5
|
-
className?: any;
|
|
6
|
-
}
|
|
7
|
-
declare const ContactMethodItem: React.FC<PropsType>;
|
|
8
|
-
export default ContactMethodItem;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface PropsType {
|
|
3
|
+
contactMethod: any;
|
|
4
|
+
type: any;
|
|
5
|
+
className?: any;
|
|
6
|
+
}
|
|
7
|
+
declare const ContactMethodItem: React.FC<PropsType>;
|
|
8
|
+
export default ContactMethodItem;
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
-
if (!m) return o;
|
|
15
|
-
var i = m.call(o), r, ar = [], e;
|
|
16
|
-
try {
|
|
17
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
-
}
|
|
19
|
-
catch (error) { e = { error: error }; }
|
|
20
|
-
finally {
|
|
21
|
-
try {
|
|
22
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
-
}
|
|
24
|
-
finally { if (e) throw e.error; }
|
|
25
|
-
}
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
import { ContactMethod as GenericContactMethod } from '@
|
|
29
|
-
import { useContainer, useDispatch } from '@
|
|
30
|
-
import React, { useEffect, useState } from 'react';
|
|
31
|
-
var ContactMethodItem = function (props) {
|
|
32
|
-
var dispatch = useDispatch();
|
|
33
|
-
var container = useContainer();
|
|
34
|
-
var _a = __read(useState(props.contactMethod.body), 2), body = _a[0], setBody = _a[1];
|
|
35
|
-
useEffect(function () {
|
|
36
|
-
if (!container || !container.get('$widget')) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
var events = container.get('$widget').events;
|
|
40
|
-
events.subscribe('form:validated', function (_event, _data) {
|
|
41
|
-
// TODO: this is a due to props not being updated when props.contactMethod.body changes
|
|
42
|
-
// perhaps there is a cleaner way of doing this
|
|
43
|
-
setBody(props.contactMethod.body);
|
|
44
|
-
});
|
|
45
|
-
}, [container]);
|
|
46
|
-
return (React.createElement(GenericContactMethod, __assign({ className: props.className, onClick: function () {
|
|
47
|
-
dispatch('action', props.contactMethod.id
|
|
48
|
-
// dispatch(
|
|
49
|
-
// "expand",
|
|
50
|
-
// `${props.contactMethod.id}/${props.type.toString()}`
|
|
51
|
-
// );
|
|
52
|
-
}, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
|
|
53
|
-
};
|
|
54
|
-
export default ContactMethodItem;
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
import { ContactMethod as GenericContactMethod } from '@telia-ace/knowledge-widget-adapters';
|
|
29
|
+
import { useContainer, useDispatch } from '@telia-ace/knowledge-widget-ui';
|
|
30
|
+
import React, { useEffect, useState } from 'react';
|
|
31
|
+
var ContactMethodItem = function (props) {
|
|
32
|
+
var dispatch = useDispatch();
|
|
33
|
+
var container = useContainer();
|
|
34
|
+
var _a = __read(useState(props.contactMethod.body), 2), body = _a[0], setBody = _a[1];
|
|
35
|
+
useEffect(function () {
|
|
36
|
+
if (!container || !container.get('$widget')) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
var events = container.get('$widget').events;
|
|
40
|
+
events.subscribe('form:validated', function (_event, _data) {
|
|
41
|
+
// TODO: this is a due to props not being updated when props.contactMethod.body changes
|
|
42
|
+
// perhaps there is a cleaner way of doing this
|
|
43
|
+
setBody(props.contactMethod.body);
|
|
44
|
+
});
|
|
45
|
+
}, [container]);
|
|
46
|
+
return (React.createElement(GenericContactMethod, __assign({ className: props.className, onClick: function () {
|
|
47
|
+
dispatch('action', "".concat(props.contactMethod.id, "/").concat(props.type.toString(), "/").concat(props.contactMethod.title));
|
|
48
|
+
// dispatch(
|
|
49
|
+
// "expand",
|
|
50
|
+
// `${props.contactMethod.id}/${props.type.toString()}`
|
|
51
|
+
// );
|
|
52
|
+
}, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
|
|
53
|
+
};
|
|
54
|
+
export default ContactMethodItem;
|