@twilio/conversations 2.1.0 → 2.2.0-rc.12

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +216 -0
  2. package/README.md +8 -4
  3. package/builds/browser.js +2911 -1974
  4. package/builds/browser.js.map +1 -1
  5. package/builds/lib.d.ts +572 -285
  6. package/builds/lib.js +2911 -1974
  7. package/builds/lib.js.map +1 -1
  8. package/builds/twilio-conversations.js +4995 -3430
  9. package/builds/twilio-conversations.min.js +1 -16
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/client.js +466 -281
  12. package/dist/client.js.map +1 -1
  13. package/dist/command-executor.js.map +1 -1
  14. package/dist/configuration.js +2 -2
  15. package/dist/configuration.js.map +1 -1
  16. package/dist/conversation.js +426 -370
  17. package/dist/conversation.js.map +1 -1
  18. package/dist/data/conversations.js +25 -13
  19. package/dist/data/conversations.js.map +1 -1
  20. package/dist/data/messages.js +56 -32
  21. package/dist/data/messages.js.map +1 -1
  22. package/dist/data/participants.js +21 -12
  23. package/dist/data/participants.js.map +1 -1
  24. package/dist/data/users.js +2 -2
  25. package/dist/data/users.js.map +1 -1
  26. package/dist/detailed-delivery-receipt.js.map +1 -1
  27. package/dist/index.js +6 -4
  28. package/dist/index.js.map +1 -1
  29. package/dist/interfaces/attributes.js.map +1 -1
  30. package/dist/interfaces/notification-types.js.map +1 -1
  31. package/dist/logger.js +2 -4
  32. package/dist/logger.js.map +1 -1
  33. package/dist/media.js +36 -25
  34. package/dist/media.js.map +1 -1
  35. package/dist/message-builder.js +24 -18
  36. package/dist/message-builder.js.map +1 -1
  37. package/dist/message.js +89 -17
  38. package/dist/message.js.map +1 -1
  39. package/dist/node_modules/tslib/tslib.es6.js +1 -1
  40. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  41. package/dist/packages/conversations/package.json.js +1 -1
  42. package/dist/participant.js +2 -2
  43. package/dist/participant.js.map +1 -1
  44. package/dist/push-notification.js.map +1 -1
  45. package/dist/rest-paginator.js.map +1 -1
  46. package/dist/services/network.js.map +1 -1
  47. package/dist/services/typing-indicator.js +1 -1
  48. package/dist/services/typing-indicator.js.map +1 -1
  49. package/dist/unsent-message.js +13 -3
  50. package/dist/unsent-message.js.map +1 -1
  51. package/dist/user.js +2 -2
  52. package/dist/user.js.map +1 -1
  53. package/dist/util/deferred.js.map +1 -1
  54. package/dist/util/index.js.map +1 -1
  55. package/docs/assets/js/search.js +1 -1
  56. package/docs/classes/CancellablePromise.html +3213 -0
  57. package/docs/classes/Client.html +243 -58
  58. package/docs/classes/Conversation.html +76 -47
  59. package/docs/classes/Media.html +2 -28
  60. package/docs/classes/Message.html +94 -39
  61. package/docs/classes/MessageBuilder.html +31 -8
  62. package/docs/classes/PushNotification.html +1 -1
  63. package/docs/classes/UnsentMessage.html +2 -2
  64. package/docs/index.html +25 -28
  65. package/docs/interfaces/ConversationLimits.html +12 -12
  66. package/docs/interfaces/ConversationState.html +2 -2
  67. package/docs/interfaces/ConversationUpdatedEventArgs.html +3001 -0
  68. package/docs/interfaces/PushNotificationData.html +48 -0
  69. package/docs/modules.html +24 -27
  70. package/package.json +24 -20
package/builds/lib.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { SyncClient, SyncDocument, SyncList } from "twilio-sync";
2
3
  import { LogLevelDesc } from "loglevel";
3
4
  import { Transport, TwilsockClient, InitRegistration, TransportResult } from "twilsock";
@@ -5,7 +6,7 @@ import { ConnectionState as TwilsockConnectionState } from "twilsock";
5
6
  import { ReplayEventEmitter } from "@twilio/replay-event-emitter";
6
7
  import { ChannelType, Notifications } from "@twilio/notifications";
7
8
  import { Notifications as NotificationClient } from "@twilio/notifications";
8
- import { McsClient, MediaCategory, McsMedia } from "@twilio/mcs-client";
9
+ import { CancellablePromise, McsClient, MediaCategory, McsMedia } from "@twilio/mcs-client";
9
10
  import { MediaCategory as McsMediaCategory } from "@twilio/mcs-client";
