@telia-ace/widget-conversation 1.0.12 → 1.0.15

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 (136) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +256 -256
  3. package/{lib-esm → dist}/agent.d.ts +17 -17
  4. package/{lib-esm → dist}/conversation-controller.d.ts +88 -88
  5. package/{lib-esm → dist}/conversation-form-adapter.d.ts +7 -7
  6. package/{lib-esm → dist}/conversation-platform.d.ts +50 -49
  7. package/{lib-esm → dist}/conversation-provider.d.ts +22 -22
  8. package/dist/conversation.js +558 -0
  9. package/dist/conversation.js.map +1 -0
  10. package/{lib → dist}/index.d.ts +9 -9
  11. package/dist/index.js +10 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/index2.js +1678 -0
  14. package/dist/index2.js.map +1 -0
  15. package/{lib-esm → dist}/resolve-entity-value.d.ts +10 -10
  16. package/dist/return-button.js +174 -0
  17. package/dist/return-button.js.map +1 -0
  18. package/{lib → dist}/types.d.ts +110 -110
  19. package/{lib-esm → dist}/ui/conversation/conversation-component.d.ts +37 -37
  20. package/{lib → dist}/ui/conversation/conversation-content.d.ts +12 -11
  21. package/{lib-esm → dist}/ui/conversation/conversation-input.d.ts +6 -6
  22. package/{lib → dist}/ui/conversation/conversation-loader.d.ts +8 -8
  23. package/{lib → dist}/ui/conversation/conversation-message.d.ts +7 -7
  24. package/{lib-esm → dist}/ui/conversation/conversation-styles.d.ts +11 -11
  25. package/{lib → dist}/ui/conversation/conversation.d.ts +6 -6
  26. package/{lib → dist}/ui/conversation/index.d.ts +3 -2
  27. package/{lib-esm → dist}/ui/conversation/message-types/agent.d.ts +11 -11
  28. package/{lib → dist}/ui/conversation/message-types/custom-message-list-item.d.ts +9 -9
  29. package/{lib → dist}/ui/conversation/message-types/custom.d.ts +9 -9
  30. package/{lib → dist}/ui/conversation/message-types/index.d.ts +5 -5
  31. package/{lib-esm → dist}/ui/conversation/message-types/system.d.ts +12 -12
  32. package/{lib → dist}/ui/conversation/message-types/timestamp.d.ts +8 -8
  33. package/{lib-esm → dist}/ui/conversation/message-types/user.d.ts +8 -8
  34. package/dist/ui/index.d.ts +2 -0
  35. package/{lib-esm → dist}/ui/return-button/index.d.ts +2 -2
  36. package/{lib → dist}/ui/return-button/return-button-component.d.ts +19 -19
  37. package/{lib → dist}/ui/return-button/return-button.d.ts +6 -6
  38. package/{lib → dist}/user.d.ts +7 -7
  39. package/{lib-esm → dist}/utils/custom-message.d.ts +3 -3
  40. package/{lib-esm → dist}/utils/index.d.ts +1 -1
  41. package/{lib-esm → dist}/utils/open-chat-widget.d.ts +4 -4
  42. package/package.json +15 -16
  43. package/lib/agent.d.ts +0 -17
  44. package/lib/agent.js +0 -37
  45. package/lib/conversation-controller.d.ts +0 -88
  46. package/lib/conversation-controller.js +0 -318
  47. package/lib/conversation-form-adapter.d.ts +0 -7
  48. package/lib/conversation-form-adapter.js +0 -88
  49. package/lib/conversation-platform.d.ts +0 -49
  50. package/lib/conversation-platform.js +0 -295
  51. package/lib/conversation-provider.d.ts +0 -22
  52. package/lib/conversation-provider.js +0 -73
  53. package/lib/index.js +0 -17
  54. package/lib/resolve-entity-value.d.ts +0 -10
  55. package/lib/resolve-entity-value.js +0 -22
  56. package/lib/types.js +0 -19
  57. package/lib/ui/conversation/conversation-component.d.ts +0 -37
  58. package/lib/ui/conversation/conversation-component.js +0 -152
  59. package/lib/ui/conversation/conversation-content.js +0 -240
  60. package/lib/ui/conversation/conversation-input.d.ts +0 -6
  61. package/lib/ui/conversation/conversation-input.js +0 -163
  62. package/lib/ui/conversation/conversation-loader.js +0 -18
  63. package/lib/ui/conversation/conversation-message.js +0 -141
  64. package/lib/ui/conversation/conversation-styles.d.ts +0 -11
  65. package/lib/ui/conversation/conversation-styles.js +0 -65
  66. package/lib/ui/conversation/conversation.js +0 -139
  67. package/lib/ui/conversation/index.js +0 -7
  68. package/lib/ui/conversation/message-types/agent.d.ts +0 -11
  69. package/lib/ui/conversation/message-types/agent.js +0 -54
  70. package/lib/ui/conversation/message-types/custom-message-list-item.js +0 -27
  71. package/lib/ui/conversation/message-types/custom.js +0 -50
  72. package/lib/ui/conversation/message-types/index.js +0 -16
  73. package/lib/ui/conversation/message-types/system.d.ts +0 -12
  74. package/lib/ui/conversation/message-types/system.js +0 -26
  75. package/lib/ui/conversation/message-types/timestamp.js +0 -36
  76. package/lib/ui/conversation/message-types/user.d.ts +0 -8
  77. package/lib/ui/conversation/message-types/user.js +0 -24
  78. package/lib/ui/index.d.ts +0 -2
  79. package/lib/ui/index.js +0 -10
  80. package/lib/ui/return-button/index.d.ts +0 -2
  81. package/lib/ui/return-button/index.js +0 -7
  82. package/lib/ui/return-button/return-button-component.js +0 -70
  83. package/lib/ui/return-button/return-button.js +0 -82
  84. package/lib/user.js +0 -16
  85. package/lib/utils/custom-message.d.ts +0 -3
  86. package/lib/utils/custom-message.js +0 -56
  87. package/lib/utils/index.d.ts +0 -1
  88. package/lib/utils/index.js +0 -7
  89. package/lib/utils/open-chat-widget.d.ts +0 -4
  90. package/lib/utils/open-chat-widget.js +0 -148
  91. package/lib-esm/agent.js +0 -34
  92. package/lib-esm/conversation-controller.js +0 -314
  93. package/lib-esm/conversation-form-adapter.js +0 -85
  94. package/lib-esm/conversation-platform.js +0 -292
  95. package/lib-esm/conversation-provider.js +0 -70
  96. package/lib-esm/index.d.ts +0 -9
  97. package/lib-esm/index.js +0 -6
  98. package/lib-esm/resolve-entity-value.js +0 -18
  99. package/lib-esm/types.d.ts +0 -110
  100. package/lib-esm/types.js +0 -16
  101. package/lib-esm/ui/conversation/conversation-component.js +0 -127
  102. package/lib-esm/ui/conversation/conversation-content.d.ts +0 -11
  103. package/lib-esm/ui/conversation/conversation-content.js +0 -212
  104. package/lib-esm/ui/conversation/conversation-input.js +0 -138
  105. package/lib-esm/ui/conversation/conversation-loader.d.ts +0 -8
  106. package/lib-esm/ui/conversation/conversation-loader.js +0 -13
  107. package/lib-esm/ui/conversation/conversation-message.d.ts +0 -7
  108. package/lib-esm/ui/conversation/conversation-message.js +0 -113
  109. package/lib-esm/ui/conversation/conversation-styles.js +0 -39
  110. package/lib-esm/ui/conversation/conversation.d.ts +0 -6
  111. package/lib-esm/ui/conversation/conversation.js +0 -111
  112. package/lib-esm/ui/conversation/index.d.ts +0 -2
  113. package/lib-esm/ui/conversation/index.js +0 -2
  114. package/lib-esm/ui/conversation/message-types/agent.js +0 -25
  115. package/lib-esm/ui/conversation/message-types/custom-message-list-item.d.ts +0 -9
  116. package/lib-esm/ui/conversation/message-types/custom-message-list-item.js +0 -22
  117. package/lib-esm/ui/conversation/message-types/custom.d.ts +0 -9
  118. package/lib-esm/ui/conversation/message-types/custom.js +0 -25
  119. package/lib-esm/ui/conversation/message-types/index.d.ts +0 -5
  120. package/lib-esm/ui/conversation/message-types/index.js +0 -5
  121. package/lib-esm/ui/conversation/message-types/system.js +0 -20
  122. package/lib-esm/ui/conversation/message-types/timestamp.d.ts +0 -8
  123. package/lib-esm/ui/conversation/message-types/timestamp.js +0 -31
  124. package/lib-esm/ui/conversation/message-types/user.js +0 -19
  125. package/lib-esm/ui/index.d.ts +0 -2
  126. package/lib-esm/ui/index.js +0 -2
  127. package/lib-esm/ui/return-button/index.js +0 -2
  128. package/lib-esm/ui/return-button/return-button-component.d.ts +0 -19
  129. package/lib-esm/ui/return-button/return-button-component.js +0 -44
  130. package/lib-esm/ui/return-button/return-button.d.ts +0 -6
  131. package/lib-esm/ui/return-button/return-button.js +0 -54
  132. package/lib-esm/user.d.ts +0 -7
  133. package/lib-esm/user.js +0 -13
  134. package/lib-esm/utils/custom-message.js +0 -52
  135. package/lib-esm/utils/index.js +0 -1
  136. package/lib-esm/utils/open-chat-widget.js +0 -142
