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