@twilio/conversations 2.1.0-rc.9 → 2.2.0-rc.11
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/CHANGELOG.md +214 -0
- package/README.md +8 -4
- package/builds/browser.js +2911 -1974
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +572 -285
- package/builds/lib.js +2911 -1974
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +27160 -11795
- package/builds/twilio-conversations.min.js +1 -16
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +466 -281
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +2 -2
- package/dist/configuration.js.map +1 -1
- package/dist/conversation.js +426 -370
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +25 -13
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +56 -32
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +21 -12
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +2 -2
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces/attributes.js.map +1 -1
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/logger.js +2 -4
- package/dist/logger.js.map +1 -1
- package/dist/media.js +36 -25
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +24 -18
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +89 -17
- package/dist/message.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js +1 -1
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js +2 -2
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +1 -1
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js +13 -3
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +2 -2
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js.map +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/classes/CancellablePromise.html +3213 -0
- package/docs/classes/Client.html +243 -58
- package/docs/classes/Conversation.html +76 -47
- package/docs/classes/Media.html +2 -28
- package/docs/classes/Message.html +94 -39
- package/docs/classes/MessageBuilder.html +31 -8
- package/docs/classes/PushNotification.html +1 -1
- package/docs/classes/UnsentMessage.html +2 -2
- package/docs/index.html +25 -28
- package/docs/interfaces/ConversationLimits.html +12 -12
- package/docs/interfaces/ConversationState.html +2 -2
- package/docs/interfaces/ConversationUpdatedEventArgs.html +3001 -0
- package/docs/interfaces/PushNotificationData.html +48 -0
- package/docs/modules.html +24 -27
- package/package.json +24 -20
package/dist/client.js
CHANGED
@@ -149,10 +149,13 @@ var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
|
149
149
|
var _package = require('./packages/conversations/package.json.js');
|
150
150
|
var commandExecutor = require('./command-executor.js');
|
151
151
|
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
152
|
+
var media = require('./media.js');
|
153
|
+
var deprecationDecorator = require('@twilio/deprecation-decorator');
|
152
154
|
|
153
155
|
var Client_1;
|
154
|
-
|
155
|
-
|
156
|
+
/**
|
157
|
+
* Client services.
|
158
|
+
*/
|
156
159
|
class ClientServices {
|
157
160
|
}
|
158
161
|
/**
|
@@ -160,9 +163,11 @@ class ClientServices {
|
|
160
163
|
*/
|
161
164
|
exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventEmitter {
|
162
165
|
/**
|
163
|
-
* Returned Conversations instance is not yet fully initialized. Calling any
|
164
|
-
* Use connection events to monitor when
|
165
|
-
*
|
166
|
+
* Returned Conversations instance is not yet fully initialized. Calling any
|
167
|
+
* operations will block until it is. Use connection events to monitor when
|
168
|
+
* client becomes fully available (connectionStateChanged with state
|
169
|
+
* 'connected') or not available (connectionStateChange with state 'denied',
|
170
|
+
* event tokenExpired, event connectionError).
|
166
171
|
*
|
167
172
|
* @param fpaToken Access token
|
168
173
|
* @param options Options to customize the Client
|
@@ -171,6 +176,10 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
171
176
|
constructor(fpaToken, options = {}) {
|
172
177
|
var _a, _b, _c, _d, _e;
|
173
178
|
super();
|
179
|
+
/**
|
180
|
+
* Current version of the Conversations client.
|
181
|
+
*/
|
182
|
+
this.version = _package.version;
|
174
183
|
/**
|
175
184
|
* Client connection state.
|
176
185
|
*/
|
@@ -178,98 +187,110 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
178
187
|
/**
|
179
188
|
* Current version of the Conversations client.
|
180
189
|
*/
|
181
|
-
this.version = SDK_VERSION;
|
182
190
|
this.parsePushNotification = Client_1.parsePushNotification;
|
183
|
-
this.
|
184
|
-
this.
|
185
|
-
if (!this.
|
186
|
-
let options = Object.assign(Object.assign({}, this.
|
191
|
+
this._fpaToken = fpaToken !== null && fpaToken !== void 0 ? fpaToken : "";
|
192
|
+
this._options = options !== null && options !== void 0 ? options : {};
|
193
|
+
if (!this._options.disableDeepClone) {
|
194
|
+
let options = Object.assign(Object.assign({}, this._options), { transport: undefined, twilsockClient: undefined });
|
187
195
|
options = index.deepClone(options);
|
188
|
-
options.transport = this.
|
189
|
-
options.twilsockClient = this.
|
190
|
-
this.
|
196
|
+
options.transport = this._options.transport;
|
197
|
+
options.twilsockClient = this._options.twilsockClient;
|
198
|
+
this._options = options;
|
191
199
|
}
|
192
|
-
this.
|
193
|
-
|
194
|
-
const productId = (this.
|
200
|
+
this._options.logLevel = (_a = this._options.logLevel) !== null && _a !== void 0 ? _a : "silent";
|
201
|
+
Client_1._logger.setLevel(this._options.logLevel);
|
202
|
+
const productId = (this._options.productId = "ip_messaging");
|
195
203
|
// Filling ClientMetadata
|
196
|
-
this.
|
197
|
-
if (!this.
|
198
|
-
this.
|
204
|
+
this._options.clientMetadata = this._options.clientMetadata || {};
|
205
|
+
if (!this._options.clientMetadata.hasOwnProperty("type")) {
|
206
|
+
this._options.clientMetadata.type = "conversations";
|
199
207
|
}
|
200
|
-
if (!this.
|
201
|
-
this.
|
202
|
-
this.
|
208
|
+
if (!this._options.clientMetadata.hasOwnProperty("sdk")) {
|
209
|
+
this._options.clientMetadata.sdk = "JS";
|
210
|
+
this._options.clientMetadata.sdkv = _package.version;
|
203
211
|
}
|
204
212
|
// Enable session local storage for Sync
|
205
|
-
this.
|
206
|
-
if (typeof this.
|
207
|
-
this.
|
213
|
+
this._options.Sync = this._options.Sync || {};
|
214
|
+
if (typeof this._options.Sync.enableSessionStorage === "undefined") {
|
215
|
+
this._options.Sync.enableSessionStorage = true;
|
208
216
|
}
|
209
|
-
if (this.
|
210
|
-
this.
|
217
|
+
if (this._options.region) {
|
218
|
+
this._options.Sync.region = this._options.region;
|
211
219
|
}
|
212
220
|
if (!fpaToken) {
|
213
221
|
throw new Error("A valid Twilio token should be provided");
|
214
222
|
}
|
215
|
-
this.
|
216
|
-
this._myself = new user.User("", "", null, this.
|
217
|
-
const startTwilsock = !this.
|
223
|
+
this._services = new ClientServices();
|
224
|
+
this._myself = new user.User("", "", null, this._services);
|
225
|
+
const startTwilsock = !this._options.twilsockClient;
|
218
226
|
// Create default init registrations if none were provided.
|
219
227
|
// Otherwise, the outside party have to list all the init registrations they
|
220
228
|
// need.
|
221
229
|
// Init registrations passed to the Conversations client will be passed down
|
222
230
|
// to the Sync client as well.
|
223
|
-
if (!this.
|
231
|
+
if (!this._options.initRegistrations) {
|
224
232
|
const initRegistration = new twilsock.InitRegistration(productId);
|
225
233
|
Client_1.populateInitRegistrations(initRegistration);
|
226
|
-
this.
|
234
|
+
this._options.initRegistrations = [initRegistration];
|
227
235
|
}
|
228
|
-
this.
|
229
|
-
(_b = this.
|
230
|
-
this.
|
231
|
-
this.
|
232
|
-
this.
|
233
|
-
this.
|
234
|
-
|
236
|
+
this._services.twilsockClient = this._options.twilsockClient =
|
237
|
+
(_b = this._options.twilsockClient) !== null && _b !== void 0 ? _b : new twilsock.TwilsockClient(fpaToken, productId, this._options);
|
238
|
+
this._services.twilsockClient.on("tokenAboutToExpire", () => this.emit("tokenAboutToExpire"));
|
239
|
+
this._services.twilsockClient.on("tokenExpired", () => this.emit("tokenExpired"));
|
240
|
+
this._services.twilsockClient.on("connectionError", (error) => this.emit("connectionError", error));
|
241
|
+
this._services.twilsockClient.on("stateChanged", (state) => {
|
242
|
+
Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state ${state}`);
|
235
243
|
if (state !== this.connectionState) {
|
236
244
|
this.connectionState = state;
|
237
245
|
this.emit("connectionStateChanged", this.connectionState);
|
238
246
|
}
|
239
247
|
});
|
240
|
-
this.
|
241
|
-
.transport) !== null && _c !== void 0 ? _c : this.
|
242
|
-
this.
|
243
|
-
(_d = this.
|
244
|
-
this.
|
245
|
-
(_e = this.
|
248
|
+
this._services.transport = this._options.transport = ((_c = this._options
|
249
|
+
.transport) !== null && _c !== void 0 ? _c : this._options.twilsockClient);
|
250
|
+
this._services.notificationClient = this._options.notificationsClient =
|
251
|
+
(_d = this._options.notificationsClient) !== null && _d !== void 0 ? _d : new notifications.Notifications(fpaToken, this._options);
|
252
|
+
this._services.syncClient = this._options.syncClient =
|
253
|
+
(_e = this._options.syncClient) !== null && _e !== void 0 ? _e : new twilioSync.SyncClient(fpaToken, this._options);
|
246
254
|
const configurationOptions = (options === null || options === void 0 ? void 0 : options.Chat) || (options === null || options === void 0 ? void 0 : options.IPMessaging) || options || {};
|
247
255
|
const region = configurationOptions.region || (options === null || options === void 0 ? void 0 : options.region);
|
248
256
|
const baseUrl = configurationOptions.apiUri ||
|
249
257
|
configurationOptions.typingUri ||
|
250
258
|
`https://aim.${region || "us1"}.twilio.com`;
|
251
|
-
this.
|
252
|
-
const emitFailed = (
|
253
|
-
this._rejectEnsureReady(
|
259
|
+
this._services.commandExecutor = new commandExecutor.CommandExecutor(baseUrl, { transport: this._options.transport }, productId);
|
260
|
+
const emitFailed = (error) => {
|
261
|
+
this._rejectEnsureReady(error);
|
254
262
|
this.emit("stateChanged", "failed");
|
263
|
+
this.emit("initFailed", { error });
|
255
264
|
};
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
265
|
+
const emitDisconnected = () => {
|
266
|
+
emitFailed({
|
267
|
+
terminal: true,
|
268
|
+
message: "Twilsock has disconnected.",
|
269
|
+
});
|
270
|
+
};
|
271
|
+
this._services.twilsockClient.on("connectionError", emitFailed);
|
272
|
+
this._services.twilsockClient.on("disconnected", emitDisconnected);
|
273
|
+
this._services.twilsockClient.on("connected", async () => {
|
274
|
+
Client_1._logger.debug(`ConversationsClient started INITIALIZING`);
|
275
|
+
this._services.twilsockClient.off("connectionError", emitFailed);
|
276
|
+
this._services.twilsockClient.off("disconnected", emitDisconnected);
|
263
277
|
try {
|
264
278
|
const startupEvent = "conversations.client.startup";
|
265
|
-
this.
|
279
|
+
this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
|
266
280
|
await this._initialize();
|
267
|
-
this.
|
281
|
+
this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
|
268
282
|
}
|
269
283
|
catch (err) {
|
270
284
|
// Fail ChatClient if initialization is incomplete
|
271
|
-
|
285
|
+
const connectionError = {
|
286
|
+
terminal: true,
|
287
|
+
message: err.message,
|
288
|
+
};
|
289
|
+
this._rejectEnsureReady(connectionError);
|
272
290
|
this.emit("stateChanged", "failed");
|
291
|
+
this.emit("initFailed", {
|
292
|
+
error: connectionError,
|
293
|
+
});
|
273
294
|
}
|
274
295
|
});
|
275
296
|
this._ensureReady = new Promise((resolve, reject) => {
|
@@ -277,12 +298,36 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
277
298
|
this._rejectEnsureReady = reject;
|
278
299
|
}).catch(() => void 0); // @todo How to process unhandled rejection here?
|
279
300
|
if (startTwilsock) {
|
280
|
-
this.
|
301
|
+
this._services.twilsockClient.connect();
|
281
302
|
}
|
282
303
|
}
|
283
|
-
|
284
|
-
|
285
|
-
|
304
|
+
/**
|
305
|
+
* Information of the logged-in user. Before client initialization, returns an
|
306
|
+
* uninitialized user. Will trigger a {@link Client.userUpdated} event after
|
307
|
+
* initialization.
|
308
|
+
*/
|
309
|
+
get user() {
|
310
|
+
return this._myself;
|
311
|
+
}
|
312
|
+
/**
|
313
|
+
* Client reachability state. Throws an error if accessed before the client
|
314
|
+
* initialization was completed.
|
315
|
+
*/
|
316
|
+
get reachabilityEnabled() {
|
317
|
+
if (!this._configuration) {
|
318
|
+
throw new Error("Reachability information could not yet be accessed as the client " +
|
319
|
+
"has not yet been initialized. Subscribe to the 'stateChanged' event " +
|
320
|
+
"to properly react to the client initialization.");
|
321
|
+
}
|
322
|
+
return this._configuration.reachabilityEnabled;
|
323
|
+
}
|
324
|
+
/**
|
325
|
+
* @deprecated
|
326
|
+
* Current token.
|
327
|
+
* @internal
|
328
|
+
*/
|
329
|
+
get token() {
|
330
|
+
return this._fpaToken;
|
286
331
|
}
|
287
332
|
/**
|
288
333
|
* @deprecated Call constructor directly.
|
@@ -320,109 +365,105 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
320
365
|
return client;
|
321
366
|
}
|
322
367
|
/**
|
323
|
-
*
|
324
|
-
*
|
325
|
-
*
|
368
|
+
* Static method for push notification payload parsing. Returns parsed push as
|
369
|
+
* a {@link PushNotification} object.
|
370
|
+
* @param notificationPayload Push notification payload.
|
326
371
|
*/
|
327
|
-
|
328
|
-
|
372
|
+
static parsePushNotification(notificationPayload) {
|
373
|
+
var _a, _b;
|
374
|
+
Client_1._logger.debug("parsePushNotification, notificationPayload=", notificationPayload);
|
375
|
+
// APNS specifics
|
376
|
+
if (typeof notificationPayload.aps !== "undefined") {
|
377
|
+
if (!notificationPayload.twi_message_type) {
|
378
|
+
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
379
|
+
}
|
380
|
+
const data = Client_1._parsePushNotificationChatData(notificationPayload);
|
381
|
+
const apsPayload = notificationPayload.aps;
|
382
|
+
let body;
|
383
|
+
let title = null;
|
384
|
+
if (typeof apsPayload.alert === "string") {
|
385
|
+
body = apsPayload.alert || null;
|
386
|
+
}
|
387
|
+
else {
|
388
|
+
body = ((_a = apsPayload.alert) === null || _a === void 0 ? void 0 : _a.body) || null;
|
389
|
+
title = ((_b = apsPayload.alert) === null || _b === void 0 ? void 0 : _b.title) || null;
|
390
|
+
}
|
391
|
+
return new pushNotification.PushNotification({
|
392
|
+
title,
|
393
|
+
body,
|
394
|
+
sound: apsPayload.sound || null,
|
395
|
+
badge: apsPayload.badge || null,
|
396
|
+
action: apsPayload.category || null,
|
397
|
+
type: notificationPayload.twi_message_type,
|
398
|
+
data: data,
|
399
|
+
});
|
400
|
+
}
|
401
|
+
// FCM specifics
|
402
|
+
if (typeof notificationPayload.data !== "undefined") {
|
403
|
+
const dataPayload = notificationPayload.data;
|
404
|
+
if (!dataPayload.twi_message_type) {
|
405
|
+
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
406
|
+
}
|
407
|
+
const data = Client_1._parsePushNotificationChatData(notificationPayload.data);
|
408
|
+
return new pushNotification.PushNotification({
|
409
|
+
title: dataPayload.twi_title || null,
|
410
|
+
body: dataPayload.twi_body || null,
|
411
|
+
sound: dataPayload.twi_sound || null,
|
412
|
+
badge: null,
|
413
|
+
action: dataPayload.twi_action || null,
|
414
|
+
type: dataPayload.twi_message_type,
|
415
|
+
data: data,
|
416
|
+
});
|
417
|
+
}
|
418
|
+
throw new Error("Provided push notification payload is not Programmable Chat notification");
|
329
419
|
}
|
330
420
|
/**
|
331
|
-
*
|
332
|
-
*
|
421
|
+
* Static method for parsing push notification chat data.
|
422
|
+
* @param data Data to parse
|
333
423
|
*/
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
424
|
+
static _parsePushNotificationChatData(data) {
|
425
|
+
const result = {};
|
426
|
+
for (const key in Client_1._supportedPushDataFields) {
|
427
|
+
const value = data[key];
|
428
|
+
if (typeof value === "undefined" || value === null) {
|
429
|
+
continue;
|
430
|
+
}
|
431
|
+
if (key === "message_index" || key === "media_count") {
|
432
|
+
const number = index.parseToNumber(value);
|
433
|
+
if (number !== null) {
|
434
|
+
result[Client_1._supportedPushDataFields[key]] = number;
|
435
|
+
}
|
436
|
+
continue;
|
437
|
+
}
|
438
|
+
if (key === "media") {
|
439
|
+
if (typeof value === "string") {
|
440
|
+
try {
|
441
|
+
result[Client_1._supportedPushDataFields[key]] = JSON.parse(value);
|
442
|
+
}
|
443
|
+
catch (_a) {
|
444
|
+
Client_1._logger.debug("Media message notification parsing error");
|
445
|
+
}
|
446
|
+
}
|
447
|
+
continue;
|
448
|
+
}
|
449
|
+
result[Client_1._supportedPushDataFields[key]] = value;
|
339
450
|
}
|
340
|
-
return
|
341
|
-
}
|
342
|
-
get token() {
|
343
|
-
return this.fpaToken;
|
344
|
-
}
|
345
|
-
_subscribeToPushNotifications(channelType) {
|
346
|
-
[
|
347
|
-
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
348
|
-
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
349
|
-
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
350
|
-
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
351
|
-
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
352
|
-
].forEach((messageType) => {
|
353
|
-
this.services.notificationClient.subscribe(channelType, messageType);
|
354
|
-
});
|
355
|
-
}
|
356
|
-
_unsubscribeFromPushNotifications(channelType) {
|
357
|
-
[
|
358
|
-
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
359
|
-
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
360
|
-
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
361
|
-
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
362
|
-
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
363
|
-
].forEach((messageType) => {
|
364
|
-
this.services.notificationClient.unsubscribe(channelType, messageType);
|
365
|
-
});
|
451
|
+
return result;
|
366
452
|
}
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
this.services.users.on("userSubscribed", (user) => {
|
375
|
-
this.emit("userSubscribed", user);
|
376
|
-
});
|
377
|
-
this.services.users.on("userUpdated", (args) => this.emit("userUpdated", args));
|
378
|
-
this.services.users.on("userUnsubscribed", (user) => {
|
379
|
-
this.emit("userUnsubscribed", user);
|
380
|
-
});
|
381
|
-
this.conversations = new conversations.Conversations(this.configuration, this.services);
|
382
|
-
this.conversations.on("conversationAdded", (conversation) => {
|
383
|
-
this.emit("conversationAdded", conversation);
|
384
|
-
});
|
385
|
-
this.conversations.on("conversationRemoved", (conversation) => {
|
386
|
-
this.emit("conversationRemoved", conversation);
|
387
|
-
});
|
388
|
-
this.conversations.on("conversationJoined", (conversation) => {
|
389
|
-
this.emit("conversationJoined", conversation);
|
390
|
-
});
|
391
|
-
this.conversations.on("conversationLeft", (conversation) => {
|
392
|
-
this.emit("conversationLeft", conversation);
|
393
|
-
});
|
394
|
-
this.conversations.on("conversationUpdated", (args) => this.emit("conversationUpdated", args));
|
395
|
-
this.conversations.on("participantJoined", (participant) => {
|
396
|
-
this.emit("participantJoined", participant);
|
397
|
-
});
|
398
|
-
this.conversations.on("participantLeft", (participant) => {
|
399
|
-
this.emit("participantLeft", participant);
|
400
|
-
});
|
401
|
-
this.conversations.on("participantUpdated", (args) => this.emit("participantUpdated", args));
|
402
|
-
this.conversations.on("messageAdded", (message) => this.emit("messageAdded", message));
|
403
|
-
this.conversations.on("messageUpdated", (args) => this.emit("messageUpdated", args));
|
404
|
-
this.conversations.on("messageRemoved", (message) => this.emit("messageRemoved", message));
|
405
|
-
this.conversations.on("typingStarted", (participant) => this.emit("typingStarted", participant));
|
406
|
-
this.conversations.on("typingEnded", (participant) => this.emit("typingEnded", participant));
|
407
|
-
this.conversationsPromise = this.conversations
|
408
|
-
.fetchConversations()
|
409
|
-
.then(() => this.conversations)
|
410
|
-
.catch((error) => {
|
411
|
-
throw error;
|
412
|
-
});
|
413
|
-
await this.services.users.myself._ensureFetched();
|
414
|
-
Client_1.supportedPushChannels.forEach((channelType) => this._subscribeToPushNotifications(channelType));
|
415
|
-
this.services.typingIndicator.initialize();
|
416
|
-
this.services.mcsClient = new mcsClient.McsClient(this.fpaToken, this.configuration.links.mediaService, this.configuration.links.mediaSetService, Object.assign(Object.assign({}, this.options), { transport: undefined }));
|
417
|
-
this._resolveEnsureReady();
|
418
|
-
this.emit("stateChanged", "initialized");
|
453
|
+
/**
|
454
|
+
* Populate the client with init registrations.
|
455
|
+
* @param reg The init registration to populate.
|
456
|
+
*/
|
457
|
+
static populateInitRegistrations(reg) {
|
458
|
+
reg.populateInitRegistrations([notificationTypes.NotificationTypes.TYPING_INDICATOR]);
|
459
|
+
twilioSync.SyncClient.populateInitRegistrations(reg);
|
419
460
|
}
|
420
461
|
/**
|
421
462
|
* Gracefully shut down the client.
|
422
463
|
*/
|
423
464
|
async shutdown() {
|
424
465
|
await this._ensureReady;
|
425
|
-
await this.
|
466
|
+
await this._services.twilsockClient.disconnect();
|
426
467
|
}
|
427
468
|
/**
|
428
469
|
* Update the token used by the client and re-register with the Conversations services.
|
@@ -430,14 +471,14 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
430
471
|
*/
|
431
472
|
async updateToken(token) {
|
432
473
|
await this._ensureReady;
|
433
|
-
|
434
|
-
if (this.
|
474
|
+
Client_1._logger.info("updateToken");
|
475
|
+
if (this._fpaToken === token) {
|
435
476
|
return this;
|
436
477
|
}
|
437
|
-
await this.
|
438
|
-
await this.
|
439
|
-
await this.
|
440
|
-
this.
|
478
|
+
await this._services.twilsockClient.updateToken(token);
|
479
|
+
await this._services.notificationClient.updateToken(token);
|
480
|
+
await this._services.mcsClient.updateToken(token);
|
481
|
+
this._fpaToken = token;
|
441
482
|
return this;
|
442
483
|
}
|
443
484
|
/**
|
@@ -446,13 +487,27 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
446
487
|
*/
|
447
488
|
async getConversationBySid(conversationSid) {
|
448
489
|
await this._ensureReady;
|
449
|
-
await this.
|
450
|
-
let conversation = await this.
|
490
|
+
await this._conversationsEntity.myConversationsRead.promise;
|
491
|
+
let conversation = await this._conversationsEntity.getConversation(conversationSid);
|
451
492
|
if (!conversation) {
|
452
|
-
|
493
|
+
deprecationDecorator.deprecationWarning("The method getConversationBySid is deprecated to retrieve conversations you're not part of. Use peekConversationBySid instead.");
|
494
|
+
conversation = await this.peekConversationBySid(conversationSid);
|
453
495
|
}
|
454
496
|
if (!conversation) {
|
455
|
-
throw new Error(`Conversation with SID ${conversationSid}
|
497
|
+
throw new Error(`Conversation with SID ${conversationSid} was not found.`);
|
498
|
+
}
|
499
|
+
return conversation;
|
500
|
+
}
|
501
|
+
/**
|
502
|
+
* Peek a conversation by its SID.
|
503
|
+
* @param conversationSid Conversation sid
|
504
|
+
* @internal
|
505
|
+
*/
|
506
|
+
async peekConversationBySid(conversationSid) {
|
507
|
+
await this._ensureReady;
|
508
|
+
const conversation = await this._conversationsEntity.peekConversation(conversationSid);
|
509
|
+
if (!conversation) {
|
510
|
+
throw new Error(`Conversation with SID ${conversationSid} was not found.`);
|
456
511
|
}
|
457
512
|
return conversation;
|
458
513
|
}
|
@@ -462,10 +517,10 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
462
517
|
*/
|
463
518
|
async getConversationByUniqueName(uniqueName) {
|
464
519
|
await this._ensureReady;
|
465
|
-
await this.
|
466
|
-
const conversation = await this.
|
520
|
+
await this._conversationsEntity.myConversationsRead.promise;
|
521
|
+
const conversation = await this._conversationsEntity.getConversationByUniqueName(uniqueName);
|
467
522
|
if (!conversation) {
|
468
|
-
throw new Error(`Conversation with unique name ${uniqueName}
|
523
|
+
throw new Error(`Conversation with unique name ${uniqueName} was not found.`);
|
469
524
|
}
|
470
525
|
return conversation;
|
471
526
|
}
|
@@ -474,7 +529,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
474
529
|
*/
|
475
530
|
async getSubscribedConversations() {
|
476
531
|
await this._ensureReady;
|
477
|
-
return this.
|
532
|
+
return this._conversationsPromise.then((conversations) => conversations.getConversations());
|
478
533
|
}
|
479
534
|
/**
|
480
535
|
* Create a conversation on the server and subscribe to its events.
|
@@ -484,18 +539,19 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
484
539
|
async createConversation(options) {
|
485
540
|
await this._ensureReady;
|
486
541
|
options = options || {};
|
487
|
-
return this.
|
542
|
+
return this._conversationsPromise.then((conversationsEntity) => conversationsEntity.addConversation(options));
|
488
543
|
}
|
489
544
|
/**
|
490
545
|
* Register for push notifications.
|
491
546
|
* @param channelType Channel type.
|
492
|
-
* @param registrationId Push notification ID provided by the FCM/APNS service
|
547
|
+
* @param registrationId Push notification ID provided by the FCM/APNS service
|
548
|
+
* on the platform.
|
493
549
|
*/
|
494
550
|
async setPushRegistrationId(channelType, registrationId) {
|
495
551
|
await this._ensureReady;
|
496
552
|
this._subscribeToPushNotifications(channelType);
|
497
|
-
this.
|
498
|
-
await this.
|
553
|
+
this._services.notificationClient.setPushRegistrationId(channelType, registrationId);
|
554
|
+
await this._services.notificationClient.commitChanges(); // Committing before this point is useless because we have no push id
|
499
555
|
}
|
500
556
|
/**
|
501
557
|
* Unregister from push notifications.
|
@@ -505,132 +561,181 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
505
561
|
async unsetPushRegistrationId(channelType) {
|
506
562
|
await this._ensureReady;
|
507
563
|
this._unsubscribeFromPushNotifications(channelType);
|
508
|
-
await this.
|
564
|
+
await this._services.notificationClient.commitChanges();
|
509
565
|
}
|
510
566
|
/**
|
511
567
|
* Clear existing registrations directly using provided device token.
|
512
568
|
* This is useful to ensure stopped subscriptions without resubscribing.
|
513
569
|
*
|
514
|
-
* This function goes completely beside the state machine and removes all
|
515
|
-
*
|
570
|
+
* This function goes completely beside the state machine and removes all
|
571
|
+
* registrations.
|
572
|
+
* Use with caution: if it races with current state machine operations,
|
573
|
+
* madness will ensue.
|
516
574
|
*
|
517
575
|
* @param channelType Channel type.
|
518
|
-
* @param registrationId Push notification ID provided by the FCM/APNS service
|
576
|
+
* @param registrationId Push notification ID provided by the FCM/APNS service
|
577
|
+
* on the platform.
|
519
578
|
*/
|
520
579
|
async removePushRegistrations(channelType, registrationId) {
|
521
580
|
// do not await this._ensureReady() here - it could be called at any moment
|
522
|
-
await this.
|
523
|
-
}
|
524
|
-
static parsePushNotificationChatData(data) {
|
525
|
-
const result = {};
|
526
|
-
for (const key in Client_1.supportedPushDataFields) {
|
527
|
-
if (typeof data[key] === "undefined" || data[key] === null) {
|
528
|
-
continue;
|
529
|
-
}
|
530
|
-
if (key !== "message_index") {
|
531
|
-
result[Client_1.supportedPushDataFields[key]] = data[key];
|
532
|
-
continue;
|
533
|
-
}
|
534
|
-
if (index.parseToNumber(data[key]) !== null) {
|
535
|
-
result[Client_1.supportedPushDataFields[key]] = Number(data[key]);
|
536
|
-
}
|
537
|
-
}
|
538
|
-
return result;
|
539
|
-
}
|
540
|
-
/**
|
541
|
-
* Static method for push notification payload parsing. Returns parsed push as a {@link PushNotification} object.
|
542
|
-
* @param notificationPayload Push notification payload.
|
543
|
-
*/
|
544
|
-
static parsePushNotification(notificationPayload) {
|
545
|
-
log.debug("parsePushNotification, notificationPayload=", notificationPayload);
|
546
|
-
// APNS specifics
|
547
|
-
if (typeof notificationPayload.aps !== "undefined") {
|
548
|
-
if (!notificationPayload.twi_message_type) {
|
549
|
-
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
550
|
-
}
|
551
|
-
const data = Client_1.parsePushNotificationChatData(notificationPayload);
|
552
|
-
const apsPayload = notificationPayload.aps;
|
553
|
-
let body;
|
554
|
-
let title = null;
|
555
|
-
if (typeof apsPayload.alert === "string") {
|
556
|
-
body = apsPayload.alert || null;
|
557
|
-
}
|
558
|
-
else {
|
559
|
-
body = apsPayload.alert.body || null;
|
560
|
-
title = apsPayload.alert.title || null;
|
561
|
-
}
|
562
|
-
return new pushNotification.PushNotification({
|
563
|
-
title,
|
564
|
-
body,
|
565
|
-
sound: apsPayload.sound || null,
|
566
|
-
badge: apsPayload.badge || null,
|
567
|
-
action: apsPayload.category || null,
|
568
|
-
type: notificationPayload.twi_message_type,
|
569
|
-
data: data,
|
570
|
-
});
|
571
|
-
}
|
572
|
-
// FCM specifics
|
573
|
-
if (typeof notificationPayload.data !== "undefined") {
|
574
|
-
const dataPayload = notificationPayload.data;
|
575
|
-
if (!dataPayload.twi_message_type) {
|
576
|
-
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
577
|
-
}
|
578
|
-
const data = Client_1.parsePushNotificationChatData(notificationPayload.data);
|
579
|
-
return new pushNotification.PushNotification({
|
580
|
-
title: dataPayload.twi_title || null,
|
581
|
-
body: dataPayload.twi_body || null,
|
582
|
-
sound: dataPayload.twi_sound || null,
|
583
|
-
badge: null,
|
584
|
-
action: dataPayload.twi_action || null,
|
585
|
-
type: dataPayload.twi_message_type,
|
586
|
-
data: data,
|
587
|
-
});
|
588
|
-
}
|
589
|
-
throw new Error("Provided push notification payload is not Programmable Chat notification");
|
581
|
+
await this._services.notificationClient.removeRegistrations(channelType, registrationId);
|
590
582
|
}
|
591
583
|
/**
|
592
|
-
* Handle push notification payload parsing and emit the
|
584
|
+
* Handle push notification payload parsing and emit the
|
585
|
+
* {@link Client.pushNotification} event on this {@link Client} instance.
|
593
586
|
* @param notificationPayload Push notification payload
|
594
587
|
*/
|
595
588
|
async handlePushNotification(notificationPayload) {
|
596
589
|
await this._ensureReady;
|
597
|
-
|
590
|
+
Client_1._logger.debug("handlePushNotification, notificationPayload=", notificationPayload);
|
598
591
|
this.emit("pushNotification", Client_1.parsePushNotification(notificationPayload));
|
599
592
|
}
|
600
593
|
/**
|
601
|
-
* Gets a user with the given identity. If it's in the subscribed list, then
|
594
|
+
* Gets a user with the given identity. If it's in the subscribed list, then
|
595
|
+
* return the user object from it;
|
602
596
|
* if not, then subscribe and add user to the subscribed list.
|
603
597
|
* @param identity Identity of the user.
|
604
598
|
* @returns A fully initialized user.
|
605
599
|
*/
|
606
600
|
async getUser(identity) {
|
607
601
|
await this._ensureReady;
|
608
|
-
return this.
|
602
|
+
return this._services.users.getUser(identity);
|
609
603
|
}
|
610
604
|
/**
|
611
605
|
* Get a list of subscribed user objects.
|
612
606
|
*/
|
613
607
|
async getSubscribedUsers() {
|
614
608
|
await this._ensureReady;
|
615
|
-
return this.
|
609
|
+
return this._services.users.getSubscribedUsers();
|
610
|
+
}
|
611
|
+
/**
|
612
|
+
* Get content URLs for all media attachments in the given set of media sids
|
613
|
+
* using a single operation.
|
614
|
+
* @param mediaSids Set of media sids to query for the content URL.
|
615
|
+
*/
|
616
|
+
getTemporaryContentUrlsForMediaSids(mediaSids) {
|
617
|
+
return new mcsClient.CancellablePromise(async (resolve, reject, onCancel) => {
|
618
|
+
if (!this._services.mcsClient || !mediaSids) {
|
619
|
+
reject(new Error("Media Content Service is unavailable"));
|
620
|
+
return;
|
621
|
+
}
|
622
|
+
const request = this._services.mcsClient.mediaSetGetContentUrls(mediaSids);
|
623
|
+
onCancel(() => {
|
624
|
+
request.cancel();
|
625
|
+
});
|
626
|
+
try {
|
627
|
+
const urls = await request;
|
628
|
+
resolve(urls);
|
629
|
+
}
|
630
|
+
catch (e) {
|
631
|
+
reject(e);
|
632
|
+
}
|
633
|
+
});
|
634
|
+
}
|
635
|
+
/**
|
636
|
+
* Get content URLs for all media attachments in the given set using a single
|
637
|
+
* operation.
|
638
|
+
* @param contentSet Set of media attachments to query content URLs.
|
639
|
+
*/
|
640
|
+
getTemporaryContentUrlsForMedia(contentSet) {
|
641
|
+
// We ignore existing mcsMedia members of each of the media entries.
|
642
|
+
// Instead, we just collect their sids and pull new descriptors from a
|
643
|
+
// mediaSet GET endpoint.
|
644
|
+
const sids = contentSet.map((m) => m.sid);
|
645
|
+
return this.getTemporaryContentUrlsForMediaSids(sids);
|
646
|
+
}
|
647
|
+
/**
|
648
|
+
* Initialize the client.
|
649
|
+
*/
|
650
|
+
async _initialize() {
|
651
|
+
const configurationResponse = await this._services.commandExecutor.fetchResource("Client/v2/Configuration");
|
652
|
+
this._configuration = new configuration.Configuration(this._options, configurationResponse, Client_1._logger);
|
653
|
+
this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
|
654
|
+
this._services.typingIndicator = new typingIndicator.TypingIndicator(this.getConversationBySid.bind(this), this._configuration, this._services);
|
655
|
+
this._services.network = new network.Network(this._configuration, this._services);
|
656
|
+
this._services.users = new users.Users(this._myself, this._configuration, this._services);
|
657
|
+
this._services.users.on("userSubscribed", (user) => {
|
658
|
+
this.emit("userSubscribed", user);
|
659
|
+
});
|
660
|
+
this._services.users.on("userUpdated", (args) => this.emit("userUpdated", args));
|
661
|
+
this._services.users.on("userUnsubscribed", (user) => {
|
662
|
+
this.emit("userUnsubscribed", user);
|
663
|
+
});
|
664
|
+
this._conversationsEntity = new conversations.Conversations(this._configuration, this._services);
|
665
|
+
this._conversationsEntity.on("conversationAdded", (conversation) => {
|
666
|
+
this.emit("conversationAdded", conversation);
|
667
|
+
});
|
668
|
+
this._conversationsEntity.on("conversationRemoved", (conversation) => {
|
669
|
+
this.emit("conversationRemoved", conversation);
|
670
|
+
});
|
671
|
+
this._conversationsEntity.on("conversationJoined", (conversation) => {
|
672
|
+
this.emit("conversationJoined", conversation);
|
673
|
+
});
|
674
|
+
this._conversationsEntity.on("conversationLeft", (conversation) => {
|
675
|
+
this.emit("conversationLeft", conversation);
|
676
|
+
});
|
677
|
+
this._conversationsEntity.on("conversationUpdated", (args) => this.emit("conversationUpdated", args));
|
678
|
+
this._conversationsEntity.on("participantJoined", (participant) => {
|
679
|
+
this.emit("participantJoined", participant);
|
680
|
+
});
|
681
|
+
this._conversationsEntity.on("participantLeft", (participant) => {
|
682
|
+
this.emit("participantLeft", participant);
|
683
|
+
});
|
684
|
+
this._conversationsEntity.on("participantUpdated", (args) => this.emit("participantUpdated", args));
|
685
|
+
this._conversationsEntity.on("messageAdded", (message) => this.emit("messageAdded", message));
|
686
|
+
this._conversationsEntity.on("messageUpdated", (args) => this.emit("messageUpdated", args));
|
687
|
+
this._conversationsEntity.on("messageRemoved", (message) => this.emit("messageRemoved", message));
|
688
|
+
this._conversationsEntity.on("typingStarted", (participant) => this.emit("typingStarted", participant));
|
689
|
+
this._conversationsEntity.on("typingEnded", (participant) => this.emit("typingEnded", participant));
|
690
|
+
this._conversationsPromise = this._conversationsEntity
|
691
|
+
.fetchConversations()
|
692
|
+
.then(() => this._conversationsEntity)
|
693
|
+
.catch((error) => {
|
694
|
+
throw error;
|
695
|
+
});
|
696
|
+
await this._services.users.myself._ensureFetched();
|
697
|
+
Client_1._supportedPushChannels.forEach((channelType) => this._subscribeToPushNotifications(channelType));
|
698
|
+
this._services.typingIndicator.initialize();
|
699
|
+
this._services.mcsClient = new mcsClient.McsClient(this._fpaToken, this._configuration.links.mediaService, this._configuration.links.mediaSetService, Object.assign(Object.assign({}, this._options), { transport: undefined }));
|
700
|
+
this._resolveEnsureReady();
|
701
|
+
this.emit("stateChanged", "initialized");
|
702
|
+
this.emit("initialized", {});
|
703
|
+
}
|
704
|
+
/**
|
705
|
+
* Subscribe to push notifications.
|
706
|
+
* @param channelType The channel type to subscribe to.
|
707
|
+
*/
|
708
|
+
_subscribeToPushNotifications(channelType) {
|
709
|
+
[
|
710
|
+
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
711
|
+
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
712
|
+
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
713
|
+
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
714
|
+
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
715
|
+
].forEach((messageType) => {
|
716
|
+
this._services.notificationClient.subscribe(channelType, messageType);
|
717
|
+
});
|
718
|
+
}
|
719
|
+
/**
|
720
|
+
* Unsubscribe from push notifications.
|
721
|
+
* @param channelType The channel type to unsubscribe from.
|
722
|
+
*/
|
723
|
+
_unsubscribeFromPushNotifications(channelType) {
|
724
|
+
[
|
725
|
+
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
726
|
+
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
727
|
+
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
728
|
+
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
729
|
+
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
730
|
+
].forEach((messageType) => {
|
731
|
+
this._services.notificationClient.unsubscribe(channelType, messageType);
|
732
|
+
});
|
616
733
|
}
|
617
734
|
};
|
618
735
|
/**
|
619
|
-
*
|
620
|
-
|
621
|
-
|
622
|
-
exports.Client.supportedPushChannels = [
|
623
|
-
"fcm",
|
624
|
-
"apn",
|
625
|
-
];
|
626
|
-
exports.Client.supportedPushDataFields = {
|
627
|
-
conversation_sid: "conversationSid",
|
628
|
-
message_sid: "messageSid",
|
629
|
-
message_index: "messageIndex",
|
630
|
-
};
|
631
|
-
/**
|
632
|
-
* Fired when a conversation becomes visible to the client. The event is also triggered when the client creates a new conversation.
|
633
|
-
* Fired for all conversations client has joined.
|
736
|
+
* Fired when a conversation becomes visible to the client. The event is also
|
737
|
+
* triggered when the client creates a new conversation.
|
738
|
+
* Fired for all conversations that the client has joined.
|
634
739
|
*
|
635
740
|
* Parameters:
|
636
741
|
* 1. {@link Conversation} `conversation` - the conversation in question
|
@@ -662,14 +767,17 @@ exports.Client.conversationLeft = "conversationLeft";
|
|
662
767
|
*/
|
663
768
|
exports.Client.conversationRemoved = "conversationRemoved";
|
664
769
|
/**
|
665
|
-
* Fired when the attributes or the metadata of a conversation have been
|
666
|
-
* During conversation's creation and initialization, this event
|
667
|
-
* for same joined or created conversation as
|
770
|
+
* Fired when the attributes or the metadata of a conversation have been
|
771
|
+
* updated. During conversation's creation and initialization, this event
|
772
|
+
* might be fired multiple times for same joined or created conversation as
|
773
|
+
* new data is arriving from different sources.
|
668
774
|
*
|
669
775
|
* Parameters:
|
670
|
-
* 1. object `data` - info object provided with the event. It has the
|
776
|
+
* 1. object `data` - info object provided with the event. It has the
|
777
|
+
* following properties:
|
671
778
|
* * {@link Conversation} `conversation` - the conversation in question
|
672
|
-
* * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons
|
779
|
+
* * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons
|
780
|
+
* for the update
|
673
781
|
* @event
|
674
782
|
*/
|
675
783
|
exports.Client.conversationUpdated = "conversationUpdated";
|
@@ -693,9 +801,11 @@ exports.Client.participantLeft = "participantLeft";
|
|
693
801
|
* Fired when a participant's fields have been updated.
|
694
802
|
*
|
695
803
|
* Parameters:
|
696
|
-
* 1. object `data` - info object provided with the event. It has the
|
804
|
+
* 1. object `data` - info object provided with the event. It has the
|
805
|
+
* following properties:
|
697
806
|
* * {@link Participant} `participant` - the participant in question
|
698
|
-
* * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons
|
807
|
+
* * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons
|
808
|
+
* for the update
|
699
809
|
* @event
|
700
810
|
*/
|
701
811
|
exports.Client.participantUpdated = "participantUpdated";
|
@@ -719,16 +829,16 @@ exports.Client.messageRemoved = "messageRemoved";
|
|
719
829
|
* Fired when the fields of an existing message are updated with new values.
|
720
830
|
*
|
721
831
|
* Parameters:
|
722
|
-
* 1. object `data` - info object provided with the event. It has the
|
832
|
+
* 1. object `data` - info object provided with the event. It has the
|
833
|
+
* following properties:
|
723
834
|
* * {@link Message} `message` - the message in question
|
724
|
-
* * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for
|
835
|
+
* * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for
|
836
|
+
* the update
|
725
837
|
* @event
|
726
838
|
*/
|
727
839
|
exports.Client.messageUpdated = "messageUpdated";
|
728
840
|
/**
|
729
841
|
* Fired when the token is about to expire and needs to be updated.
|
730
|
-
* * Parameters:
|
731
|
-
* 1. number `message` - token's time to live
|
732
842
|
* @event
|
733
843
|
*/
|
734
844
|
exports.Client.tokenAboutToExpire = "tokenAboutToExpire";
|
@@ -754,10 +864,12 @@ exports.Client.typingEnded = "typingEnded";
|
|
754
864
|
*/
|
755
865
|
exports.Client.typingStarted = "typingStarted";
|
756
866
|
/**
|
757
|
-
* Fired when the client has received (and parsed) a push notification via one
|
867
|
+
* Fired when the client has received (and parsed) a push notification via one
|
868
|
+
* of the push channels (apn or fcm).
|
758
869
|
*
|
759
870
|
* Parameters:
|
760
|
-
* 1. {@link PushNotification} `pushNotification` - the push notification in
|
871
|
+
* 1. {@link PushNotification} `pushNotification` - the push notification in
|
872
|
+
* question
|
761
873
|
* @event
|
762
874
|
*/
|
763
875
|
exports.Client.pushNotification = "pushNotification";
|
@@ -778,16 +890,20 @@ exports.Client.userSubscribed = "userSubscribed";
|
|
778
890
|
*/
|
779
891
|
exports.Client.userUnsubscribed = "userUnsubscribed";
|
780
892
|
/**
|
781
|
-
* Fired when the properties or the reachability status of a user have been
|
893
|
+
* Fired when the properties or the reachability status of a user have been
|
894
|
+
* updated.
|
782
895
|
*
|
783
896
|
* Parameters:
|
784
|
-
* 1. object `data` - info object provided with the event. It has the
|
897
|
+
* 1. object `data` - info object provided with the event. It has the
|
898
|
+
* following properties:
|
785
899
|
* * {@link User} `user` - the user in question
|
786
|
-
* * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the
|
900
|
+
* * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the
|
901
|
+
* update
|
787
902
|
* @event
|
788
903
|
*/
|
789
904
|
exports.Client.userUpdated = "userUpdated";
|
790
905
|
/**
|
906
|
+
* @deprecated Use initialized or initFailed events instead
|
791
907
|
* Fired when the state of the client has been changed.
|
792
908
|
*
|
793
909
|
* Parameters:
|
@@ -795,10 +911,28 @@ exports.Client.userUpdated = "userUpdated";
|
|
795
911
|
* @event
|
796
912
|
*/
|
797
913
|
exports.Client.stateChanged = "stateChanged";
|
914
|
+
/**
|
915
|
+
* Fired when the client has completed initialization successfully.
|
916
|
+
*
|
917
|
+
* Parameters:
|
918
|
+
* 1. object `data` - Optional info object provided with the event
|
919
|
+
* @event
|
920
|
+
*/
|
921
|
+
exports.Client.initialized = "initialized";
|
922
|
+
/**
|
923
|
+
* Fired when the client initialization failed.
|
924
|
+
*
|
925
|
+
* Parameters:
|
926
|
+
* 1. object `data` - info object provided with the event. It has the
|
927
|
+
* following property:
|
928
|
+
* * Error? `error` - the initialization error if present
|
929
|
+
* @event
|
930
|
+
*/
|
931
|
+
exports.Client.initFailed = "initFailed";
|
798
932
|
/**
|
799
933
|
* Fired when the connection state of the client has been changed.
|
800
934
|
*
|
801
|
-
*
|
935
|
+
* Parameters:
|
802
936
|
* 1. {@link ConnectionState} `state` - the new connection state
|
803
937
|
* @event
|
804
938
|
*/
|
@@ -807,7 +941,8 @@ exports.Client.connectionStateChanged = "connectionStateChanged";
|
|
807
941
|
* Fired when the connection is interrupted for an unexpected reason.
|
808
942
|
*
|
809
943
|
* Parameters:
|
810
|
-
* 1. object `data` - info object provided with the event. It has the
|
944
|
+
* 1. object `data` - info object provided with the event. It has the
|
945
|
+
* following properties:
|
811
946
|
* * boolean `terminal` - Twilsock will stop connection attempts if true
|
812
947
|
* * string `message` - the error message of the root cause
|
813
948
|
* * number? `httpStatusCode` - http status code if available
|
@@ -815,6 +950,37 @@ exports.Client.connectionStateChanged = "connectionStateChanged";
|
|
815
950
|
* @event
|
816
951
|
*/
|
817
952
|
exports.Client.connectionError = "connectionError";
|
953
|
+
/**
|
954
|
+
* Current version of the Conversations client.
|
955
|
+
*/
|
956
|
+
exports.Client.version = _package.version;
|
957
|
+
/**
|
958
|
+
* Logger instance.
|
959
|
+
*/
|
960
|
+
exports.Client._logger = logger.Logger.scope("Client");
|
961
|
+
/**
|
962
|
+
* Supported push notification channels.
|
963
|
+
*/
|
964
|
+
exports.Client._supportedPushChannels = [
|
965
|
+
"fcm",
|
966
|
+
"apn",
|
967
|
+
];
|
968
|
+
/**
|
969
|
+
* Supported push data fields.
|
970
|
+
*/
|
971
|
+
exports.Client._supportedPushDataFields = {
|
972
|
+
conversation_sid: "conversationSid",
|
973
|
+
conversation_title: "conversationTitle",
|
974
|
+
message_sid: "messageSid",
|
975
|
+
message_index: "messageIndex",
|
976
|
+
media_count: "mediaCount",
|
977
|
+
media: "media", // object
|
978
|
+
};
|
979
|
+
tslib_es6.__decorate([
|
980
|
+
deprecationDecorator.deprecated("token"),
|
981
|
+
tslib_es6.__metadata("design:type", String),
|
982
|
+
tslib_es6.__metadata("design:paramtypes", [])
|
983
|
+
], exports.Client.prototype, "token", null);
|
818
984
|
tslib_es6.__decorate([
|
819
985
|
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
820
986
|
tslib_es6.__metadata("design:type", Function),
|
@@ -827,6 +993,12 @@ tslib_es6.__decorate([
|
|
827
993
|
tslib_es6.__metadata("design:paramtypes", [String]),
|
828
994
|
tslib_es6.__metadata("design:returntype", Promise)
|
829
995
|
], exports.Client.prototype, "getConversationBySid", null);
|
996
|
+
tslib_es6.__decorate([
|
997
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
998
|
+
tslib_es6.__metadata("design:type", Function),
|
999
|
+
tslib_es6.__metadata("design:paramtypes", [String]),
|
1000
|
+
tslib_es6.__metadata("design:returntype", Promise)
|
1001
|
+
], exports.Client.prototype, "peekConversationBySid", null);
|
830
1002
|
tslib_es6.__decorate([
|
831
1003
|
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
832
1004
|
tslib_es6.__metadata("design:type", Function),
|
@@ -877,6 +1049,19 @@ tslib_es6.__decorate([
|
|
877
1049
|
tslib_es6.__metadata("design:returntype", Promise)
|
878
1050
|
], exports.Client.prototype, "getUser", null);
|
879
1051
|
tslib_es6.__decorate([
|
1052
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("strings", "string")),
|
1053
|
+
tslib_es6.__metadata("design:type", Function),
|
1054
|
+
tslib_es6.__metadata("design:paramtypes", [Array]),
|
1055
|
+
tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
|
1056
|
+
], exports.Client.prototype, "getTemporaryContentUrlsForMediaSids", null);
|
1057
|
+
tslib_es6.__decorate([
|
1058
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("media", media.Media)),
|
1059
|
+
tslib_es6.__metadata("design:type", Function),
|
1060
|
+
tslib_es6.__metadata("design:paramtypes", [Array]),
|
1061
|
+
tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
|
1062
|
+
], exports.Client.prototype, "getTemporaryContentUrlsForMedia", null);
|
1063
|
+
tslib_es6.__decorate([
|
1064
|
+
deprecationDecorator.deprecated("Client.create()", "new Client()"),
|
880
1065
|
declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]),
|
881
1066
|
tslib_es6.__metadata("design:type", Function),
|
882
1067
|
tslib_es6.__metadata("design:paramtypes", [String, Object]),
|