@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.
Files changed (129) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +12 -12
  3. package/lib/client/chat.client.d.ts +16 -16
  4. package/lib/client/chat.client.js +79 -79
  5. package/lib/client/contact-method.client.d.ts +30 -25
  6. package/lib/client/contact-method.client.js +292 -282
  7. package/lib/client/http.client.d.ts +25 -23
  8. package/lib/client/http.client.js +130 -113
  9. package/lib/client/middleware.client.d.ts +14 -14
  10. package/lib/client/middleware.client.js +115 -118
  11. package/lib/contract/custom-component/contact-method-item.d.ts +8 -8
  12. package/lib/contract/custom-component/contact-method-item.js +54 -54
  13. package/lib/contract/custom-component/contact-method-list.d.ts +7 -7
  14. package/lib/contract/custom-component/contact-method-list.js +13 -13
  15. package/lib/contract/custom-component/contact-method.d.ts +3 -3
  16. package/lib/contract/custom-component/contact-method.js +34 -34
  17. package/lib/contract/enum/server-entry-type.enum.d.ts +7 -7
  18. package/lib/contract/enum/server-entry-type.enum.js +8 -8
  19. package/lib/contract/model/conversation-api-model/list.model.d.ts +5 -5
  20. package/lib/contract/model/conversation-api-model/list.model.js +1 -0
  21. package/lib/contract/model/conversation-api-model/message.model.d.ts +7 -7
  22. package/lib/contract/model/conversation-api-model/message.model.js +1 -0
  23. package/lib/contract/model/http/action.model.d.ts +3 -3
  24. package/lib/contract/model/http/action.model.js +1 -0
  25. package/lib/contract/model/http/client-action.model.d.ts +4 -4
  26. package/lib/contract/model/http/client-action.model.js +2 -1
  27. package/lib/contract/model/http/client-envelope.model.d.ts +9 -9
  28. package/lib/contract/model/http/client-envelope.model.js +1 -0
  29. package/lib/contract/model/http/connect-options.model.d.ts +5 -5
  30. package/lib/contract/model/http/connect-options.model.js +1 -0
  31. package/lib/contract/model/http/global-state.model.d.ts +8 -8
  32. package/lib/contract/model/http/global-state.model.js +1 -0
  33. package/lib/contract/model/http/http-client-options.model.d.ts +5 -5
  34. package/lib/contract/model/http/http-client-options.model.js +1 -0
  35. package/lib/contract/model/http/server-entry.model.d.ts +11 -11
  36. package/lib/contract/model/http/server-entry.model.js +1 -0
  37. package/lib/contract/model/http/server-envelope.model.d.ts +10 -10
  38. package/lib/contract/model/http/server-envelope.model.js +1 -0
  39. package/lib/contract/model/middleware/aggregator-state.model.d.ts +4 -4
  40. package/lib/contract/model/middleware/aggregator-state.model.js +2 -1
  41. package/lib/contract/model/shared/loose-object.model.d.ts +3 -3
  42. package/lib/contract/model/shared/loose-object.model.js +1 -0
  43. package/lib/helper/chat.helper.d.ts +8 -8
  44. package/lib/helper/chat.helper.js +18 -18
  45. package/lib/helper/http.helper.d.ts +13 -13
  46. package/lib/helper/http.helper.js +28 -28
  47. package/lib/helper/middleware.helper.d.ts +12 -12
  48. package/lib/helper/middleware.helper.js +69 -67
  49. package/lib/helper/store.helper.d.ts +22 -22
  50. package/lib/helper/store.helper.js +77 -77
  51. package/lib/index.d.ts +2 -2
  52. package/lib/index.js +2 -2
  53. package/lib/interface/entry.interface.d.ts +20 -20
  54. package/lib/interface/entry.interface.js +258 -262
  55. package/lib/interface/middleware/paging.interface.d.ts +4 -4
  56. package/lib/interface/middleware/paging.interface.js +53 -53
  57. package/lib/interface/middleware/processor.interface.d.ts +10 -10
  58. package/lib/interface/middleware/processor.interface.js +118 -118
  59. package/lib/plugin.d.ts +3 -3
  60. package/lib/plugin.js +149 -139
  61. package/lib/utils.d.ts +1 -0
  62. package/lib/utils.js +5 -0
  63. package/lib-esm/client/chat.client.d.ts +16 -16
  64. package/lib-esm/client/chat.client.js +79 -79
  65. package/lib-esm/client/contact-method.client.d.ts +30 -25
  66. package/lib-esm/client/contact-method.client.js +292 -282
  67. package/lib-esm/client/http.client.d.ts +25 -23
  68. package/lib-esm/client/http.client.js +130 -113
  69. package/lib-esm/client/middleware.client.d.ts +14 -14
  70. package/lib-esm/client/middleware.client.js +115 -118
  71. package/lib-esm/contract/custom-component/contact-method-item.d.ts +8 -8
  72. package/lib-esm/contract/custom-component/contact-method-item.js +54 -54
  73. package/lib-esm/contract/custom-component/contact-method-list.d.ts +7 -7
  74. package/lib-esm/contract/custom-component/contact-method-list.js +13 -13
  75. package/lib-esm/contract/custom-component/contact-method.d.ts +3 -3
  76. package/lib-esm/contract/custom-component/contact-method.js +34 -34
  77. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +7 -7
  78. package/lib-esm/contract/enum/server-entry-type.enum.js +8 -8
  79. package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +5 -5
  80. package/lib-esm/contract/model/conversation-api-model/list.model.js +1 -0
  81. package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +7 -7
  82. package/lib-esm/contract/model/conversation-api-model/message.model.js +1 -0
  83. package/lib-esm/contract/model/http/action.model.d.ts +3 -3
  84. package/lib-esm/contract/model/http/action.model.js +1 -0
  85. package/lib-esm/contract/model/http/client-action.model.d.ts +4 -4
  86. package/lib-esm/contract/model/http/client-action.model.js +2 -1
  87. package/lib-esm/contract/model/http/client-envelope.model.d.ts +9 -9
  88. package/lib-esm/contract/model/http/client-envelope.model.js +1 -0
  89. package/lib-esm/contract/model/http/connect-options.model.d.ts +5 -5
  90. package/lib-esm/contract/model/http/connect-options.model.js +1 -0
  91. package/lib-esm/contract/model/http/global-state.model.d.ts +8 -8
  92. package/lib-esm/contract/model/http/global-state.model.js +1 -0
  93. package/lib-esm/contract/model/http/http-client-options.model.d.ts +5 -5
  94. package/lib-esm/contract/model/http/http-client-options.model.js +1 -0
  95. package/lib-esm/contract/model/http/server-entry.model.d.ts +11 -11
  96. package/lib-esm/contract/model/http/server-entry.model.js +1 -0
  97. package/lib-esm/contract/model/http/server-envelope.model.d.ts +10 -10
  98. package/lib-esm/contract/model/http/server-envelope.model.js +1 -0
  99. package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +4 -4
  100. package/lib-esm/contract/model/middleware/aggregator-state.model.js +2 -1
  101. package/lib-esm/contract/model/shared/loose-object.model.d.ts +3 -3
  102. package/lib-esm/contract/model/shared/loose-object.model.js +1 -0
  103. package/lib-esm/helper/chat.helper.d.ts +8 -8
  104. package/lib-esm/helper/chat.helper.js +18 -18
  105. package/lib-esm/helper/http.helper.d.ts +13 -13
  106. package/lib-esm/helper/http.helper.js +28 -28
  107. package/lib-esm/helper/middleware.helper.d.ts +12 -12
  108. package/lib-esm/helper/middleware.helper.js +69 -67
  109. package/lib-esm/helper/store.helper.d.ts +22 -22
  110. package/lib-esm/helper/store.helper.js +77 -77
  111. package/lib-esm/index.d.ts +2 -2
  112. package/lib-esm/index.js +2 -2
  113. package/lib-esm/interface/entry.interface.d.ts +20 -20
  114. package/lib-esm/interface/entry.interface.js +258 -262
  115. package/lib-esm/interface/middleware/paging.interface.d.ts +4 -4
  116. package/lib-esm/interface/middleware/paging.interface.js +53 -53
  117. package/lib-esm/interface/middleware/processor.interface.d.ts +10 -10
  118. package/lib-esm/interface/middleware/processor.interface.js +118 -118
  119. package/lib-esm/plugin.d.ts +3 -3
  120. package/lib-esm/plugin.js +149 -139
  121. package/lib-esm/utils.d.ts +1 -0
  122. package/lib-esm/utils.js +5 -0
  123. package/package.json +15 -24
  124. package/lib/interface/_mocked-contact-method.json +0 -375
  125. package/lib/interface/convert.d.ts +0 -1
  126. package/lib/interface/convert.js +0 -68
  127. package/lib-esm/interface/_mocked-contact-method.json +0 -375
  128. package/lib-esm/interface/convert.d.ts +0 -1
  129. 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 text entries by user
