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