@twilio/conversations 2.1.0-rc.9 → 3.0.0-canary.9
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 +7 -3
- package/builds/browser.js +2707 -1986
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +513 -305
- package/builds/lib.js +2707 -1986
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +5232 -5070
- package/builds/twilio-conversations.min.js +1 -16
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +417 -283
- 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 +407 -374
- 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 +1 -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 +53 -26
- 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/package.json +22 -18
- package/CHANGELOG.md +0 -412
- package/docs/assets/css/main.css +0 -2660
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +0 -3184
- package/docs/classes/Client.html +0 -4073
- package/docs/classes/Conversation.html +0 -4325
- package/docs/classes/DetailedDeliveryReceipt.html +0 -3163
- package/docs/classes/Media.html +0 -3193
- package/docs/classes/Message.html +0 -3677
- package/docs/classes/MessageBuilder.html +0 -3254
- package/docs/classes/Participant.html +0 -3444
- package/docs/classes/PushNotification.html +0 -3130
- package/docs/classes/RestPaginator.html +0 -3160
- package/docs/classes/UnsentMessage.html +0 -3042
- package/docs/classes/User.html +0 -3349
- package/docs/index.html +0 -3512
- package/docs/interfaces/ClientOptions.html +0 -3034
- package/docs/interfaces/ConversationBindings.html +0 -3001
- package/docs/interfaces/ConversationEmailBinding.html +0 -3001
- package/docs/interfaces/ConversationLimits.html +0 -3098
- package/docs/interfaces/ConversationState.html +0 -3050
- package/docs/interfaces/CreateConversationOptions.html +0 -3066
- package/docs/interfaces/LastMessage.html +0 -3050
- package/docs/interfaces/Paginator.html +0 -3141
- package/docs/interfaces/ParticipantBindings.html +0 -3001
- package/docs/interfaces/ParticipantEmailBinding.html +0 -3001
- package/docs/interfaces/PushNotificationData.html +0 -3066
- package/docs/interfaces/SendEmailOptions.html +0 -3034
- package/docs/interfaces/SendMediaOptions.html +0 -3068
- package/docs/modules.html +0 -3513
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,96 @@ 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
|
-
this.
|
257
|
-
this.
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
this.
|
262
|
-
this.services.twilsockClient.off("disconnected", emitFailed);
|
263
|
+
this._services.twilsockClient.onceWithReplay("connectionError", emitFailed);
|
264
|
+
this._services.twilsockClient.onceWithReplay("disconnected", emitFailed);
|
265
|
+
this._services.twilsockClient.onceWithReplay("connected", async () => {
|
266
|
+
Client_1._logger.debug(`ConversationsClient started INITIALIZING`);
|
267
|
+
this._services.twilsockClient.off("connectionError", emitFailed);
|
268
|
+
this._services.twilsockClient.off("disconnected", emitFailed);
|
263
269
|
try {
|
264
270
|
const startupEvent = "conversations.client.startup";
|
265
|
-
this.
|
271
|
+
this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
|
266
272
|
await this._initialize();
|
267
|
-
this.
|
273
|
+
this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
|
268
274
|
}
|
269
275
|
catch (err) {
|
270
276
|
// Fail ChatClient if initialization is incomplete
|
271
277
|
this._rejectEnsureReady(err);
|
272
|
-
this.emit("stateChanged", "failed");
|
278
|
+
this.emit("stateChanged", { state: "failed", error: err });
|
273
279
|
}
|
274
280
|
});
|
275
281
|
this._ensureReady = new Promise((resolve, reject) => {
|
@@ -277,12 +283,28 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
277
283
|
this._rejectEnsureReady = reject;
|
278
284
|
}).catch(() => void 0); // @todo How to process unhandled rejection here?
|
279
285
|
if (startTwilsock) {
|
280
|
-
this.
|
286
|
+
this._services.twilsockClient.connect();
|
281
287
|
}
|
282
288
|
}
|
283
|
-
|
284
|
-
|
285
|
-
|
289
|
+
/**
|
290
|
+
* Information of the logged-in user. Before client initialization, returns an
|
291
|
+
* uninitialized user. Will trigger a {@link Client.userUpdated} event after
|
292
|
+
* initialization.
|
293
|
+
*/
|
294
|
+
get user() {
|
295
|
+
return this._myself;
|
296
|
+
}
|
297
|
+
/**
|
298
|
+
* Client reachability state. Throws an error if accessed before the client
|
299
|
+
* initialization was completed.
|
300
|
+
*/
|
301
|
+
get reachabilityEnabled() {
|
302
|
+
if (!this._configuration) {
|
303
|
+
throw new Error("Reachability information could not yet be accessed as the client " +
|
304
|
+
"has not yet been initialized. Subscribe to the 'stateChanged' event " +
|
305
|
+
"to properly react to the client initialization.");
|
306
|
+
}
|
307
|
+
return this._configuration.reachabilityEnabled;
|
286
308
|
}
|
287
309
|
/**
|
288
310
|
* @deprecated Call constructor directly.
|
@@ -320,109 +342,104 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
320
342
|
return client;
|
321
343
|
}
|
322
344
|
/**
|
323
|
-
*
|
324
|
-
*
|
325
|
-
*
|
345
|
+
* Static method for push notification payload parsing. Returns parsed push as
|
346
|
+
* a {@link PushNotification} object.
|
347
|
+
* @param notificationPayload Push notification payload.
|
326
348
|
*/
|
327
|
-
|
328
|
-
|
349
|
+
static parsePushNotification(notificationPayload) {
|
350
|
+
Client_1._logger.debug("parsePushNotification, notificationPayload=", notificationPayload);
|
351
|
+
// APNS specifics
|
352
|
+
if (typeof notificationPayload.aps !== "undefined") {
|
353
|
+
if (!notificationPayload.twi_message_type) {
|
354
|
+
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
355
|
+
}
|
356
|
+
const data = Client_1._parsePushNotificationChatData(notificationPayload);
|
357
|
+
const apsPayload = notificationPayload.aps;
|
358
|
+
let body;
|
359
|
+
let title = null;
|
360
|
+
if (typeof apsPayload.alert === "string") {
|
361
|
+
body = apsPayload.alert || null;
|
362
|
+
}
|
363
|
+
else {
|
364
|
+
body = apsPayload.alert.body || null;
|
365
|
+
title = apsPayload.alert.title || null;
|
366
|
+
}
|
367
|
+
return new pushNotification.PushNotification({
|
368
|
+
title,
|
369
|
+
body,
|
370
|
+
sound: apsPayload.sound || null,
|
371
|
+
badge: apsPayload.badge || null,
|
372
|
+
action: apsPayload.category || null,
|
373
|
+
type: notificationPayload.twi_message_type,
|
374
|
+
data: data,
|
375
|
+
});
|
376
|
+
}
|
377
|
+
// FCM specifics
|
378
|
+
if (typeof notificationPayload.data !== "undefined") {
|
379
|
+
const dataPayload = notificationPayload.data;
|
380
|
+
if (!dataPayload.twi_message_type) {
|
381
|
+
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
382
|
+
}
|
383
|
+
const data = Client_1._parsePushNotificationChatData(notificationPayload.data);
|
384
|
+
return new pushNotification.PushNotification({
|
385
|
+
title: dataPayload.twi_title || null,
|
386
|
+
body: dataPayload.twi_body || null,
|
387
|
+
sound: dataPayload.twi_sound || null,
|
388
|
+
badge: null,
|
389
|
+
action: dataPayload.twi_action || null,
|
390
|
+
type: dataPayload.twi_message_type,
|
391
|
+
data: data,
|
392
|
+
});
|
393
|
+
}
|
394
|
+
throw new Error("Provided push notification payload is not Programmable Chat notification");
|
329
395
|
}
|
330
396
|
/**
|
331
|
-
*
|
332
|
-
*
|
397
|
+
* Static method for parsing push notification chat data.
|
398
|
+
* @param data Data to parse
|
333
399
|
*/
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
400
|
+
static _parsePushNotificationChatData(data) {
|
401
|
+
const result = {};
|
402
|
+
for (const key in Client_1._supportedPushDataFields) {
|
403
|
+
const value = data[key];
|
404
|
+
if (typeof value === "undefined" || value === null) {
|
405
|
+
continue;
|
406
|
+
}
|
407
|
+
if (key === "message_index" || key === "media_count") {
|
408
|
+
const number = index.parseToNumber(value);
|
409
|
+
if (number !== null) {
|
410
|
+
result[Client_1._supportedPushDataFields[key]] = number;
|
411
|
+
}
|
412
|
+
continue;
|
413
|
+
}
|
414
|
+
if (key === "media") {
|
415
|
+
if (typeof value === "string") {
|
416
|
+
try {
|
417
|
+
result[Client_1._supportedPushDataFields[key]] = JSON.parse(value);
|
418
|
+
}
|
419
|
+
catch (_a) {
|
420
|
+
Client_1._logger.debug("Media message notification parsing error");
|
421
|
+
}
|
422
|
+
}
|
423
|
+
continue;
|
424
|
+
}
|
425
|
+
result[Client_1._supportedPushDataFields[key]] = value;
|
339
426
|
}
|
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
|
-
});
|
427
|
+
return result;
|
366
428
|
}
|
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");
|
429
|
+
/**
|
430
|
+
* Populate the client with init registrations.
|
431
|
+
* @param reg The init registration to populate.
|
432
|
+
*/
|
433
|
+
static populateInitRegistrations(reg) {
|
434
|
+
reg.populateInitRegistrations([notificationTypes.NotificationTypes.TYPING_INDICATOR]);
|
435
|
+
twilioSync.SyncClient.populateInitRegistrations(reg);
|
419
436
|
}
|
420
437
|
/**
|
421
438
|
* Gracefully shut down the client.
|
422
439
|
*/
|
423
440
|
async shutdown() {
|
424
441
|
await this._ensureReady;
|
425
|
-
await this.
|
442
|
+
await this._services.twilsockClient.disconnect();
|
426
443
|
}
|
427
444
|
/**
|
428
445
|
* Update the token used by the client and re-register with the Conversations services.
|
@@ -430,14 +447,14 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
430
447
|
*/
|
431
448
|
async updateToken(token) {
|
432
449
|
await this._ensureReady;
|
433
|
-
|
434
|
-
if (this.
|
450
|
+
Client_1._logger.info("updateToken");
|
451
|
+
if (this._fpaToken === token) {
|
435
452
|
return this;
|
436
453
|
}
|
437
|
-
await this.
|
438
|
-
await this.
|
439
|
-
await this.
|
440
|
-
this.
|
454
|
+
await this._services.twilsockClient.updateToken(token);
|
455
|
+
await this._services.notificationClient.updateToken(token);
|
456
|
+
await this._services.mcsClient.updateToken(token);
|
457
|
+
this._fpaToken = token;
|
441
458
|
return this;
|
442
459
|
}
|
443
460
|
/**
|
@@ -446,13 +463,23 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
446
463
|
*/
|
447
464
|
async getConversationBySid(conversationSid) {
|
448
465
|
await this._ensureReady;
|
449
|
-
await this.
|
450
|
-
|
466
|
+
await this._conversationsEntity.myConversationsRead.promise;
|
467
|
+
const conversation = await this._conversationsEntity.getConversation(conversationSid);
|
451
468
|
if (!conversation) {
|
452
|
-
|
469
|
+
throw new Error(`Conversation with SID ${conversationSid} was not found.`);
|
453
470
|
}
|
471
|
+
return conversation;
|
472
|
+
}
|
473
|
+
/**
|
474
|
+
* Peek a conversation by its SID.
|
475
|
+
* @param conversationSid Conversation sid
|
476
|
+
* @internal
|
477
|
+
*/
|
478
|
+
async peekConversationBySid(conversationSid) {
|
479
|
+
await this._ensureReady;
|
480
|
+
const conversation = await this._conversationsEntity.peekConversation(conversationSid);
|
454
481
|
if (!conversation) {
|
455
|
-
throw new Error(`Conversation with SID ${conversationSid}
|
482
|
+
throw new Error(`Conversation with SID ${conversationSid} was not found.`);
|
456
483
|
}
|
457
484
|
return conversation;
|
458
485
|
}
|
@@ -462,10 +489,10 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
462
489
|
*/
|
463
490
|
async getConversationByUniqueName(uniqueName) {
|
464
491
|
await this._ensureReady;
|
465
|
-
await this.
|
466
|
-
const conversation = await this.
|
492
|
+
await this._conversationsEntity.myConversationsRead.promise;
|
493
|
+
const conversation = await this._conversationsEntity.getConversationByUniqueName(uniqueName);
|
467
494
|
if (!conversation) {
|
468
|
-
throw new Error(`Conversation with unique name ${uniqueName}
|
495
|
+
throw new Error(`Conversation with unique name ${uniqueName} was not found.`);
|
469
496
|
}
|
470
497
|
return conversation;
|
471
498
|
}
|
@@ -474,7 +501,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
474
501
|
*/
|
475
502
|
async getSubscribedConversations() {
|
476
503
|
await this._ensureReady;
|
477
|
-
return this.
|
504
|
+
return this._conversationsPromise.then((conversations) => conversations.getConversations());
|
478
505
|
}
|
479
506
|
/**
|
480
507
|
* Create a conversation on the server and subscribe to its events.
|
@@ -484,18 +511,19 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
484
511
|
async createConversation(options) {
|
485
512
|
await this._ensureReady;
|
486
513
|
options = options || {};
|
487
|
-
return this.
|
514
|
+
return this._conversationsPromise.then((conversationsEntity) => conversationsEntity.addConversation(options));
|
488
515
|
}
|
489
516
|
/**
|
490
517
|
* Register for push notifications.
|
491
518
|
* @param channelType Channel type.
|
492
|
-
* @param registrationId Push notification ID provided by the FCM/APNS service
|
519
|
+
* @param registrationId Push notification ID provided by the FCM/APNS service
|
520
|
+
* on the platform.
|
493
521
|
*/
|
494
522
|
async setPushRegistrationId(channelType, registrationId) {
|
495
523
|
await this._ensureReady;
|
496
524
|
this._subscribeToPushNotifications(channelType);
|
497
|
-
this.
|
498
|
-
await this.
|
525
|
+
this._services.notificationClient.setPushRegistrationId(channelType, registrationId);
|
526
|
+
await this._services.notificationClient.commitChanges(); // Committing before this point is useless because we have no push id
|
499
527
|
}
|
500
528
|
/**
|
501
529
|
* Unregister from push notifications.
|
@@ -505,132 +533,180 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
505
533
|
async unsetPushRegistrationId(channelType) {
|
506
534
|
await this._ensureReady;
|
507
535
|
this._unsubscribeFromPushNotifications(channelType);
|
508
|
-
await this.
|
536
|
+
await this._services.notificationClient.commitChanges();
|
509
537
|
}
|
510
538
|
/**
|
511
539
|
* Clear existing registrations directly using provided device token.
|
512
540
|
* This is useful to ensure stopped subscriptions without resubscribing.
|
513
541
|
*
|
514
|
-
* This function goes completely beside the state machine and removes all
|
515
|
-
*
|
542
|
+
* This function goes completely beside the state machine and removes all
|
543
|
+
* registrations.
|
544
|
+
* Use with caution: if it races with current state machine operations,
|
545
|
+
* madness will ensue.
|
516
546
|
*
|
517
547
|
* @param channelType Channel type.
|
518
|
-
* @param registrationId Push notification ID provided by the FCM/APNS service
|
548
|
+
* @param registrationId Push notification ID provided by the FCM/APNS service
|
549
|
+
* on the platform.
|
519
550
|
*/
|
520
551
|
async removePushRegistrations(channelType, registrationId) {
|
521
552
|
// 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;
|
553
|
+
await this._services.notificationClient.removeRegistrations(channelType, registrationId);
|
539
554
|
}
|
540
555
|
/**
|
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.
|
556
|
+
* Handle push notification payload parsing and emit the
|
557
|
+
* {@link Client.pushNotification} event on this {@link Client} instance.
|
593
558
|
* @param notificationPayload Push notification payload
|
594
559
|
*/
|
595
560
|
async handlePushNotification(notificationPayload) {
|
596
561
|
await this._ensureReady;
|
597
|
-
|
562
|
+
Client_1._logger.debug("handlePushNotification, notificationPayload=", notificationPayload);
|
598
563
|
this.emit("pushNotification", Client_1.parsePushNotification(notificationPayload));
|
599
564
|
}
|
600
565
|
/**
|
601
|
-
* Gets a user with the given identity. If it's in the subscribed list, then
|
566
|
+
* Gets a user with the given identity. If it's in the subscribed list, then
|
567
|
+
* return the user object from it;
|
602
568
|
* if not, then subscribe and add user to the subscribed list.
|
603
569
|
* @param identity Identity of the user.
|
604
570
|
* @returns A fully initialized user.
|
605
571
|
*/
|
606
572
|
async getUser(identity) {
|
607
573
|
await this._ensureReady;
|
608
|
-
return this.
|
574
|
+
return this._services.users.getUser(identity);
|
609
575
|
}
|
610
576
|
/**
|
611
577
|
* Get a list of subscribed user objects.
|
612
578
|
*/
|
613
579
|
async getSubscribedUsers() {
|
614
580
|
await this._ensureReady;
|
615
|
-
return this.
|
581
|
+
return this._services.users.getSubscribedUsers();
|
582
|
+
}
|
583
|
+
/**
|
584
|
+
* Get content URLs for all media attachments in the given set of media sids
|
585
|
+
* using a single operation.
|
586
|
+
* @param mediaSids Set of media sids to query for the content URL.
|
587
|
+
*/
|
588
|
+
getTemporaryContentUrlsForMediaSids(mediaSids) {
|
589
|
+
return new mcsClient.CancellablePromise(async (resolve, reject, onCancel) => {
|
590
|
+
if (!this._services.mcsClient || !mediaSids) {
|
591
|
+
reject(new Error("Media Content Service is unavailable"));
|
592
|
+
return;
|
593
|
+
}
|
594
|
+
const request = this._services.mcsClient.mediaSetGetContentUrls(mediaSids);
|
595
|
+
onCancel(() => {
|
596
|
+
request.cancel();
|
597
|
+
});
|
598
|
+
try {
|
599
|
+
const urls = await request;
|
600
|
+
resolve(urls);
|
601
|
+
}
|
602
|
+
catch (e) {
|
603
|
+
reject(e);
|
604
|
+
}
|
605
|
+
});
|
606
|
+
}
|
607
|
+
/**
|
608
|
+
* Get content URLs for all media attachments in the given set using a single
|
609
|
+
* operation.
|
610
|
+
* @param contentSet Set of media attachments to query content URLs.
|
611
|
+
*/
|
612
|
+
getTemporaryContentUrlsForMedia(contentSet) {
|
613
|
+
// We ignore existing mcsMedia members of each of the media entries.
|
614
|
+
// Instead, we just collect their sids and pull new descriptors from a
|
615
|
+
// mediaSet GET endpoint.
|
616
|
+
const sids = contentSet.map((m) => m.sid);
|
617
|
+
return this.getTemporaryContentUrlsForMediaSids(sids);
|
618
|
+
}
|
619
|
+
/**
|
620
|
+
* Initialize the client.
|
621
|
+
*/
|
622
|
+
async _initialize() {
|
623
|
+
const configurationResponse = await this._services.commandExecutor.fetchResource("Client/v2/Configuration");
|
624
|
+
this._configuration = new configuration.Configuration(this._options, configurationResponse, Client_1._logger);
|
625
|
+
this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
|
626
|
+
this._services.typingIndicator = new typingIndicator.TypingIndicator(this.getConversationBySid.bind(this), this._configuration, this._services);
|
627
|
+
this._services.network = new network.Network(this._configuration, this._services);
|
628
|
+
this._services.users = new users.Users(this._myself, this._configuration, this._services);
|
629
|
+
this._services.users.on("userSubscribed", (user) => {
|
630
|
+
this.emit("userSubscribed", user);
|
631
|
+
});
|
632
|
+
this._services.users.on("userUpdated", (args) => this.emit("userUpdated", args));
|
633
|
+
this._services.users.on("userUnsubscribed", (user) => {
|
634
|
+
this.emit("userUnsubscribed", user);
|
635
|
+
});
|
636
|
+
this._conversationsEntity = new conversations.Conversations(this._configuration, this._services);
|
637
|
+
this._conversationsEntity.on("conversationAdded", (conversation) => {
|
638
|
+
this.emit("conversationAdded", conversation);
|
639
|
+
});
|
640
|
+
this._conversationsEntity.on("conversationRemoved", (conversation) => {
|
641
|
+
this.emit("conversationRemoved", conversation);
|
642
|
+
});
|
643
|
+
this._conversationsEntity.on("conversationJoined", (conversation) => {
|
644
|
+
this.emit("conversationJoined", conversation);
|
645
|
+
});
|
646
|
+
this._conversationsEntity.on("conversationLeft", (conversation) => {
|
647
|
+
this.emit("conversationLeft", conversation);
|
648
|
+
});
|
649
|
+
this._conversationsEntity.on("conversationUpdated", (args) => this.emit("conversationUpdated", args));
|
650
|
+
this._conversationsEntity.on("participantJoined", (participant) => {
|
651
|
+
this.emit("participantJoined", participant);
|
652
|
+
});
|
653
|
+
this._conversationsEntity.on("participantLeft", (participant) => {
|
654
|
+
this.emit("participantLeft", participant);
|
655
|
+
});
|
656
|
+
this._conversationsEntity.on("participantUpdated", (args) => this.emit("participantUpdated", args));
|
657
|
+
this._conversationsEntity.on("messageAdded", (message) => this.emit("messageAdded", message));
|
658
|
+
this._conversationsEntity.on("messageUpdated", (args) => this.emit("messageUpdated", args));
|
659
|
+
this._conversationsEntity.on("messageRemoved", (message) => this.emit("messageRemoved", message));
|
660
|
+
this._conversationsEntity.on("typingStarted", (participant) => this.emit("typingStarted", participant));
|
661
|
+
this._conversationsEntity.on("typingEnded", (participant) => this.emit("typingEnded", participant));
|
662
|
+
this._conversationsPromise = this._conversationsEntity
|
663
|
+
.fetchConversations()
|
664
|
+
.then(() => this._conversationsEntity)
|
665
|
+
.catch((error) => {
|
666
|
+
throw error;
|
667
|
+
});
|
668
|
+
await this._services.users.myself._ensureFetched();
|
669
|
+
Client_1._supportedPushChannels.forEach((channelType) => this._subscribeToPushNotifications(channelType));
|
670
|
+
this._services.typingIndicator.initialize();
|
671
|
+
this._services.mcsClient = new mcsClient.McsClient(this._fpaToken, this._configuration.links.mediaService, this._configuration.links.mediaSetService, Object.assign(Object.assign({}, this._options), { transport: undefined }));
|
672
|
+
this._resolveEnsureReady();
|
673
|
+
this.emit("stateChanged", { state: "initialized" });
|
674
|
+
}
|
675
|
+
/**
|
676
|
+
* Subscribe to push notifications.
|
677
|
+
* @param channelType The channel type to subscribe to.
|
678
|
+
*/
|
679
|
+
_subscribeToPushNotifications(channelType) {
|
680
|
+
[
|
681
|
+
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
682
|
+
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
683
|
+
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
684
|
+
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
685
|
+
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
686
|
+
].forEach((messageType) => {
|
687
|
+
this._services.notificationClient.subscribe(channelType, messageType);
|
688
|
+
});
|
689
|
+
}
|
690
|
+
/**
|
691
|
+
* Unsubscribe from push notifications.
|
692
|
+
* @param channelType The channel type to unsubscribe from.
|
693
|
+
*/
|
694
|
+
_unsubscribeFromPushNotifications(channelType) {
|
695
|
+
[
|
696
|
+
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
697
|
+
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
698
|
+
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
699
|
+
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
700
|
+
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
701
|
+
].forEach((messageType) => {
|
702
|
+
this._services.notificationClient.unsubscribe(channelType, messageType);
|
703
|
+
});
|
616
704
|
}
|
617
705
|
};
|
618
706
|
/**
|
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.
|
707
|
+
* Fired when a conversation becomes visible to the client. The event is also
|
708
|
+
* triggered when the client creates a new conversation.
|
709
|
+
* Fired for all conversations that the client has joined.
|
634
710
|
*
|
635
711
|
* Parameters:
|
636
712
|
* 1. {@link Conversation} `conversation` - the conversation in question
|
@@ -662,14 +738,17 @@ exports.Client.conversationLeft = "conversationLeft";
|
|
662
738
|
*/
|
663
739
|
exports.Client.conversationRemoved = "conversationRemoved";
|
664
740
|
/**
|
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
|
741
|
+
* Fired when the attributes or the metadata of a conversation have been
|
742
|
+
* updated. During conversation's creation and initialization, this event
|
743
|
+
* might be fired multiple times for same joined or created conversation as
|
744
|
+
* new data is arriving from different sources.
|
668
745
|
*
|
669
746
|
* Parameters:
|
670
|
-
* 1. object `data` - info object provided with the event. It has the
|
747
|
+
* 1. object `data` - info object provided with the event. It has the
|
748
|
+
* following properties:
|
671
749
|
* * {@link Conversation} `conversation` - the conversation in question
|
672
|
-
* * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons
|
750
|
+
* * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons
|
751
|
+
* for the update
|
673
752
|
* @event
|
674
753
|
*/
|
675
754
|
exports.Client.conversationUpdated = "conversationUpdated";
|
@@ -693,9 +772,11 @@ exports.Client.participantLeft = "participantLeft";
|
|
693
772
|
* Fired when a participant's fields have been updated.
|
694
773
|
*
|
695
774
|
* Parameters:
|
696
|
-
* 1. object `data` - info object provided with the event. It has the
|
775
|
+
* 1. object `data` - info object provided with the event. It has the
|
776
|
+
* following properties:
|
697
777
|
* * {@link Participant} `participant` - the participant in question
|
698
|
-
* * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons
|
778
|
+
* * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons
|
779
|
+
* for the update
|
699
780
|
* @event
|
700
781
|
*/
|
701
782
|
exports.Client.participantUpdated = "participantUpdated";
|
@@ -719,16 +800,16 @@ exports.Client.messageRemoved = "messageRemoved";
|
|
719
800
|
* Fired when the fields of an existing message are updated with new values.
|
720
801
|
*
|
721
802
|
* Parameters:
|
722
|
-
* 1. object `data` - info object provided with the event. It has the
|
803
|
+
* 1. object `data` - info object provided with the event. It has the
|
804
|
+
* following properties:
|
723
805
|
* * {@link Message} `message` - the message in question
|
724
|
-
* * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for
|
806
|
+
* * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for
|
807
|
+
* the update
|
725
808
|
* @event
|
726
809
|
*/
|
727
810
|
exports.Client.messageUpdated = "messageUpdated";
|
728
811
|
/**
|
729
812
|
* 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
813
|
* @event
|
733
814
|
*/
|
734
815
|
exports.Client.tokenAboutToExpire = "tokenAboutToExpire";
|
@@ -754,10 +835,12 @@ exports.Client.typingEnded = "typingEnded";
|
|
754
835
|
*/
|
755
836
|
exports.Client.typingStarted = "typingStarted";
|
756
837
|
/**
|
757
|
-
* Fired when the client has received (and parsed) a push notification via one
|
838
|
+
* Fired when the client has received (and parsed) a push notification via one
|
839
|
+
* of the push channels (apn or fcm).
|
758
840
|
*
|
759
841
|
* Parameters:
|
760
|
-
* 1. {@link PushNotification} `pushNotification` - the push notification in
|
842
|
+
* 1. {@link PushNotification} `pushNotification` - the push notification in
|
843
|
+
* question
|
761
844
|
* @event
|
762
845
|
*/
|
763
846
|
exports.Client.pushNotification = "pushNotification";
|
@@ -778,12 +861,15 @@ exports.Client.userSubscribed = "userSubscribed";
|
|
778
861
|
*/
|
779
862
|
exports.Client.userUnsubscribed = "userUnsubscribed";
|
780
863
|
/**
|
781
|
-
* Fired when the properties or the reachability status of a user have been
|
864
|
+
* Fired when the properties or the reachability status of a user have been
|
865
|
+
* updated.
|
782
866
|
*
|
783
867
|
* Parameters:
|
784
|
-
* 1. object `data` - info object provided with the event. It has the
|
868
|
+
* 1. object `data` - info object provided with the event. It has the
|
869
|
+
* following properties:
|
785
870
|
* * {@link User} `user` - the user in question
|
786
|
-
* * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the
|
871
|
+
* * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the
|
872
|
+
* update
|
787
873
|
* @event
|
788
874
|
*/
|
789
875
|
exports.Client.userUpdated = "userUpdated";
|
@@ -791,14 +877,17 @@ exports.Client.userUpdated = "userUpdated";
|
|
791
877
|
* Fired when the state of the client has been changed.
|
792
878
|
*
|
793
879
|
* Parameters:
|
794
|
-
* 1.
|
880
|
+
* 1. object `data` - info object provided with the event. It has the
|
881
|
+
* following properties:
|
882
|
+
* * {@link State} `state` - the new client state
|
883
|
+
* * Error? `error` - the initialization error if present
|
795
884
|
* @event
|
796
885
|
*/
|
797
886
|
exports.Client.stateChanged = "stateChanged";
|
798
887
|
/**
|
799
888
|
* Fired when the connection state of the client has been changed.
|
800
889
|
*
|
801
|
-
*
|
890
|
+
* Parameters:
|
802
891
|
* 1. {@link ConnectionState} `state` - the new connection state
|
803
892
|
* @event
|
804
893
|
*/
|
@@ -807,7 +896,8 @@ exports.Client.connectionStateChanged = "connectionStateChanged";
|
|
807
896
|
* Fired when the connection is interrupted for an unexpected reason.
|
808
897
|
*
|
809
898
|
* Parameters:
|
810
|
-
* 1. object `data` - info object provided with the event. It has the
|
899
|
+
* 1. object `data` - info object provided with the event. It has the
|
900
|
+
* following properties:
|
811
901
|
* * boolean `terminal` - Twilsock will stop connection attempts if true
|
812
902
|
* * string `message` - the error message of the root cause
|
813
903
|
* * number? `httpStatusCode` - http status code if available
|
@@ -815,6 +905,32 @@ exports.Client.connectionStateChanged = "connectionStateChanged";
|
|
815
905
|
* @event
|
816
906
|
*/
|
817
907
|
exports.Client.connectionError = "connectionError";
|
908
|
+
/**
|
909
|
+
* Current version of the Conversations client.
|
910
|
+
*/
|
911
|
+
exports.Client.version = _package.version;
|
912
|
+
/**
|
913
|
+
* Logger instance.
|
914
|
+
*/
|
915
|
+
exports.Client._logger = logger.Logger.scope("Client");
|
916
|
+
/**
|
917
|
+
* Supported push notification channels.
|
918
|
+
*/
|
919
|
+
exports.Client._supportedPushChannels = [
|
920
|
+
"fcm",
|
921
|
+
"apn",
|
922
|
+
];
|
923
|
+
/**
|
924
|
+
* Supported push data fields.
|
925
|
+
*/
|
926
|
+
exports.Client._supportedPushDataFields = {
|
927
|
+
conversation_sid: "conversationSid",
|
928
|
+
conversation_title: "conversationTitle",
|
929
|
+
message_sid: "messageSid",
|
930
|
+
message_index: "messageIndex",
|
931
|
+
media_count: "mediaCount",
|
932
|
+
media: "media", // object
|
933
|
+
};
|
818
934
|
tslib_es6.__decorate([
|
819
935
|
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
820
936
|
tslib_es6.__metadata("design:type", Function),
|
@@ -827,6 +943,12 @@ tslib_es6.__decorate([
|
|
827
943
|
tslib_es6.__metadata("design:paramtypes", [String]),
|
828
944
|
tslib_es6.__metadata("design:returntype", Promise)
|
829
945
|
], exports.Client.prototype, "getConversationBySid", null);
|
946
|
+
tslib_es6.__decorate([
|
947
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
948
|
+
tslib_es6.__metadata("design:type", Function),
|
949
|
+
tslib_es6.__metadata("design:paramtypes", [String]),
|
950
|
+
tslib_es6.__metadata("design:returntype", Promise)
|
951
|
+
], exports.Client.prototype, "peekConversationBySid", null);
|
830
952
|
tslib_es6.__decorate([
|
831
953
|
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
832
954
|
tslib_es6.__metadata("design:type", Function),
|
@@ -876,6 +998,18 @@ tslib_es6.__decorate([
|
|
876
998
|
tslib_es6.__metadata("design:paramtypes", [String]),
|
877
999
|
tslib_es6.__metadata("design:returntype", Promise)
|
878
1000
|
], exports.Client.prototype, "getUser", null);
|
1001
|
+
tslib_es6.__decorate([
|
1002
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("strings", "string")),
|
1003
|
+
tslib_es6.__metadata("design:type", Function),
|
1004
|
+
tslib_es6.__metadata("design:paramtypes", [Array]),
|
1005
|
+
tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
|
1006
|
+
], exports.Client.prototype, "getTemporaryContentUrlsForMediaSids", null);
|
1007
|
+
tslib_es6.__decorate([
|
1008
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("media", media.Media)),
|
1009
|
+
tslib_es6.__metadata("design:type", Function),
|
1010
|
+
tslib_es6.__metadata("design:paramtypes", [Array]),
|
1011
|
+
tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
|
1012
|
+
], exports.Client.prototype, "getTemporaryContentUrlsForMedia", null);
|
879
1013
|
tslib_es6.__decorate([
|
880
1014
|
declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]),
|
881
1015
|
tslib_es6.__metadata("design:type", Function),
|