@twilio/conversations 2.0.1-rc.9 → 2.1.0-rc.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/CHANGELOG.md +74 -0
- package/NOTICE.txt +679 -0
- package/builds/browser.js +892 -619
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +371 -124
- package/builds/lib.js +892 -619
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +1067 -939
- package/builds/twilio-conversations.min.js +2 -14
- package/dist/aggregated-delivery-receipt.js +6 -1
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +165 -142
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +16 -14
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +14 -10
- package/dist/configuration.js.map +1 -1
- package/dist/conversation.js +232 -159
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +82 -78
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +43 -39
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +100 -78
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +24 -22
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +1 -1
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/attributes.js +147 -0
- package/dist/interfaces/attributes.js.map +1 -0
- package/dist/interfaces/notification-types.js +5 -5
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/logger.js +36 -15
- package/dist/logger.js.map +1 -1
- package/dist/media.js +21 -9
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +56 -3
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +158 -78
- package/dist/message.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js +101 -50
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +16 -6
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +18 -14
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +20 -17
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +87 -60
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +3 -1
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +6 -6
- package/dist/util/index.js.map +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +15 -0
- package/docs/classes/Client.html +39 -30
- package/docs/classes/Conversation.html +52 -30
- package/docs/classes/DetailedDeliveryReceipt.html +16 -1
- package/docs/classes/Media.html +15 -0
- package/docs/classes/Message.html +88 -7
- package/docs/classes/MessageBuilder.html +93 -2
- package/docs/classes/Participant.html +52 -8
- package/docs/classes/PushNotification.html +15 -0
- package/docs/classes/RestPaginator.html +15 -0
- package/docs/classes/UnsentMessage.html +15 -0
- package/docs/classes/User.html +22 -7
- package/docs/index.html +37 -3
- package/docs/interfaces/ClientOptions.html +15 -0
- package/docs/interfaces/ConversationBindings.html +3118 -0
- package/docs/interfaces/ConversationEmailBinding.html +3118 -0
- package/docs/interfaces/ConversationState.html +15 -0
- package/docs/interfaces/CreateConversationOptions.html +16 -1
- package/docs/interfaces/LastMessage.html +15 -0
- package/docs/interfaces/Paginator.html +15 -0
- package/docs/interfaces/ParticipantBindings.html +3118 -0
- package/docs/interfaces/ParticipantEmailBinding.html +3118 -0
- package/docs/interfaces/PushNotificationData.html +15 -0
- package/docs/interfaces/SendEmailOptions.html +15 -0
- package/docs/interfaces/SendMediaOptions.html +15 -0
- package/docs/modules.html +37 -3
- package/package.json +24 -18
package/dist/client.js
CHANGED
@@ -151,7 +151,7 @@ var commandExecutor = require('./command-executor.js');
|
|
151
151
|
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
152
152
|
|
153
153
|
var Client_1;
|
154
|
-
const log = logger.Logger.scope(
|
154
|
+
const log = logger.Logger.scope("Client");
|
155
155
|
const SDK_VERSION = _package.version;
|
156
156
|
class ClientServices {
|
157
157
|
}
|
@@ -174,18 +174,14 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
174
174
|
/**
|
175
175
|
* Client connection state.
|
176
176
|
*/
|
177
|
-
this.connectionState =
|
178
|
-
this.conversationsPromise = null;
|
179
|
-
this._ensureReady = null;
|
180
|
-
this._resolveEnsureReady = null;
|
181
|
-
this._rejectEnsureReady = null;
|
177
|
+
this.connectionState = "unknown";
|
182
178
|
/**
|
183
179
|
* Current version of the Conversations client.
|
184
180
|
*/
|
185
181
|
this.version = SDK_VERSION;
|
186
182
|
this.parsePushNotification = Client_1.parsePushNotification;
|
187
|
-
this.fpaToken = fpaToken;
|
188
|
-
this.options = options;
|
183
|
+
this.fpaToken = fpaToken !== null && fpaToken !== void 0 ? fpaToken : "";
|
184
|
+
this.options = options !== null && options !== void 0 ? options : {};
|
189
185
|
if (!this.options.disableDeepClone) {
|
190
186
|
let options = Object.assign(Object.assign({}, this.options), { transport: undefined, twilsockClient: undefined });
|
191
187
|
options = index.deepClone(options);
|
@@ -193,31 +189,31 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
193
189
|
options.twilsockClient = this.options.twilsockClient;
|
194
190
|
this.options = options;
|
195
191
|
}
|
196
|
-
this.options.logLevel = (_a = this.options.logLevel) !== null && _a !== void 0 ? _a :
|
192
|
+
this.options.logLevel = (_a = this.options.logLevel) !== null && _a !== void 0 ? _a : "silent";
|
197
193
|
log.setLevel(this.options.logLevel);
|
198
|
-
const productId = this.options.productId =
|
194
|
+
const productId = (this.options.productId = "ip_messaging");
|
199
195
|
// Filling ClientMetadata
|
200
196
|
this.options.clientMetadata = this.options.clientMetadata || {};
|
201
|
-
if (!this.options.clientMetadata.hasOwnProperty(
|
202
|
-
this.options.clientMetadata.type =
|
197
|
+
if (!this.options.clientMetadata.hasOwnProperty("type")) {
|
198
|
+
this.options.clientMetadata.type = "conversations";
|
203
199
|
}
|
204
|
-
if (!this.options.clientMetadata.hasOwnProperty(
|
205
|
-
this.options.clientMetadata.sdk =
|
200
|
+
if (!this.options.clientMetadata.hasOwnProperty("sdk")) {
|
201
|
+
this.options.clientMetadata.sdk = "JS";
|
206
202
|
this.options.clientMetadata.sdkv = SDK_VERSION;
|
207
203
|
}
|
208
204
|
// Enable session local storage for Sync
|
209
205
|
this.options.Sync = this.options.Sync || {};
|
210
|
-
if (typeof this.options.Sync.enableSessionStorage ===
|
206
|
+
if (typeof this.options.Sync.enableSessionStorage === "undefined") {
|
211
207
|
this.options.Sync.enableSessionStorage = true;
|
212
208
|
}
|
213
209
|
if (this.options.region) {
|
214
210
|
this.options.Sync.region = this.options.region;
|
215
211
|
}
|
216
212
|
if (!fpaToken) {
|
217
|
-
throw new Error(
|
213
|
+
throw new Error("A valid Twilio token should be provided");
|
218
214
|
}
|
219
215
|
this.services = new ClientServices();
|
220
|
-
this._myself = new user.User(
|
216
|
+
this._myself = new user.User("", "", null, this.services);
|
221
217
|
const startTwilsock = !this.options.twilsockClient;
|
222
218
|
// Create default init registrations if none were provided.
|
223
219
|
// Otherwise, the outside party have to list all the init registrations they
|
@@ -229,53 +225,57 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
229
225
|
Client_1.populateInitRegistrations(initRegistration);
|
230
226
|
this.options.initRegistrations = [initRegistration];
|
231
227
|
}
|
232
|
-
this.services.twilsockClient =
|
233
|
-
|
234
|
-
this.services.twilsockClient.on(
|
235
|
-
this.services.twilsockClient.on(
|
236
|
-
this.services.twilsockClient.on(
|
228
|
+
this.services.twilsockClient = this.options.twilsockClient =
|
229
|
+
(_b = this.options.twilsockClient) !== null && _b !== void 0 ? _b : new twilsock.TwilsockClient(fpaToken, productId, this.options);
|
230
|
+
this.services.twilsockClient.on("tokenAboutToExpire", (ttl) => this.emit("tokenAboutToExpire", ttl));
|
231
|
+
this.services.twilsockClient.on("tokenExpired", () => this.emit("tokenExpired"));
|
232
|
+
this.services.twilsockClient.on("connectionError", (error) => this.emit("connectionError", error));
|
233
|
+
this.services.twilsockClient.on("stateChanged", (state) => {
|
237
234
|
log.debug(`Handling stateChanged for ConversationsClient: new state ${state}`);
|
238
235
|
if (state !== this.connectionState) {
|
239
236
|
this.connectionState = state;
|
240
|
-
this.emit(
|
237
|
+
this.emit("connectionStateChanged", this.connectionState);
|
241
238
|
}
|
242
239
|
});
|
243
|
-
this.services.transport =
|
244
|
-
|
245
|
-
this.services.
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
240
|
+
this.services.transport = this.options.transport = ((_c = this.options
|
241
|
+
.transport) !== null && _c !== void 0 ? _c : this.options.twilsockClient);
|
242
|
+
this.services.notificationClient = this.options.notificationsClient =
|
243
|
+
(_d = this.options.notificationsClient) !== null && _d !== void 0 ? _d : new notifications.Notifications(fpaToken, this.options);
|
244
|
+
this.services.syncClient = this.options.syncClient =
|
245
|
+
(_e = this.options.syncClient) !== null && _e !== void 0 ? _e : new twilioSync.SyncClient(fpaToken, this.options);
|
246
|
+
const configurationOptions = (options === null || options === void 0 ? void 0 : options.Chat) || (options === null || options === void 0 ? void 0 : options.IPMessaging) || options || {};
|
247
|
+
const region = configurationOptions.region || (options === null || options === void 0 ? void 0 : options.region);
|
248
|
+
const baseUrl = configurationOptions.apiUri ||
|
249
|
+
configurationOptions.typingUri ||
|
250
|
+
`https://aim.${region || "us1"}.twilio.com`;
|
251
251
|
this.services.commandExecutor = new commandExecutor.CommandExecutor(baseUrl, { transport: this.options.transport }, productId);
|
252
252
|
const emitFailed = (err) => {
|
253
253
|
this._rejectEnsureReady(err);
|
254
|
-
this.emit(
|
254
|
+
this.emit("stateChanged", "failed");
|
255
255
|
};
|
256
|
-
this.services.twilsockClient.once(
|
257
|
-
this.services.twilsockClient.once(
|
256
|
+
this.services.twilsockClient.once("connectionError", emitFailed);
|
257
|
+
this.services.twilsockClient.once("disconnected", emitFailed);
|
258
258
|
// ConversationsClient will be able to initialize only after twilsock is connected
|
259
|
-
this.services.twilsockClient.once(
|
259
|
+
this.services.twilsockClient.once("connected", async () => {
|
260
260
|
log.debug(`ConversationsClient started INITIALIZING`);
|
261
|
-
this.services.twilsockClient.off(
|
262
|
-
this.services.twilsockClient.off(
|
261
|
+
this.services.twilsockClient.off("connectionError", emitFailed);
|
262
|
+
this.services.twilsockClient.off("disconnected", emitFailed);
|
263
263
|
try {
|
264
|
-
const startupEvent =
|
265
|
-
this.services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent,
|
264
|
+
const startupEvent = "conversations.client.startup";
|
265
|
+
this.services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
|
266
266
|
await this._initialize();
|
267
|
-
this.services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(
|
267
|
+
this.services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
|
268
268
|
}
|
269
269
|
catch (err) {
|
270
270
|
// Fail ChatClient if initialization is incomplete
|
271
271
|
this._rejectEnsureReady(err);
|
272
|
-
this.emit(
|
272
|
+
this.emit("stateChanged", "failed");
|
273
273
|
}
|
274
274
|
});
|
275
275
|
this._ensureReady = new Promise((resolve, reject) => {
|
276
276
|
this._resolveEnsureReady = resolve;
|
277
277
|
this._rejectEnsureReady = reject;
|
278
|
-
}).catch((
|
278
|
+
}).catch(() => void 0); // @todo How to process unhandled rejection here?
|
279
279
|
if (startTwilsock) {
|
280
280
|
this.services.twilsockClient.connect();
|
281
281
|
}
|
@@ -310,10 +310,10 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
310
310
|
// - If twilsock was passed in from the outside, but customer called ConversationsClient.create() then they are
|
311
311
|
// using an obsolete workflow and the startup sequence will never complete.
|
312
312
|
if (options === null || options === void 0 ? void 0 : options.twilsockClient) {
|
313
|
-
throw new Error(
|
314
|
-
|
315
|
-
|
316
|
-
|
313
|
+
throw new Error("Obsolete usage of ConversationsClient.create() " +
|
314
|
+
"factory method: if you pass twilsock from the outside then you must " +
|
315
|
+
"use ConversationsClient constructor and be prepared to work with " +
|
316
|
+
"uninitialized client.");
|
317
317
|
}
|
318
318
|
const client = new Client_1(token, options);
|
319
319
|
await client._ensureReady;
|
@@ -324,75 +324,98 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
324
324
|
* uninitialized user. Will trigger a {@link Client.userUpdated} event after
|
325
325
|
* initialization.
|
326
326
|
*/
|
327
|
-
get user() {
|
327
|
+
get user() {
|
328
|
+
return this._myself;
|
329
|
+
}
|
328
330
|
/**
|
329
331
|
* Client reachability state. Throws if accessed before the client
|
330
332
|
* initialization was completed.
|
331
333
|
*/
|
332
334
|
get reachabilityEnabled() {
|
333
335
|
if (!this.configuration) {
|
334
|
-
throw new Error(
|
336
|
+
throw new Error("Reachability information could not yet be accessed as the client " +
|
335
337
|
"has not yet been initialized. Subscribe to the 'stateChanged' event " +
|
336
|
-
|
338
|
+
"to properly react to the client initialization.");
|
337
339
|
}
|
338
340
|
return this.configuration.reachabilityEnabled;
|
339
341
|
}
|
340
|
-
get token() {
|
342
|
+
get token() {
|
343
|
+
return this.fpaToken;
|
344
|
+
}
|
341
345
|
_subscribeToPushNotifications(channelType) {
|
342
|
-
[
|
346
|
+
[
|
347
|
+
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
343
348
|
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
344
349
|
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
345
350
|
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
346
|
-
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE
|
347
|
-
|
351
|
+
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
352
|
+
].forEach((messageType) => {
|
348
353
|
this.services.notificationClient.subscribe(channelType, messageType);
|
349
354
|
});
|
350
355
|
}
|
351
356
|
_unsubscribeFromPushNotifications(channelType) {
|
352
|
-
[
|
357
|
+
[
|
358
|
+
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
353
359
|
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
354
360
|
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
355
361
|
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
356
|
-
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE
|
357
|
-
|
362
|
+
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
363
|
+
].forEach((messageType) => {
|
358
364
|
this.services.notificationClient.unsubscribe(channelType, messageType);
|
359
365
|
});
|
360
366
|
}
|
361
367
|
async _initialize() {
|
362
|
-
const configurationResponse = await this.services.commandExecutor.fetchResource(
|
368
|
+
const configurationResponse = await this.services.commandExecutor.fetchResource("Client/v2/Configuration");
|
363
369
|
this.configuration = new configuration.Configuration(this.options, configurationResponse, log);
|
364
370
|
this._myself._resolveInitialization(this.configuration, this.configuration.userIdentity, this.configuration.userInfo, true);
|
365
371
|
this.services.typingIndicator = new typingIndicator.TypingIndicator(this.getConversationBySid.bind(this), this.configuration, this.services);
|
366
372
|
this.services.network = new network.Network(this.configuration, this.services);
|
367
373
|
this.services.users = new users.Users(this._myself, this.configuration, this.services);
|
368
|
-
this.services.users.on(
|
369
|
-
|
370
|
-
|
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
|
+
});
|
371
381
|
this.conversations = new conversations.Conversations(this.configuration, this.services);
|
372
|
-
this.conversations.on(
|
373
|
-
|
374
|
-
|
375
|
-
this.conversations.on(
|
376
|
-
|
377
|
-
|
378
|
-
this.conversations.on(
|
379
|
-
|
380
|
-
|
381
|
-
this.conversations.on(
|
382
|
-
|
383
|
-
|
384
|
-
this.conversations.on(
|
385
|
-
this.
|
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()
|
386
409
|
.then(() => this.conversations)
|
387
410
|
.catch((error) => {
|
388
411
|
throw error;
|
389
412
|
});
|
390
413
|
await this.services.users.myself._ensureFetched();
|
391
|
-
Client_1.supportedPushChannels.forEach(channelType => this._subscribeToPushNotifications(channelType));
|
414
|
+
Client_1.supportedPushChannels.forEach((channelType) => this._subscribeToPushNotifications(channelType));
|
392
415
|
this.services.typingIndicator.initialize();
|
393
|
-
this.services.mcsClient = new mcsClient.McsClient(this.fpaToken, this.configuration.links.mediaService, this.configuration.links.mediaSetService, Object.assign(Object.assign({}, this.options), { transport:
|
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 }));
|
394
417
|
this._resolveEnsureReady();
|
395
|
-
this.emit(
|
418
|
+
this.emit("stateChanged", "initialized");
|
396
419
|
}
|
397
420
|
/**
|
398
421
|
* Gracefully shut down the client.
|
@@ -407,7 +430,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
407
430
|
*/
|
408
431
|
async updateToken(token) {
|
409
432
|
await this._ensureReady;
|
410
|
-
log.info(
|
433
|
+
log.info("updateToken");
|
411
434
|
if (this.fpaToken === token) {
|
412
435
|
return this;
|
413
436
|
}
|
@@ -449,9 +472,9 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
449
472
|
/**
|
450
473
|
* Get the current list of all the subscribed conversations.
|
451
474
|
*/
|
452
|
-
async getSubscribedConversations(
|
475
|
+
async getSubscribedConversations() {
|
453
476
|
await this._ensureReady;
|
454
|
-
return this.conversationsPromise.then(conversations => conversations.getConversations(
|
477
|
+
return this.conversationsPromise.then((conversations) => conversations.getConversations());
|
455
478
|
}
|
456
479
|
/**
|
457
480
|
* Create a conversation on the server and subscribe to its events.
|
@@ -461,7 +484,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
461
484
|
async createConversation(options) {
|
462
485
|
await this._ensureReady;
|
463
486
|
options = options || {};
|
464
|
-
return this.conversationsPromise.then(conversationsEntity => conversationsEntity.addConversation(options));
|
487
|
+
return this.conversationsPromise.then((conversationsEntity) => conversationsEntity.addConversation(options));
|
465
488
|
}
|
466
489
|
/**
|
467
490
|
* Register for push notifications.
|
@@ -500,11 +523,11 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
500
523
|
}
|
501
524
|
static parsePushNotificationChatData(data) {
|
502
525
|
const result = {};
|
503
|
-
for (
|
504
|
-
if (typeof data[key] ===
|
526
|
+
for (const key in Client_1.supportedPushDataFields) {
|
527
|
+
if (typeof data[key] === "undefined" || data[key] === null) {
|
505
528
|
continue;
|
506
529
|
}
|
507
|
-
if (key !==
|
530
|
+
if (key !== "message_index") {
|
508
531
|
result[Client_1.supportedPushDataFields[key]] = data[key];
|
509
532
|
continue;
|
510
533
|
}
|
@@ -519,17 +542,17 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
519
542
|
* @param notificationPayload Push notification payload.
|
520
543
|
*/
|
521
544
|
static parsePushNotification(notificationPayload) {
|
522
|
-
log.debug(
|
545
|
+
log.debug("parsePushNotification, notificationPayload=", notificationPayload);
|
523
546
|
// APNS specifics
|
524
|
-
if (typeof notificationPayload.aps !==
|
547
|
+
if (typeof notificationPayload.aps !== "undefined") {
|
525
548
|
if (!notificationPayload.twi_message_type) {
|
526
|
-
throw new Error(
|
549
|
+
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
527
550
|
}
|
528
|
-
|
529
|
-
|
530
|
-
let body
|
551
|
+
const data = Client_1.parsePushNotificationChatData(notificationPayload);
|
552
|
+
const apsPayload = notificationPayload.aps;
|
553
|
+
let body;
|
531
554
|
let title = null;
|
532
|
-
if (typeof apsPayload.alert ===
|
555
|
+
if (typeof apsPayload.alert === "string") {
|
533
556
|
body = apsPayload.alert || null;
|
534
557
|
}
|
535
558
|
else {
|
@@ -537,22 +560,22 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
537
560
|
title = apsPayload.alert.title || null;
|
538
561
|
}
|
539
562
|
return new pushNotification.PushNotification({
|
540
|
-
title
|
541
|
-
body
|
563
|
+
title,
|
564
|
+
body,
|
542
565
|
sound: apsPayload.sound || null,
|
543
566
|
badge: apsPayload.badge || null,
|
544
567
|
action: apsPayload.category || null,
|
545
568
|
type: notificationPayload.twi_message_type,
|
546
|
-
data: data
|
569
|
+
data: data,
|
547
570
|
});
|
548
571
|
}
|
549
572
|
// FCM specifics
|
550
|
-
if (typeof notificationPayload.data !==
|
551
|
-
|
573
|
+
if (typeof notificationPayload.data !== "undefined") {
|
574
|
+
const dataPayload = notificationPayload.data;
|
552
575
|
if (!dataPayload.twi_message_type) {
|
553
|
-
throw new Error(
|
576
|
+
throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
|
554
577
|
}
|
555
|
-
|
578
|
+
const data = Client_1.parsePushNotificationChatData(notificationPayload.data);
|
556
579
|
return new pushNotification.PushNotification({
|
557
580
|
title: dataPayload.twi_title || null,
|
558
581
|
body: dataPayload.twi_body || null,
|
@@ -560,10 +583,10 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
560
583
|
badge: null,
|
561
584
|
action: dataPayload.twi_action || null,
|
562
585
|
type: dataPayload.twi_message_type,
|
563
|
-
data: data
|
586
|
+
data: data,
|
564
587
|
});
|
565
588
|
}
|
566
|
-
throw new Error(
|
589
|
+
throw new Error("Provided push notification payload is not Programmable Chat notification");
|
567
590
|
}
|
568
591
|
/**
|
569
592
|
* Handle push notification payload parsing and emit the {@link Client.pushNotification} event on this {@link Client} instance.
|
@@ -571,8 +594,8 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
571
594
|
*/
|
572
595
|
async handlePushNotification(notificationPayload) {
|
573
596
|
await this._ensureReady;
|
574
|
-
log.debug(
|
575
|
-
this.emit(
|
597
|
+
log.debug("handlePushNotification, notificationPayload=", notificationPayload);
|
598
|
+
this.emit("pushNotification", Client_1.parsePushNotification(notificationPayload));
|
576
599
|
}
|
577
600
|
/**
|
578
601
|
* Gets a user with the given identity. If it's in the subscribed list, then return the user object from it;
|
@@ -596,11 +619,14 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
596
619
|
* Current version of the Conversations client.
|
597
620
|
*/
|
598
621
|
exports.Client.version = SDK_VERSION;
|
599
|
-
exports.Client.supportedPushChannels = [
|
622
|
+
exports.Client.supportedPushChannels = [
|
623
|
+
"fcm",
|
624
|
+
"apn",
|
625
|
+
];
|
600
626
|
exports.Client.supportedPushDataFields = {
|
601
|
-
|
602
|
-
|
603
|
-
|
627
|
+
conversation_sid: "conversationSid",
|
628
|
+
message_sid: "messageSid",
|
629
|
+
message_index: "messageIndex",
|
604
630
|
};
|
605
631
|
/**
|
606
632
|
* Fired when a conversation becomes visible to the client. The event is also triggered when the client creates a new conversation.
|
@@ -610,7 +636,7 @@ exports.Client.supportedPushDataFields = {
|
|
610
636
|
* 1. {@link Conversation} `conversation` - the conversation in question
|
611
637
|
* @event
|
612
638
|
*/
|
613
|
-
exports.Client.conversationAdded =
|
639
|
+
exports.Client.conversationAdded = "conversationAdded";
|
614
640
|
/**
|
615
641
|
* Fired when the client joins a conversation.
|
616
642
|
*
|
@@ -618,7 +644,7 @@ exports.Client.conversationAdded = 'conversationAdded';
|
|
618
644
|
* 1. {@link Conversation} `conversation` - the conversation in question
|
619
645
|
* @event
|
620
646
|
*/
|
621
|
-
exports.Client.conversationJoined =
|
647
|
+
exports.Client.conversationJoined = "conversationJoined";
|
622
648
|
/**
|
623
649
|
* Fired when the client leaves a conversation.
|
624
650
|
*
|
@@ -626,7 +652,7 @@ exports.Client.conversationJoined = 'conversationJoined';
|
|
626
652
|
* 1. {@link Conversation} `conversation` - the conversation in question
|
627
653
|
* @event
|
628
654
|
*/
|
629
|
-
exports.Client.conversationLeft =
|
655
|
+
exports.Client.conversationLeft = "conversationLeft";
|
630
656
|
/**
|
631
657
|
* Fired when a conversation is no longer visible to the client.
|
632
658
|
*
|
@@ -634,7 +660,7 @@ exports.Client.conversationLeft = 'conversationLeft';
|
|
634
660
|
* 1. {@link Conversation} `conversation` - the conversation in question
|
635
661
|
* @event
|
636
662
|
*/
|
637
|
-
exports.Client.conversationRemoved =
|
663
|
+
exports.Client.conversationRemoved = "conversationRemoved";
|
638
664
|
/**
|
639
665
|
* Fired when the attributes or the metadata of a conversation have been updated.
|
640
666
|
* During conversation's creation and initialization, this event might be fired multiple times
|
@@ -646,7 +672,7 @@ exports.Client.conversationRemoved = 'conversationRemoved';
|
|
646
672
|
* * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons for the update
|
647
673
|
* @event
|
648
674
|
*/
|
649
|
-
exports.Client.conversationUpdated =
|
675
|
+
exports.Client.conversationUpdated = "conversationUpdated";
|
650
676
|
/**
|
651
677
|
* Fired when a participant has joined a conversation.
|
652
678
|
*
|
@@ -654,7 +680,7 @@ exports.Client.conversationUpdated = 'conversationUpdated';
|
|
654
680
|
* 1. {@link Participant} `participant` - the participant in question
|
655
681
|
* @event
|
656
682
|
*/
|
657
|
-
exports.Client.participantJoined =
|
683
|
+
exports.Client.participantJoined = "participantJoined";
|
658
684
|
/**
|
659
685
|
* Fired when a participant has left a conversation.
|
660
686
|
*
|
@@ -662,7 +688,7 @@ exports.Client.participantJoined = 'participantJoined';
|
|
662
688
|
* 1. {@link Participant} `participant` - the participant in question
|
663
689
|
* @event
|
664
690
|
*/
|
665
|
-
exports.Client.participantLeft =
|
691
|
+
exports.Client.participantLeft = "participantLeft";
|
666
692
|
/**
|
667
693
|
* Fired when a participant's fields have been updated.
|
668
694
|
*
|
@@ -672,7 +698,7 @@ exports.Client.participantLeft = 'participantLeft';
|
|
672
698
|
* * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons for the update
|
673
699
|
* @event
|
674
700
|
*/
|
675
|
-
exports.Client.participantUpdated =
|
701
|
+
exports.Client.participantUpdated = "participantUpdated";
|
676
702
|
/**
|
677
703
|
* Fired when a new message has been added to the conversation on the server.
|
678
704
|
*
|
@@ -680,7 +706,7 @@ exports.Client.participantUpdated = 'participantUpdated';
|
|
680
706
|
* 1. {@link Message} `message` - the message in question
|
681
707
|
* @event
|
682
708
|
*/
|
683
|
-
exports.Client.messageAdded =
|
709
|
+
exports.Client.messageAdded = "messageAdded";
|
684
710
|
/**
|
685
711
|
* Fired when a message is removed from the message list of a conversation.
|
686
712
|
*
|
@@ -688,7 +714,7 @@ exports.Client.messageAdded = 'messageAdded';
|
|
688
714
|
* 1. {@link Message} `message` - the message in question
|
689
715
|
* @event
|
690
716
|
*/
|
691
|
-
exports.Client.messageRemoved =
|
717
|
+
exports.Client.messageRemoved = "messageRemoved";
|
692
718
|
/**
|
693
719
|
* Fired when the fields of an existing message are updated with new values.
|
694
720
|
*
|
@@ -698,19 +724,19 @@ exports.Client.messageRemoved = 'messageRemoved';
|
|
698
724
|
* * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for the update
|
699
725
|
* @event
|
700
726
|
*/
|
701
|
-
exports.Client.messageUpdated =
|
727
|
+
exports.Client.messageUpdated = "messageUpdated";
|
702
728
|
/**
|
703
729
|
* Fired when the token is about to expire and needs to be updated.
|
704
730
|
* * Parameters:
|
705
731
|
* 1. number `message` - token's time to live
|
706
732
|
* @event
|
707
733
|
*/
|
708
|
-
exports.Client.tokenAboutToExpire =
|
734
|
+
exports.Client.tokenAboutToExpire = "tokenAboutToExpire";
|
709
735
|
/**
|
710
736
|
* Fired when the token has expired.
|
711
737
|
* @event
|
712
738
|
*/
|
713
|
-
exports.Client.tokenExpired =
|
739
|
+
exports.Client.tokenExpired = "tokenExpired";
|
714
740
|
/**
|
715
741
|
* Fired when a participant has stopped typing.
|
716
742
|
*
|
@@ -718,7 +744,7 @@ exports.Client.tokenExpired = 'tokenExpired';
|
|
718
744
|
* 1. {@link Participant} `participant` - the participant in question
|
719
745
|
* @event
|
720
746
|
*/
|
721
|
-
exports.Client.typingEnded =
|
747
|
+
exports.Client.typingEnded = "typingEnded";
|
722
748
|
/**
|
723
749
|
* Fired when a participant has started typing.
|
724
750
|
*
|
@@ -726,7 +752,7 @@ exports.Client.typingEnded = 'typingEnded';
|
|
726
752
|
* 1. {@link Participant} `participant` - the participant in question
|
727
753
|
* @event
|
728
754
|
*/
|
729
|
-
exports.Client.typingStarted =
|
755
|
+
exports.Client.typingStarted = "typingStarted";
|
730
756
|
/**
|
731
757
|
* Fired when the client has received (and parsed) a push notification via one of the push channels (apn or fcm).
|
732
758
|
*
|
@@ -734,7 +760,7 @@ exports.Client.typingStarted = 'typingStarted';
|
|
734
760
|
* 1. {@link PushNotification} `pushNotification` - the push notification in question
|
735
761
|
* @event
|
736
762
|
*/
|
737
|
-
exports.Client.pushNotification =
|
763
|
+
exports.Client.pushNotification = "pushNotification";
|
738
764
|
/**
|
739
765
|
* Fired when the client has subscribed to a user.
|
740
766
|
*
|
@@ -742,7 +768,7 @@ exports.Client.pushNotification = 'pushNotification';
|
|
742
768
|
* 1. {@link User} `user` - the user in question
|
743
769
|
* @event
|
744
770
|
*/
|
745
|
-
exports.Client.userSubscribed =
|
771
|
+
exports.Client.userSubscribed = "userSubscribed";
|
746
772
|
/**
|
747
773
|
* Fired when the client has unsubscribed from a user.
|
748
774
|
*
|
@@ -750,7 +776,7 @@ exports.Client.userSubscribed = 'userSubscribed';
|
|
750
776
|
* 1. {@link User} `user` - the user in question
|
751
777
|
* @event
|
752
778
|
*/
|
753
|
-
exports.Client.userUnsubscribed =
|
779
|
+
exports.Client.userUnsubscribed = "userUnsubscribed";
|
754
780
|
/**
|
755
781
|
* Fired when the properties or the reachability status of a user have been updated.
|
756
782
|
*
|
@@ -760,7 +786,7 @@ exports.Client.userUnsubscribed = 'userUnsubscribed';
|
|
760
786
|
* * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update
|
761
787
|
* @event
|
762
788
|
*/
|
763
|
-
exports.Client.userUpdated =
|
789
|
+
exports.Client.userUpdated = "userUpdated";
|
764
790
|
/**
|
765
791
|
* Fired when the state of the client has been changed.
|
766
792
|
*
|
@@ -768,7 +794,7 @@ exports.Client.userUpdated = 'userUpdated';
|
|
768
794
|
* 1. {@link State} `state` - the new client state
|
769
795
|
* @event
|
770
796
|
*/
|
771
|
-
exports.Client.stateChanged =
|
797
|
+
exports.Client.stateChanged = "stateChanged";
|
772
798
|
/**
|
773
799
|
* Fired when the connection state of the client has been changed.
|
774
800
|
*
|
@@ -776,7 +802,7 @@ exports.Client.stateChanged = 'stateChanged';
|
|
776
802
|
* 1. {@link ConnectionState} `state` - the new connection state
|
777
803
|
* @event
|
778
804
|
*/
|
779
|
-
exports.Client.connectionStateChanged =
|
805
|
+
exports.Client.connectionStateChanged = "connectionStateChanged";
|
780
806
|
/**
|
781
807
|
* Fired when the connection is interrupted for an unexpected reason.
|
782
808
|
*
|
@@ -788,7 +814,7 @@ exports.Client.connectionStateChanged = 'connectionStateChanged';
|
|
788
814
|
* * number? `errorCode` - Twilio public error code if available
|
789
815
|
* @event
|
790
816
|
*/
|
791
|
-
exports.Client.connectionError =
|
817
|
+
exports.Client.connectionError = "connectionError";
|
792
818
|
tslib_es6.__decorate([
|
793
819
|
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
794
820
|
tslib_es6.__metadata("design:type", Function),
|
@@ -809,31 +835,31 @@ tslib_es6.__decorate([
|
|
809
835
|
], exports.Client.prototype, "getConversationByUniqueName", null);
|
810
836
|
tslib_es6.__decorate([
|
811
837
|
declarativeTypeValidator.validateTypesAsync([
|
812
|
-
|
813
|
-
declarativeTypeValidator.objectSchema(
|
814
|
-
friendlyName: [
|
815
|
-
isPrivate: [
|
816
|
-
uniqueName: [
|
817
|
-
})
|
838
|
+
"undefined",
|
839
|
+
declarativeTypeValidator.objectSchema("conversation options", {
|
840
|
+
friendlyName: ["string", "undefined"],
|
841
|
+
isPrivate: ["boolean", "undefined"],
|
842
|
+
uniqueName: ["string", "undefined"],
|
843
|
+
}),
|
818
844
|
]),
|
819
845
|
tslib_es6.__metadata("design:type", Function),
|
820
846
|
tslib_es6.__metadata("design:paramtypes", [Object]),
|
821
847
|
tslib_es6.__metadata("design:returntype", Promise)
|
822
848
|
], exports.Client.prototype, "createConversation", null);
|
823
849
|
tslib_es6.__decorate([
|
824
|
-
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal(
|
850
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn"), "string"),
|
825
851
|
tslib_es6.__metadata("design:type", Function),
|
826
852
|
tslib_es6.__metadata("design:paramtypes", [String, String]),
|
827
853
|
tslib_es6.__metadata("design:returntype", Promise)
|
828
854
|
], exports.Client.prototype, "setPushRegistrationId", null);
|
829
855
|
tslib_es6.__decorate([
|
830
|
-
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal(
|
856
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn")),
|
831
857
|
tslib_es6.__metadata("design:type", Function),
|
832
858
|
tslib_es6.__metadata("design:paramtypes", [String]),
|
833
859
|
tslib_es6.__metadata("design:returntype", Promise)
|
834
860
|
], exports.Client.prototype, "unsetPushRegistrationId", null);
|
835
861
|
tslib_es6.__decorate([
|
836
|
-
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal(
|
862
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn"), declarativeTypeValidator.nonEmptyString),
|
837
863
|
tslib_es6.__metadata("design:type", Function),
|
838
864
|
tslib_es6.__metadata("design:paramtypes", [String, String]),
|
839
865
|
tslib_es6.__metadata("design:returntype", Promise)
|
@@ -851,7 +877,7 @@ tslib_es6.__decorate([
|
|
851
877
|
tslib_es6.__metadata("design:returntype", Promise)
|
852
878
|
], exports.Client.prototype, "getUser", null);
|
853
879
|
tslib_es6.__decorate([
|
854
|
-
declarativeTypeValidator.validateTypesAsync(
|
880
|
+
declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]),
|
855
881
|
tslib_es6.__metadata("design:type", Function),
|
856
882
|
tslib_es6.__metadata("design:paramtypes", [String, Object]),
|
857
883
|
tslib_es6.__metadata("design:returntype", Promise)
|
@@ -863,10 +889,7 @@ tslib_es6.__decorate([
|
|
863
889
|
tslib_es6.__metadata("design:returntype", pushNotification.PushNotification)
|
864
890
|
], exports.Client, "parsePushNotification", null);
|
865
891
|
exports.Client = Client_1 = tslib_es6.__decorate([
|
866
|
-
declarativeTypeValidator.validateConstructorTypes(declarativeTypeValidator.nonEmptyString, [
|
867
|
-
declarativeTypeValidator.pureObject,
|
868
|
-
'undefined'
|
869
|
-
]),
|
892
|
+
declarativeTypeValidator.validateConstructorTypes(declarativeTypeValidator.nonEmptyString, [declarativeTypeValidator.pureObject, "undefined"]),
|
870
893
|
tslib_es6.__metadata("design:paramtypes", [String, Object])
|
871
894
|
], exports.Client);
|
872
895
|
//# sourceMappingURL=client.js.map
|