@twilio/conversations 3.0.1-rc.1 → 3.0.1-rc.102
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/builds/browser.js +9276 -4305
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +133 -35
- package/builds/lib.js +9276 -4305
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +44416 -27540
- package/builds/twilio-conversations.min.js +1 -200
- package/dist/channel-metadata-client.js +1 -1
- package/dist/channel-metadata-client.js.map +1 -1
- package/dist/client.js +151 -43
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +31 -50
- package/dist/command-executor.js.map +1 -1
- package/dist/content-template.js +1 -1
- package/dist/content-template.js.map +1 -1
- package/dist/conversation.js +6 -46
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +2 -18
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +13 -3
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +2 -4
- 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/index.js +2 -6
- package/dist/index.js.map +1 -1
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +51 -0
- package/dist/message.js.map +1 -1
- package/dist/node_modules/quick-lru/index.js.map +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 +34 -34
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +11 -11
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +11 -101
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +5 -13
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js.map +1 -1
- package/dist/util/index.js.map +1 -1
- package/docs/assets/css/main.css +2660 -0
- 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 +248 -0
- package/docs/assets/js/search.js +1 -0
- package/docs/classes/AggregatedDeliveryReceipt.html +3182 -144
- package/docs/classes/CancellablePromise.html +3209 -224
- package/docs/classes/ChannelMetadata.html +3049 -66
- package/docs/classes/Client.html +4276 -701
- package/docs/classes/ContentTemplate.html +3115 -96
- package/docs/classes/ContentTemplateVariable.html +3114 -88
- package/docs/classes/Conversation.html +4357 -768
- package/docs/classes/DetailedDeliveryReceipt.html +3162 -116
- package/docs/classes/Media.html +3165 -119
- package/docs/classes/Message.html +3801 -417
- package/docs/classes/MessageBuilder.html +3315 -208
- package/docs/classes/Participant.html +3442 -258
- package/docs/classes/PushNotification.html +3129 -101
- package/docs/classes/RestPaginator.html +3158 -120
- package/docs/classes/UnsentMessage.html +3040 -63
- package/docs/classes/User.html +3347 -209
- package/docs/index.html +4326 -146
- package/docs/interfaces/ClientOptions.html +3049 -66
- package/docs/interfaces/ConversationBindings.html +3000 -109
- package/docs/interfaces/ConversationEmailBinding.html +3000 -109
- package/docs/interfaces/ConversationLimits.html +3097 -87
- package/docs/interfaces/ConversationState.html +3049 -66
- package/docs/interfaces/ConversationUpdatedEventArgs.html +3000 -109
- package/docs/interfaces/CreateConversationOptions.html +3065 -73
- package/docs/interfaces/LastMessage.html +3049 -66
- package/docs/interfaces/Paginator.html +3139 -110
- package/docs/interfaces/ParticipantBindings.html +3000 -109
- package/docs/interfaces/ParticipantEmailBinding.html +3000 -109
- package/docs/interfaces/PushNotificationData.html +3113 -94
- package/docs/interfaces/SendEmailOptions.html +3033 -59
- package/docs/interfaces/SendMediaOptions.html +3067 -75
- package/docs/modules.html +4333 -180
- package/package.json +13 -14
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1279
- package/docs/classes/CancellationError.html +0 -112
- package/docs/interfaces/ParticipantBindingOptions.html +0 -110
- package/docs/types/ChannelType.html +0 -106
- package/docs/types/ConnectionState.html +0 -115
- package/docs/types/ContentData.html +0 -106
- package/docs/types/ContentDataAction.html +0 -107
- package/docs/types/ContentDataActionOther.html +0 -121
- package/docs/types/ContentDataActionPhone.html +0 -128
- package/docs/types/ContentDataActionReply.html +0 -133
- package/docs/types/ContentDataActionUrl.html +0 -128
- package/docs/types/ContentDataCallToAction.html +0 -131
- package/docs/types/ContentDataCard.html +0 -137
- package/docs/types/ContentDataListItem.html +0 -121
- package/docs/types/ContentDataListPicker.html +0 -134
- package/docs/types/ContentDataLocation.html +0 -134
- package/docs/types/ContentDataMedia.html +0 -129
- package/docs/types/ContentDataOther.html +0 -121
- package/docs/types/ContentDataQuickReply.html +0 -131
- package/docs/types/ContentDataReply.html +0 -119
- package/docs/types/ContentDataText.html +0 -125
- package/docs/types/ConversationStatus.html +0 -107
- package/docs/types/ConversationUpdateReason.html +0 -106
- package/docs/types/DeliveryAmount.html +0 -106
- package/docs/types/DeliveryStatus.html +0 -106
- package/docs/types/JSONArray.html +0 -106
- package/docs/types/JSONObject.html +0 -111
- package/docs/types/JSONValue.html +0 -106
- package/docs/types/LogLevel.html +0 -106
- package/docs/types/MediaCategory.html +0 -106
- package/docs/types/MessageType.html +0 -106
- package/docs/types/MessageUpdateReason.html +0 -106
- package/docs/types/NotificationLevel.html +0 -109
- package/docs/types/NotificationsChannelType.html +0 -110
- package/docs/types/ParticipantEmailLevel.html +0 -108
- package/docs/types/ParticipantType.html +0 -107
- package/docs/types/ParticipantUpdateReason.html +0 -106
- package/docs/types/PushNotificationType.html +0 -106
- package/docs/types/State.html +0 -110
- package/docs/types/UserUpdateReason.html +0 -106
@@ -179,7 +179,7 @@ class ChannelMetadataClient {
|
|
179
179
|
this._cache.set(key, { item: null });
|
180
180
|
return null;
|
181
181
|
}
|
182
|
-
throw e;
|
182
|
+
throw new Error(e);
|
183
183
|
}
|
184
184
|
const metadata = new ChannelMetadata(metadataResponse.type, metadataResponse.data);
|
185
185
|
this._cache.set(key, { item: metadata });
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"channel-metadata-client.js","sources":["../src/channel-metadata-client.ts"],"sourcesContent":["import {\n ChannelMetadataNotFoundError,\n CommandExecutor,\n} from \"./command-executor\";\nimport { ChannelMetadataResponse } from \"./interfaces/commands/channel-metadata-response\";\nimport QuickLRU from \"quick-lru\";\nimport { Configuration } from \"./configuration\";\n\ntype ChannelMetadataClientServices = {\n commandExecutor: CommandExecutor;\n};\n\ntype CacheEntry = {\n item: ChannelMetadata | null;\n};\n\n/**\n * Represents channel metadata.\n */\nclass ChannelMetadata {\n /**\n * Communication channel type.\n */\n public readonly type: string;\n\n /**\n * The actual metadata.\n */\n public readonly data: unknown;\n\n /**\n * @internal\n */\n public constructor(type: string, data: unknown) {\n this.type = type;\n this.data = data;\n\n Object.freeze(data);\n }\n}\n\nclass ChannelMetadataClient {\n private readonly _services: ChannelMetadataClientServices;\n private readonly _configuration: Configuration;\n private readonly _cache: QuickLRU<string, CacheEntry>;\n\n public constructor(\n services: ChannelMetadataClientServices,\n configuration: Configuration\n ) {\n this._services = services;\n this._configuration = configuration;\n this._cache = new QuickLRU({\n maxSize: configuration.channelMetadataCacheCapacity,\n });\n }\n\n public async getChannelMetadata(\n conversationSid: string,\n messageSid: string\n ): Promise<ChannelMetadata | null> {\n const key = `${conversationSid},${messageSid}`;\n const cachedItem = this._cache.get(key);\n\n if (cachedItem) {\n return cachedItem.item;\n }\n\n const url = `${this._configuration.links.conversations}/${conversationSid}/Messages/${messageSid}/ChannelMetadata`;\n let metadataResponse: ChannelMetadataResponse;\n\n try {\n metadataResponse = await this._services.commandExecutor.fetchResource<\n void,\n ChannelMetadataResponse\n >(url);\n } catch (e) {\n if (e instanceof ChannelMetadataNotFoundError) {\n this._cache.set(key, { item: null });\n return null;\n }\n\n throw e;\n }\n\n const metadata = new ChannelMetadata(\n metadataResponse.type,\n metadataResponse.data\n );\n this._cache.set(key, { item: metadata });\n return metadata;\n }\n}\n\nexport { ChannelMetadataClient, ChannelMetadata };\n"],"names":["QuickLRU","ChannelMetadataNotFoundError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;;AAEG;AACH,MAAM,eAAe,CAAA;AAWnB;;AAEG;IACH,WAAmB,CAAA,IAAY,EAAE,IAAa,EAAA;AAC5C,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACjB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AAEjB,QAAA,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KACrB;AACF,CAAA;AAED,MAAM,qBAAqB,CAAA;IAKzB,WACE,CAAA,QAAuC,EACvC,aAA4B,EAAA;AAE5B,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;AAC1B,QAAA,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;AACpC,QAAA,IAAI,CAAC,MAAM,GAAG,IAAIA,gBAAQ,CAAC;YACzB,OAAO,EAAE,aAAa,CAAC,4BAA4B;AACpD,SAAA,CAAC,CAAC;KACJ;AAEM,IAAA,MAAM,kBAAkB,CAC7B,eAAuB,EACvB,UAAkB,EAAA;AAElB,QAAA,MAAM,GAAG,GAAG,CAAA,EAAG,eAAe,CAAI,CAAA,EAAA,UAAU,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAExC,QAAA,IAAI,UAAU,EAAE;YACd,OAAO,UAAU,CAAC,IAAI,CAAC;AACxB,SAAA;AAED,QAAA,MAAM,GAAG,GAAG,CAAG,EAAA,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,aAAa,CAAI,CAAA,EAAA,eAAe,CAAa,UAAA,EAAA,UAAU,kBAAkB,CAAC;AACnH,QAAA,IAAI,gBAAyC,CAAC;QAE9C,IAAI;AACF,YAAA,gBAAgB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,aAAa,CAGnE,GAAG,CAAC,CAAC;AACR,SAAA;AAAC,QAAA,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,YAAYC,4CAA4B,EAAE;AAC7C,gBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACrC,gBAAA,OAAO,IAAI,CAAC;AACb,aAAA;AAED,YAAA,MAAM,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"channel-metadata-client.js","sources":["../src/channel-metadata-client.ts"],"sourcesContent":["import {\n ChannelMetadataNotFoundError,\n CommandExecutor,\n} from \"./command-executor\";\nimport { ChannelMetadataResponse } from \"./interfaces/commands/channel-metadata-response\";\nimport QuickLRU from \"quick-lru\";\nimport { Configuration } from \"./configuration\";\n\ntype ChannelMetadataClientServices = {\n commandExecutor: CommandExecutor;\n};\n\ntype CacheEntry = {\n item: ChannelMetadata | null;\n};\n\n/**\n * Represents channel metadata.\n */\nclass ChannelMetadata {\n /**\n * Communication channel type.\n */\n public readonly type: string;\n\n /**\n * The actual metadata.\n */\n public readonly data: unknown;\n\n /**\n * @internal\n */\n public constructor(type: string, data: unknown) {\n this.type = type;\n this.data = data;\n\n Object.freeze(data);\n }\n}\n\nclass ChannelMetadataClient {\n private readonly _services: ChannelMetadataClientServices;\n private readonly _configuration: Configuration;\n private readonly _cache: QuickLRU<string, CacheEntry>;\n\n public constructor(\n services: ChannelMetadataClientServices,\n configuration: Configuration\n ) {\n this._services = services;\n this._configuration = configuration;\n this._cache = new QuickLRU({\n maxSize: configuration.channelMetadataCacheCapacity,\n });\n }\n\n public async getChannelMetadata(\n conversationSid: string,\n messageSid: string\n ): Promise<ChannelMetadata | null> {\n const key = `${conversationSid},${messageSid}`;\n const cachedItem = this._cache.get(key);\n\n if (cachedItem) {\n return cachedItem.item;\n }\n\n const url = `${this._configuration.links.conversations}/${conversationSid}/Messages/${messageSid}/ChannelMetadata`;\n let metadataResponse: ChannelMetadataResponse;\n\n try {\n metadataResponse = await this._services.commandExecutor.fetchResource<\n void,\n ChannelMetadataResponse\n >(url);\n } catch (e) {\n if (e instanceof ChannelMetadataNotFoundError) {\n this._cache.set(key, { item: null });\n return null;\n }\n\n throw new Error(e);\n }\n\n const metadata = new ChannelMetadata(\n metadataResponse.type,\n metadataResponse.data\n );\n this._cache.set(key, { item: metadata });\n return metadata;\n }\n}\n\nexport { ChannelMetadataClient, ChannelMetadata };\n"],"names":["QuickLRU","ChannelMetadataNotFoundError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;;AAEG;AACH,MAAM,eAAe,CAAA;AAWnB;;AAEG;IACH,WAAmB,CAAA,IAAY,EAAE,IAAa,EAAA;AAC5C,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACjB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AAEjB,QAAA,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KACrB;AACF,CAAA;AAED,MAAM,qBAAqB,CAAA;IAKzB,WACE,CAAA,QAAuC,EACvC,aAA4B,EAAA;AAE5B,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;AAC1B,QAAA,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;AACpC,QAAA,IAAI,CAAC,MAAM,GAAG,IAAIA,gBAAQ,CAAC;YACzB,OAAO,EAAE,aAAa,CAAC,4BAA4B;AACpD,SAAA,CAAC,CAAC;KACJ;AAEM,IAAA,MAAM,kBAAkB,CAC7B,eAAuB,EACvB,UAAkB,EAAA;AAElB,QAAA,MAAM,GAAG,GAAG,CAAA,EAAG,eAAe,CAAI,CAAA,EAAA,UAAU,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAExC,QAAA,IAAI,UAAU,EAAE;YACd,OAAO,UAAU,CAAC,IAAI,CAAC;AACxB,SAAA;AAED,QAAA,MAAM,GAAG,GAAG,CAAG,EAAA,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,aAAa,CAAI,CAAA,EAAA,eAAe,CAAa,UAAA,EAAA,UAAU,kBAAkB,CAAC;AACnH,QAAA,IAAI,gBAAyC,CAAC;QAE9C,IAAI;AACF,YAAA,gBAAgB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,aAAa,CAGnE,GAAG,CAAC,CAAC;AACR,SAAA;AAAC,QAAA,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,YAAYC,4CAA4B,EAAE;AAC7C,gBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACrC,gBAAA,OAAO,IAAI,CAAC;AACb,aAAA;AAED,YAAA,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;AACpB,SAAA;AAED,QAAA,MAAM,QAAQ,GAAG,IAAI,eAAe,CAClC,gBAAgB,CAAC,IAAI,EACrB,gBAAgB,CAAC,IAAI,CACtB,CAAC;AACF,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AACzC,QAAA,OAAO,QAAQ,CAAC;KACjB;AACF;;;;;"}
|
package/dist/client.js
CHANGED
@@ -159,6 +159,7 @@ var _package = require('./packages/conversations/package.json.js');
|
|
159
159
|
var commandExecutor = require('./command-executor.js');
|
160
160
|
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
161
161
|
var media = require('./media.js');
|
162
|
+
var deprecationDecorator = require('@twilio/deprecation-decorator');
|
162
163
|
var contentClient = require('./content-client.js');
|
163
164
|
var channelMetadataClient = require('./channel-metadata-client.js');
|
164
165
|
|
@@ -233,31 +234,25 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
233
234
|
this._services = new ClientServices();
|
234
235
|
this._myself = new user.User("", "", null, this._services);
|
235
236
|
const startTwilsock = !this._options.twilsockClient;
|
237
|
+
// Create default init registrations if none were provided.
|
238
|
+
// Otherwise, the outside party have to list all the init registrations they
|
239
|
+
// need.
|
240
|
+
// Init registrations passed to the Conversations client will be passed down
|
241
|
+
// to the Sync client as well.
|
242
|
+
if (!this._options.initRegistrations) {
|
243
|
+
const initRegistration = new twilsock.InitRegistration(productId);
|
244
|
+
Client_1.populateInitRegistrations(initRegistration);
|
245
|
+
this._options.initRegistrations = [initRegistration];
|
246
|
+
}
|
236
247
|
this._services.twilsockClient = this._options.twilsockClient =
|
237
|
-
(_b = this._options.twilsockClient) !== null && _b !== void 0 ? _b :
|
238
|
-
// todo: remove any after the release of new Twilsock
|
239
|
-
new twilsock.TwilsockClient(fpaToken, productId, this._options);
|
240
|
-
this._services.twilsockClient.populateInitRegistrations(new Set([notificationTypes.NotificationTypes.TYPING_INDICATOR]));
|
248
|
+
(_b = this._options.twilsockClient) !== null && _b !== void 0 ? _b : new twilsock.TwilsockClient(fpaToken, productId, this._options);
|
241
249
|
this._services.twilsockClient.on("tokenAboutToExpire", () => this.emit("tokenAboutToExpire"));
|
242
250
|
this._services.twilsockClient.on("tokenExpired", () => this.emit("tokenExpired"));
|
243
|
-
this._services.twilsockClient.on("
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
this.
|
248
|
-
}
|
249
|
-
});
|
250
|
-
this._services.twilsockClient.on("connecting", () => {
|
251
|
-
Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state connecting`);
|
252
|
-
if ("connecting" !== this.connectionState) {
|
253
|
-
this.connectionState = "connecting";
|
254
|
-
this.emit("connectionStateChanged", this.connectionState);
|
255
|
-
}
|
256
|
-
});
|
257
|
-
this._services.twilsockClient.on("connected", () => {
|
258
|
-
Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state connected`);
|
259
|
-
if ("connected" !== this.connectionState) {
|
260
|
-
this.connectionState = "connected";
|
251
|
+
this._services.twilsockClient.on("connectionError", (error) => this.emit("connectionError", error));
|
252
|
+
this._services.twilsockClient.on("stateChanged", (state) => {
|
253
|
+
Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state ${state}`);
|
254
|
+
if (state !== this.connectionState) {
|
255
|
+
this.connectionState = state;
|
261
256
|
this.emit("connectionStateChanged", this.connectionState);
|
262
257
|
}
|
263
258
|
});
|
@@ -274,19 +269,28 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
274
269
|
`https://aim.${region || "us1"}.twilio.com`;
|
275
270
|
this._services.commandExecutor = new commandExecutor.CommandExecutor(baseUrl, { transport: this._options.transport }, productId);
|
276
271
|
this._services.contentClient = new contentClient.ContentClient(this._services);
|
277
|
-
const
|
278
|
-
const error = {
|
279
|
-
terminal: true,
|
280
|
-
message: errorInfo.description,
|
281
|
-
};
|
272
|
+
const emitFailed = (error) => {
|
282
273
|
this._rejectEnsureReady(error);
|
274
|
+
this.emit("stateChanged", "failed");
|
283
275
|
this.emit("initFailed", { error });
|
284
|
-
}
|
285
|
-
|
276
|
+
};
|
277
|
+
const emitDisconnected = () => {
|
278
|
+
emitFailed({
|
279
|
+
terminal: true,
|
280
|
+
message: "Twilsock has disconnected.",
|
281
|
+
});
|
282
|
+
};
|
283
|
+
this._services.twilsockClient.once("connectionError", emitFailed);
|
284
|
+
this._services.twilsockClient.once("disconnected", emitDisconnected);
|
285
|
+
this._services.twilsockClient.once("connected", async () => {
|
286
286
|
Client_1._logger.debug(`ConversationsClient started INITIALIZING`);
|
287
|
-
|
287
|
+
this._services.twilsockClient.off("connectionError", emitFailed);
|
288
|
+
this._services.twilsockClient.off("disconnected", emitDisconnected);
|
288
289
|
try {
|
290
|
+
const startupEvent = "conversations.client.startup";
|
291
|
+
this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
|
289
292
|
await this._initialize();
|
293
|
+
this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
|
290
294
|
}
|
291
295
|
catch (err) {
|
292
296
|
// Fail ChatClient if initialization is incomplete
|
@@ -295,6 +299,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
295
299
|
message: err.message,
|
296
300
|
};
|
297
301
|
this._rejectEnsureReady(connectionError);
|
302
|
+
this.emit("stateChanged", "failed");
|
298
303
|
this.emit("initFailed", {
|
299
304
|
error: connectionError,
|
300
305
|
});
|
@@ -303,9 +308,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
303
308
|
this._ensureReady = new Promise((resolve, reject) => {
|
304
309
|
this._resolveEnsureReady = resolve;
|
305
310
|
this._rejectEnsureReady = reject;
|
306
|
-
}).catch((
|
307
|
-
Client_1._logger.error(e);
|
308
|
-
});
|
311
|
+
}).catch(() => void 0); // @todo How to process unhandled rejection here?
|
309
312
|
if (startTwilsock) {
|
310
313
|
this._services.twilsockClient.connect();
|
311
314
|
}
|
@@ -325,11 +328,54 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
325
328
|
get reachabilityEnabled() {
|
326
329
|
if (!this._configuration) {
|
327
330
|
throw new Error("Reachability information could not yet be accessed as the client " +
|
328
|
-
"has not yet been initialized. Subscribe to '
|
329
|
-
"
|
331
|
+
"has not yet been initialized. Subscribe to the 'stateChanged' event " +
|
332
|
+
"to properly react to the client initialization.");
|
330
333
|
}
|
331
334
|
return this._configuration.reachabilityEnabled;
|
332
335
|
}
|
336
|
+
/**
|
337
|
+
* @deprecated
|
338
|
+
* Current token.
|
339
|
+
* @internal
|
340
|
+
*/
|
341
|
+
get token() {
|
342
|
+
return this._fpaToken;
|
343
|
+
}
|
344
|
+
/**
|
345
|
+
* @deprecated Call constructor directly.
|
346
|
+
*
|
347
|
+
* Factory method to create a Conversations client instance.
|
348
|
+
*
|
349
|
+
* The factory method will automatically trigger connection.
|
350
|
+
* Do not use it if you need finer-grained control.
|
351
|
+
*
|
352
|
+
* Since this method returns an already-initialized client, some of the events
|
353
|
+
* will be lost because they happen *before* the initialization. It is
|
354
|
+
* recommended that `client.onWithReplay` is used as opposed to `client.on`
|
355
|
+
* for subscribing to client events. The `client.onWithReplay` will re-emit
|
356
|
+
* the most recent value for a given event if it emitted before the
|
357
|
+
* subscription.
|
358
|
+
*
|
359
|
+
* @param token Access token.
|
360
|
+
* @param options Options to customize the client.
|
361
|
+
* @returns Returns a fully initialized client.
|
362
|
+
*/
|
363
|
+
static async create(token, options) {
|
364
|
+
// The logic is as follows:
|
365
|
+
// - If twilsock is not passed in, then the ConversationsClient constructor will call twilsock.connect() by itself
|
366
|
+
// and we do not need to do it here.
|
367
|
+
// - If twilsock was passed in from the outside, but customer called ConversationsClient.create() then they are
|
368
|
+
// using an obsolete workflow and the startup sequence will never complete.
|
369
|
+
if (options === null || options === void 0 ? void 0 : options.twilsockClient) {
|
370
|
+
throw new Error("Obsolete usage of ConversationsClient.create() " +
|
371
|
+
"factory method: if you pass twilsock from the outside then you must " +
|
372
|
+
"use ConversationsClient constructor and be prepared to work with " +
|
373
|
+
"uninitialized client.");
|
374
|
+
}
|
375
|
+
const client = new Client_1(token, options);
|
376
|
+
await client._ensureReady;
|
377
|
+
return client;
|
378
|
+
}
|
333
379
|
/**
|
334
380
|
* Static method for push notification payload parsing. Returns parsed push as
|
335
381
|
* a {@link PushNotification} object.
|
@@ -416,13 +462,20 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
416
462
|
}
|
417
463
|
return result;
|
418
464
|
}
|
465
|
+
/**
|
466
|
+
* Populate the client with init registrations.
|
467
|
+
* @param reg The init registration to populate.
|
468
|
+
*/
|
469
|
+
static populateInitRegistrations(reg) {
|
470
|
+
reg.populateInitRegistrations([notificationTypes.NotificationTypes.TYPING_INDICATOR]);
|
471
|
+
twilioSync.SyncClient.populateInitRegistrations(reg);
|
472
|
+
}
|
419
473
|
/**
|
420
474
|
* Gracefully shut down the client.
|
421
475
|
*/
|
422
476
|
async shutdown() {
|
423
|
-
var _a;
|
424
477
|
await this._ensureReady;
|
425
|
-
await
|
478
|
+
await this._services.twilsockClient.disconnect();
|
426
479
|
}
|
427
480
|
/**
|
428
481
|
* Update the token used by the client and re-register with the Conversations services.
|
@@ -447,7 +500,13 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
447
500
|
async getConversationBySid(conversationSid) {
|
448
501
|
await this._ensureReady;
|
449
502
|
await this._conversationsEntity.myConversationsRead.promise;
|
450
|
-
|
503
|
+
let conversation = await this._conversationsEntity.getConversation(conversationSid);
|
504
|
+
if (!conversation) {
|
505
|
+
conversation = await this.peekConversationBySid(conversationSid);
|
506
|
+
if (conversation) {
|
507
|
+
deprecationDecorator.deprecationWarning("The method getConversationBySid is deprecated to retrieve conversations you're not part of. Use peekConversationBySid instead.");
|
508
|
+
}
|
509
|
+
}
|
451
510
|
if (!conversation) {
|
452
511
|
throw new Error(`Conversation with SID ${conversationSid} was not found.`);
|
453
512
|
}
|
@@ -484,8 +543,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
484
543
|
*/
|
485
544
|
async getSubscribedConversations() {
|
486
545
|
await this._ensureReady;
|
487
|
-
|
488
|
-
return await conversations.getConversations();
|
546
|
+
return this._conversationsPromise.then((conversations) => conversations.getConversations());
|
489
547
|
}
|
490
548
|
/**
|
491
549
|
* Create a conversation on the server and subscribe to its events.
|
@@ -509,6 +567,16 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
509
567
|
this._services.notificationClient.setPushRegistrationId(channelType, registrationId);
|
510
568
|
await this._services.notificationClient.commitChanges(); // Committing before this point is useless because we have no push id
|
511
569
|
}
|
570
|
+
/**
|
571
|
+
* Unregister from push notifications.
|
572
|
+
* @param channelType Channel type.
|
573
|
+
* @deprecated Use removePushRegistrations() instead.
|
574
|
+
*/
|
575
|
+
async unsetPushRegistrationId(channelType) {
|
576
|
+
await this._ensureReady;
|
577
|
+
this._unsubscribeFromPushNotifications(channelType);
|
578
|
+
await this._services.notificationClient.commitChanges();
|
579
|
+
}
|
512
580
|
/**
|
513
581
|
* Clear existing registrations directly using provided device token.
|
514
582
|
* This is useful to ensure stopped subscriptions without resubscribing.
|
@@ -646,9 +714,6 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
646
714
|
.fetchConversations()
|
647
715
|
.then(() => this._conversationsEntity)
|
648
716
|
.catch((error) => {
|
649
|
-
if (error.message === "Client has been shut down.") {
|
650
|
-
return this._conversationsEntity;
|
651
|
-
}
|
652
717
|
throw error;
|
653
718
|
});
|
654
719
|
await this._services.users.myself._ensureFetched();
|
@@ -656,6 +721,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
656
721
|
this._services.typingIndicator.initialize();
|
657
722
|
this._services.mcsClient = new mcsClient.McsClient(this._fpaToken, this._configuration.links.mediaService, this._configuration.links.mediaSetService, Object.assign(Object.assign({}, this._options), { transport: undefined }));
|
658
723
|
this._resolveEnsureReady();
|
724
|
+
this.emit("stateChanged", "initialized");
|
659
725
|
this.emit("initialized");
|
660
726
|
}
|
661
727
|
/**
|
@@ -673,6 +739,21 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
|
|
673
739
|
this._services.notificationClient.subscribe(channelType, messageType);
|
674
740
|
});
|
675
741
|
}
|
742
|
+
/**
|
743
|
+
* Unsubscribe from push notifications.
|
744
|
+
* @param channelType The channel type to unsubscribe from.
|
745
|
+
*/
|
746
|
+
_unsubscribeFromPushNotifications(channelType) {
|
747
|
+
[
|
748
|
+
notificationTypes.NotificationTypes.NEW_MESSAGE,
|
749
|
+
notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
|
750
|
+
notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
|
751
|
+
notificationTypes.NotificationTypes.TYPING_INDICATOR,
|
752
|
+
notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
|
753
|
+
].forEach((messageType) => {
|
754
|
+
this._services.notificationClient.unsubscribe(channelType, messageType);
|
755
|
+
});
|
756
|
+
}
|
676
757
|
};
|
677
758
|
/**
|
678
759
|
* Fired when a conversation becomes visible to the client. The event is also
|
@@ -844,6 +925,15 @@ exports.Client.userUnsubscribed = "userUnsubscribed";
|
|
844
925
|
* @event
|
845
926
|
*/
|
846
927
|
exports.Client.userUpdated = "userUpdated";
|
928
|
+
/**
|
929
|
+
* @deprecated Use initialized or initFailed events instead
|
930
|
+
* Fired when the state of the client has been changed.
|
931
|
+
*
|
932
|
+
* Parameters:
|
933
|
+
* 1. {@link State} `state` - the new client state
|
934
|
+
* @event
|
935
|
+
*/
|
936
|
+
exports.Client.stateChanged = "stateChanged";
|
847
937
|
/**
|
848
938
|
* Fired when the client has completed initialization successfully.
|
849
939
|
* @event
|
@@ -906,6 +996,11 @@ exports.Client._supportedPushDataFields = {
|
|
906
996
|
media_count: "mediaCount",
|
907
997
|
media: "media", // object
|
908
998
|
};
|
999
|
+
tslib_es6.__decorate([
|
1000
|
+
deprecationDecorator.deprecated("token"),
|
1001
|
+
tslib_es6.__metadata("design:type", String),
|
1002
|
+
tslib_es6.__metadata("design:paramtypes", [])
|
1003
|
+
], exports.Client.prototype, "token", null);
|
909
1004
|
tslib_es6.__decorate([
|
910
1005
|
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
|
911
1006
|
tslib_es6.__metadata("design:type", Function),
|
@@ -949,6 +1044,12 @@ tslib_es6.__decorate([
|
|
949
1044
|
tslib_es6.__metadata("design:paramtypes", [String, String]),
|
950
1045
|
tslib_es6.__metadata("design:returntype", Promise)
|
951
1046
|
], exports.Client.prototype, "setPushRegistrationId", null);
|
1047
|
+
tslib_es6.__decorate([
|
1048
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn")),
|
1049
|
+
tslib_es6.__metadata("design:type", Function),
|
1050
|
+
tslib_es6.__metadata("design:paramtypes", [String]),
|
1051
|
+
tslib_es6.__metadata("design:returntype", Promise)
|
1052
|
+
], exports.Client.prototype, "unsetPushRegistrationId", null);
|
952
1053
|
tslib_es6.__decorate([
|
953
1054
|
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn"), declarativeTypeValidator.nonEmptyString),
|
954
1055
|
tslib_es6.__metadata("design:type", Function),
|
@@ -979,6 +1080,13 @@ tslib_es6.__decorate([
|
|
979
1080
|
tslib_es6.__metadata("design:paramtypes", [Array]),
|
980
1081
|
tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
|
981
1082
|
], exports.Client.prototype, "getTemporaryContentUrlsForMedia", null);
|
1083
|
+
tslib_es6.__decorate([
|
1084
|
+
deprecationDecorator.deprecated("Client.create()", "new Client()"),
|
1085
|
+
declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]),
|
1086
|
+
tslib_es6.__metadata("design:type", Function),
|
1087
|
+
tslib_es6.__metadata("design:paramtypes", [String, Object]),
|
1088
|
+
tslib_es6.__metadata("design:returntype", Promise)
|
1089
|
+
], exports.Client, "create", null);
|
982
1090
|
tslib_es6.__decorate([
|
983
1091
|
declarativeTypeValidator.validateTypes(declarativeTypeValidator.pureObject),
|
984
1092
|
tslib_es6.__metadata("design:type", Function),
|