10
11
  interface ConfigurationResponse {
11
12
  options: {
@@ -72,13 +73,13 @@ interface ConversationLimits {
72
73
  */
73
74
  mediaAttachmentsTotalSizeLimitInMb: number;
74
75
  /**
75
- * Allowed mime types for E-Mail histories.
76
+ * Allowed content types for E-Mail histories.
76
77
  */
77
- emailHistoriesAllowedMimeTypes: string[];
78
+ emailHistoriesAllowedContentTypes: string[];
78
79
  /**
79
- * Allowed mime types for E-Mail bodies.
80
+ * Allowed content types for E-Mail bodies.
80
81
  */
81
- emailBodiesAllowedMimeTypes: string[];
82
+ emailBodiesAllowedContentTypes: string[];
82
83
  }
83
84
  interface BackoffConfiguration {
84
85
  min: number;
@@ -301,7 +302,7 @@ declare class Users extends ReplayEventEmitter<UsersEvents> {
301
302
  * if not - then subscribes and adds user to the FIFO stack
302
303
  * @returns {Promise<User>} Fully initialized user
303
304
  */
304
- getUser(identity?: string, entityName?: string): Promise<User>;
305
+ getUser(identity: string, entityName?: string): Promise<User>;
305
306
  /**
306
307
  * @returns {Promise<Array<User>>} returns list of subscribed User objects {@see User}
307
308
  */
@@ -326,9 +327,9 @@ interface ParticipantDescriptor {
326
327
  identity: string;
327
328
  roleSid?: string;
328
329
  lastConsumedMessageIndex: number | null;
329
- lastConsumptionTimestamp: number;
330
+ lastConsumptionTimestamp: number | null;
330
331
  type: ParticipantType;
331
- userInfo: string;
332
+ userInfo?: string;
332
333
  bindings?: ParticipantBindings;
333
334
  }
334
335
  interface ParticipantServices {
@@ -499,9 +500,9 @@ interface ParticipantResponse {
499
500
  attributes: string;
500
501
  date_created: string;
501
502
  date_updated: string;
502
- identity: string | null;
503
+ identity: string;
503
504
  messaging_binding: {
504
- type: string;
505
+ type: "chat" | "sms" | "whatsapp" | "email";
505
506
  address: string;
506
507
  proxy_address: string;
507
508
  } | null;
@@ -568,17 +569,7 @@ declare class Media {
568
569
  * If the URL becomes expired, you need to request a new one.
569
570
  * Each call to this function produces a new temporary URL.
570
571
  */
571
- getContentTemporaryUrl(): Promise<string | null>;
572
- /**
573
- * Returns cached direct content URL for the media.
574
- *
575
- * This URL will expire in several minutes. This function does not refresh the URL and can be used to query it several times
576
- * without causing network traffic.
577
- * If the URL becomes expired, you need to request a new one using getContentTemporaryUrl().
578
- *
579
- * @returns {Promise<String>}
580
- */
581
- getCachedTemporaryUrl(): Promise<string | null>;
572
+ getContentTemporaryUrl(): CancellablePromise<string | null>;
582
573
  private _fetchMcsMedia;
583
574
  }
584
575
  /**
@@ -857,21 +848,29 @@ declare class Message extends ReplayEventEmitter<MessageEvents> {
857
848
  */
858
849
  get aggregatedDeliveryReceipt(): AggregatedDeliveryReceipt | null;
859
850
  /**
851
+ * @deprecated
860
852
  * Return a (possibly empty) array of media matching a specific set of categories.
861
853
  * Allowed category is so far only 'media'.
862
854
  * @param categories Array of categories to match.
863
855
  * @returns Array of media descriptors matching given categories.
864
856
  */
865
857
  getMediaByCategory(categories: Array<MediaCategory>): Array<Media> | null;
858
+ /**
859
+ * Return a (possibly empty) array of media matching a specific set of categories.
860
+ * Allowed category is so far only 'media'.
861
+ * @param categories Array of categories to match.
862
+ * @returns Array of media descriptors matching given categories.
863
+ */
864
+ getMediaByCategories(categories: MediaCategory[]): Media[] | null;
866
865
  /**
867
866
  * Get a media descriptor for an email body attachment of a provided type.
868
- * Allowed body types are returned in the Conversation.limits().emailBodiesAllowedMimeTypes array.
867
+ * Allowed body types are returned in the Conversation.limits().emailBodiesAllowedContentTypes array.
869
868
  * @param type Type of email body to request, defaults to `text/plain`.
870
869
  */
871
870
  getEmailBody(type?: string): Media | null;
872
871
  /**
873
872
  * Get a media descriptor for an email history attachment of a provided type.
874
- * Allowed body types are returned in the Conversation.limits().emailHistoriesAllowedMimeTypes array.
873
+ * Allowed body types are returned in the Conversation.limits().emailHistoriesAllowedContentTypes array.
875
874
  * @param type Type of email history to request, defaults to `text/plain`.
876
875
  */
877
876
  getEmailHistory(type?: string): Media | null;
@@ -899,10 +898,25 @@ declare class Message extends ReplayEventEmitter<MessageEvents> {
899
898
  */
900
899
  updateAttributes(attributes: JSONValue): Promise<Message>;
901
900
  /**
902
- * Get content URLs for all media attachments in the given set using single operation.
903
- * @param contentSet Set of media attachments to query for content URL.
901
+ * @deprecated
902
+ * Get content URLs for all media attachments in the given set using a single operation.
903
+ * @param contentSet Set of media attachments to query content URLs.
904
904
  */
905
905
  attachTemporaryUrlsFor(contentSet: Media[] | null): Promise<Media[]>;
906
+ /**
907
+ * Get content URLs for all media attachments in the given set using a single operation.
908
+ * @param contentSet Set of media attachments to query content URLs.
909
+ */
910
+ getTemporaryContentUrlsForMedia(contentSet: Media[]): CancellablePromise<Map<string, string>>;
911
+ /**
912
+ * Get content URLs for all media attachments in the given set of media sids using a single operation.
913
+ * @param mediaSids Set of media sids to query for the content URL.
914
+ */
915
+ getTemporaryContentUrlsForMediaSids(mediaSids: string[]): CancellablePromise<Map<string, string>>;
916
+ /**
917
+ * Get content URLs for all media attached to the message.
918
+ */
919
+ getTemporaryContentUrlsForAttachedMedia(): CancellablePromise<Map<string, string>>;
906
920
  private _getDetailedDeliveryReceiptsPaginator;
907
921
  }
908
922
  /**
@@ -959,7 +973,7 @@ declare class TypingIndicator {
959
973
  private sentUpdates;
960
974
  private getConversation;
961
975
  private serviceTypingTimeout;
962
- constructor(getConversation: any, config: Configuration, services: TypingIndicatorServices);
976
+ constructor(getConversation: (conversationSid: string) => Promise<Conversation>, config: Configuration, services: TypingIndicatorServices);
963
977
  get typingTimeout(): number;
964
978
  /**
965
979
  * Initialize TypingIndicator controller
@@ -978,25 +992,6 @@ declare class TypingIndicator {
978
992
  send(conversationSid: string): Promise<void>;
979
993
  private _send;
980
994
  }
981
- /**
982
- * An unsent message. Returned from {@link MessageBuilder.build}.
983
- */
984
- declare class UnsentMessage {
985
- private messagesEntity;
986
- text?: string;
987
- attributes: JSONValue;
988
- mediaContent: [MediaCategory, FormData | SendMediaOptions][];
989
- emailOptions: SendEmailOptions;
990
- /**
991
- * @internal
992
- */
993
- constructor(messagesEntity: any);
994
- /**
995
- * Send the prepared message to the conversation.
996
- * @returns Index of the new message in the conversation.
997
- */
998
- send(): Promise<number | null>;
999
- }
1000
995
  /**
1001
996
  * Pagination helper class.
1002
997
  */
@@ -1098,16 +1093,16 @@ declare class Messages extends ReplayEventEmitter<MessagesEvents> {
1098
1093
  constructor(conversation: Conversation, configuration: Configuration, services: MessagesServices);
1099
1094
  /**
1100
1095
  * Subscribe to the Messages Event Stream
1101
- * @param name - The name of Sync object for the Messages resource.
1096
+ * @param arg - Name of the Sync object, or the SyncList itself, that
1097
+ * represents the Messages resource.
1102
1098
  */
1103
- subscribe(name: string): Promise<SyncList>;
1099
+ subscribe(arg: string | SyncList): Promise<SyncList>;
1104
1100
  unsubscribe(): Promise<void>;
1105
1101
  /**
1106
- * Send Message to the conversation, message could include both text and multiple media attachments.
1102
+ * Send a message to the conversation. The message could include text and multiple media attachments.
1107
1103
  * @param message Message to post
1108
- * @returns Returns a promise which can fail
1109
1104
  */
1110
- sendV2(message: UnsentMessage): Promise<MessageResponse>;
1105
+ sendV2(message: UnsentMessage): CancellablePromise<MessageResponse>;
1111
1106
  /**
1112
1107
  * Send Message to the conversation
1113
1108
  * @param message Message to post
@@ -1144,6 +1139,28 @@ declare class Messages extends ReplayEventEmitter<MessagesEvents> {
1144
1139
  */
1145
1140
  private _getMessages;
1146
1141
  }
1142
+ /**
1143
+ * An unsent message. Returned from {@link MessageBuilder.build}.
1144
+ */
1145
+ declare class UnsentMessage {
1146
+ private messagesEntity;
1147
+ text?: string;
1148
+ attributes: JSONValue;
1149
+ mediaContent: [
1150
+ MediaCategory,
1151
+ FormData | SendMediaOptions
1152
+ ][];
1153
+ emailOptions: SendEmailOptions;
1154
+ /**
1155
+ * @internal
1156
+ */
1157
+ constructor(messagesEntity: Messages);
1158
+ /**
1159
+ * Send the prepared message to the conversation.
1160
+ * @returns Index of the new message in the conversation.
1161
+ */
1162
+ send(): CancellablePromise<number | null>;
1163
+ }
1147
1164
  /**
1148
1165
  * Message builder. Allows the message to be built and sent via method chaining.
1149
1166
  *
@@ -1184,17 +1201,17 @@ declare class MessageBuilder {
1184
1201
  */
1185
1202
  setAttributes(attributes: JSONValue): MessageBuilder;
1186
1203
  /**
1187
- * Set email body with given MIME-type.
1188
- * @param mimeType Format of the body to set (text/plain or text/html).
1189
- * @param body Body payload in selected format.
1204
+ * Set the email body with a given content type.
1205
+ * @param contentType Format of the body to set (text/plain or text/html).
1206
+ * @param body Body payload in the selected format.
1190
1207
  */
1191
- setEmailBody(mimeType: string, body: FormData | SendMediaOptions): MessageBuilder;
1208
+ setEmailBody(contentType: string, body: FormData | SendMediaOptions): MessageBuilder;
1192
1209
  /**
1193
- * Set email history with given MIME-type.
1194
- * @param mimeType Format of the history to set (text/plain or text/html).
1195
- * @param history History payload in selected format.
1210
+ * Set the email history with a given content type.
1211
+ * @param contentType Format of the history to set (text/plain or text/html).
1212
+ * @param history History payload in the selected format.
1196
1213
  */
1197
- setEmailHistory(mimeType: string, history: FormData | SendMediaOptions): MessageBuilder;
1214
+ setEmailHistory(contentType: string, history: FormData | SendMediaOptions): MessageBuilder;
1198
1215
  /**
1199
1216
  * Adds media to the message.
1200
1217
  * @param payload Media to add.
@@ -1204,8 +1221,15 @@ declare class MessageBuilder {
1204
1221
  * Builds the message, making it ready to be sent.
1205
1222
  */
1206
1223
  build(): UnsentMessage;
1224
+ /**
1225
+ * Prepares a message and sends it to the conversation.
1226
+ */
1227
+ buildAndSend(): CancellablePromise<number | null>;
1207
1228
  private getPayloadContentType;
1208
1229
  }
1230
+ /**
1231
+ * Conversation events.
1232
+ */
1209
1233
  type ConversationEvents = {
1210
1234
  participantJoined: (participant: Participant) => void;
1211
1235
  participantLeft: (participant: Participant) => void;
@@ -1227,55 +1251,28 @@ type ConversationEvents = {
1227
1251
  }) => void;
1228
1252
  removed: (conversation: Conversation) => void;
1229
1253
  };
1230
- interface ConversationServices {
1231
- users: Users;
1232
- typingIndicator: TypingIndicator;
1233
- network: Network;
1234
- mcsClient: McsClient;
1235
- syncClient: SyncClient;
1236
- commandExecutor: CommandExecutor;
1237
- }
1238
- interface ConversationDescriptor {
1239
- channel: string;
1240
- entityName: string;
1241
- uniqueName: string;
1242
- attributes: JSONValue;
1243
- createdBy?: string;
1244
- friendlyName?: string;
1245
- lastConsumedMessageIndex: number;
1246
- dateCreated: Date | null;
1247
- dateUpdated: Date | null;
1248
- notificationLevel?: NotificationLevel;
1249
- bindings?: ConversationBindings;
1250
- }
1251
- interface ConversationLinks {
1252
- self: string;
1253
- messages: string;
1254
- participants: string;
1255
- }
1256
1254
  /**
1257
- * The reason for the `updated` event being emitted by a conversation.
1255
+ * Reason for the `updated` event emission by a conversation.
1258
1256
  */
1259
1257
  type ConversationUpdateReason = "attributes" | "createdBy" | "dateCreated" | "dateUpdated" | "friendlyName" | "lastReadMessageIndex" | "state" | "status" | "uniqueName" | "lastMessage" | "notificationLevel" | "bindings";
1260
1258
  /**
1261
- * The status of the conversation, relative to the client: whether
1262
- * the conversation has been `joined` or the client is
1263
- * `notParticipating` in the conversation.
1259
+ * Status of the conversation, relative to the client: whether the conversation
1260
+ * has been `joined` or the client is `notParticipating` in the conversation.
1264
1261
  */
1265
1262
  type ConversationStatus = "notParticipating" | "joined";
1266
1263
  /**
1267
- * The user's notification level for the conversation. Determines
1264
+ * User's notification level for the conversation. Determines
1268
1265
  * whether the currently logged-in user will receive pushes for events
1269
1266
  * in this conversation. Can be either `muted` or `default`, where
1270
1267
  * `default` defers to the global service push configuration.
1271
1268
  */
1272
1269
  type NotificationLevel = "default" | "muted";
1273
1270
  /**
1274
- * The state of the conversation.
1271
+ * State of the conversation.
1275
1272
  */
1276
1273
  interface ConversationState {
1277
1274
  /**
1278
- * The current state.
1275
+ * Current state.
1279
1276
  */
1280
1277
  current: "active" | "inactive" | "closed";
1281
1278
  /**
@@ -1283,6 +1280,9 @@ interface ConversationState {
1283
1280
  */
1284
1281
  dateUpdated: Date;
1285
1282
  }
1283
+ /**
1284
+ * Event arguments for the `updated` event.
1285
+ */
1286
1286
  interface ConversationUpdatedEventArgs {
1287
1287
  conversation: Conversation;
1288
1288
  updateReasons: ConversationUpdateReason[];
@@ -1301,6 +1301,9 @@ interface ConversationEmailBinding {
1301
1301
  name?: string;
1302
1302
  projected_address: string;
1303
1303
  }
1304
+ /**
1305
+ * Binding for SMS conversation.
1306
+ */
1304
1307
  interface ConversationSmsBinding {
1305
1308
  address?: string;
1306
1309
  }
@@ -1346,33 +1349,51 @@ interface LastMessage {
1346
1349
  dateCreated?: Date;
1347
1350
  }
1348
1351
  /**
1349
- * A conversation represents communication between multiple Conversations clients
1352
+ * Conversation services.
1353
+ */
1354
+ interface ConversationServices {
1355
+ users: Users;
1356
+ typingIndicator: TypingIndicator;
1357
+ network: Network;
1358
+ mcsClient: McsClient;
1359
+ syncClient: SyncClient;
1360
+ commandExecutor: CommandExecutor;
1361
+ }
1362
+ /**
1363
+ * Conversation descriptor.
1364
+ */
1365
+ interface ConversationDescriptor {
1366
+ channel: string;
1367
+ entityName: string;
1368
+ uniqueName: string;
1369
+ attributes: JSONValue;
1370
+ createdBy?: string;
1371
+ friendlyName?: string;
1372
+ lastConsumedMessageIndex: number;
1373
+ dateCreated: Date | null;
1374
+ dateUpdated: Date | null;
1375
+ notificationLevel?: NotificationLevel;
1376
+ bindings?: ConversationBindings;
1377
+ }
1378
+ /**
1379
+ * Conversation links.
1380
+ */
1381
+ interface ConversationLinks {
1382
+ self: string;
1383
+ messages: string;
1384
+ participants: string;
1385
+ }
1386
+ /**
1387
+ * A conversation represents communication between multiple Conversations
1388
+ * clients.
1350
1389
  */
1351
1390
  declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1352
- /**
1353
- * Unique system identifier of the conversation.
1354
- */
1355
- readonly sid: string;
1356
- readonly links: ConversationLinks;
1357
- private readonly configuration;
1358
- private readonly services;
1359
- private channelState;
1360
- private statusSource;
1361
- private entityPromise;
1362
- private entityName;
1363
- private entity;
1364
- private messagesEntity;
1365
- private participantsEntity;
1366
- private readonly participants;
1367
- /**
1368
- * @internal
1369
- */
1370
- constructor(descriptor: ConversationDescriptor, sid: string, links: ConversationLinks, configuration: Configuration, services: ConversationServices);
1371
1391
  /**
1372
1392
  * Fired when a participant has joined the conversation.
1373
1393
  *
1374
1394
  * Parameters:
1375
- * 1. {@link Participant} `participant` - participant that joined the conversation
1395
+ * 1. {@link Participant} `participant` - participant that joined the
1396
+ * conversation
1376
1397
  * @event
1377
1398
  */
1378
1399
  static readonly participantJoined = "participantJoined";
@@ -1380,7 +1401,8 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1380
1401
  * Fired when a participant has left the conversation.
1381
1402
  *
1382
1403
  * Parameters:
1383
- * 1. {@link Participant} `participant` - participant that left the conversation
1404
+ * 1. {@link Participant} `participant` - participant that left the
1405
+ * conversation
1384
1406
  * @event
1385
1407
  */
1386
1408
  static readonly participantLeft = "participantLeft";
@@ -1388,9 +1410,12 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1388
1410
  * Fired when data of a participant has been updated.
1389
1411
  *
1390
1412
  * Parameters:
1391
- * 1. object `data` - info object provided with the event. It has the following properties:
1392
- * * {@link Participant} `participant` - participant that has received the update
1393
- * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons for update
1413
+ * 1. object `data` - info object provided with the event. It has the
1414
+ * following properties:
1415
+ * * {@link Participant} `participant` - participant that has received the
1416
+ * update
1417
+ * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons
1418
+ * for the update
1394
1419
  * @event
1395
1420
  */
1396
1421
  static readonly participantUpdated = "participantUpdated";
@@ -1414,9 +1439,11 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1414
1439
  * Fired when data of a message has been updated.
1415
1440
  *
1416
1441
  * Parameters:
1417
- * 1. object `data` - info object provided with the event. It has the following properties:
1442
+ * 1. object `data` - info object provided with the event. It has the
1443
+ * following properties:
1418
1444
  * * {@link Message} `message` - message that has received the update
1419
- * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for update
1445
+ * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for
1446
+ * the update
1420
1447
  * @event
1421
1448
  */
1422
1449
  static readonly messageUpdated = "messageUpdated";
@@ -1424,7 +1451,8 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1424
1451
  * Fired when a participant has stopped typing.
1425
1452
  *
1426
1453
  * Parameters:
1427
- * 1. {@link Participant} `participant` - the participant that has stopped typing
1454
+ * 1. {@link Participant} `participant` - the participant that has stopped
1455
+ * typing
1428
1456
  * @event
1429
1457
  */
1430
1458
  static readonly typingEnded = "typingEnded";
@@ -1432,7 +1460,8 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1432
1460
  * Fired when a participant has started typing.
1433
1461
  *
1434
1462
  * Parameters:
1435
- * 1. {@link Participant} `participant` - the participant that has started typing
1463
+ * 1. {@link Participant} `participant` - the participant that has started
1464
+ * typing
1436
1465
  * @event
1437
1466
  */
1438
1467
  static readonly typingStarted = "typingStarted";
@@ -1440,20 +1469,95 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1440
1469
  * Fired when the data of the conversation has been updated.
1441
1470
  *
1442
1471
  * Parameters:
1443
- * 1. object `data` - info object provided with the event. It has the following properties:
1444
- * * {@link Conversation} `conversation` - conversation that has received the update
1445
- * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons for update
1472
+ * 1. object `data` - info object provided with the event. It has the
1473
+ * following properties:
1474
+ * * {@link Conversation} `conversation` - conversation that has received
1475
+ * the update
1476
+ * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons
1477
+ * for the update
1446
1478
  * @event
1447
1479
  */
1448
1480
  static readonly updated = "updated";
1449
1481
  /**
1450
- * Fired when the conversation was destroyed or the currently-logged-in user has left private conversation.
1482
+ * Fired when the conversation was destroyed or the currently-logged-in user
1483
+ * has left private conversation.
1451
1484
  *
1452
1485
  * Parameters:
1453
1486
  * 1. {@link Conversation} `conversation` - conversation that has been removed
1454
1487
  * @event
1455
1488
  */
1456
1489
  static readonly removed = "removed";
1490
+ /**
1491
+ * Logger instance.
1492
+ */
1493
+ private static readonly _logger;
1494
+ /**
1495
+ * Unique system identifier of the conversation.
1496
+ */
1497
+ readonly sid: string;
1498
+ /**
1499
+ * Conversation links for REST requests.
1500
+ * @internal
1501
+ */
1502
+ readonly _links: ConversationLinks;
1503
+ /**
1504
+ * Map of participants.
1505
+ * @internal
1506
+ */
1507
+ readonly _participants: Map<string, Participant>;
1508
+ /**
1509
+ * Configuration of the client that the conversation belongs to.
1510
+ */
1511
+ private readonly _configuration;
1512
+ /**
1513
+ * Conversation service objects.
1514
+ */
1515
+ private readonly _services;
1516
+ /**
1517
+ * Internal state of the conversation.
1518
+ */
1519
+ private readonly _internalState;
1520
+ /**
1521
+ * Name of the conversation entity document.
1522
+ */
1523
+ private readonly _entityName;
1524
+ /**
1525
+ * Messages entity.
1526
+ */
1527
+ private readonly _messagesEntity;
1528
+ /**
1529
+ * Sync list containing messages.
1530
+ */
1531
+ private _messagesList?;
1532
+ /**
1533
+ * Participants entity.
1534
+ */
1535
+ private readonly _participantsEntity;
1536
+ /**
1537
+ * Sync map containing participants.
1538
+ */
1539
+ private _participantsMap?;
1540
+ /**
1541
+ * Source of the most recent update.
1542
+ */
1543
+ private _dataSource;
1544
+ /**
1545
+ * Promise for the conversation entity document.
1546
+ */
1547
+ private _entityPromise;
1548
+ /**
1549
+ * Conversation entity document.
1550
+ */
1551
+ private _entity;
1552
+ /**
1553
+ * @param descriptor Conversation descriptor.
1554
+ * @param sid Conversation SID.
1555
+ * @param links Conversation links for REST requests.
1556
+ * @param configuration Client configuration.
1557
+ * @param services Conversation services.
1558
+ * @internal
1559
+ */
1560
+ constructor(descriptor: ConversationDescriptor, sid: string, links: ConversationLinks, configuration: Configuration, services: ConversationServices);
1457
1561
  /**
1458
1562
  * Unique name of the conversation.
1459
1563
  */
@@ -1494,6 +1598,10 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1494
1598
  * User notification level for this conversation.
1495
1599
  */
1496
1600
  get notificationLevel(): NotificationLevel;
1601
+ /**
1602
+ * Conversation bindings. Undocumented feature (for now).
1603
+ * @internal
1604
+ */
1497
1605
  get bindings(): ConversationBindings;
1498
1606
  /**
1499
1607
  * Current conversation limits.
@@ -1504,51 +1612,21 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1504
1612
  */
1505
1613
  get state(): ConversationState | undefined;
1506
1614
  /**
1507
- * Load and subscribe to this conversation and do not subscribe to its participants and messages.
1508
- * This or _subscribeStreams will need to be called before any events on conversation will fire.
1509
- * @internal
1510
- */
1511
- _subscribe(): Promise<void | SyncDocument>;
1512
- /**
1513
- * Load the attributes of this conversation and instantiate its participants and messages.
1514
- * This or _subscribe will need to be called before any events on the conversation will fire.
1515
- * This will need to be called before any events on participants or messages will fire
1516
- * @internal
1517
- */
1518
- _subscribeStreams(): Promise<void>;
1519
- /**
1520
- * Stop listening for and firing events on this conversation.
1521
- * @internal
1522
- */
1523
- _unsubscribe(): Promise<[
1524
- void,
1525
- void
1526
- ]>;
1527
- /**
1528
- * Set conversation status.
1615
+ * Source of the conversation update.
1529
1616
  * @internal
1530
1617
  */
1531
- _setStatus(status: ConversationStatus, source: ConversationsDataSource): void;
1618
+ get _statusSource(): ConversationsDataSource;
1532
1619
  /**
1533
- * Get the source of the conversation update.
1534
- * @internal
1620
+ * Preprocess the update object.
1621
+ * @param update The update object received from Sync.
1622
+ * @param conversationSid The SID of the conversation in question.
1535
1623
  */
1536
- _statusSource(): ConversationsDataSource;
1537
1624
  private static preprocessUpdate;
1538
- /**
1539
- * Update the local conversation object with new values.
1540
- * @internal
1541
- */
1542
- _update(update: any): void;
1543
- /**
1544
- * @internal
1545
- */
1546
- private _onMessageAdded;
1547
- private _setLastReadMessageIndex;
1548
1625
  /**
1549
1626
  * Add a participant to the conversation by its identity.
1550
1627
  * @param identity Identity of the Client to add.
1551
1628
  * @param attributes Attributes to be attached to the participant.
1629
+ * @returns The added participant.
1552
1630
  */
1553
1631
  add(identity: string, attributes?: JSONValue): Promise<ParticipantResponse>;
1554
1632
  /**
@@ -1556,13 +1634,16 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1556
1634
  * @param proxyAddress Proxy (Twilio) address of the participant.
1557
1635
  * @param address User address of the participant.
1558
1636
  * @param attributes Attributes to be attached to the participant.
1559
- * @param bindingOptions Options for adding email participants - name and CC/To level.
1637
+ * @param bindingOptions Options for adding email participants - name and
1638
+ * CC/To level.
1639
+ * @returns The added participant.
1560
1640
  */
1561
1641
  addNonChatParticipant(proxyAddress: string, address: string, attributes?: JSONValue, bindingOptions?: ParticipantBindingOptions): Promise<ParticipantResponse>;
1562
1642
  /**
1563
- * Advance the conversation's last read message index to the current read horizon.
1564
- * Rejects if the user is not a participant of the conversation.
1565
- * Last read message index is updated only if the new index value is higher than the previous.
1643
+ * Advance the conversation's last read message index to the current read
1644
+ * horizon. Rejects if the user is not a participant of the conversation. Last
1645
+ * read message index is updated only if the new index value is higher than
1646
+ * the previous.
1566
1647
  * @param index Message index to advance to.
1567
1648
  * @return Resulting unread messages count in the conversation.
1568
1649
  */
@@ -1577,10 +1658,13 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1577
1658
  getAttributes(): Promise<JSONValue>;
1578
1659
  /**
1579
1660
  * Returns messages from the conversation using the paginator interface.
1580
- * @param pageSize Number of messages to return in a single chunk. Default is 30.
1581
- * @param anchor Index of the newest message to fetch. Default is from the end.
1582
- * @param direction Query direction. By default it queries backwards
1583
- * from newer to older. The `"forward"` value will query in the opposite direction.
1661
+ * @param pageSize Number of messages to return in a single chunk. Default is
1662
+ * 30.
1663
+ * @param anchor Index of the newest message to fetch. Default is from the
1664
+ * end.
1665
+ * @param direction Query direction. By default, it queries backwards
1666
+ * from newer to older. The `"forward"` value will query in the opposite
1667
+ * direction.
1584
1668
  * @return A page of messages.
1585
1669
  */
1586
1670
  getMessages(pageSize?: number, anchor?: number, direction?: "backwards" | "forward"): Promise<Paginator<Message>>;
@@ -1591,12 +1675,13 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1591
1675
  /**
1592
1676
  * Get conversation participants count.
1593
1677
  *
1594
- * This method is semi-realtime. This means that this data will be eventually correct,
1595
- * but will also be possibly incorrect for a few seconds. The Conversations system does not
1596
- * provide real time events for counter values changes.
1678
+ * This method is semi-realtime. This means that this data will be eventually
1679
+ * correct, but will also be possibly incorrect for a few seconds. The
1680
+ * Conversations system does not provide real time events for counter values
1681
+ * changes.
1597
1682
  *
1598
- * This is useful for any UI badges, but it is not recommended to build any core application
1599
- * logic based on these counters being accurate in real time.
1683
+ * This is useful for any UI badges, but it is not recommended to build any
1684
+ * core application logic based on these counters being accurate in real time.
1600
1685
  */
1601
1686
  getParticipantsCount(): Promise<number>;
1602
1687
  /**
@@ -1612,28 +1697,30 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1612
1697
  /**
1613
1698
  * Get the total message count in the conversation.
1614
1699
  *
1615
- * This method is semi-realtime. This means that this data will be eventually correct,
1616
- * but will also be possibly incorrect for a few seconds. The Conversations system does not
1617
- * provide real time events for counter values changes.
1700
+ * This method is semi-realtime. This means that this data will be eventually
1701
+ * correct, but will also be possibly incorrect for a few seconds. The
1702
+ * Conversations system does not provide real time events for counter values
1703
+ * changes.
1618
1704
  *
1619
- * This is useful for any UI badges, but it is not recommended to build any core application
1620
- * logic based on these counters being accurate in real time.
1705
+ * This is useful for any UI badges, but it is not recommended to build any
1706
+ * core application logic based on these counters being accurate in real time.
1621
1707
  */
1622
1708
  getMessagesCount(): Promise<number>;
1623
1709
  /**
1624
- * Get unread messages count for the user if they are a participant of this conversation.
1625
- * Rejects if the user is not a participant of the conversation.
1710
+ * Get unread messages count for the user if they are a participant of this
1711
+ * conversation. Rejects if the user is not a participant of the conversation.
1626
1712
  *
1627
1713
  * Use this method to obtain the number of unread messages together with
1628
1714
  * {@link Conversation.updateLastReadMessageIndex} instead of relying on the
1629
1715
  * message indices which may have gaps. See {@link Message.index} for details.
1630
1716
  *
1631
- * This method is semi-realtime. This means that this data will be eventually correct,
1632
- * but will also be possibly incorrect for a few seconds. The Conversations system does not
1633
- * provide real time events for counter values changes.
1717
+ * This method is semi-realtime. This means that this data will be eventually
1718
+ * correct, but will also be possibly incorrect for a few seconds. The
1719
+ * Conversations system does not provide real time events for counter values
1720
+ * changes.
1634
1721
  *
1635
- * This is useful for any UI badges, but it is not recommended to build any core application
1636
- * logic based on these counters being accurate in real time.
1722
+ * This is useful for any UI badges, but it is not recommended to build any
1723
+ * core application logic based on these counters being accurate in real time.
1637
1724
  */
1638
1725
  getUnreadMessagesCount(): Promise<number | null>;
1639
1726
  /**
@@ -1649,13 +1736,12 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1649
1736
  * argument, it will assume that the string is an identity or SID.
1650
1737
  * @param participant Identity, SID or the participant object to remove.
1651
1738
  */
1652
- /* eslint-disable @typescript-eslint/ban-ts-comment */
1653
- // @ts-ignore TODO: fix validateTypesAsync typing
1654
1739
  removeParticipant(participant: string | Participant): Promise<void>;
1655
1740
  /**
1656
1741
  * Send a message to the conversation.
1657
1742
  * @param message Message body for the text message,
1658
- * `FormData` or {@link SendMediaOptions} for media content. Sending FormData is supported only with the browser engine.
1743
+ * `FormData` or {@link SendMediaOptions} for media content. Sending FormData
1744
+ * is supported only with the browser engine.
1659
1745
  * @param messageAttributes Attributes for the message.
1660
1746
  * @param emailOptions Email options for the message.
1661
1747
  * @return Index of the new message.
@@ -1663,12 +1749,13 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1663
1749
  sendMessage(message: null | string | FormData | SendMediaOptions, messageAttributes?: JSONValue, emailOptions?: SendEmailOptions): Promise<number>;
1664
1750
  /**
1665
1751
  * New interface to prepare for sending a message.
1666
- * Use instead of `sendMessage`.
1752
+ * Use this instead of {@link Message.sendMessage}.
1667
1753
  * @return A MessageBuilder to help set all message sending options.
1668
1754
  */
1669
1755
  prepareMessage(): MessageBuilder;
1670
1756
  /**
1671
- * Set last read message index of the conversation to the index of the last known message.
1757
+ * Set last read message index of the conversation to the index of the last
1758
+ * known message.
1672
1759
  * @return Resulting unread messages count in the conversation.
1673
1760
  */
1674
1761
  setAllMessagesRead(): Promise<number>;
@@ -1683,8 +1770,10 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1683
1770
  */
1684
1771
  setUserNotificationLevel(notificationLevel: NotificationLevel): Promise<void>;
1685
1772
  /**
1686
- * Send a notification to the server indicating that this client is currently typing in this conversation.
1687
- * Typing ended notification is sent after a while automatically, but by calling this method again you ensure that typing ended is not received.
1773
+ * Send a notification to the server indicating that this client is currently
1774
+ * typing in this conversation. Typing ended notification is sent after a
1775
+ * while automatically, but by calling this method again you ensure that
1776
+ * typing ended is not received.
1688
1777
  */
1689
1778
  typing(): Promise<void>;
1690
1779
  /**
@@ -1699,21 +1788,71 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1699
1788
  updateFriendlyName(friendlyName: string): Promise<Conversation>;
1700
1789
  /**
1701
1790
  * Set the last read message index to the current read horizon.
1702
- * @param index Message index to set as last read.
1703
- * If null is provided, then the behavior is identical to {@link Conversation.setAllMessagesUnread}.
1791
+ * @param index Message index to set as last read. If null is provided, then
1792
+ * the behavior is identical to {@link Conversation.setAllMessagesUnread}.
1704
1793
  * @returns Resulting unread messages count in the conversation.
1705
1794
  */
1706
1795
  updateLastReadMessageIndex(index: number | null): Promise<number>;
1707
1796
  /**
1708
1797
  * Update the unique name of the conversation.
1709
- * @param uniqueName New unique name for the conversation. Setting unique name to null removes it.
1798
+ * @param uniqueName New unique name for the conversation. Setting unique name
1799
+ * to null removes it.
1710
1800
  */
1711
1801
  updateUniqueName(uniqueName: string | null): Promise<Conversation>;
1802
+ /**
1803
+ * Load and subscribe to this conversation and do not subscribe to its
1804
+ * participants and messages. This or _subscribeStreams will need to be called
1805
+ * before any events on conversation will fire.
1806
+ * @internal
1807
+ */
1808
+ _subscribe(): Promise<SyncDocument>;
1809
+ /**
1810
+ * Fetch participants and messages of the conversation. This method needs to
1811
+ * be called during conversation initialization to catch broken conversations
1812
+ * (broken conversations are conversations that have essential Sync entities
1813
+ * missing, i.e. the conversation document, the messages list or the
1814
+ * participant map). In case of this conversation being broken, the method
1815
+ * will throw an exception that will be caught and handled gracefully.
1816
+ * @internal
1817
+ */
1818
+ _fetchStreams(): Promise<void>;
1819
+ /**
1820
+ * Load the attributes of this conversation and instantiate its participants
1821
+ * and messages. This or _subscribe will need to be called before any events
1822
+ * on the conversation will fire. This will need to be called before any
1823
+ * events on participants or messages will fire
1824
+ * @internal
1825
+ */
1826
+ _subscribeStreams(): Promise<void>;
1827
+ /**
1828
+ * Stop listening for and firing events on this conversation.
1829
+ * @internal
1830
+ */
1831
+ _unsubscribe(): Promise<[
1832
+ void,
1833
+ void
1834
+ ]>;
1835
+ /**
1836
+ * Set conversation status.
1837
+ * @internal
1838
+ */
1839
+ _setStatus(status: ConversationStatus, source: ConversationsDataSource): void;
1840
+ /**
1841
+ * Update the local conversation object with new values.
1842
+ * @internal
1843
+ */
1844
+ _update(update: any): void;
1845
+ /**
1846
+ * Handle onMessageAdded event.
1847
+ */
1848
+ private _onMessageAdded;
1849
+ /**
1850
+ * Set last read message index.
1851
+ * @param index New index to set.
1852
+ */
1853
+ private _setLastReadMessageIndex;
1712
1854
  }
1713
- type ConversationsDataSource = "sync" | "chat" | "rest";
1714
- /**
1715
- * Push notification type.
1716
- */
1855
+ type ConversationsDataSource = "sync" | "rest";
1717
1856
  type PushNotificationType = "twilio.conversations.new_message" | "twilio.conversations.added_to_conversation" | "twilio.conversations.removed_from_conversation";
1718
1857
  interface PushNotificationDescriptor {
1719
1858
  title: string | null;
@@ -1732,6 +1871,10 @@ interface PushNotificationData {
1732
1871
  * SID of the conversation.
1733
1872
  */
1734
1873
  conversationSid?: string;
1874
+ /**
1875
+ * Title of the conversation.
1876
+ */
1877
+ conversationTitle?: string;
1735
1878
  /**
1736
1879
  * Index of the message in the conversation.
1737
1880
  */
@@ -1740,6 +1883,14 @@ interface PushNotificationData {
1740
1883
  * SID of the message in the conversation.
1741
1884
  */
1742
1885
  messageSid?: string;
1886
+ /**
1887
+ * Media of the notification
1888
+ */
1889
+ media?: Media;
1890
+ /**
1891
+ * Count of the attached media of the message.
1892
+ */
1893
+ mediaCount?: number;
1743
1894
  }
1744
1895
  /**
1745
1896
  * Push notification for a Conversations client.
@@ -1778,6 +1929,9 @@ declare class PushNotification {
1778
1929
  */
1779
1930
  constructor(data: PushNotificationDescriptor);
1780
1931
  }
1932
+ /**
1933
+ * Client events.
1934
+ */
1781
1935
  type ClientEvents = {
1782
1936
  conversationAdded: (conversation: Conversation) => void;
1783
1937
  conversationJoined: (conversation: Conversation) => void;
@@ -1799,7 +1953,7 @@ type ClientEvents = {
1799
1953
  message: Message;
1800
1954
  updateReasons: MessageUpdateReason[];
1801
1955
  }) => void;
1802
- tokenAboutToExpire: (ttl: number) => void;
1956
+ tokenAboutToExpire: () => void;
1803
1957
  tokenExpired: () => void;
1804
1958
  typingEnded: (participant: Participant) => void;
1805
1959
  typingStarted: (participant: Participant) => void;
@@ -1811,21 +1965,22 @@ type ClientEvents = {
1811
1965
  updateReasons: UserUpdateReason[];
1812
1966
  }) => void;
1813
1967
  stateChanged: (state: State) => void;
1814
- connectionStateChanged: (state: TwilsockConnectionState) => void;
1815
- connectionError: (data: {
1816
- terminal: boolean;
1817
- message: string;
1818
- httpStatusCode?: number;
1819
- errorCode?: number;
1968
+ initialized: (props: Record<string, unknown>) => void;
1969
+ initFailed: ({ error }: {
1970
+ error?: ConnectionError;
1820
1971
  }) => void;
1972
+ connectionStateChanged: (state: TwilsockConnectionState) => void;
1973
+ connectionError: (data: ConnectionError) => void;
1821
1974
  };
1822
1975
  /**
1823
1976
  * Connection state of the client. Possible values are as follows:
1824
1977
  * * `'connecting'` - client is offline and connection attempt is in process
1825
1978
  * * `'connected'` - client is online and ready
1826
1979
  * * `'disconnecting'` - client is going offline as disconnection is in process
1827
- * * `'disconnected'` - client is offline and no connection attempt is in process
1828
- * * `'denied'` - client connection is denied because of invalid JWT access token. User must refresh token in order to proceed
1980
+ * * `'disconnected'` - client is offline and no connection attempt is in
1981
+ * process
1982
+ * * `'denied'` - client connection is denied because of invalid JWT access
1983
+ * token. User must refresh token in order to proceed
1829
1984
  */
1830
1985
  type ConnectionState = TwilsockConnectionState;
1831
1986
  /**
@@ -1840,6 +1995,9 @@ type State = "failed" | "initialized";
1840
1995
  * * `'apn'`
1841
1996
  */
1842
1997
  type NotificationsChannelType = ChannelType;
1998
+ /**
1999
+ * Level of logging.
2000
+ */
1843
2001
  type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "silent";
1844
2002
  /**
1845
2003
  * Conversations client options.
@@ -1872,6 +2030,10 @@ interface ClientOptions {
1872
2030
  typingUri?: string;
1873
2031
  apiUri?: string;
1874
2032
  }
2033
+ type ConnectionError = {
2034
+ terminal: boolean;
2035
+ message: string;
2036
+ };
1875
2037
  /**
1876
2038
  * Options for {@link Client.createConversation}.
1877
2039
  */
@@ -1894,43 +2056,9 @@ interface CreateConversationOptions {
1894
2056
  */
1895
2057
  declare class Client extends ReplayEventEmitter<ClientEvents> {
1896
2058
  /**
1897
- * Client connection state.
1898
- */
1899
- connectionState: ConnectionState;
1900
- private conversationsPromise;
1901
- private _ensureReady;
1902
- private _resolveEnsureReady;
1903
- private _rejectEnsureReady;
1904
- private fpaToken;
1905
- private configuration;
1906
- private conversations;
1907
- private readonly options;
1908
- private services;
1909
- private readonly _myself;
1910
- /**
1911
- * Current version of the Conversations client.
1912
- */
1913
- static readonly version: string;
1914
- /**
1915
- * Current version of the Conversations client.
1916
- */
1917
- readonly version: string;
1918
- private static readonly supportedPushChannels;
1919
- private static readonly supportedPushDataFields;
1920
- /**
1921
- * Returned Conversations instance is not yet fully initialized. Calling any operations will block until it is.
1922
- * Use connection events to monitor when client becomes fully available (connectionStateChanged with state
1923
- * 'connected') or not available (connectionStateChange with state 'denied', event tokenExpired, event connectionError).
1924
- *
1925
- * @param fpaToken Access token
1926
- * @param options Options to customize the Client
1927
- * @returns A not yet fully-initialized client.
1928
- */
1929
- constructor(fpaToken: string, options?: ClientOptions | null);
1930
- static populateInitRegistrations(reg: InitRegistration): void;
1931
- /**
1932
- * Fired when a conversation becomes visible to the client. The event is also triggered when the client creates a new conversation.
1933
- * Fired for all conversations client has joined.
2059
+ * Fired when a conversation becomes visible to the client. The event is also
2060
+ * triggered when the client creates a new conversation.
2061
+ * Fired for all conversations that the client has joined.
1934
2062
  *
1935
2063
  * Parameters:
1936
2064
  * 1. {@link Conversation} `conversation` - the conversation in question
@@ -1962,14 +2090,17 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
1962
2090
  */
1963
2091
  static readonly conversationRemoved = "conversationRemoved";
1964
2092
  /**
1965
- * Fired when the attributes or the metadata of a conversation have been updated.
1966
- * During conversation's creation and initialization, this event might be fired multiple times
1967
- * for same joined or created conversation as new data is arriving from different sources.
2093
+ * Fired when the attributes or the metadata of a conversation have been
2094
+ * updated. During conversation's creation and initialization, this event
2095
+ * might be fired multiple times for same joined or created conversation as
2096
+ * new data is arriving from different sources.
1968
2097
  *
1969
2098
  * Parameters:
1970
- * 1. object `data` - info object provided with the event. It has the following properties:
2099
+ * 1. object `data` - info object provided with the event. It has the
2100
+ * following properties:
1971
2101
  * * {@link Conversation} `conversation` - the conversation in question
1972
- * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons for the update
2102
+ * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons
2103
+ * for the update
1973
2104
  * @event
1974
2105
  */
1975
2106
  static readonly conversationUpdated = "conversationUpdated";
@@ -1993,9 +2124,11 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
1993
2124
  * Fired when a participant's fields have been updated.
1994
2125
  *
1995
2126
  * Parameters:
1996
- * 1. object `data` - info object provided with the event. It has the following properties:
2127
+ * 1. object `data` - info object provided with the event. It has the
2128
+ * following properties:
1997
2129
  * * {@link Participant} `participant` - the participant in question
1998
- * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons for the update
2130
+ * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons
2131
+ * for the update
1999
2132
  * @event
2000
2133
  */
2001
2134
  static readonly participantUpdated = "participantUpdated";
@@ -2019,16 +2152,16 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2019
2152
  * Fired when the fields of an existing message are updated with new values.
2020
2153
  *
2021
2154
  * Parameters:
2022
- * 1. object `data` - info object provided with the event. It has the following properties:
2155
+ * 1. object `data` - info object provided with the event. It has the
2156
+ * following properties:
2023
2157
  * * {@link Message} `message` - the message in question
2024
- * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for the update
2158
+ * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for
2159
+ * the update
2025
2160
  * @event
2026
2161
  */
2027
2162
  static readonly messageUpdated = "messageUpdated";
2028
2163
  /**
2029
2164
  * Fired when the token is about to expire and needs to be updated.
2030
- * * Parameters:
2031
- * 1. number `message` - token's time to live
2032
2165
  * @event
2033
2166
  */
2034
2167
  static readonly tokenAboutToExpire = "tokenAboutToExpire";
@@ -2054,10 +2187,12 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2054
2187
  */
2055
2188
  static readonly typingStarted = "typingStarted";
2056
2189
  /**
2057
- * Fired when the client has received (and parsed) a push notification via one of the push channels (apn or fcm).
2190
+ * Fired when the client has received (and parsed) a push notification via one
2191
+ * of the push channels (apn or fcm).
2058
2192
  *
2059
2193
  * Parameters:
2060
- * 1. {@link PushNotification} `pushNotification` - the push notification in question
2194
+ * 1. {@link PushNotification} `pushNotification` - the push notification in
2195
+ * question
2061
2196
  * @event
2062
2197
  */
2063
2198
  static readonly pushNotification = "pushNotification";
@@ -2078,16 +2213,20 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2078
2213
  */
2079
2214
  static readonly userUnsubscribed = "userUnsubscribed";
2080
2215
  /**
2081
- * Fired when the properties or the reachability status of a user have been updated.
2216
+ * Fired when the properties or the reachability status of a user have been
2217
+ * updated.
2082
2218
  *
2083
2219
  * Parameters:
2084
- * 1. object `data` - info object provided with the event. It has the following properties:
2220
+ * 1. object `data` - info object provided with the event. It has the
2221
+ * following properties:
2085
2222
  * * {@link User} `user` - the user in question
2086
- * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update
2223
+ * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the
2224
+ * update
2087
2225
  * @event
2088
2226
  */
2089
2227
  static readonly userUpdated = "userUpdated";
2090
2228
  /**
2229
+ * @deprecated Use initialized or initFailed events instead
2091
2230
  * Fired when the state of the client has been changed.
2092
2231
  *
2093
2232
  * Parameters:
@@ -2095,10 +2234,28 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2095
2234
  * @event
2096
2235
  */
2097
2236
  static readonly stateChanged = "stateChanged";
2237
+ /**
2238
+ * Fired when the client has completed initialization successfully.
2239
+ *
2240
+ * Parameters:
2241
+ * 1. object `data` - Optional info object provided with the event
2242
+ * @event
2243
+ */
2244
+ static readonly initialized = "initialized";
2245
+ /**
2246
+ * Fired when the client initialization failed.
2247
+ *
2248
+ * Parameters:
2249
+ * 1. object `data` - info object provided with the event. It has the
2250
+ * following property:
2251
+ * * Error? `error` - the initialization error if present
2252
+ * @event
2253
+ */
2254
+ static readonly initFailed = "initFailed";
2098
2255
  /**
2099
2256
  * Fired when the connection state of the client has been changed.
2100
2257
  *
2101
- * Paremeters:
2258
+ * Parameters:
2102
2259
  * 1. {@link ConnectionState} `state` - the new connection state
2103
2260
  * @event
2104
2261
  */
@@ -2107,7 +2264,8 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2107
2264
  * Fired when the connection is interrupted for an unexpected reason.
2108
2265
  *
2109
2266
  * Parameters:
2110
- * 1. object `data` - info object provided with the event. It has the following properties:
2267
+ * 1. object `data` - info object provided with the event. It has the
2268
+ * following properties:
2111
2269
  * * boolean `terminal` - Twilsock will stop connection attempts if true
2112
2270
  * * string `message` - the error message of the root cause
2113
2271
  * * number? `httpStatusCode` - http status code if available
@@ -2115,6 +2273,99 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2115
2273
  * @event
2116
2274
  */
2117
2275
  static readonly connectionError = "connectionError";
2276
+ /**
2277
+ * Current version of the Conversations client.
2278
+ */
2279
+ static readonly version: string;
2280
+ /**
2281
+ * Logger instance.
2282
+ */
2283
+ private static readonly _logger;
2284
+ /**
2285
+ * Supported push notification channels.
2286
+ */
2287
+ private static readonly _supportedPushChannels;
2288
+ /**
2289
+ * Supported push data fields.
2290
+ */
2291
+ private static readonly _supportedPushDataFields;
2292
+ /**
2293
+ * Current version of the Conversations client.
2294
+ */
2295
+ readonly version: string;
2296
+ /**
2297
+ * Client connection state.
2298
+ */
2299
+ connectionState: ConnectionState;
2300
+ /**
2301
+ * Promise that resolves on successful initialization.
2302
+ */
2303
+ private readonly _ensureReady;
2304
+ /**
2305
+ * Options passed to the client.
2306
+ */
2307
+ private readonly _options;
2308
+ /**
2309
+ * Client service objects.
2310
+ */
2311
+ private readonly _services;
2312
+ /**
2313
+ * The user of the client.
2314
+ */
2315
+ private readonly _myself;
2316
+ /**
2317
+ * Resolves the {@link Client._ensureReady} promise.
2318
+ */
2319
+ private _resolveEnsureReady;
2320
+ /**
2321
+ * Rejects the {@link Client._ensureReady} promise.
2322
+ */
2323
+ private _rejectEnsureReady;
2324
+ /**
2325
+ * The current token of the client.
2326
+ */
2327
+ private _fpaToken;
2328
+ /**
2329
+ * The constructed configuration object.
2330
+ */
2331
+ private _configuration;
2332
+ /**
2333
+ * The Conversations entity.
2334
+ */
2335
+ private _conversationsEntity;
2336
+ /**
2337
+ * Promise that resolves when initial conversations are fetched.
2338
+ */
2339
+ private _conversationsPromise;
2340
+ /**
2341
+ * Returned Conversations instance is not yet fully initialized. Calling any
2342
+ * operations will block until it is. Use connection events to monitor when
2343
+ * client becomes fully available (connectionStateChanged with state
2344
+ * 'connected') or not available (connectionStateChange with state 'denied',
2345
+ * event tokenExpired, event connectionError).
2346
+ *
2347
+ * @param fpaToken Access token
2348
+ * @param options Options to customize the Client
2349
+ * @returns A not yet fully-initialized client.
2350
+ */
2351
+ constructor(fpaToken: string, options?: ClientOptions | null);
2352
+ /**
2353
+ * Information of the logged-in user. Before client initialization, returns an
2354
+ * uninitialized user. Will trigger a {@link Client.userUpdated} event after
2355
+ * initialization.
2356
+ */
2357
+ get user(): User;
2358
+ /**
2359
+ * Client reachability state. Throws an error if accessed before the client
2360
+ * initialization was completed.
2361
+ */
2362
+ get reachabilityEnabled(): boolean;
2363
+ /**
2364
+ * @deprecated
2365
+ * Current token.
2366
+ * @internal
2367
+ */
2368
+ get token(): string;
2118
2369
  /**
2119
2370
  * @deprecated Call constructor directly.
2120
2371
  *
@@ -2136,20 +2387,21 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2136
2387
  */
2137
2388
  static create(token: string, options?: ClientOptions | null): Promise<Client>;
2138
2389
  /**
2139
- * Information of the logged-in user. Before client initialization, returns an
2140
- * uninitialized user. Will trigger a {@link Client.userUpdated} event after
2141
- * initialization.
2390
+ * Static method for push notification payload parsing. Returns parsed push as
2391
+ * a {@link PushNotification} object.
2392
+ * @param notificationPayload Push notification payload.
2142
2393
  */
2143
- get user(): User;
2394
+ static parsePushNotification(notificationPayload: any): PushNotification;
2144
2395
  /**
2145
- * Client reachability state. Throws if accessed before the client
2146
- * initialization was completed.
2396
+ * Static method for parsing push notification chat data.
2397
+ * @param data Data to parse
2147
2398
  */
2148
- get reachabilityEnabled(): boolean;
2149
- get token(): string;
2150
- private _subscribeToPushNotifications;
2151
- private _unsubscribeFromPushNotifications;
2152
- private _initialize;
2399
+ private static _parsePushNotificationChatData;
2400
+ /**
2401
+ * Populate the client with init registrations.
2402
+ * @param reg The init registration to populate.
2403
+ */
2404
+ static populateInitRegistrations(reg: InitRegistration): void;
2153
2405
  /**
2154
2406
  * Gracefully shut down the client.
2155
2407
  */
@@ -2164,6 +2416,12 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2164
2416
  * @param conversationSid Conversation sid
2165
2417
  */
2166
2418
  getConversationBySid(conversationSid: string): Promise<Conversation>;
2419
+ /**
2420
+ * Peek a conversation by its SID.
2421
+ * @param conversationSid Conversation sid
2422
+ * @internal
2423
+ */
2424
+ private peekConversationBySid;
2167
2425
  /**
2168
2426
  * Get a known conversation by its unique identifier name.
2169
2427
  * @param uniqueName The unique identifier name of the conversation.
@@ -2182,7 +2440,8 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2182
2440
  /**
2183
2441
  * Register for push notifications.
2184
2442
  * @param channelType Channel type.
2185
- * @param registrationId Push notification ID provided by the FCM/APNS service on the platform.
2443
+ * @param registrationId Push notification ID provided by the FCM/APNS service
2444
+ * on the platform.
2186
2445
  */
2187
2446
  setPushRegistrationId(channelType: NotificationsChannelType, registrationId: string): Promise<void>;
2188
2447
  /**
@@ -2195,27 +2454,29 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2195
2454
  * Clear existing registrations directly using provided device token.
2196
2455
  * This is useful to ensure stopped subscriptions without resubscribing.
2197
2456
  *
2198
- * This function goes completely beside the state machine and removes all registrations.
2199
- * Use with caution: if it races with current state machine operations, madness will ensue.
2457
+ * This function goes completely beside the state machine and removes all
2458
+ * registrations.
2459
+ * Use with caution: if it races with current state machine operations,
2460
+ * madness will ensue.
2200
2461
  *
2201
2462
  * @param channelType Channel type.
2202
- * @param registrationId Push notification ID provided by the FCM/APNS service on the platform.
2463
+ * @param registrationId Push notification ID provided by the FCM/APNS service
2464
+ * on the platform.
2203
2465
  */
2204
2466
  removePushRegistrations(channelType: ChannelType, registrationId: string): Promise<void>;
2205
- private static parsePushNotificationChatData;
2206
2467
  /**
2207
- * Static method for push notification payload parsing. Returns parsed push as a {@link PushNotification} object.
2208
- * @param notificationPayload Push notification payload.
2468
+ * Current version of the Conversations client.
2209
2469
  */
2210
- static parsePushNotification(notificationPayload: any): PushNotification;
2211
2470
  parsePushNotification: typeof Client.parsePushNotification;
2212
2471
  /**
2213
- * Handle push notification payload parsing and emit the {@link Client.pushNotification} event on this {@link Client} instance.
2472
+ * Handle push notification payload parsing and emit the
2473
+ * {@link Client.pushNotification} event on this {@link Client} instance.
2214
2474
  * @param notificationPayload Push notification payload
2215
2475
  */
2216
2476
  handlePushNotification(notificationPayload: any): Promise<void>;
2217
2477
  /**
2218
- * Gets a user with the given identity. If it's in the subscribed list, then return the user object from it;
2478
+ * Gets a user with the given identity. If it's in the subscribed list, then
2479
+ * return the user object from it;
2219
2480
  * if not, then subscribe and add user to the subscribed list.
2220
2481
  * @param identity Identity of the user.
2221
2482
  * @returns A fully initialized user.
@@ -2225,6 +2486,32 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2225
2486
  * Get a list of subscribed user objects.
2226
2487
  */
2227
2488
  getSubscribedUsers(): Promise<Array<User>>;
2489
+ /**
2490
+ * Get content URLs for all media attachments in the given set of media sids
2491
+ * using a single operation.
2492
+ * @param mediaSids Set of media sids to query for the content URL.
2493
+ */
2494
+ getTemporaryContentUrlsForMediaSids(mediaSids: string[]): CancellablePromise<Map<string, string>>;
2495
+ /**
2496
+ * Get content URLs for all media attachments in the given set using a single
2497
+ * operation.
2498
+ * @param contentSet Set of media attachments to query content URLs.
2499
+ */
2500
+ getTemporaryContentUrlsForMedia(contentSet: Media[]): CancellablePromise<Map<string, string>>;
2501
+ /**
2502
+ * Initialize the client.
2503
+ */
2504
+ private _initialize;
2505
+ /**
2506
+ * Subscribe to push notifications.
2507
+ * @param channelType The channel type to subscribe to.
2508
+ */
2509
+ private _subscribeToPushNotifications;
2510
+ /**
2511
+ * Unsubscribe from push notifications.
2512
+ * @param channelType The channel type to unsubscribe from.
2513
+ */
2514
+ private _unsubscribeFromPushNotifications;
2228
2515
  }
2229
2516
  declare class NotificationTypes {
2230
2517
  static readonly TYPING_INDICATOR = "twilio.ipmsg.typing_indicator";
@@ -2234,4 +2521,4 @@ declare class NotificationTypes {
2234
2521
  static readonly REMOVED_FROM_CONVERSATION = "twilio.conversations.removed_from_conversation";
2235
2522
  static readonly CONSUMPTION_UPDATE = "twilio.channel.consumption_update";
2236
2523
  }
2237
- export { Conversation, ConversationBindings, ConversationEmailBinding, ConversationUpdateReason, ConversationStatus, NotificationLevel, ConversationState, ConversationUpdatedEventArgs, SendMediaOptions, SendEmailOptions, LastMessage, Participant, ParticipantUpdateReason, ParticipantType, ParticipantUpdatedEventArgs, ParticipantBindings, ParticipantEmailBinding, ParticipantEmailLevel, Message, MessageUpdateReason, MessageType, MessageUpdatedEventArgs, Media, MediaCategory$0 as MediaCategory, AggregatedDeliveryReceipt, DeliveryAmount, DetailedDeliveryReceipt, DeliveryStatus, RestPaginator, MessageBuilder, UnsentMessage, Paginator, ParticipantBindingOptions, User, UserUpdateReason, UserUpdatedEventArgs, PushNotification, PushNotificationType, PushNotificationDescriptor, PushNotificationData, NotificationTypes, Client, State, ConnectionState, NotificationsChannelType, ClientOptions, CreateConversationOptions, ConversationLimits, JSONValue, JSONObject, JSONArray };
2524
+ export { Conversation, ConversationBindings, ConversationEmailBinding, ConversationUpdateReason, ConversationStatus, NotificationLevel, ConversationState, ConversationUpdatedEventArgs, SendMediaOptions, SendEmailOptions, LastMessage, Participant, ParticipantUpdateReason, ParticipantType, ParticipantUpdatedEventArgs, ParticipantBindings, ParticipantEmailBinding, ParticipantEmailLevel, Message, MessageUpdateReason, MessageType, MessageUpdatedEventArgs, Media, MediaCategory$0 as MediaCategory, AggregatedDeliveryReceipt, DeliveryAmount, DetailedDeliveryReceipt, DeliveryStatus, RestPaginator, MessageBuilder, UnsentMessage, Paginator, ParticipantBindingOptions, User, UserUpdateReason, UserUpdatedEventArgs, PushNotification, PushNotificationType, PushNotificationDescriptor, PushNotificationData, NotificationTypes, Client, State, ConnectionState, NotificationsChannelType, ClientOptions, CreateConversationOptions, ConversationLimits, JSONValue, JSONObject, JSONArray, CancellablePromise };