@twilio/conversations 2.0.0-rc.1 → 2.0.1-canary.1

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 (90) hide show
  1. package/README.md +25 -28
  2. package/dist/browser.js +3125 -3460
  3. package/dist/browser.js.map +1 -1
  4. package/dist/docs/assets/js/search.js +1 -1
  5. package/dist/docs/classes/AggregatedDeliveryReceipt.html +22 -6
  6. package/dist/docs/classes/Client.html +78 -33
  7. package/dist/docs/classes/Conversation.html +33 -17
  8. package/dist/docs/classes/DetailedDeliveryReceipt.html +22 -6
  9. package/dist/docs/classes/Media.html +23 -7
  10. package/dist/docs/classes/Message.html +23 -7
  11. package/dist/docs/classes/MessageBuilder.html +3280 -0
  12. package/dist/docs/classes/Participant.html +23 -7
  13. package/dist/docs/classes/PushNotification.html +24 -8
  14. package/dist/docs/classes/RestPaginator.html +28 -9
  15. package/dist/docs/classes/UnsentMessage.html +3144 -0
  16. package/dist/docs/classes/User.html +25 -9
  17. package/dist/docs/index.html +89 -47
  18. package/dist/docs/interfaces/ClientOptions.html +22 -6
  19. package/dist/docs/interfaces/ConversationState.html +22 -6
  20. package/dist/docs/interfaces/CreateConversationOptions.html +22 -6
  21. package/dist/docs/interfaces/LastMessage.html +22 -6
  22. package/dist/docs/interfaces/Paginator.html +3243 -0
  23. package/dist/docs/interfaces/PushNotificationData.html +3168 -0
  24. package/dist/docs/interfaces/SendEmailOptions.html +22 -6
  25. package/dist/docs/interfaces/SendMediaOptions.html +24 -7
  26. package/dist/docs/modules.html +88 -46
  27. package/dist/lib/aggregated-delivery-receipt.js +227 -0
  28. package/dist/lib/aggregated-delivery-receipt.js.map +1 -0
  29. package/dist/lib/client.js +872 -0
  30. package/dist/lib/client.js.map +1 -0
  31. package/dist/lib/command-executor.js +203 -0
  32. package/dist/lib/command-executor.js.map +1 -0
  33. package/dist/lib/configuration.js +196 -0
  34. package/dist/lib/configuration.js.map +1 -0
  35. package/dist/lib/conversation.js +973 -0
  36. package/dist/lib/conversation.js.map +1 -0
  37. package/dist/lib/data/conversations.js +443 -0
  38. package/dist/lib/data/conversations.js.map +1 -0
  39. package/dist/lib/data/messages.js +341 -0
  40. package/dist/lib/data/messages.js.map +1 -0
  41. package/dist/lib/data/participants.js +313 -0
  42. package/dist/lib/data/participants.js.map +1 -0
  43. package/dist/lib/data/users.js +228 -0
  44. package/dist/lib/data/users.js.map +1 -0
  45. package/dist/lib/detailed-delivery-receipt.js +154 -0
  46. package/dist/lib/detailed-delivery-receipt.js.map +1 -0
  47. package/dist/lib/index.js +167 -0
  48. package/dist/lib/index.js.map +1 -0
  49. package/dist/lib/interfaces/notification-types.js +143 -0
  50. package/dist/lib/interfaces/notification-types.js.map +1 -0
  51. package/dist/lib/logger.js +190 -0
  52. package/dist/lib/logger.js.map +1 -0
  53. package/dist/lib/media.js +213 -0
  54. package/dist/lib/media.js.map +1 -0
  55. package/dist/lib/message-builder.js +209 -0
  56. package/dist/lib/message-builder.js.map +1 -0
  57. package/dist/lib/message.js +450 -0
  58. package/dist/lib/message.js.map +1 -0
  59. package/dist/lib/node_modules/tslib/tslib.es6.js +161 -0
  60. package/dist/lib/node_modules/tslib/tslib.es6.js.map +1 -0
  61. package/dist/lib/packages/conversations/package.json.js +136 -0
  62. package/dist/lib/packages/conversations/package.json.js.map +1 -0
  63. package/dist/lib/participant.js +346 -0
  64. package/dist/lib/participant.js.map +1 -0
  65. package/dist/lib/push-notification.js +152 -0
  66. package/dist/lib/push-notification.js.map +1 -0
  67. package/dist/lib/rest-paginator.js +175 -0
  68. package/dist/lib/rest-paginator.js.map +1 -0
  69. package/dist/lib/services/network.js +205 -0
  70. package/dist/lib/services/network.js.map +1 -0
  71. package/dist/lib/services/typing-indicator.js +235 -0
  72. package/dist/lib/services/typing-indicator.js.map +1 -0
  73. package/dist/lib/unsent-message.js +159 -0
  74. package/dist/lib/unsent-message.js.map +1 -0
  75. package/dist/lib/user.js +392 -0
  76. package/dist/lib/user.js.map +1 -0
  77. package/dist/lib/util/deferred.js +154 -0
  78. package/dist/lib/util/deferred.js.map +1 -0
  79. package/dist/lib/util/index.js +206 -0
  80. package/dist/lib/util/index.js.map +1 -0
  81. package/dist/lib.d.ts +250 -59
  82. package/dist/lib.js +3055 -2919
  83. package/dist/lib.js.map +1 -1
  84. package/dist/twilio-conversations.js +25175 -23918
  85. package/dist/twilio-conversations.min.js +14 -2
  86. package/package.json +16 -14
  87. package/CHANGELOG.md +0 -168
  88. package/dist/post-install.js +0 -29
  89. package/dist/react-native.js +0 -4412
  90. package/dist/react-native.js.map +0 -1