46
- HttpClient.prototype.handlePhrase = function (phrase) {
47
- var envelope = this.constructPhraseEnvelope(phrase);
48
- this.postAndHandleTheData(envelope);
49
- };
50
- HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
51
- var _this = this;
52
- return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
53
- .then(function (response) {
54
- if (response.ok)
55
- return response.json();
56
- throw response;
57
- })
58
- .then(function (data) {
59
- _this.handleResponseData(data, action);
60
- })
61
- .catch(function (err) { return console.log(err); });
62
- };
63
- HttpClient.prototype.postAndHandleTheUpdateData = function (envelope, action) {
64
- var _this = this;
65
- return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
66
- .then(function (response) {
67
- if (response.ok)
68
- return response.json();
69
- throw response;
70
- })
71
- .then(function (data) {
72
- _this.handleUpdateResponseData(data, action);
73
- })
74
- .catch(function (err) { return console.log(err); });
75
- };
76
- HttpClient.prototype.getHttpOptions = function (envelope) {
77
- return Object.assign({}, HttpHelper.fetchOptions, {
78
- body: JSON.stringify(envelope),
79
- credentials: this.options.credentials,
80
- });
81
- };
82
- HttpClient.prototype.constructInputEnvelope = function (action) {
83
- return {
84
- action: StoreHelper.getAction(action),
85
- localState: StoreHelper.getLocalState(action),
86
- globalState: StoreHelper.getGlobalState(),
87
- clientId: this.clientId,
88
- };
89
- };
90
- HttpClient.prototype.constructPhraseEnvelope = function (phrase) {
91
- return {
92
- command: { phrase: phrase },
93
- globalState: StoreHelper.getGlobalState(),
94
- clientId: this.clientId,
95
- };
96
- };
97
- HttpClient.prototype.constructFirstHitEnvelope = function () {
98
- return {
99
- command: { site: this.endpointUrl },
100
- clientId: this.clientId,
101
- globalState: {},
102
- };
103
- };
104
- HttpClient.prototype.handleResponseData = function (envelope, action) {
105
- StoreHelper.setGlobalState(envelope.globalState);
106
- this.middlewareClient.handleEntries(envelope.entries, action);
107
- };
108
- HttpClient.prototype.handleUpdateResponseData = function (envelope, action) {
109
- this.middlewareClient.handleUpdate(envelope.entries, action);
110
- };
111
- return HttpClient;
112
- }());
113
- export { HttpClient };
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
- console.log('widgetentry', widgetEntry);
64
- if (widgetEntry) {
65
- agent = ChatHelper.getAgent();
66
- console.log('current agent', agent);
67
- if (agent) {
68
- agent.update({
69
- name: 'RockstarBot',
70
- avatar: '',
71
- });
72
- console.log('asdf', ChatHelper.getAgent());
73
- }
74
- }
75
- o = this.executeMiddlewares(entries, false, action);
76
- return [4 /*yield*/, this.entryInterface.transformArray(o)];
77
- case 1:
78
- messageArray = _a.sent();
79
- this.chatClient.processMessageArrayAndStoreIt(messageArray);
80
- return [2 /*return*/];
81
- }
82
- });
83
- });
84
- };
85
- // called on situations such as paging changes
86
- // when no new entries will be printed
87
- MiddlewareClient.prototype.handleUpdate = function (entries, action) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- var o, messageArray;
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0:
93
- o = this.executeMiddlewares(entries, true, action);
94
- return [4 /*yield*/, this.entryInterface.transformArray(o)];
95
- case 1:
96
- messageArray = _a.sent();
97
- this.chatClient.updateMessageArrayAndStoreIt(messageArray);
98
- return [2 /*return*/];
99
- }
100
- });
101
- });
102
- };
103
- // checks whether the action was of an update type
104
- MiddlewareClient.prototype.checkForUpdate = function (input) {
105
- return input === 'next';
106
- };
107
- MiddlewareClient.prototype.executeMiddlewares = function (entries, isUpdate, action) {
108
- if (isUpdate && action)
109
- entries = this.processor.processUpdate(StoreHelper.getEntry(action), entries);
110
- else {
111
- entries = this.processor.process(entries);
112
- }
113
- entries = this.paging.process(entries);
114
- return entries;
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 '@humany/widget-adapters';
29
- import { useContainer, useDispatch } from '@humany/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', props.contactMethod.id + "/" + props.type.toString() + "/" + 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;
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;