@@ -1,295 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ConversationPlatform = exports.ConversationEndedBehavior = void 0;
40
- var widget_core_1 = require("@telia-ace/widget-core");
41
- var widget_services_1 = require("@telia-ace/widget-services");
42
- var widget_utilities_1 = require("@telia-ace/widget-utilities");
43
- var conversation_controller_1 = require("./conversation-controller");
44
- var utils_1 = require("./utils");
45
- var STORAGE_KEY = 'conversations';
46
- var ConversationEndedBehavior;
47
- (function (ConversationEndedBehavior) {
48
- ConversationEndedBehavior["Deactivate"] = "deactivate";
49
- ConversationEndedBehavior["Navigate"] = "navigate";
50
- ConversationEndedBehavior["None"] = "none";
51
- })(ConversationEndedBehavior = exports.ConversationEndedBehavior || (exports.ConversationEndedBehavior = {}));
52
- var ConversationPlatform = /** @class */ (function () {
53
- function ConversationPlatform(container, components) {
54
- this.container = container;
55
- this.components = components;
56
- this.controllers = [];
57
- this.providers = [];
58
- this.disposeProviders = {};
59
- this.subscriptions = [];
60
- this.storageWriter = null;
61
- this.router = null;
62
- this.buttonQuery = null;
63
- this.sessionInfo = null;
64
- var widget = container.get('$widget');
65
- this.events = widget.events.createChild(this);
66
- }
67
- ConversationPlatform.prototype.initialize = function () {
68
- var _this = this;
69
- (0, widget_services_1.createStorageWriter)(this.container, STORAGE_KEY, widget_services_1.StorageCategory.Necessary, {
70
- medium: widget_services_1.StorageMedium.Local,
71
- }).then(function (writer) { return (_this.storageWriter = writer); });
72
- (0, widget_services_1.readStorage)(this.container, STORAGE_KEY, widget_services_1.StorageMedium.Local).then(function (storedSession) {
73
- _this.buttonQuery = _this.components
74
- .components()
75
- .ofType('conversation-return-button');
76
- if (storedSession) {
77
- _this.sessionInfo = storedSession;
78
- if (storedSession.id && storedSession.route) {
79
- _this.writeToComponents({ active: true, alert: { show: false } });
80
- }
81
- }
82
- });
83
- this.container.getAsync('router').then(function (router) { return (_this.router = router); });
84
- this.events.subscribe('conversation:ended', function (event, data) {
85
- var _a, _b, _c;
86
- switch ((_a = _this.sessionInfo) === null || _a === void 0 ? void 0 : _a.conversationEndedBehavior) {
87
- case ConversationEndedBehavior.Deactivate:
88
- var widget = _this.container.get('$widget');
89
- widget.deactivate();
90
- break;
91
- case ConversationEndedBehavior.Navigate:
92
- var initialRoute = (_b = _this.router) === null || _b === void 0 ? void 0 : _b.getInitialRoute();
93
- if (initialRoute) {
94
- (_c = _this.router) === null || _c === void 0 ? void 0 : _c.navigate(initialRoute.name);
95
- }
96
- break;
97
- case ConversationEndedBehavior.None:
98
- default:
99
- break;
100
- }
101
- _this.writeToComponents({ active: false });
102
- _this.sessionInfo = null;
103
- _this.storageWriter && _this.storageWriter();
104
- });
105
- };
106
- ConversationPlatform.prototype.addSubscription = function (sub) {
107
- this.subscriptions.push(sub);
108
- };
109
- ConversationPlatform.getInstance = function (container, key) {
110
- if (key === void 0) { key = 'conversation'; }
111
- return (0, widget_utilities_1.lock)(container)(function () {
112
- return container.getAsync(key).then(function (value) {
113
- var conversation = value;
114
- if (!conversation) {
115
- return widget_core_1.ComponentPlatform.getInstance(container).then(function (components) {
116
- conversation = new ConversationPlatform(container, components);
117
- conversation.initialize();
118
- container.registerAsync(key, function () { return conversation; });
119
- return conversation;
120
- });
121
- }
122
- return conversation;
123
- });
124
- });
125
- };
126
- ConversationPlatform.prototype.navigateToConversationIfActive = function (id) {
127
- var _this = this;
128
- return (0, widget_services_1.readStorage)(this.container, STORAGE_KEY, widget_services_1.StorageMedium.Local).then(function (storedSession) {
129
- var _a;
130
- if (storedSession && storedSession.id === id) {
131
- if (storedSession.route) {
132
- var _b = storedSession.route, name_1 = _b.name, params = _b.params;
133
- (_a = _this.router) === null || _a === void 0 ? void 0 : _a.navigate(name_1, params);
134
- }
135
- }
136
- });
137
- };
138
- ConversationPlatform.prototype.setConversationEndedBehavior = function (behavior) {
139
- var _this = this;
140
- return (0, widget_services_1.readStorage)(this.container, STORAGE_KEY, widget_services_1.StorageMedium.Local).then(function (stored) {
141
- var storedSession = stored;
142
- if (storedSession) {
143
- storedSession.conversationEndedBehavior = behavior;
144
- }
145
- else {
146
- storedSession = { conversationEndedBehavior: behavior };
147
- }
148
- _this.sessionInfo = storedSession;
149
- return ((_this.storageWriter && _this.storageWriter(_this.sessionInfo)) ||
150
- Promise.resolve());
151
- });
152
- };
153
- ConversationPlatform.prototype.createController = function (id) {
154
- var index = this.controllers.findIndex(function (c) { return c.conversation.id === id; });
155
- if (index > -1) {
156
- return this.controllers[index].conversation;
157
- }
158
- return new conversation_controller_1.ConversationController(this.container, id);
159
- };
160
- ConversationPlatform.prototype.registerProvider = function (name, handler) {
161
- var _this = this;
162
- var provider = {
163
- name: name,
164
- handler: handler,
165
- };
166
- this.providers.push(provider);
167
- // execute provider for all matching controllers
168
- this.controllers
169
- .filter(function (controller) { return controller.conversation.providers.indexOf(name) > -1; })
170
- .forEach(function (controller) {
171
- _this.invokeHandler(provider, controller);
172
- });
173
- };
174
- ConversationPlatform.prototype.registerController = function (conversation, component) {
175
- var _this = this;
176
- var index = this.controllers.findIndex(function (c) { return c.conversation.id === conversation.id; });
177
- var controller;
178
- if (index < 0) {
179
- controller = { conversation: conversation, component: component };
180
- this.controllers.push(controller);
181
- var invokeHandlers_1 = function (providers) {
182
- if (providers) {
183
- _this.providers
184
- .filter(function (provider) { return providers.indexOf(provider.name) > -1; })
185
- .forEach(function (provider) {
186
- _this.invokeHandler(provider, controller);
187
- });
188
- }
189
- };
190
- this.subscriptions.push(conversation.onDispose(function (event, data) {
191
- var index = _this.controllers.findIndex(function (c) { return c.conversation === data; });
192
- index > -1 && _this.controllers.splice(index, 1);
193
- _this.components
194
- .components()
195
- .ofType('conversation-return-button')
196
- .select()
197
- .writeProperties({ active: false });
198
- _this.events.dispatch('conversation:ended', {}, { bubbles: true });
199
- }));
200
- this.subscriptions.push(conversation.onProvidersChange(function (event, data) {
201
- var added = data.added, removed = data.removed;
202
- removed.forEach(function (removedProvider) {
203
- _this.disposeProviders[removedProvider].forEach(function (dispose) {
204
- dispose();
205
- });
206
- });
207
- invokeHandlers_1(added);
208
- }));
209
- this.subscriptions.push(conversation.onStarted(function (event, isActive) {
210
- var _a, _b;
211
- var session = {
212
- id: conversation.id,
213
- route: (_a = _this.router) === null || _a === void 0 ? void 0 : _a.getRouteData(),
214
- conversationEndedBehavior: (_b = _this.sessionInfo) === null || _b === void 0 ? void 0 : _b.conversationEndedBehavior,
215
- };
216
- _this.sessionInfo = session;
217
- _this.storageWriter && _this.storageWriter(session);
218
- _this.writeToComponents({ active: isActive });
219
- }));
220
- this.subscriptions.push(conversation.onUnreadMessage(function (event, data) {
221
- _this.events.dispatch('conversation:unread-message', data);
222
- _this.writeToComponents({ alert: { show: data } });
223
- }));
224
- invokeHandlers_1(conversation.providers);
225
- return true;
226
- }
227
- controller = this.controllers[index];
228
- return false;
229
- };
230
- ConversationPlatform.prototype.writeToComponents = function (properties, key) {
231
- if (key === void 0) { key = 'conversationReturnButtonState'; }
232
- if (this.buttonQuery) {
233
- this.components.write({
234
- key: 'conversationReturnButtonState',
235
- attributes: { properties: properties },
236
- target: this.buttonQuery,
237
- provider: 'localStorage',
238
- });
239
- }
240
- };
241
- ConversationPlatform.prototype.invokeHandler = function (provider, controller) {
242
- var dispose = provider.handler(controller.conversation.createProvider(provider.name), controller.component);
243
- if (dispose) {
244
- if (!this.disposeProviders[provider.name]) {
245
- this.disposeProviders[provider.name] = [];
246
- }
247
- this.disposeProviders[provider.name].push(dispose);
248
- }
249
- };
250
- ConversationPlatform.prototype.getComponentRoute = function () {
251
- return (0, widget_services_1.readStorage)(this.container, STORAGE_KEY, widget_services_1.StorageMedium.Local).then(function (stored) { return stored === null || stored === void 0 ? void 0 : stored.route; });
252
- };
253
- ConversationPlatform.prototype.dispose = function () {
254
- var _this = this;
255
- Object.keys(this.disposeProviders).forEach(function (key) {
256
- _this.disposeProviders[key].forEach(function (dispose) {
257
- dispose();
258
- });
259
- });
260
- this.subscriptions.forEach(function (unsubscribe) {
261
- unsubscribe();
262
- });
263
- this.controllers = [];
264
- this.providers = [];
265
- };
266
- ConversationPlatform.handleContactMethodClick = function (event, container, contactMethod, callback) {
267
- return __awaiter(this, void 0, void 0, function () {
268
- var triggerEl;
269
- return __generator(this, function (_a) {
270
- if ((0, utils_1.shouldPreventDefault)(container)) {
271
- event.preventDefault();
272
- triggerEl = document.getElementById('humany-dynamic-anchor');
273
- if (!triggerEl) {
274
- triggerEl = document.createElement('a');
275
- triggerEl.setAttribute('href', '#');
276
- triggerEl.id = 'humany-dynamic-anchor';
277
- document.body.appendChild(triggerEl);
278
- }
279
- (0, utils_1.openChatWidget)(container, contactMethod, triggerEl);
280
- }
281
- (0, utils_1.openChatWidget)(container, contactMethod);
282
- return [2 /*return*/];
283
- });
284
- });
285
- };
286
- ConversationPlatform.handleContactMethodSubmit = function (container, contactMethod) {
287
- return __awaiter(this, void 0, void 0, function () {
288
- return __generator(this, function (_a) {
289
- return [2 /*return*/, (0, utils_1.navigateToConversation)(container, contactMethod)];
290
- });
291
- });
292
- };
293
- return ConversationPlatform;
294
- }());
295
- exports.ConversationPlatform = ConversationPlatform;
@@ -1,22 +0,0 @@
1
- import { Container, EventListener, EventSubscriptionCancellation } from '@webprovisions/platform';
2
- import { Agent, AgentSettings } from './agent';
3
- import { CancelLoaderDelegate, ConversationController, ConversationEntry, ConversationMessageType } from './conversation-controller';
4
- import { ConversationMessageContent, ConversationMessageSender, ConversationMessageSettings } from './types';
5
- export declare class ConversationProvider {
6
- name: string;
7
- private container;
8
- controller: ConversationController | null;
9
- private subscriptions;
10
- user: any;
11
- private constructor();
12
- static create(name: string, container: Container, controller: ConversationController): ConversationProvider;
13
- createAgent(settings?: AgentSettings): Agent | undefined;
14
- print(settings: string | ConversationMessageSettings): ConversationEntry | undefined;
15
- setTypingState(sender: ConversationMessageSender, type?: ConversationMessageType): (() => void) | undefined;
16
- loading(): CancelLoaderDelegate;
17
- createEntry(key: string, content: ConversationMessageContent, type: ConversationMessageType, sender?: ConversationMessageSender, timestamp?: number | null): ConversationEntry | undefined;
18
- dispose(): void;
19
- onUnreadMessage(fn: EventListener): EventSubscriptionCancellation | void;
20
- onMounted(fn: EventListener): EventSubscriptionCancellation | void;
21
- }
22
- export default ConversationProvider;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConversationProvider = void 0;
4
- var agent_1 = require("./agent");
5
- var ConversationProvider = /** @class */ (function () {
6
- function ConversationProvider(name, container, controller) {
7
- this.name = name;
8
- this.container = container;
9
- this.controller = controller;
10
- this.subscriptions = [];
11
- this.user = controller === null || controller === void 0 ? void 0 : controller.user;
12
- }
13
- ConversationProvider.create = function (name, container, controller) {
14
- return new ConversationProvider(name, container, controller);
15
- };
16
- ConversationProvider.prototype.createAgent = function (settings) {
17
- if (settings === void 0) { settings = {}; }
18
- if (this.controller) {
19
- return new agent_1.Agent(this, settings);
20
- }
21
- };
22
- ConversationProvider.prototype.print = function (settings) {
23
- var _a;
24
- return (_a = this.controller) === null || _a === void 0 ? void 0 : _a.print(settings);
25
- };
26
- ConversationProvider.prototype.setTypingState = function (sender, type) {
27
- var _a;
28
- return (_a = this.controller) === null || _a === void 0 ? void 0 : _a.setTypingState(sender, type);
29
- };
30
- ConversationProvider.prototype.loading = function () {
31
- if (!this.controller) {
32
- return function () { return function () { }; };
33
- }
34
- return this.controller.loader();
35
- };
36
- ConversationProvider.prototype.createEntry = function (key, content, type, sender, timestamp) {
37
- var _a;
38
- return (_a = this.controller) === null || _a === void 0 ? void 0 : _a.createEntry(key, content, type, sender, timestamp);
39
- };
40
- ConversationProvider.prototype.dispose = function () {
41
- var _a;
42
- if (process.env.NODE_ENV !== 'production') {
43
- console.log("conversation-provider: dispose (".concat(this.name, ")"));
44
- }
45
- (_a = this.controller) === null || _a === void 0 ? void 0 : _a.disposeProvider(this);
46
- this.controller = null;
47
- this.subscriptions.forEach(function (unsub) { return unsub(); });
48
- };
49
- ConversationProvider.prototype.onUnreadMessage = function (fn) {
50
- var _a;
51
- if (this.controller) {
52
- var unsubscribe_1 = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.onUnreadMessage(fn);
53
- this.subscriptions.push(unsubscribe_1);
54
- return function () {
55
- unsubscribe_1();
56
- };
57
- }
58
- };
59
- ConversationProvider.prototype.onMounted = function (fn) {
60
- var _a;
61
- if (this.controller) {
62
- var unsubscribe_2 = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.events.subscribe('conversation:component-mount-changed', fn);
63
- this.subscriptions.push(unsubscribe_2);
64
- fn({}, this.controller.getComponentMountedState());
65
- return function () {
66
- unsubscribe_2();
67
- };
68
- }
69
- };
70
- return ConversationProvider;
71
- }());
72
- exports.ConversationProvider = ConversationProvider;
73
- exports.default = ConversationProvider;
package/lib/index.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConversationEndedBehavior = exports.ConversationPlatform = exports.registerCustomMessageComponent = exports.ConversationReturnButtonComponent = exports.ConversationComponent = exports.ConversationMessageListItemType = exports.ConversationMessageType = exports.ConversationEntry = exports.ConversationController = void 0;
4
- var conversation_platform_1 = require("./conversation-platform");
5
- Object.defineProperty(exports, "ConversationEndedBehavior", { enumerable: true, get: function () { return conversation_platform_1.ConversationEndedBehavior; } });
6
- Object.defineProperty(exports, "ConversationPlatform", { enumerable: true, get: function () { return conversation_platform_1.ConversationPlatform; } });
7
- var conversation_controller_1 = require("./conversation-controller");
8
- Object.defineProperty(exports, "ConversationController", { enumerable: true, get: function () { return conversation_controller_1.ConversationController; } });
9
- Object.defineProperty(exports, "ConversationEntry", { enumerable: true, get: function () { return conversation_controller_1.ConversationEntry; } });
10
- Object.defineProperty(exports, "ConversationMessageType", { enumerable: true, get: function () { return conversation_controller_1.ConversationMessageType; } });
11
- var types_1 = require("./types");
12
- Object.defineProperty(exports, "ConversationMessageListItemType", { enumerable: true, get: function () { return types_1.ConversationMessageListItemType; } });
13
- var ui_1 = require("./ui");
14
- Object.defineProperty(exports, "ConversationComponent", { enumerable: true, get: function () { return ui_1.ConversationComponent; } });
15
- Object.defineProperty(exports, "ConversationReturnButtonComponent", { enumerable: true, get: function () { return ui_1.ConversationReturnButtonComponent; } });
16
- var custom_message_1 = require("./utils/custom-message");
17
- Object.defineProperty(exports, "registerCustomMessageComponent", { enumerable: true, get: function () { return custom_message_1.registerCustomMessageComponent; } });
@@ -1,10 +0,0 @@
1
- import { EventSubscriptionCancellation, Widget } from '@webprovisions/platform';
2
- export declare type EntityValueResolver = (value: any) => void;
3
- export declare type ResolveEntityValueHandler = (resolve: EntityValueResolver, originalValue: any) => any | Promise<any>;
4
- /**
5
- * Registers a handler to resolve entity values initiated by the backend service.
6
- * @param widget Widget to resolve the entity value for.
7
- * @param name Name of entity to resolve.
8
- * @param handler Handler for resolving value.
9
- */
10
- export declare const resolveEntityValue: (widget: Widget, name: string, handler: ResolveEntityValueHandler) => EventSubscriptionCancellation;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveEntityValue = void 0;
4
- /**
5
- * Registers a handler to resolve entity values initiated by the backend service.
6
- * @param widget Widget to resolve the entity value for.
7
- * @param name Name of entity to resolve.
8
- * @param handler Handler for resolving value.
9
- */
10
- var resolveEntityValue = function (widget, name, handler) {
11
- return widget.events.subscribe('data:resolve-entity-value', function (event, data) {
12
- if (data.name === name) {
13
- return new Promise(function (resolve) {
14
- handler(function (value) {
15
- data.value = value;
16
- resolve();
17
- }, data.value);
18
- });
19
- }
20
- });
21
- };
22
- exports.resolveEntityValue = resolveEntityValue;
package/lib/types.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConversationMessageListItemType = exports.ConversationMessageListType = void 0;
4
- var ConversationMessageListType;
5
- (function (ConversationMessageListType) {
6
- ConversationMessageListType["Ordinary"] = "ordinary";
7
- ConversationMessageListType["Seperator"] = "seperator";
8
- })(ConversationMessageListType = exports.ConversationMessageListType || (exports.ConversationMessageListType = {}));
9
- var ConversationMessageListItemType;
10
- (function (ConversationMessageListItemType) {
11
- ConversationMessageListItemType["Header"] = "header";
12
- ConversationMessageListItemType["LinkList"] = "link-list";
13
- ConversationMessageListItemType["Separator"] = "separator";
14
- ConversationMessageListItemType["NoGoodAlternative"] = "no-good-alternative";
15
- ConversationMessageListItemType["ButtonList"] = "button-list";
16
- ConversationMessageListItemType["Text"] = "text";
17
- ConversationMessageListItemType["HTML"] = "html";
18
- ConversationMessageListItemType["FeedbackList"] = "feedback-list";
19
- })(ConversationMessageListItemType = exports.ConversationMessageListItemType || (exports.ConversationMessageListItemType = {}));
@@ -1,37 +0,0 @@
1
- import { Container } from '@webprovisions/platform';
2
- import { ConversationMessage, ConversationMessageType } from '../../conversation-controller';
3
- import { ConversationMessageContent, ConversationMessageSender } from '../../types';
4
- export declare type BundledConversationMessage = {
5
- timestamp: number;
6
- content: [BundledMessageContent];
7
- sender: ConversationMessageSender;
8
- type: ConversationMessageType;
9
- };
10
- declare type BundledMessageContent = {
11
- key: string;
12
- } & ConversationMessageContent;
13
- export declare type ConversationContent = {
14
- loading: boolean;
15
- typingActors: ConversationMessageSender[];
16
- messages: ConversationMessage[];
17
- };
18
- export declare type ConversationComponentProperties = {
19
- providers: string[];
20
- messages: BundledConversationMessage[];
21
- loading: boolean;
22
- inputPlaceholder: string;
23
- inputDisabled: boolean;
24
- inputHidden: boolean;
25
- inputMultiline: boolean;
26
- userLabel: string;
27
- avatarSize: string;
28
- typingActors: any[];
29
- sendButtonLabel: string;
30
- secondaryAction?: {
31
- icon?: string;
32
- action: string;
33
- label: string;
34
- };
35
- };
36
- declare const ConversationComponent: (container: Container) => Promise<void>;
37
- export default ConversationComponent;
@@ -1,152 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __read = (this && this.__read) || function (o, n) {
37
- var m = typeof Symbol === "function" && o[Symbol.iterator];
38
- if (!m) return o;
39
- var i = m.call(o), r, ar = [], e;
40
- try {
41
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
42
- }
43
- catch (error) { e = { error: error }; }
44
- finally {
45
- try {
46
- if (r && !r.done && (m = i["return"])) m.call(i);
47
- }
48
- finally { if (e) throw e.error; }
49
- }
50
- return ar;
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var widget_ui_1 = require("@telia-ace/widget-ui");
54
- var conversation_controller_1 = require("../../conversation-controller");
55
- var conversation_platform_1 = require("../../conversation-platform");
56
- /**
57
- * Group items by sender, type and time. Current grouping threshold is 2000 ms.
58
- * Put this as a property on either the component or on the provider?
59
- * Could possibly be implemented directly in the createEntry method
60
- * of the conversation controller to avoid iterating over the entire array on
61
- * each update.
62
- */
63
- var groupedMessages = function (messages, timeout) {
64
- return messages.reduce(function (acc, current, index) {
65
- var _a, _b;
66
- var newItem = __assign(__assign({}, current), { content: [__assign(__assign({}, current.content), { key: current.key })] });
67
- if (acc.length > 0 && current.type !== conversation_controller_1.ConversationMessageType.System) {
68
- var previous = acc[acc.length - 1];
69
- if ((!timeout && timeout !== 0) ||
70
- Math.abs(previous.timestamp - current.timestamp) < timeout) {
71
- if (((_a = previous.sender) === null || _a === void 0 ? void 0 : _a.name) === ((_b = current.sender) === null || _b === void 0 ? void 0 : _b.name) &&
72
- previous.type === current.type) {
73
- previous.timestamp = current.timestamp;
74
- previous.content.push(__assign(__assign({}, current.content), { key: current.key }));
75
- return acc;
76
- }
77
- }
78
- }
79
- acc.push(newItem);
80
- return acc;
81
- }, []);
82
- };
83
- var ConversationComponent = function (container) {
84
- return Promise.all([
85
- conversation_platform_1.ConversationPlatform.getInstance(container),
86
- container.getAsync('router'),
87
- ]).then(function (_a) {
88
- var _b = __read(_a, 2), platform = _b[0], router = _b[1];
89
- return (0, widget_ui_1.createReactComponent)(container, 'conversation', Promise.resolve().then(function () { return __importStar(require('./conversation')); }), function (component) {
90
- var routeData = router.getRouteData();
91
- var name = routeData.params.id || component.node.name || 'component';
92
- var conversation = platform.createController(name);
93
- var isNewController = platform.registerController(conversation, component);
94
- var messageGroupingTimeout = 3 * 60 * 1000;
95
- var setProperties = function (properties) {
96
- var _a = properties.providers, providers = _a === void 0 ? [] : _a;
97
- if (providers) {
98
- var providerKeys = Array.isArray(providers) ? providers : [providers];
99
- conversation.setProviders(providerKeys);
100
- return providerKeys;
101
- }
102
- };
103
- setProperties(component.properties(setProperties));
104
- conversation.setComponentMountedState(true);
105
- var writeMessages = function (messageStream) {
106
- var loading = messageStream.loading, typingActors = messageStream.typingActors, messages = messageStream.messages;
107
- component.writeProperties({
108
- loading: loading,
109
- typingActors: typingActors,
110
- messages: groupedMessages(messages, messageGroupingTimeout),
111
- });
112
- };
113
- writeMessages(conversation.getMessageStream());
114
- if (isNewController) {
115
- // todo: dont create actions here, there will be duplicates due to reuseController = true
116
- component.actions.create('user-submit', function (data, options) {
117
- if (options) {
118
- var preventDefault = options.preventDefault, validationPromise = options.validationPromise;
119
- if (preventDefault) {
120
- if (validationPromise) {
121
- validationPromise().then(function (text) {
122
- if (text) {
123
- conversation.user.print(text);
124
- }
125
- });
126
- }
127
- return;
128
- }
129
- }
130
- conversation.user.print(data.text);
131
- });
132
- component.actions.create('user-typing', function (data, options) { });
133
- component.actions.create('form', function (data, options) { });
134
- component.actions.create('action', function (data, options) { });
135
- }
136
- var unsubscribe = conversation.events.subscribe('conversation:updated', function (e, conversationData) {
137
- writeMessages(conversationData);
138
- });
139
- return function () {
140
- conversation.setComponentMountedState(false);
141
- unsubscribe();
142
- if (!conversation.active) {
143
- // unregisterController();
144
- // todo: add possibility to dispose this through extendComponent()
145
- // component.dispose();
146
- writeMessages({ messages: [], typingActors: [], loading: false });
147
- }
148
- };
149
- }, { reuseController: true });
150
- });
151
- };
152
- exports.default = ConversationComponent;