package/dist/lib.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { EventEmitter } from "events";
2
1
  import { SyncClient } from "twilio-sync";
3
2
  import { Transport, TwilsockClient, InitRegistration } from "twilsock";
4
3
  import { ConnectionState as TwilsockConnectionState } from "twilsock";
4
+ import { ReplayEventEmitter } from "@twilio/replay-event-emitter";
5
5
  import { ChannelType, Notifications } from "@twilio/notifications";
6
6
  import { Notifications as NotificationClient } from "@twilio/notifications";
7
7
  import { McsClient, MediaCategory, McsMedia } from "@twilio/mcs-client";
8
+ import { MediaCategory as McsMediaCategory } from "@twilio/mcs-client";
8
9
  interface ConfigurationResponse {
9
10
  options: {
10
11
  consumption_report_interval: string;
@@ -104,42 +105,53 @@ declare class CommandExecutor {
104
105
  fetchResource<REQ = void, RESP = void>(url: string, requestBody?: REQ): Promise<RESP>;
105
106
  mutateResource<REQ = void, RESP = void>(method: "post" | "delete", url: string, requestBody?: REQ): Promise<RESP>;
106
107
  }
108
+ type UserEvents = {
109
+ updated: (data: {
110
+ user: User;
111
+ updateReasons: UserUpdateReason[];
112
+ }) => void;
113
+ userSubscribed: (user: User) => void;
114
+ userUnsubscribed: (user: User) => void;
115
+ };
107
116
  interface UserServices {
108
117
  syncClient: SyncClient;
109
118
  commandExecutor: CommandExecutor;
110
119
  }
111
- interface UserLinks {
112
- self: string;
113
- }
114
120
  /**
115
121
  * The reason for the `updated` event being emitted by a user.
116
122
  */
117
123
  type UserUpdateReason = "friendlyName" | "attributes" | "reachabilityOnline" | "reachabilityNotifiable";
124
+ interface UserUpdatedEventArgs {
125
+ user: User;
126
+ updateReasons: UserUpdateReason[];
127
+ }
118
128
  /**
119
129
  * Extended user information.
120
130
  * Note that `isOnline` and `isNotifiable` properties are eligible
121
131
  * for use only if the reachability function is enabled.
122
132
  * You may check if it is enabled by reading the value of {@link Client.reachabilityEnabled}.
123
133
  */
124
- declare class User extends EventEmitter {
125
- private readonly links;
126
- private readonly configuration;
134
+ declare class User extends ReplayEventEmitter<UserEvents> {
135
+ private links;
136
+ private configuration;
127
137
  private readonly services;
128
138
  private entity;
129
139
  private state;
130
140
  private promiseToFetch;
131
141
  private subscribed;
142
+ private _initializationPromise;
143
+ private _resolveInitializationPromise;
132
144
  /**
133
145
  * @internal
134
146
  */
135
- constructor(identity: string, entityName: string, links: UserLinks, configuration: Configuration, services: UserServices);
147
+ constructor(identity: string, entityName: string, configuration: Configuration | null, services: UserServices);
136
148
  /**
137
149
  * Fired when the properties or the reachability status of the message has been updated.
138
150
  *
139
151
  * Parameters:
140
152
  * 1. object `data` - info object provided with the event. It has the following properties:
141
- * * {@link User} user - the user in question
142
- * * {@link UserUpdateReason}[] updateReasons - array of reasons for the update
153
+ * * {@link User} `user` - the user in question
154
+ * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update
143
155
  * @event
144
156
  */
145
157
  readonly updated = "updated";
@@ -186,7 +198,7 @@ declare class User extends EventEmitter {
186
198
  */
187
199
  get isSubscribed(): boolean;
188
200
  // Handles service updates
189
- _update(key: string, value: any): void;
201
+ _update(key: string, value: any): Promise<void>;
190
202
  // Fetch reachability info
191
203
  private _updateReachabilityInfo;
192
204
  // Fetch user
@@ -207,6 +219,7 @@ declare class User extends EventEmitter {
207
219
  * @return A promise of completion.
208
220
  */
209
221
  unsubscribe(): Promise<void>;
222
+ _resolveInitialization(configuration: Configuration, identity: string, entityName: string, emitUpdated: boolean): void;
210
223
  }
211
224
  declare class Network {
212
225
  private readonly configuration;
@@ -221,22 +234,29 @@ declare class Network {
221
234
  private executeWithRetry;
222
235
  get(url: string): Promise<any>;
223
236
  }
237
+ type UsersEvents = {
238
+ userUpdated: (data: {
239
+ user: User;
240
+ updateReasons: UserUpdateReason[];
241
+ }) => void;
242
+ userSubscribed: (user: User) => void;
243
+ userUnsubscribed: (user: User) => void;
244
+ };
224
245
  interface UsersServices {
225
246
  network: Network;
226
247
  syncClient: SyncClient;
227
248
  commandExecutor: CommandExecutor;
228
249
  }
229
250
  /**
230
- * @classdesc Container for known users
231
- * @fires Users#userUpdated
251
+ * Container for known users
232
252
  */
233
- declare class Users extends EventEmitter {
253
+ declare class Users extends ReplayEventEmitter<UsersEvents> {
234
254
  private readonly configuration;
235
255
  private readonly services;
236
256
  private subscribedUsers;
237
257
  private fifoStack;
238
258
  readonly myself: User;
239
- constructor(configuration: Configuration, services: UsersServices);
259
+ constructor(myself: User, configuration: Configuration, services: UsersServices);
240
260
  private handleUnsubscribeUser;
241
261
  private handleSubscribeUser;
242
262
  /**
@@ -254,6 +274,14 @@ declare class Users extends EventEmitter {
254
274
  */
255
275
  private getSyncUniqueName;
256
276
  }
277
+ type ParticipantEvents = {
278
+ typingEnded: (participant: Participant) => void;
279
+ typingStarted: (participant: Participant) => void;
280
+ updated: (data: {
281
+ participant: Participant;
282
+ updateReasons: ParticipantUpdateReason[];
283
+ }) => void;
284
+ };
257
285
  interface ParticipantDescriptor {
258
286
  attributes?: Object;
259
287
  dateCreated: any;
@@ -277,13 +305,17 @@ interface ParticipantLinks {
277
305
  */
278
306
  type ParticipantUpdateReason = "attributes" | "dateCreated" | "dateUpdated" | "roleSid" | "lastReadMessageIndex" | "lastReadTimestamp";
279
307
  /**
280
- * Push notification type of a participant.
308
+ * Type of a participant.
281
309
  */
282
310
  type ParticipantType = "chat" | "sms" | "whatsapp";
311
+ interface ParticipantUpdatedEventArgs {
312
+ participant: Participant;
313
+ updateReasons: ParticipantUpdateReason[];
314
+ }
283
315
  /**
284
316
  * A participant represents a remote client in a conversation.
285
317
  */
286
- declare class Participant extends EventEmitter {
318
+ declare class Participant extends ReplayEventEmitter<ParticipantEvents> {
287
319
  private state;
288
320
  private readonly links;
289
321
  private readonly services;
@@ -390,9 +422,16 @@ declare class Participant extends EventEmitter {
390
422
  */
391
423
  updateAttributes(attributes: any): Promise<Participant>;
392
424
  }
425
+ /**
426
+ * Category of media. Possible values are as follows:
427
+ * * `'media'`
428
+ * * `'body'`
429
+ * * `'history'`
430
+ */
431
+ type MediaCategory$0 = McsMediaCategory;
393
432
  interface MediaState {
394
433
  sid: string;
395
- category: MediaCategory;
434
+ category: MediaCategory$0;
396
435
  filename?: string;
397
436
  contentType: string;
398
437
  size: number;
@@ -428,9 +467,9 @@ declare class Media {
428
467
  */
429
468
  get size(): number;
430
469
  /**
431
- * Media category, can be one of the {MediaCategory} values.
470
+ * Media category, can be one of the {@link MediaCategory} values.
432
471
  */
433
- get category(): MediaCategory;
472
+ get category(): MediaCategory$0;
434
473
  /**
435
474
  * Returns the direct content URL for the media.
436
475
  *
@@ -593,6 +632,12 @@ declare class DetailedDeliveryReceipt {
593
632
  */
594
633
  constructor(descriptor: DetailedDeliveryReceiptDescriptor);
595
634
  }
635
+ type MessageEvents = {
636
+ updated: (data: {
637
+ message: Message;
638
+ updateReasons: MessageUpdateReason[];
639
+ }) => void;
640
+ };
596
641
  interface MessageServices {
597
642
  mcsClient: McsClient;
598
643
  network: Network;
@@ -608,13 +653,17 @@ interface MessageLinks {
608
653
  */
609
654
  type MessageUpdateReason = "body" | "lastUpdatedBy" | "dateCreated" | "dateUpdated" | "attributes" | "author" | "deliveryReceipt" | "subject";
610
655
  /**
611
- * Push notification type of a message.
656
+ * Type of a message.
612
657
  */
613
658
  type MessageType = "text" | "media";
659
+ interface MessageUpdatedEventArgs {
660
+ message: Message;
661
+ updateReasons: MessageUpdateReason[];
662
+ }
614
663
  /**
615
664
  * A message in a conversation.
616
665
  */
617
- declare class Message extends EventEmitter {
666
+ declare class Message extends ReplayEventEmitter<MessageEvents> {
618
667
  /**
619
668
  * Conversation that the message is in.
620
669
  */
@@ -739,29 +788,30 @@ declare class Message extends EventEmitter {
739
788
  private _getDetailedDeliveryReceiptsPaginator;
740
789
  }
741
790
  /**
742
- * Pagination helper class.
743
- *
744
- * @interface
745
- * @property {Array} items Elements on current page
746
- * @property {boolean} hasNextPage Indicates the existence of next page
747
- * @property {boolean} hasPrevPage Indicates the existence of previous page
748
- * @function {Promise<Paginator>} nextPage() Request next page. Does not modify existing object
749
- * @function {Promise<Paginator>} prevPage() Request previous page. Does not modify existing object
791
+ * Pagination helper interface.
792
+ * @typeParam T The item type.
750
793
  */
751
794
  interface Paginator<T> {
795
+ /**
796
+ * Indicates the existence of the next page.
797
+ */
752
798
  hasNextPage: boolean;
799
+ /**
800
+ * Indicates the existence of the previous page.
801
+ */
753
802
  hasPrevPage: boolean;
754
- items: Array<T>;
803
+ /**
804
+ * Array of elements of type T on the current page.
805
+ */
806
+ items: T[];
755
807
  /**
756
808
  * Request next page.
757
- * Does not modify existing object.
758
- * @return {Promise<Paginator<T>>}
809
+ * Does not modify the existing object.
759
810
  */
760
811
  nextPage(): Promise<Paginator<T>>;
761
812
  /**
762
813
  * Request previous page.
763
- * Does not modify existing object.
764
- * @return {Promise<Paginator<T>>}
814
+ * Does not modify the existing object.
765
815
  */
766
816
  prevPage(): Promise<Paginator<T>>;
767
817
  }
@@ -810,30 +860,94 @@ declare class TypingIndicator {
810
860
  send(conversationSid: string): Promise<void>;
811
861
  private _send;
812
862
  }
863
+ /**
864
+ * An unsent message. Returned from {@link MessageBuilder.build}.
865
+ */
813
866
  declare class UnsentMessage {
814
867
  private messagesEntity;
815
868
  text?: string;
816
869
  attributes: any;
817
870
  mediaContent: [MediaCategory, FormData | SendMediaOptions][];
818
871
  emailOptions?: SendEmailOptions;
872
+ /**
873
+ * @internal
874
+ */
819
875
  constructor(messagesEntity: any);
820
876
  /**
821
877
  * Send the prepared message to the conversation.
822
- * @returns {Promise<number>} new Message's index in the Conversation's messages list
878
+ * @returns Index of the new message in the conversation.
823
879
  */
824
880
  send(): Promise<number>;
825
881
  }
882
+ /**
883
+ * Message builder. Allows the message to be built and sent via method chaining.
884
+ *
885
+ * Example:
886
+ *
887
+ * ```ts
888
+ * await testConversation.prepareMessage()
889
+ * .setBody('Hello!')
890
+ * .setAttributes({foo: 'bar'})
891
+ * .addMedia(media1)
892
+ * .addMedia(media2)
893
+ * .build()
894
+ * .send();
895
+ * ```
896
+ */
826
897
  declare class MessageBuilder {
827
898
  private readonly limits;
828
899
  private readonly message;
900
+ /**
901
+ * @internal
902
+ */
829
903
  constructor(limits: Limits, messagesEntity: any);
904
+ /**
905
+ * Sets the message body.
906
+ * @param text Contents of the body.
907
+ */
830
908
  setBody(text: string): MessageBuilder;
909
+ /**
910
+ * Sets the message subject.
911
+ * @param subject Contents of the subject.
912
+ */
831
913
  setSubject(subject: string): MessageBuilder;
914
+ /**
915
+ * Sets the message attributes.
916
+ * @param attributes Message attributes.
917
+ */
832
918
  setAttributes(attributes: any): MessageBuilder;
919
+ /**
920
+ * Adds media to the message.
921
+ * @param payload Media to add.
922
+ */
833
923
  addMedia(payload: FormData | SendMediaOptions): MessageBuilder;
924
+ /**
925
+ * Builds the message, making it ready to be sent.
926
+ */
834
927
  build(): UnsentMessage;
835
928
  private getPayloadContentType;
836
929
  }
930
+ type ConversationEvents = {
931
+ participantJoined: (participant: Participant) => void;
932
+ participantLeft: (participant: Participant) => void;
933
+ participantUpdated: (data: {
934
+ participant: Participant;
935
+ updateReasons: ParticipantUpdateReason[];
936
+ }) => void;
937
+ messageAdded: (message: Message) => void;
938
+ messageRemoved: (message: Message) => void;
939
+ messageUpdated: (data: {
940
+ message: Message;
941
+ updateReasons: MessageUpdateReason[];
942
+ }) => void;
943
+ typingEnded: (participant: Participant) => void;
944
+ typingStarted: (participant: Participant) => void;
945
+ updated: (data: {
946
+ conversation: Conversation;
947
+ updateReasons: ConversationUpdateReason[];
948
+ }) => void;
949
+ removed: (conversation: Conversation) => void;
950
+ };
837
951
  interface ConversationServices {
838
952
  users: Users;
839
953
  typingIndicator: TypingIndicator;
@@ -895,7 +1009,8 @@ interface ConversationUpdatedEventArgs {
895
1009
  }
896
1010
  /**
897
1011
  * Configuration for attaching a media file to a message.
898
- * These options can be passed to {@link Conversation.sendMessage}.
1012
+ * These options can be passed to {@link Conversation.sendMessage} and
1013
+ * {@link MessageBuilder.addMedia}.
899
1014
  */
900
1015
  interface SendMediaOptions {
901
1016
  /**
@@ -936,7 +1051,7 @@ interface LastMessage {
936
1051
  /**
937
1052
  * A conversation represents communication between multiple Conversations clients
938
1053
  */
939
- declare class Conversation extends EventEmitter {
1054
+ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
940
1055
  /**
941
1056
  * Unique system identifier of the conversation.
942
1057
  */
@@ -1141,7 +1256,7 @@ declare class Conversation extends EventEmitter {
1141
1256
  * @param address User address of the participant.
1142
1257
  * @param attributes Attributes to be attached to the participant.
1143
1258
  */
1144
- addNonChatParticipant(proxyAddress: string, address: string, attributes?: Record<string, any>): Promise<void>;
1259
+ addNonChatParticipant(proxyAddress: string, address: string, attributes?: any): Promise<void>;
1145
1260
  /**
1146
1261
  * Advance the conversation's last read message index to the current read horizon.
1147
1262
  * Rejects if the user is not a participant of the conversation.
@@ -1228,14 +1343,15 @@ declare class Conversation extends EventEmitter {
1228
1343
  */
1229
1344
  leave(): Promise<Conversation>;
1230
1345
  /**
1231
- * Remove a participant from the conversation. When a string is passed as the argument, it will assume that the string is an identity.
1232
- * @param participant Identity or the participant object to remove.
1346
+ * Remove a participant from the conversation. When a string is passed as the
1347
+ * argument, it will assume that the string is an identity or SID.
1348
+ * @param participant Identity, SID or the participant object to remove.
1233
1349
  */
1234
1350
  removeParticipant(participant: string | Participant): Promise<void>;
1235
1351
  /**
1236
1352
  * Send a message to the conversation.
1237
1353
  * @param message Message body for the text message,
1238
- * `FormData` or {@link Conversation.MediaOptions) for media content. Sending FormData is supported only with the browser engine.
1354
+ * `FormData` or {@link SendMediaOptions} for media content. Sending FormData is supported only with the browser engine.
1239
1355
  * @param messageAttributes Attributes for the message.
1240
1356
  * @param emailOptions Email options for the message.
1241
1357
  * @return Index of the new message.
@@ -1244,7 +1360,6 @@ declare class Conversation extends EventEmitter {
1244
1360
  /**
1245
1361
  * New interface to prepare for sending a message.
1246
1362
  * Use instead of `sendMessage`.
1247
- * @return {MessageBuilder} [description]
1248
1363
  */
1249
1364
  prepareMessage(): MessageBuilder;
1250
1365
  /**
@@ -1276,7 +1391,7 @@ declare class Conversation extends EventEmitter {
1276
1391
  * Update the friendly name of the conversation.
1277
1392
  * @param friendlyName New friendly name.
1278
1393
  */
1279
- updateFriendlyName(friendlyName: string | null): Promise<Conversation>;
1394
+ updateFriendlyName(friendlyName: string): Promise<Conversation>;
1280
1395
  /**
1281
1396
  * Set the last read message index to the current read horizon.
1282
1397
  * @param index Message index to set as last read.
@@ -1317,7 +1432,7 @@ interface PushNotificationData {
1317
1432
  */
1318
1433
  messageIndex?: number;
1319
1434
  /**
1320
- * SID of the message in the conversation.s
1435
+ * SID of the message in the conversation.
1321
1436
  */
1322
1437
  messageSid?: string;
1323
1438
  }
@@ -1342,7 +1457,7 @@ declare class PushNotification {
1342
1457
  */
1343
1458
  readonly badge: number;
1344
1459
  /**
1345
- * Notification action (`click_action` in FCM/GCM terms and `category` in APN terms).
1460
+ * Notification action (`click_action` in FCM terms and `category` in APN terms).
1346
1461
  */
1347
1462
  readonly action: string;
1348
1463
  /**
@@ -1358,6 +1473,47 @@ declare class PushNotification {
1358
1473
  */
1359
1474
  constructor(data: PushNotificationDescriptor);
1360
1475
  }
1476
+ type ClientEvents = {
1477
+ conversationAdded: (conversation: Conversation) => void;
1478
+ conversationJoined: (conversation: Conversation) => void;
1479
+ conversationLeft: (conversation: Conversation) => void;
1480
+ conversationRemoved: (conversation: Conversation) => void;
1481
+ conversationUpdated: (data: {
1482
+ conversation: Conversation;
1483
+ updateReasons: ConversationUpdateReason[];
1484
+ }) => void;
1485
+ participantJoined: (participant: Participant) => void;
1486
+ participantLeft: (participant: Participant) => void;
1487
+ participantUpdated: (data: {
1488
+ participant: Participant;
1489
+ updateReasons: ParticipantUpdateReason[];
1490
+ }) => void;
1491
+ messageAdded: (message: Message) => void;
1492
+ messageRemoved: (message: Message) => void;
1493
+ messageUpdated: (data: {
1494
+ message: Message;
1495
+ updateReasons: MessageUpdateReason[];
1496
+ }) => void;
1497
+ tokenAboutToExpire: (ttl: number) => void;
1498
+ tokenExpired: () => void;
1499
+ typingEnded: (participant: Participant) => void;
1500
+ typingStarted: (participant: Participant) => void;
1501
+ pushNotification: (pushNotification: PushNotification) => void;
1502
+ userSubscribed: (user: User) => void;
1503
+ userUnsubscribed: (user: User) => void;
1504
+ userUpdated: (data: {
1505
+ user: User;
1506
+ updateReasons: UserUpdateReason[];
1507
+ }) => void;
1508
+ stateChanged: (state: State) => void;
1509
+ connectionStateChanged: (state: TwilsockConnectionState) => void;
1510
+ connectionError: (data: {
1511
+ terminal: boolean;
1512
+ message: string;
1513
+ httpStatusCode?: number;
1514
+ errorCode?: number;
1515
+ }) => void;
1516
+ };
1361
1517
  /**
1362
1518
  * Connection state of the client. Possible values are as follows:
1363
1519
  * * `'connecting'` - client is offline and connection attempt is in process
@@ -1367,6 +1523,12 @@ declare class PushNotification {
1367
1523
  * * `'denied'` - client connection is denied because of invalid JWT access token. User must refresh token in order to proceed
1368
1524
  */
1369
1525
  type ConnectionState = TwilsockConnectionState;
1526
+ /**
1527
+ * State of the client. Possible values are as follows:
1528
+ * * `'failed'` - the client failed to initialize
1529
+ * * `'initialized'` - the client successfully initialized
1530
+ */
1531
+ type State = "failed" | "initialized";
1370
1532
  /**
1371
1533
  * Notifications channel type. Possible values are as follows:
1372
1534
  * * `'fcm'`
@@ -1423,7 +1585,7 @@ interface CreateConversationOptions {
1423
1585
  /**
1424
1586
  * A client is the starting point to the Twilio Conversations functionality.
1425
1587
  */
1426
- declare class Client extends EventEmitter {
1588
+ declare class Client extends ReplayEventEmitter<ClientEvents> {
1427
1589
  /**
1428
1590
  * Client connection state.
1429
1591
  */
@@ -1437,6 +1599,7 @@ declare class Client extends EventEmitter {
1437
1599
  private conversations;
1438
1600
  private readonly options;
1439
1601
  private services;
1602
+ private readonly _myself;
1440
1603
  /**
1441
1604
  * Current version of the Conversations client.
1442
1605
  */
@@ -1493,7 +1656,7 @@ declare class Client extends EventEmitter {
1493
1656
  static readonly conversationRemoved = "conversationRemoved";
1494
1657
  /**
1495
1658
  * Fired when the attributes or the metadata of a conversation have been updated.
1496
- * During conversation's {@link Client.create| creation and initialization}, this event might be fired multiple times
1659
+ * During conversation's creation and initialization, this event might be fired multiple times
1497
1660
  * for same joined or created conversation as new data is arriving from different sources.
1498
1661
  *
1499
1662
  * Parameters:
@@ -1503,14 +1666,6 @@ declare class Client extends EventEmitter {
1503
1666
  * @event
1504
1667
  */
1505
1668
  static readonly conversationUpdated = "conversationUpdated";
1506
- /**
1507
- * Fired when the connection state of the client has been changed.
1508
- *
1509
- * Parameters:
1510
- * 1. {@link Conversation} `conversation` - the conversation in question
1511
- * @event
1512
- */
1513
- static readonly conversationStateChanged = "connectionStateChanged";
1514
1669
  /**
1515
1670
  * Fired when a participant has joined a conversation.
1516
1671
  *
@@ -1565,6 +1720,8 @@ declare class Client extends EventEmitter {
1565
1720
  static readonly messageUpdated = "messageUpdated";
1566
1721
  /**
1567
1722
  * Fired when the token is about to expire and needs to be updated.
1723
+ * * Parameters:
1724
+ * 1. number `message` - token's time to live
1568
1725
  * @event
1569
1726
  */
1570
1727
  static readonly tokenAboutToExpire = "tokenAboutToExpire";
@@ -1623,6 +1780,22 @@ declare class Client extends EventEmitter {
1623
1780
  * @event
1624
1781
  */
1625
1782
  static readonly userUpdated = "userUpdated";
1783
+ /**
1784
+ * Fired when the state of the client has been changed.
1785
+ *
1786
+ * Parameters:
1787
+ * 1. {@link State} `state` - the new client state
1788
+ * @event
1789
+ */
1790
+ static readonly stateChanged = "stateChanged";
1791
+ /**
1792
+ * Fired when the connection state of the client has been changed.
1793
+ *
1794
+ * Paremeters:
1795
+ * 1. {@link ConnectionState} `state` - the new connection state
1796
+ * @event
1797
+ */
1798
+ static readonly connectionStateChanged = "connectionStateChanged";
1626
1799
  /**
1627
1800
  * Fired when the connection is interrupted for an unexpected reason.
1628
1801
  *
@@ -1643,17 +1816,27 @@ declare class Client extends EventEmitter {
1643
1816
  * The factory method will automatically trigger connection.
1644
1817
  * Do not use it if you need finer-grained control.
1645
1818
  *
1819
+ * Since this method returns an already-initialized client, some of the events
1820
+ * will be lost because they happen *before* the initialization. It is
1821
+ * recommended that `client.onWithReplay` is used as opposed to `client.on`
1822
+ * for subscribing to client events. The `client.onWithReplay` will re-emit
1823
+ * the most recent value for a given event if it emitted before the
1824
+ * subscription.
1825
+ *
1646
1826
  * @param token Access token.
1647
1827
  * @param options Options to customize the client.
1648
1828
  * @returns Returns a fully initialized client.
1649
1829
  */
1650
1830
  static create(token: string, options?: ClientOptions): Promise<Client>;
1651
1831
  /**
1652
- * Information of the logged-in user.
1832
+ * Information of the logged-in user. Before client initialization, returns an
1833
+ * uninitialized user. Will trigger a {@link Client.userUpdated} event after
1834
+ * initialization.
1653
1835
  */
1654
1836
  get user(): User;
1655
1837
  /**
1656
- * Client reachability state.
1838
+ * Client reachability state. Throws if accessed before the client
1839
+ * initialization was completed.
1657
1840
  */
1658
1841
  get reachabilityEnabled(): boolean;
1659
1842
  get token(): string;
@@ -1766,4 +1949,12 @@ declare class RestPaginator<T> implements Paginator<T> {
1766
1949
  */
1767
1950
  prevPage(): Promise<RestPaginator<T>>;
1768
1951
  }
1769
- export { Client as default, Client, Conversation, ConversationUpdateReason, ConversationStatus, NotificationLevel, ConversationState, ConversationUpdatedEventArgs, SendMediaOptions, SendEmailOptions, LastMessage, Participant, ParticipantUpdateReason, ParticipantType, Message, MessageUpdateReason, MessageType, Media, AggregatedDeliveryReceipt, DeliveryAmount, DetailedDeliveryReceipt, DeliveryStatus, RestPaginator, User, UserUpdateReason, PushNotification, PushNotificationType, PushNotificationDescriptor, ConnectionState, NotificationsChannelType, ClientOptions, CreateConversationOptions };
1952
+ declare class NotificationTypes {
1953
+ static readonly TYPING_INDICATOR = "twilio.ipmsg.typing_indicator";
1954
+ static readonly NEW_MESSAGE = "twilio.conversations.new_message";
1955
+ static readonly ADDED_TO_CONVERSATION = "twilio.conversations.added_to_conversation";
1956
+ // static readonly INVITED_TO_CHANNEL = 'twilio.channel.invited_to_channel';
1957
+ static readonly REMOVED_FROM_CONVERSATION = "twilio.conversations.removed_from_conversation";
1958
+ static readonly CONSUMPTION_UPDATE = "twilio.channel.consumption_update";
1959
+ }
1960
+ export { Conversation, ConversationUpdateReason, ConversationStatus, NotificationLevel, ConversationState, ConversationUpdatedEventArgs, SendMediaOptions, SendEmailOptions, LastMessage, Participant, ParticipantUpdateReason, ParticipantType, ParticipantUpdatedEventArgs, Message, MessageUpdateReason, MessageType, MessageUpdatedEventArgs, Media, MediaCategory$0 as MediaCategory, AggregatedDeliveryReceipt, DeliveryAmount, DetailedDeliveryReceipt, DeliveryStatus, RestPaginator, MessageBuilder, UnsentMessage, Paginator, User, UserUpdateReason, UserUpdatedEventArgs, PushNotification, PushNotificationType, PushNotificationDescriptor, PushNotificationData, NotificationTypes, Client, State, ConnectionState, NotificationsChannelType, ClientOptions, CreateConversationOptions };