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