@twilio/conversations 3.0.0-canary.5 → 3.0.0-canary2.100

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 (53) hide show
  1. package/README.md +22 -18
  2. package/builds/browser.js +1360 -2410
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +74 -69
  5. package/builds/lib.js +1360 -2410
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +25229 -25615
  8. package/builds/twilio-conversations.min.js +1 -16
  9. package/dist/aggregated-delivery-receipt.js +1 -1
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/client.js +99 -70
  12. package/dist/client.js.map +1 -1
  13. package/dist/command-executor.js +30 -12
  14. package/dist/command-executor.js.map +1 -1
  15. package/dist/configuration.js.map +1 -1
  16. package/dist/conversation.js +92 -23
  17. package/dist/conversation.js.map +1 -1
  18. package/dist/data/conversations.js +21 -5
  19. package/dist/data/conversations.js.map +1 -1
  20. package/dist/data/messages.js +13 -19
  21. package/dist/data/messages.js.map +1 -1
  22. package/dist/data/participants.js +6 -4
  23. package/dist/data/participants.js.map +1 -1
  24. package/dist/data/users.js +4 -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.map +1 -1
  34. package/dist/message-builder.js.map +1 -1
  35. package/dist/message.js +24 -21
  36. package/dist/message.js.map +1 -1
  37. package/dist/node_modules/tslib/tslib.es6.js +1 -1
  38. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  39. package/dist/packages/conversations/package.json.js +1 -1
  40. package/dist/participant.js +2 -2
  41. package/dist/participant.js.map +1 -1
  42. package/dist/push-notification.js.map +1 -1
  43. package/dist/rest-paginator.js.map +1 -1
  44. package/dist/services/network.js +38 -15
  45. package/dist/services/network.js.map +1 -1
  46. package/dist/services/typing-indicator.js +7 -5
  47. package/dist/services/typing-indicator.js.map +1 -1
  48. package/dist/unsent-message.js.map +1 -1
  49. package/dist/user.js +2 -2
  50. package/dist/user.js.map +1 -1
  51. package/dist/util/deferred.js.map +1 -1
  52. package/dist/util/index.js.map +1 -1
  53. package/package.json +27 -23
@@ -131,6 +131,7 @@ This software includes platform.js under the following license.
131
131
  Object.defineProperty(exports, '__esModule', { value: true });
132
132
 
133
133
  var tslib_es6 = require('./node_modules/tslib/tslib.es6.js');
134
+ require('isomorphic-form-data');
134
135
  var logger = require('./logger.js');
135
136
  var participants = require('./data/participants.js');
136
137
  var participant = require('./participant.js');
@@ -323,7 +324,9 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
323
324
  update.attributes = {};
324
325
  }
325
326
  try {
326
- update.dateCreated && (update.dateCreated = new Date(update.dateCreated));
327
+ if (update.dateCreated) {
328
+ update.dateCreated = new Date(update.dateCreated);
329
+ }
327
330
  }
328
331
  catch (e) {
329
332
  Conversation._logger.warn("Retrieved malformed dateCreated from the server for conversation: " +
@@ -331,7 +334,9 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
331
334
  delete update.dateCreated;
332
335
  }
333
336
  try {
334
- update.dateUpdated && (update.dateUpdated = new Date(update.dateUpdated));
337
+ if (update.dateUpdated) {
338
+ update.dateUpdated = new Date(update.dateUpdated);
339
+ }
335
340
  }
336
341
  catch (e) {
337
342
  Conversation._logger.warn("Retrieved malformed dateUpdated from the server for conversation: " +
@@ -438,6 +443,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
438
443
  const url = new index.UriBuilder(this._configuration.links.conversations)
439
444
  .path(this.sid)
440
445
  .build();
446
+ // todo: remove any after the release of new Twilsock
441
447
  const response = await this._services.network.get(url);
442
448
  return (_a = response.body.participants_count) !== null && _a !== void 0 ? _a : 0;
443
449
  }
@@ -471,11 +477,12 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
471
477
  const url = new index.UriBuilder(this._configuration.links.conversations)
472
478
  .path(this.sid)
473
479
  .build();
480
+ // todo: remove any after the release of new Twilsock
474
481
  const response = await this._services.network.get(url);
475
482
  return (_a = response.body.messages_count) !== null && _a !== void 0 ? _a : 0;
476
483
  }
477
484
  /**
478
- * Get unread messages count for the user if they are a participant of this
485
+ * Get count of unread messages for the user if they are a participant of this
479
486
  * conversation. Rejects if the user is not a participant of the conversation.
480
487
  *
481
488
  * Use this method to obtain the number of unread messages together with
@@ -483,17 +490,25 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
483
490
  * message indices which may have gaps. See {@link Message.index} for details.
484
491
  *
485
492
  * This method is semi-realtime. This means that this data will be eventually
486
- * correct, but will also be possibly incorrect for a few seconds. The
493
+ * correct, but it will also be possibly incorrect for a few seconds. The
487
494
  * Conversations system does not provide real time events for counter values
488
495
  * changes.
489
496
  *
490
497
  * This is useful for any UI badges, but it is not recommended to build any
491
498
  * core application logic based on these counters being accurate in real time.
499
+ *
500
+ * If the read horizon is not set, this function will return null. This could mean
501
+ * that all messages in the conversation are unread, or that the read horizon system
502
+ * is not being used. How to interpret this `null` value is up to the customer application.
503
+ *
504
+ * @return Number of unread messages based on the current read horizon set for
505
+ * the user or `null` if the read horizon is not set.
492
506
  */
493
507
  async getUnreadMessagesCount() {
494
508
  const url = new index.UriBuilder(this._configuration.links.myConversations)
495
509
  .path(this.sid)
496
510
  .build();
511
+ // todo: remove any after the release of new Twilsock
497
512
  const response = await this._services.network.get(url);
498
513
  if (response.body.conversation_sid !== this.sid) {
499
514
  throw new Error("Conversation was not found in the user conversations list");
@@ -527,8 +542,6 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
527
542
  * argument, it will assume that the string is an identity or SID.
528
543
  * @param participant Identity, SID or the participant object to remove.
529
544
  */
530
- /* eslint-disable @typescript-eslint/ban-ts-comment */
531
- // @ts-ignore TODO: fix validateTypesAsync typing
532
545
  async removeParticipant(participant) {
533
546
  await this._participantsEntity.remove(typeof participant === "string" ? participant : participant.sid);
534
547
  }
@@ -542,13 +555,48 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
542
555
  * @return Index of the new message.
543
556
  */
544
557
  async sendMessage(message, messageAttributes, emailOptions) {
545
- var _a, _b;
546
- if (typeof message === "string" || message === null) {
547
- const response = await this._messagesEntity.send(message, messageAttributes, emailOptions);
548
- return (_a = index.parseToNumber(response.index)) !== null && _a !== void 0 ? _a : 0;
558
+ const response = typeof message === "string" || message === null
559
+ ? await this._messagesEntity.send(message, messageAttributes, emailOptions)
560
+ : await this._messagesEntity.sendMedia(message, messageAttributes, emailOptions);
561
+ const type = typeof message === "string" || message === null ? "text" : "media";
562
+ let responseAttributes;
563
+ try {
564
+ responseAttributes = JSON.parse(response.attributes);
549
565
  }
550
- const response = await this._messagesEntity.sendMedia(message, messageAttributes, emailOptions);
551
- return (_b = index.parseToNumber(response.index)) !== null && _b !== void 0 ? _b : 0;
566
+ catch (e) { }
567
+ const messageData = {
568
+ sid: response.sid,
569
+ text: response.body,
570
+ type,
571
+ author: response.author,
572
+ subject: response.subject,
573
+ lastUpdatedBy: response.participant_sid,
574
+ attributes: responseAttributes,
575
+ dateUpdated: response.date_updated,
576
+ timestamp: response.date_created,
577
+ memberSid: response.participant_sid,
578
+ medias: Array.isArray(response.media)
579
+ ? response.media.map((media) => ({
580
+ sid: media["sid"],
581
+ size: Number(media["size"]),
582
+ category: media["category"],
583
+ filename: media["filename"],
584
+ contentType: media["content_type"],
585
+ }))
586
+ : null,
587
+ media: response.media &&
588
+ typeof response.media === "object" &&
589
+ !Array.isArray(response.media)
590
+ ? {
591
+ sid: response.media["sid"],
592
+ size: Number(response.media["size"]),
593
+ category: response.media["category"],
594
+ filename: response.media["filename"],
595
+ contentType: response.media["content_type"],
596
+ }
597
+ : null,
598
+ };
599
+ return this._messagesEntity._upsertMessage(response.index, messageData);
552
600
  }
553
601
  /**
554
602
  * New interface to prepare for sending a message.
@@ -573,7 +621,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
573
621
  }
574
622
  /**
575
623
  * Set all messages in the conversation unread.
576
- * @return Resulting unread messages count in the conversation.
624
+ * @returns New count of unread messages after this update.
577
625
  */
578
626
  async setAllMessagesUnread() {
579
627
  await this._subscribeStreams();
@@ -621,7 +669,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
621
669
  * Set the last read message index to the current read horizon.
622
670
  * @param index Message index to set as last read. If null is provided, then
623
671
  * the behavior is identical to {@link Conversation.setAllMessagesUnread}.
624
- * @returns Resulting unread messages count in the conversation.
672
+ * @returns New count of unread messages after this update.
625
673
  */
626
674
  async updateLastReadMessageIndex(index) {
627
675
  await this._subscribeStreams();
@@ -672,6 +720,29 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
672
720
  throw err;
673
721
  }
674
722
  }
723
+ /**
724
+ * Fetch participants and messages of the conversation. This method needs to
725
+ * be called during conversation initialization to catch broken conversations
726
+ * (broken conversations are conversations that have essential Sync entities
727
+ * missing, i.e. the conversation document, the messages list or the
728
+ * participant map). In case of this conversation being broken, the method
729
+ * will throw an exception that will be caught and handled gracefully.
730
+ * @internal
731
+ */
732
+ async _fetchStreams() {
733
+ var _a, _b;
734
+ await this._subscribe();
735
+ Conversation._logger.trace("_streamsAvailable, this.entity.data=", (_a = this._entity) === null || _a === void 0 ? void 0 : _a.data);
736
+ const data = (_b = this._entity) === null || _b === void 0 ? void 0 : _b.data;
737
+ this._messagesList = await this._services.syncClient.list({
738
+ id: data.messages,
739
+ mode: "open_existing",
740
+ });
741
+ this._participantsMap = await this._services.syncClient.map({
742
+ id: data.roster,
743
+ mode: "open_existing",
744
+ });
745
+ }
675
746
  /**
676
747
  * Load the attributes of this conversation and instantiate its participants
677
748
  * and messages. This or _subscribe will need to be called before any events
@@ -680,7 +751,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
680
751
  * @internal
681
752
  */
682
753
  async _subscribeStreams() {
683
- var _a, _b;
754
+ var _a, _b, _c, _d;
684
755
  try {
685
756
  await this._subscribe();
686
757
  Conversation._logger.trace("_subscribeStreams, this.entity.data=", (_a = this._entity) === null || _a === void 0 ? void 0 : _a.data);
@@ -688,8 +759,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
688
759
  const messagesObjectName = data.messages;
689
760
  const rosterObjectName = data.roster;
690
761
  await Promise.all([
691
- this._messagesEntity.subscribe(messagesObjectName),
692
- this._participantsEntity.subscribe(rosterObjectName),
762
+ this._messagesEntity.subscribe((_c = this._messagesList) !== null && _c !== void 0 ? _c : messagesObjectName),
763
+ this._participantsEntity.subscribe((_d = this._participantsMap) !== null && _d !== void 0 ? _d : rosterObjectName),
693
764
  ]);
694
765
  }
695
766
  catch (err) {
@@ -768,7 +839,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
768
839
  updateReasons.add(localKey);
769
840
  break;
770
841
  case fieldMappings.attributes:
771
- if (isEqual__default['default'](this._internalState.attributes, update.attributes)) {
842
+ if (isEqual__default["default"](this._internalState.attributes, update.attributes)) {
772
843
  break;
773
844
  }
774
845
  this._internalState.attributes = update.attributes;
@@ -804,7 +875,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
804
875
  update.lastMessage.timestamp;
805
876
  updateReasons.add(localKey);
806
877
  }
807
- if (isEqual__default['default'](this._internalState.lastMessage, {})) {
878
+ if (isEqual__default["default"](this._internalState.lastMessage, {})) {
808
879
  delete this._internalState.lastMessage;
809
880
  }
810
881
  break;
@@ -813,14 +884,14 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
813
884
  if (state !== undefined) {
814
885
  state.dateUpdated = new Date(state.dateUpdated);
815
886
  }
816
- if (isEqual__default['default'](this._internalState.state, state)) {
887
+ if (isEqual__default["default"](this._internalState.state, state)) {
817
888
  break;
818
889
  }
819
890
  this._internalState.state = state;
820
891
  updateReasons.add(localKey);
821
892
  break;
822
893
  case fieldMappings.bindings:
823
- if (isEqual__default['default'](this._internalState.bindings, update.bindings)) {
894
+ if (isEqual__default["default"](this._internalState.bindings, update.bindings)) {
824
895
  break;
825
896
  }
826
897
  this._internalState.bindings = update.bindings;
@@ -1016,8 +1087,6 @@ tslib_es6.__decorate([
1016
1087
  tslib_es6.__decorate([
1017
1088
  declarativeTypeValidator.validateTypesAsync([
1018
1089
  "string",
1019
- /* eslint-disable @typescript-eslint/ban-ts-comment */
1020
- // @ts-ignore TODO: fix validateTypesAsync typing
1021
1090
  FormData,
1022
1091
  declarativeTypeValidator.literal(null),
1023
1092
  declarativeTypeValidator.objectSchema("media options", {
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.js","sources":["../src/conversation.ts"],"sourcesContent":["import { Logger } from \"./logger\";\nimport { ParticipantBindingOptions, Participants } from \"./data/participants\";\nimport {\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason,\n} from \"./participant\";\nimport { Messages } from \"./data/messages\";\nimport {\n Message,\n MessageUpdatedEventArgs,\n MessageUpdateReason,\n} from \"./message\";\nimport { UriBuilder, parseToNumber, parseTime } from \"./util\";\nimport { Users } from \"./data/users\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { ConversationsDataSource } from \"./data/conversations\";\nimport { McsClient } from \"@twilio/mcs-client\";\nimport { SyncClient, SyncDocument } from \"twilio-sync\";\nimport { TypingIndicator } from \"./services/typing-indicator\";\nimport { Network } from \"./services/network\";\nimport {\n validateTypesAsync,\n custom,\n literal,\n nonEmptyString,\n nonNegativeInteger,\n objectSchema,\n} from \"@twilio/declarative-type-validator\";\nimport {\n attributesValidator,\n optionalAttributesValidator,\n} from \"./interfaces/attributes\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { AddParticipantRequest } from \"./interfaces/commands/add-participant\";\nimport { EditConversationRequest } from \"./interfaces/commands/edit-conversation\";\nimport { ConversationResponse } from \"./interfaces/commands/conversation-response\";\nimport { ParticipantResponse } from \"./interfaces/commands/participant-response\";\nimport { EditNotificationLevelRequest } from \"./interfaces/commands/edit-notification-level\";\nimport {\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse,\n} from \"./interfaces/commands/edit-last-read-message-index\";\nimport { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { MessageBuilder } from \"./message-builder\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\n\n/**\n * Conversation events.\n */\ntype ConversationEvents = {\n participantJoined: (participant: Participant) => void;\n participantLeft: (participant: Participant) => void;\n participantUpdated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n }) => void;\n removed: (conversation: Conversation) => void;\n};\n\n/**\n * Reason for the `updated` event emission by a conversation.\n */\ntype ConversationUpdateReason =\n | \"attributes\"\n | \"createdBy\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"friendlyName\"\n | \"lastReadMessageIndex\"\n | \"state\"\n | \"status\"\n | \"uniqueName\"\n | \"lastMessage\"\n | \"notificationLevel\"\n | \"bindings\";\n\n/**\n * Status of the conversation, relative to the client: whether the conversation\n * has been `joined` or the client is `notParticipating` in the conversation.\n */\ntype ConversationStatus = \"notParticipating\" | \"joined\";\n\n/**\n * User's notification level for the conversation. Determines\n * whether the currently logged-in user will receive pushes for events\n * in this conversation. Can be either `muted` or `default`, where\n * `default` defers to the global service push configuration.\n */\ntype NotificationLevel = \"default\" | \"muted\";\n\n/**\n * State of the conversation.\n */\ninterface ConversationState {\n /**\n * Current state.\n */\n current: \"active\" | \"inactive\" | \"closed\";\n\n /**\n * Date at which the latest conversation state update happened.\n */\n dateUpdated: Date;\n}\n\n/**\n * Event arguments for the `updated` event.\n */\ninterface ConversationUpdatedEventArgs {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationBindings {\n email?: ConversationEmailBinding;\n sms?: ConversationSmsBinding;\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationEmailBinding {\n name?: string;\n projected_address: string;\n}\n\n/**\n * Binding for SMS conversation.\n */\ninterface ConversationSmsBinding {\n address?: string;\n}\n\n/**\n * Configuration for attaching a media file to a message.\n * These options can be passed to {@link Conversation.sendMessage} and\n * {@link MessageBuilder.addMedia}.\n */\ninterface SendMediaOptions {\n /**\n * Content type of media.\n */\n contentType: null | string;\n\n /**\n * Optional filename.\n */\n filename?: string;\n\n /**\n * Content to post.\n */\n media: null | string | Buffer | Blob;\n}\n\n/**\n * These options can be passed to {@link Conversation.sendMessage}.\n */\ninterface SendEmailOptions {\n /**\n * Message subject. Ignored for media messages.\n */\n subject?: string;\n}\n\n/**\n * Information about the last message of a conversation.\n */\ninterface LastMessage {\n /**\n * Message's index.\n */\n index?: number;\n\n /**\n * Message's creation date.\n */\n dateCreated?: Date;\n}\n\n/**\n * Conversation services.\n */\ninterface ConversationServices {\n users: Users;\n typingIndicator: TypingIndicator;\n network: Network;\n mcsClient: McsClient;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Internal (private) state of the conversation.\n */\ninterface ConversationInternalState {\n uniqueName: string | null;\n status: ConversationStatus;\n attributes: JSONValue;\n createdBy?: string;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n friendlyName: string | null;\n lastReadMessageIndex: number | null;\n lastMessage?: LastMessage;\n notificationLevel?: NotificationLevel;\n state?: ConversationState;\n bindings: ConversationBindings;\n}\n\n/**\n * Conversation descriptor.\n */\ninterface ConversationDescriptor {\n channel: string;\n entityName: string;\n uniqueName: string;\n attributes: JSONValue;\n createdBy?: string;\n friendlyName?: string;\n lastConsumedMessageIndex: number;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n notificationLevel?: NotificationLevel;\n bindings?: ConversationBindings;\n}\n\n/**\n * Conversation links.\n */\ninterface ConversationLinks {\n self: string;\n messages: string;\n participants: string;\n}\n\n/**\n * Map of the fields that will be processed with update messages.\n */\nconst fieldMappings = {\n lastMessage: \"lastMessage\",\n attributes: \"attributes\",\n createdBy: \"createdBy\",\n dateCreated: \"dateCreated\",\n dateUpdated: \"dateUpdated\",\n friendlyName: \"friendlyName\",\n lastConsumedMessageIndex: \"lastConsumedMessageIndex\",\n notificationLevel: \"notificationLevel\",\n sid: \"sid\",\n status: \"status\",\n uniqueName: \"uniqueName\",\n state: \"state\",\n bindings: \"bindings\",\n};\n\n/**\n * A conversation represents communication between multiple Conversations\n * clients.\n */\nclass Conversation extends ReplayEventEmitter<ConversationEvents> {\n /**\n * Fired when a participant has joined the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that joined the\n * conversation\n * @event\n */\n public static readonly participantJoined = \"participantJoined\";\n\n /**\n * Fired when a participant has left the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that left the\n * conversation\n * @event\n */\n public static readonly participantLeft = \"participantLeft\";\n\n /**\n * Fired when data of a participant has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Participant} `participant` - participant that has received the\n * update\n * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly participantUpdated = \"participantUpdated\";\n\n /**\n * Fired when a new message has been added to the conversation.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been added\n * @event\n */\n public static readonly messageAdded = \"messageAdded\";\n\n /**\n * Fired when message is removed from the conversation's message list.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been removed\n * @event\n */\n public static readonly messageRemoved = \"messageRemoved\";\n\n /**\n * Fired when data of a message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Message} `message` - message that has received the update\n * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for\n * the update\n * @event\n */\n public static readonly messageUpdated = \"messageUpdated\";\n\n /**\n * Fired when a participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has stopped\n * typing\n * @event\n */\n public static readonly typingEnded = \"typingEnded\";\n\n /**\n * Fired when a participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has started\n * typing\n * @event\n */\n public static readonly typingStarted = \"typingStarted\";\n\n /**\n * Fired when the data of the conversation has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Conversation} `conversation` - conversation that has received\n * the update\n * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly updated = \"updated\";\n\n /**\n * Fired when the conversation was destroyed or the currently-logged-in user\n * has left private conversation.\n *\n * Parameters:\n * 1. {@link Conversation} `conversation` - conversation that has been removed\n * @event\n */\n public static readonly removed = \"removed\";\n\n /**\n * Logger instance.\n */\n private static readonly _logger = Logger.scope(\"Conversation\");\n\n /**\n * Unique system identifier of the conversation.\n */\n public readonly sid: string;\n\n /**\n * Conversation links for REST requests.\n * @internal\n */\n public readonly _links: ConversationLinks;\n\n /**\n * Map of participants.\n * @internal\n */\n public readonly _participants: Map<string, Participant>;\n\n /**\n * Configuration of the client that the conversation belongs to.\n */\n private readonly _configuration: Configuration;\n\n /**\n * Conversation service objects.\n */\n private readonly _services: ConversationServices;\n\n /**\n * Internal state of the conversation.\n */\n private readonly _internalState: ConversationInternalState;\n\n /**\n * Name of the conversation entity document.\n */\n private readonly _entityName: string;\n\n /**\n * Messages entity.\n */\n private readonly _messagesEntity: Messages;\n\n /**\n * Participants entity.\n */\n private readonly _participantsEntity: Participants;\n\n /**\n * Source of the most recent update.\n */\n private _dataSource!: ConversationsDataSource;\n\n /**\n * Promise for the conversation entity document.\n */\n private _entityPromise!: Promise<SyncDocument> | null;\n\n /**\n * Conversation entity document.\n */\n private _entity!: SyncDocument | null;\n\n /**\n * @param descriptor Conversation descriptor.\n * @param sid Conversation SID.\n * @param links Conversation links for REST requests.\n * @param configuration Client configuration.\n * @param services Conversation services.\n * @internal\n */\n public constructor(\n descriptor: ConversationDescriptor,\n sid: string,\n links: ConversationLinks,\n configuration: Configuration,\n services: ConversationServices\n ) {\n super();\n\n this.sid = sid;\n this._links = links;\n this._configuration = configuration;\n this._services = services;\n this._entityName = descriptor.channel;\n this._internalState = {\n uniqueName: descriptor.uniqueName || null,\n status: \"notParticipating\",\n attributes: descriptor.attributes ?? {},\n createdBy: descriptor.createdBy,\n dateCreated: parseTime(descriptor.dateCreated),\n dateUpdated: parseTime(descriptor.dateUpdated),\n friendlyName: descriptor.friendlyName || null,\n lastReadMessageIndex: Number.isInteger(\n descriptor.lastConsumedMessageIndex\n )\n ? descriptor.lastConsumedMessageIndex\n : null,\n bindings: descriptor.bindings ?? {},\n };\n\n if (descriptor.notificationLevel) {\n this._internalState.notificationLevel = descriptor.notificationLevel;\n }\n\n const participantsLinks = {\n participants: this._links.participants,\n };\n\n this._participants = new Map();\n this._participantsEntity = new Participants(\n this,\n this._participants,\n participantsLinks,\n this._configuration,\n this._services\n );\n this._participantsEntity.on(\"participantJoined\", (participant) =>\n this.emit(\"participantJoined\", participant)\n );\n this._participantsEntity.on(\"participantLeft\", (participant) =>\n this.emit(\"participantLeft\", participant)\n );\n this._participantsEntity.on(\n \"participantUpdated\",\n (args: ParticipantUpdatedEventArgs) =>\n this.emit(\"participantUpdated\", args)\n );\n\n this._messagesEntity = new Messages(this, configuration, services);\n this._messagesEntity.on(\"messageAdded\", (message) =>\n this._onMessageAdded(message)\n );\n this._messagesEntity.on(\"messageUpdated\", (args: MessageUpdatedEventArgs) =>\n this.emit(\"messageUpdated\", args)\n );\n this._messagesEntity.on(\"messageRemoved\", (message) =>\n this.emit(\"messageRemoved\", message)\n );\n }\n\n /**\n * Unique name of the conversation.\n */\n public get uniqueName(): string | null {\n return this._internalState.uniqueName;\n }\n\n /**\n * Status of the conversation.\n */\n public get status(): ConversationStatus {\n return this._internalState.status;\n }\n\n /**\n * Name of the conversation.\n */\n public get friendlyName(): string | null {\n return this._internalState.friendlyName;\n }\n\n /**\n * Date this conversation was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this._internalState.dateUpdated;\n }\n\n /**\n * Date this conversation was created on.\n */\n public get dateCreated(): Date | null {\n return this._internalState.dateCreated;\n }\n\n /**\n * Identity of the user that created this conversation.\n */\n public get createdBy(): string {\n return this._internalState.createdBy ?? \"\";\n }\n\n /**\n * Custom attributes of the conversation.\n */\n public get attributes(): JSONValue {\n return this._internalState.attributes;\n }\n\n /**\n * Index of the last message the user has read in this conversation.\n */\n public get lastReadMessageIndex(): number | null {\n return this._internalState.lastReadMessageIndex;\n }\n\n /**\n * Last message sent to this conversation.\n */\n public get lastMessage(): LastMessage | undefined {\n return this._internalState.lastMessage ?? undefined;\n }\n\n /**\n * User notification level for this conversation.\n */\n public get notificationLevel(): NotificationLevel {\n return this._internalState.notificationLevel ?? \"default\";\n }\n\n /**\n * Conversation bindings. Undocumented feature (for now).\n * @internal\n */\n public get bindings(): ConversationBindings {\n return this._internalState.bindings;\n }\n\n /**\n * Current conversation limits.\n */\n public get limits(): ConversationLimits {\n return this._configuration.limits;\n }\n\n /**\n * State of the conversation.\n */\n public get state(): ConversationState | undefined {\n return this._internalState.state;\n }\n\n /**\n * Source of the conversation update.\n * @internal\n */\n public get _statusSource(): ConversationsDataSource {\n return this._dataSource;\n }\n\n /**\n * Preprocess the update object.\n * @param update The update object received from Sync.\n * @param conversationSid The SID of the conversation in question.\n */\n private static preprocessUpdate(update, conversationSid: string) {\n try {\n if (typeof update.attributes === \"string\") {\n update.attributes = JSON.parse(update.attributes);\n } else if (update.attributes) {\n JSON.stringify(update.attributes);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed attributes from the server for conversation: \" +\n conversationSid\n );\n update.attributes = {};\n }\n\n try {\n update.dateCreated &&= new Date(update.dateCreated);\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateCreated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateCreated;\n }\n\n try {\n update.dateUpdated &&= new Date(update.dateUpdated);\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateUpdated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateUpdated;\n }\n\n try {\n if (update.lastMessage && update.lastMessage.timestamp) {\n update.lastMessage.timestamp = new Date(update.lastMessage.timestamp);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed lastMessage.timestamp from the server for conversation: \" +\n conversationSid\n );\n delete update.lastMessage.timestamp;\n }\n }\n\n /**\n * Add a participant to the conversation by its identity.\n * @param identity Identity of the Client to add.\n * @param attributes Attributes to be attached to the participant.\n * @returns The added participant.\n */\n @validateTypesAsync(nonEmptyString, optionalAttributesValidator)\n public async add(\n identity: string,\n attributes?: JSONValue\n ): Promise<Participant> {\n return this._participantsEntity.add(identity, attributes ?? {});\n }\n\n /**\n * Add a non-chat participant to the conversation.\n * @param proxyAddress Proxy (Twilio) address of the participant.\n * @param address User address of the participant.\n * @param attributes Attributes to be attached to the participant.\n * @param bindingOptions Options for adding email participants - name and\n * CC/To level.\n * @returns The added participant.\n */\n @validateTypesAsync(\n nonEmptyString,\n nonEmptyString,\n optionalAttributesValidator\n )\n public async addNonChatParticipant(\n proxyAddress: string,\n address: string,\n attributes: JSONValue = {},\n bindingOptions: ParticipantBindingOptions = {}\n ): Promise<Participant> {\n return this._participantsEntity.addNonChatParticipant(\n proxyAddress,\n address,\n attributes ?? {},\n bindingOptions ?? {}\n );\n }\n\n /**\n * Advance the conversation's last read message index to the current read\n * horizon. Rejects if the user is not a participant of the conversation. Last\n * read message index is updated only if the new index value is higher than\n * the previous.\n * @param index Message index to advance to.\n * @return Resulting unread messages count in the conversation.\n */\n @validateTypesAsync(nonNegativeInteger)\n public async advanceLastReadMessageIndex(index: number): Promise<number> {\n await this._subscribeStreams();\n\n if (index < (this.lastReadMessageIndex ?? 0)) {\n return await this._setLastReadMessageIndex(this.lastReadMessageIndex);\n }\n\n return await this._setLastReadMessageIndex(index);\n }\n\n /**\n * Delete the conversation and unsubscribe from its events.\n */\n public async delete(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n this._links.self\n );\n\n return this;\n }\n\n /**\n * Get the custom attributes of this Conversation.\n */\n public async getAttributes(): Promise<JSONValue> {\n await this._subscribe();\n return this.attributes;\n }\n\n /**\n * Returns messages from the conversation using the paginator interface.\n * @param pageSize Number of messages to return in a single chunk. Default is\n * 30.\n * @param anchor Index of the newest message to fetch. Default is from the\n * end.\n * @param direction Query direction. By default, it queries backwards\n * from newer to older. The `\"forward\"` value will query in the opposite\n * direction.\n * @return A page of messages.\n */\n @validateTypesAsync(\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", literal(\"backwards\", \"forward\")]\n )\n public async getMessages(\n pageSize?: number,\n anchor?: number,\n direction?: \"backwards\" | \"forward\"\n ): Promise<Paginator<Message>> {\n await this._subscribeStreams();\n return this._messagesEntity.getMessages(pageSize, anchor, direction);\n }\n\n /**\n * Get a list of all the participants who are joined to this conversation.\n */\n public async getParticipants(): Promise<Participant[]> {\n await this._subscribeStreams();\n return this._participantsEntity.getParticipants();\n }\n\n /**\n * Get conversation participants count.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getParticipantsCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n const response = await this._services.network.get<ConversationResponse>(\n url\n );\n\n return response.body.participants_count ?? 0;\n }\n\n /**\n * Get a participant by its SID.\n * @param participantSid Participant SID.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantBySid(\n participantSid: string\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantBySid(participantSid);\n }\n\n /**\n * Get a participant by its identity.\n * @param identity Participant identity.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantByIdentity(\n identity: string | null = \"\"\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantByIdentity(identity ?? \"\");\n }\n\n /**\n * Get the total message count in the conversation.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getMessagesCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n const response = await this._services.network.get<ConversationResponse>(\n url\n );\n\n return response.body.messages_count ?? 0;\n }\n\n /**\n * Get unread messages count for the user if they are a participant of this\n * conversation. Rejects if the user is not a participant of the conversation.\n *\n * Use this method to obtain the number of unread messages together with\n * {@link Conversation.updateLastReadMessageIndex} instead of relying on the\n * message indices which may have gaps. See {@link Message.index} for details.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getUnreadMessagesCount(): Promise<number | null> {\n const url = new UriBuilder(this._configuration.links.myConversations)\n .path(this.sid)\n .build();\n const response = await this._services.network.get<ConversationResponse>(\n url\n );\n\n if (response.body.conversation_sid !== this.sid) {\n throw new Error(\n \"Conversation was not found in the user conversations list\"\n );\n }\n\n const unreadMessageCount = response.body.unread_messages_count;\n\n if (typeof unreadMessageCount === \"number\") {\n return unreadMessageCount;\n }\n\n return null;\n }\n\n /**\n * Join the conversation and subscribe to its events.\n */\n public async join(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n AddParticipantRequest,\n ParticipantResponse\n >(\"post\", this._links.participants, {\n identity: this._configuration.userIdentity,\n });\n\n return this;\n }\n\n /**\n * Leave the conversation.\n */\n public async leave(): Promise<Conversation> {\n if (this._internalState.status === \"joined\") {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n `${this._links.participants}/${this._configuration.userIdentity}`\n );\n }\n\n return this;\n }\n\n /**\n * Remove a participant from the conversation. When a string is passed as the\n * argument, it will assume that the string is an identity or SID.\n * @param participant Identity, SID or the participant object to remove.\n */\n /* eslint-disable @typescript-eslint/ban-ts-comment */\n // @ts-ignore TODO: fix validateTypesAsync typing\n @validateTypesAsync([nonEmptyString, Participant])\n public async removeParticipant(\n participant: string | Participant\n ): Promise<void> {\n await this._participantsEntity.remove(\n typeof participant === \"string\" ? participant : participant.sid\n );\n }\n\n /**\n * Send a message to the conversation.\n * @param message Message body for the text message,\n * `FormData` or {@link SendMediaOptions} for media content. Sending FormData\n * is supported only with the browser engine.\n * @param messageAttributes Attributes for the message.\n * @param emailOptions Email options for the message.\n * @return Index of the new message.\n */\n @validateTypesAsync(\n [\n \"string\",\n /* eslint-disable @typescript-eslint/ban-ts-comment */\n // @ts-ignore TODO: fix validateTypesAsync typing\n FormData,\n literal(null),\n objectSchema(\"media options\", {\n contentType: nonEmptyString,\n media: custom((value) => {\n let isValid =\n (typeof value === \"string\" && value.length > 0) ||\n value instanceof Uint8Array ||\n value instanceof ArrayBuffer;\n\n if (typeof Blob === \"function\") {\n isValid = isValid || value instanceof Blob;\n }\n\n return [\n isValid,\n \"a non-empty string, an instance of Buffer or an instance of Blob\",\n ];\n }),\n }),\n ],\n optionalAttributesValidator,\n [\n \"undefined\",\n literal(null),\n objectSchema(\"email attributes\", {\n subject: [nonEmptyString, \"undefined\"],\n }),\n ]\n )\n public async sendMessage(\n message: null | string | FormData | SendMediaOptions,\n messageAttributes?: JSONValue,\n emailOptions?: SendEmailOptions\n ): Promise<number> {\n if (typeof message === \"string\" || message === null) {\n const response = await this._messagesEntity.send(\n message,\n messageAttributes,\n emailOptions\n );\n return parseToNumber(response.index) ?? 0;\n }\n\n const response = await this._messagesEntity.sendMedia(\n message,\n messageAttributes,\n emailOptions\n );\n return parseToNumber(response.index) ?? 0;\n }\n\n /**\n * New interface to prepare for sending a message.\n * Use this instead of {@link Message.sendMessage}.\n * @return A MessageBuilder to help set all message sending options.\n */\n public prepareMessage(): MessageBuilder {\n return new MessageBuilder(this.limits, this._messagesEntity);\n }\n\n /**\n * Set last read message index of the conversation to the index of the last\n * known message.\n * @return Resulting unread messages count in the conversation.\n */\n public async setAllMessagesRead(): Promise<number> {\n await this._subscribeStreams();\n\n const messagesPage = await this.getMessages(1);\n\n if (messagesPage.items.length > 0) {\n return this.advanceLastReadMessageIndex(messagesPage.items[0].index);\n }\n\n return 0;\n }\n\n /**\n * Set all messages in the conversation unread.\n * @return Resulting unread messages count in the conversation.\n */\n public async setAllMessagesUnread(): Promise<number> {\n await this._subscribeStreams();\n return await this._setLastReadMessageIndex(null);\n }\n\n /**\n * Set user notification level for this conversation.\n * @param notificationLevel New user notification level.\n */\n @validateTypesAsync(literal(\"default\", \"muted\"))\n public async setUserNotificationLevel(\n notificationLevel: NotificationLevel\n ): Promise<void> {\n await this._services.commandExecutor.mutateResource<EditNotificationLevelRequest>(\n \"post\",\n `${this._configuration.links.myConversations}/${this.sid}`,\n {\n notification_level: notificationLevel,\n }\n );\n }\n\n /**\n * Send a notification to the server indicating that this client is currently\n * typing in this conversation. Typing ended notification is sent after a\n * while automatically, but by calling this method again you ensure that\n * typing ended is not received.\n */\n public typing(): Promise<void> {\n return this._services.typingIndicator.send(this.sid);\n }\n\n /**\n * Update the attributes of the conversation.\n * @param attributes New attributes.\n */\n @validateTypesAsync(attributesValidator)\n public async updateAttributes(attributes: JSONValue): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n attributes:\n attributes !== undefined ? JSON.stringify(attributes) : undefined,\n });\n\n return this;\n }\n\n /**\n * Update the friendly name of the conversation.\n * @param friendlyName New friendly name.\n */\n @validateTypesAsync(\"string\")\n public async updateFriendlyName(friendlyName: string): Promise<Conversation> {\n if (this._internalState.friendlyName !== friendlyName) {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, { friendly_name: friendlyName });\n }\n\n return this;\n }\n\n /**\n * Set the last read message index to the current read horizon.\n * @param index Message index to set as last read. If null is provided, then\n * the behavior is identical to {@link Conversation.setAllMessagesUnread}.\n * @returns Resulting unread messages count in the conversation.\n */\n @validateTypesAsync([literal(null), nonNegativeInteger])\n public async updateLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n await this._subscribeStreams();\n return this._setLastReadMessageIndex(index);\n }\n\n /**\n * Update the unique name of the conversation.\n * @param uniqueName New unique name for the conversation. Setting unique name\n * to null removes it.\n */\n @validateTypesAsync([\"string\", literal(null)])\n public async updateUniqueName(\n uniqueName: string | null\n ): Promise<Conversation> {\n if (this._internalState.uniqueName !== uniqueName) {\n uniqueName ||= \"\";\n\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n unique_name: uniqueName,\n });\n }\n\n return this;\n }\n\n /**\n * Load and subscribe to this conversation and do not subscribe to its\n * participants and messages. This or _subscribeStreams will need to be called\n * before any events on conversation will fire.\n * @internal\n */\n public async _subscribe(): Promise<SyncDocument> {\n if (this._entityPromise) {\n return this._entityPromise;\n }\n\n this._entityPromise = this._services.syncClient.document({\n id: this._entityName,\n mode: \"open_existing\",\n });\n\n try {\n this._entity = await this._entityPromise;\n this._entity.on(\"updated\", (args) => this._update(args.data));\n this._entity.on(\"removed\", () => this.emit(\"removed\", this));\n this._update(this._entity.data);\n\n return this._entity;\n } catch (err) {\n this._entity = null;\n this._entityPromise = null;\n\n if (this._services.syncClient.connectionState != \"disconnected\") {\n Conversation._logger.error(\"Failed to get conversation object\", err);\n }\n Conversation._logger.debug(\n \"ERROR: Failed to get conversation object\",\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Load the attributes of this conversation and instantiate its participants\n * and messages. This or _subscribe will need to be called before any events\n * on the conversation will fire. This will need to be called before any\n * events on participants or messages will fire\n * @internal\n */\n public async _subscribeStreams() {\n try {\n await this._subscribe();\n Conversation._logger.trace(\n \"_subscribeStreams, this.entity.data=\",\n this._entity?.data\n );\n\n const data = this._entity?.data as Record<string, string>;\n const messagesObjectName = data.messages;\n const rosterObjectName = data.roster;\n\n await Promise.all([\n this._messagesEntity.subscribe(messagesObjectName),\n this._participantsEntity.subscribe(rosterObjectName),\n ]);\n } catch (err) {\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n Conversation._logger.error(\n \"Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n }\n Conversation._logger.debug(\n \"ERROR: Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Stop listening for and firing events on this conversation.\n * @internal\n */\n public async _unsubscribe() {\n if (this._entity) {\n await this._entity.close();\n this._entity = null;\n this._entityPromise = null;\n }\n\n return Promise.all([\n this._participantsEntity.unsubscribe(),\n this._messagesEntity.unsubscribe(),\n ]);\n }\n\n /**\n * Set conversation status.\n * @internal\n */\n public _setStatus(\n status: ConversationStatus,\n source: ConversationsDataSource\n ) {\n this._dataSource = source;\n\n if (this._internalState.status === status) {\n return;\n }\n\n this._internalState.status = status;\n\n if (status === \"joined\") {\n this._subscribeStreams().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n return;\n }\n\n if (this._entityPromise) {\n this._unsubscribe().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n }\n }\n\n /**\n * Update the local conversation object with new values.\n * @internal\n */\n public _update(update) {\n Conversation._logger.trace(\"_update\", update);\n\n Conversation.preprocessUpdate(update, this.sid);\n const updateReasons = new Set<ConversationUpdateReason>();\n\n for (const key of Object.keys(update)) {\n const localKey = fieldMappings[key];\n\n if (!localKey) {\n continue;\n }\n\n switch (localKey) {\n case fieldMappings.status:\n if (\n !update.status ||\n update.status === \"unknown\" ||\n this._internalState.status === update.status\n ) {\n break;\n }\n\n this._internalState.status = update.status;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.attributes:\n if (isEqual(this._internalState.attributes, update.attributes)) {\n break;\n }\n\n this._internalState.attributes = update.attributes;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.lastConsumedMessageIndex:\n if (\n update.lastConsumedMessageIndex === undefined ||\n update.lastConsumedMessageIndex ===\n this._internalState.lastReadMessageIndex\n ) {\n break;\n }\n\n this._internalState.lastReadMessageIndex =\n update.lastConsumedMessageIndex;\n updateReasons.add(\"lastReadMessageIndex\");\n\n break;\n case fieldMappings.lastMessage:\n if (this._internalState.lastMessage && !update.lastMessage) {\n delete this._internalState.lastMessage;\n updateReasons.add(localKey);\n\n break;\n }\n\n this._internalState.lastMessage =\n this._internalState.lastMessage || {};\n\n if (\n update.lastMessage?.index !== undefined &&\n update.lastMessage.index !== this._internalState.lastMessage.index\n ) {\n this._internalState.lastMessage.index = update.lastMessage.index;\n updateReasons.add(localKey);\n }\n\n if (\n update.lastMessage?.timestamp !== undefined &&\n this._internalState.lastMessage?.dateCreated?.getTime() !==\n update.lastMessage.timestamp.getTime()\n ) {\n this._internalState.lastMessage.dateCreated =\n update.lastMessage.timestamp;\n updateReasons.add(localKey);\n }\n\n if (isEqual(this._internalState.lastMessage, {})) {\n delete this._internalState.lastMessage;\n }\n\n break;\n case fieldMappings.state:\n const state = update.state || undefined;\n\n if (state !== undefined) {\n state.dateUpdated = new Date(state.dateUpdated);\n }\n\n if (isEqual(this._internalState.state, state)) {\n break;\n }\n\n this._internalState.state = state;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.bindings:\n if (isEqual(this._internalState.bindings, update.bindings)) {\n break;\n }\n\n this._internalState.bindings = update.bindings;\n updateReasons.add(localKey);\n\n break;\n default:\n const isDate = update[key] instanceof Date;\n const keysMatchAsDates =\n isDate &&\n this._internalState[localKey]?.getTime() === update[key].getTime();\n const keysMatchAsNonDates = !isDate && this[localKey] === update[key];\n\n if (keysMatchAsDates || keysMatchAsNonDates) {\n break;\n }\n\n this._internalState[localKey] = update[key];\n updateReasons.add(localKey);\n }\n }\n\n if (updateReasons.size > 0) {\n this.emit(\"updated\", {\n conversation: this,\n updateReasons: [...updateReasons],\n });\n }\n }\n\n /**\n * Handle onMessageAdded event.\n */\n private _onMessageAdded(message) {\n for (const participant of this._participants.values()) {\n if (participant.identity === message.author) {\n participant._endTyping();\n break;\n }\n }\n this.emit(\"messageAdded\", message);\n }\n\n /**\n * Set last read message index.\n * @param index New index to set.\n */\n private async _setLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n const result = await this._services.commandExecutor.mutateResource<\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse\n >(\"post\", `${this._configuration.links.myConversations}/${this.sid}`, {\n last_read_message_index: index,\n });\n\n return result.unread_messages_count;\n }\n}\n\nexport {\n ConversationDescriptor,\n Conversation,\n ConversationServices,\n ConversationUpdateReason,\n ConversationStatus,\n NotificationLevel,\n ConversationState,\n ConversationUpdatedEventArgs,\n SendMediaOptions,\n SendEmailOptions,\n LastMessage,\n ConversationBindings,\n ConversationEmailBinding,\n};\n"],"names":["ReplayEventEmitter","parseTime","Participants","Messages","UriBuilder","parseToNumber","MessageBuilder","isEqual","Logger","__decorate","validateTypesAsync","nonEmptyString","optionalAttributesValidator","nonNegativeInteger","literal","Participant","objectSchema","custom","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;;;;4DAW/C;AAiBDL;IADCC,2CAAkB,CAACQ,8BAAmB,CAAC;;;;oDAWvC;AAODT;IADCC,2CAAkB,CAAC,QAAQ,CAAC;;;;sDAU5B;AASDD;IADCC,2CAAkB,CAAC,CAACI,gCAAO,CAAC,IAAI,CAAC,EAAED,2CAAkB,CAAC,CAAC;;;;8DAMvD;AAQDJ;IADCC,2CAAkB,CAAC,CAAC,QAAQ,EAAEI,gCAAO,CAAC,IAAI,CAAC,CAAC,CAAC;;;;oDAgB7C;;;;"}
1
+ {"version":3,"file":"conversation.js","sources":["../src/conversation.ts"],"sourcesContent":["import \"isomorphic-form-data\";\nimport { Logger } from \"./logger\";\nimport { ParticipantBindingOptions, Participants } from \"./data/participants\";\nimport {\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason,\n} from \"./participant\";\nimport { Messages } from \"./data/messages\";\nimport {\n Message,\n MessageType,\n MessageUpdatedEventArgs,\n MessageUpdateReason,\n} from \"./message\";\nimport { UriBuilder, parseTime } from \"./util\";\nimport { Users } from \"./data/users\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { ConversationsDataSource } from \"./data/conversations\";\nimport { McsClient } from \"@twilio/mcs-client\";\nimport { SyncClient, SyncDocument, SyncList, SyncMap } from \"twilio-sync\";\nimport { TypingIndicator } from \"./services/typing-indicator\";\nimport { Network } from \"./services/network\";\nimport {\n validateTypesAsync,\n custom,\n literal,\n nonEmptyString,\n nonNegativeInteger,\n objectSchema,\n} from \"@twilio/declarative-type-validator\";\nimport {\n attributesValidator,\n optionalAttributesValidator,\n} from \"./interfaces/attributes\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { AddParticipantRequest } from \"./interfaces/commands/add-participant\";\nimport { EditConversationRequest } from \"./interfaces/commands/edit-conversation\";\nimport { ConversationResponse } from \"./interfaces/commands/conversation-response\";\nimport { ParticipantResponse } from \"./interfaces/commands/participant-response\";\nimport { EditNotificationLevelRequest } from \"./interfaces/commands/edit-notification-level\";\nimport {\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse,\n} from \"./interfaces/commands/edit-last-read-message-index\";\nimport { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { MessageBuilder } from \"./message-builder\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"@twilio/shared\";\nimport { MediaCategory } from \"./media\";\nimport { MessageResponse } from \"./interfaces/commands/message-response\";\n\n/**\n * Conversation events.\n */\ntype ConversationEvents = {\n participantJoined: (participant: Participant) => void;\n participantLeft: (participant: Participant) => void;\n participantUpdated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n }) => void;\n removed: (conversation: Conversation) => void;\n};\n\n/**\n * Reason for the `updated` event emission by a conversation.\n */\ntype ConversationUpdateReason =\n | \"attributes\"\n | \"createdBy\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"friendlyName\"\n | \"lastReadMessageIndex\"\n | \"state\"\n | \"status\"\n | \"uniqueName\"\n | \"lastMessage\"\n | \"notificationLevel\"\n | \"bindings\";\n\n/**\n * Status of the conversation, relative to the client: whether the conversation\n * has been `joined` or the client is `notParticipating` in the conversation.\n */\ntype ConversationStatus = \"notParticipating\" | \"joined\";\n\n/**\n * User's notification level for the conversation. Determines\n * whether the currently logged-in user will receive pushes for events\n * in this conversation. Can be either `muted` or `default`, where\n * `default` defers to the global service push configuration.\n */\ntype NotificationLevel = \"default\" | \"muted\";\n\n/**\n * State of the conversation.\n */\ninterface ConversationState {\n /**\n * Current state.\n */\n current: \"active\" | \"inactive\" | \"closed\";\n\n /**\n * Date at which the latest conversation state update happened.\n */\n dateUpdated: Date;\n}\n\n/**\n * Event arguments for the `updated` event.\n */\ninterface ConversationUpdatedEventArgs {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationBindings {\n email?: ConversationEmailBinding;\n sms?: ConversationSmsBinding;\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationEmailBinding {\n name?: string;\n projected_address: string;\n}\n\n/**\n * Binding for SMS conversation.\n */\ninterface ConversationSmsBinding {\n address?: string;\n}\n\n/**\n * Configuration for attaching a media file to a message.\n * These options can be passed to {@link Conversation.sendMessage} and\n * {@link MessageBuilder.addMedia}.\n */\ninterface SendMediaOptions {\n /**\n * Content type of media.\n */\n contentType: null | string;\n\n /**\n * Optional filename.\n */\n filename?: string;\n\n /**\n * Content to post.\n */\n media: null | string | Buffer | Blob;\n}\n\n/**\n * These options can be passed to {@link Conversation.sendMessage}.\n */\ninterface SendEmailOptions {\n /**\n * Message subject. Ignored for media messages.\n */\n subject?: string;\n}\n\n/**\n * Information about the last message of a conversation.\n */\ninterface LastMessage {\n /**\n * Message's index.\n */\n index?: number;\n\n /**\n * Message's creation date.\n */\n dateCreated?: Date;\n}\n\n/**\n * Conversation services.\n */\ninterface ConversationServices {\n users: Users;\n typingIndicator: TypingIndicator;\n network: Network;\n mcsClient: McsClient;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Internal (private) state of the conversation.\n */\ninterface ConversationInternalState {\n uniqueName: string | null;\n status: ConversationStatus;\n attributes: JSONValue;\n createdBy?: string;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n friendlyName: string | null;\n lastReadMessageIndex: number | null;\n lastMessage?: LastMessage;\n notificationLevel?: NotificationLevel;\n state?: ConversationState;\n bindings: ConversationBindings;\n}\n\n/**\n * Conversation descriptor.\n */\ninterface ConversationDescriptor {\n channel: string;\n entityName: string;\n uniqueName: string;\n attributes: JSONValue;\n createdBy?: string;\n friendlyName?: string;\n lastConsumedMessageIndex: number;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n notificationLevel?: NotificationLevel;\n bindings?: ConversationBindings;\n}\n\n/**\n * Conversation links.\n */\ninterface ConversationLinks {\n self: string;\n messages: string;\n participants: string;\n}\n\n/**\n * Map of the fields that will be processed with update messages.\n */\nconst fieldMappings = {\n lastMessage: \"lastMessage\",\n attributes: \"attributes\",\n createdBy: \"createdBy\",\n dateCreated: \"dateCreated\",\n dateUpdated: \"dateUpdated\",\n friendlyName: \"friendlyName\",\n lastConsumedMessageIndex: \"lastConsumedMessageIndex\",\n notificationLevel: \"notificationLevel\",\n sid: \"sid\",\n status: \"status\",\n uniqueName: \"uniqueName\",\n state: \"state\",\n bindings: \"bindings\",\n};\n\n/**\n * A conversation represents communication between multiple Conversations\n * clients.\n */\nclass Conversation extends ReplayEventEmitter<ConversationEvents> {\n /**\n * Fired when a participant has joined the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that joined the\n * conversation\n * @event\n */\n public static readonly participantJoined = \"participantJoined\";\n\n /**\n * Fired when a participant has left the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that left the\n * conversation\n * @event\n */\n public static readonly participantLeft = \"participantLeft\";\n\n /**\n * Fired when data of a participant has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Participant} `participant` - participant that has received the\n * update\n * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly participantUpdated = \"participantUpdated\";\n\n /**\n * Fired when a new message has been added to the conversation.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been added\n * @event\n */\n public static readonly messageAdded = \"messageAdded\";\n\n /**\n * Fired when message is removed from the conversation's message list.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been removed\n * @event\n */\n public static readonly messageRemoved = \"messageRemoved\";\n\n /**\n * Fired when data of a message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Message} `message` - message that has received the update\n * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for\n * the update\n * @event\n */\n public static readonly messageUpdated = \"messageUpdated\";\n\n /**\n * Fired when a participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has stopped\n * typing\n * @event\n */\n public static readonly typingEnded = \"typingEnded\";\n\n /**\n * Fired when a participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has started\n * typing\n * @event\n */\n public static readonly typingStarted = \"typingStarted\";\n\n /**\n * Fired when the data of the conversation has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Conversation} `conversation` - conversation that has received\n * the update\n * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly updated = \"updated\";\n\n /**\n * Fired when the conversation was destroyed or the currently-logged-in user\n * has left private conversation.\n *\n * Parameters:\n * 1. {@link Conversation} `conversation` - conversation that has been removed\n * @event\n */\n public static readonly removed = \"removed\";\n\n /**\n * Logger instance.\n */\n private static readonly _logger = Logger.scope(\"Conversation\");\n\n /**\n * Unique system identifier of the conversation.\n */\n public readonly sid: string;\n\n /**\n * Conversation links for REST requests.\n * @internal\n */\n public readonly _links: ConversationLinks;\n\n /**\n * Map of participants.\n * @internal\n */\n public readonly _participants: Map<string, Participant>;\n\n /**\n * Configuration of the client that the conversation belongs to.\n */\n private readonly _configuration: Configuration;\n\n /**\n * Conversation service objects.\n */\n private readonly _services: ConversationServices;\n\n /**\n * Internal state of the conversation.\n */\n private readonly _internalState: ConversationInternalState;\n\n /**\n * Name of the conversation entity document.\n */\n private readonly _entityName: string;\n\n /**\n * Messages entity.\n */\n private readonly _messagesEntity: Messages;\n\n /**\n * Sync list containing messages.\n */\n private _messagesList?: SyncList;\n\n /**\n * Participants entity.\n */\n private readonly _participantsEntity: Participants;\n\n /**\n * Sync map containing participants.\n */\n private _participantsMap?: SyncMap;\n\n /**\n * Source of the most recent update.\n */\n private _dataSource!: ConversationsDataSource;\n\n /**\n * Promise for the conversation entity document.\n */\n private _entityPromise!: Promise<SyncDocument> | null;\n\n /**\n * Conversation entity document.\n */\n private _entity!: SyncDocument | null;\n\n /**\n * @param descriptor Conversation descriptor.\n * @param sid Conversation SID.\n * @param links Conversation links for REST requests.\n * @param configuration Client configuration.\n * @param services Conversation services.\n * @internal\n */\n public constructor(\n descriptor: ConversationDescriptor,\n sid: string,\n links: ConversationLinks,\n configuration: Configuration,\n services: ConversationServices\n ) {\n super();\n\n this.sid = sid;\n this._links = links;\n this._configuration = configuration;\n this._services = services;\n this._entityName = descriptor.channel;\n this._internalState = {\n uniqueName: descriptor.uniqueName || null,\n status: \"notParticipating\",\n attributes: descriptor.attributes ?? {},\n createdBy: descriptor.createdBy,\n dateCreated: parseTime(descriptor.dateCreated),\n dateUpdated: parseTime(descriptor.dateUpdated),\n friendlyName: descriptor.friendlyName || null,\n lastReadMessageIndex: Number.isInteger(\n descriptor.lastConsumedMessageIndex\n )\n ? descriptor.lastConsumedMessageIndex\n : null,\n bindings: descriptor.bindings ?? {},\n };\n\n if (descriptor.notificationLevel) {\n this._internalState.notificationLevel = descriptor.notificationLevel;\n }\n\n const participantsLinks = {\n participants: this._links.participants,\n };\n\n this._participants = new Map();\n this._participantsEntity = new Participants(\n this,\n this._participants,\n participantsLinks,\n this._configuration,\n this._services\n );\n this._participantsEntity.on(\"participantJoined\", (participant) =>\n this.emit(\"participantJoined\", participant)\n );\n this._participantsEntity.on(\"participantLeft\", (participant) =>\n this.emit(\"participantLeft\", participant)\n );\n this._participantsEntity.on(\n \"participantUpdated\",\n (args: ParticipantUpdatedEventArgs) =>\n this.emit(\"participantUpdated\", args)\n );\n\n this._messagesEntity = new Messages(this, configuration, services);\n this._messagesEntity.on(\"messageAdded\", (message) =>\n this._onMessageAdded(message)\n );\n this._messagesEntity.on(\"messageUpdated\", (args: MessageUpdatedEventArgs) =>\n this.emit(\"messageUpdated\", args)\n );\n this._messagesEntity.on(\"messageRemoved\", (message) =>\n this.emit(\"messageRemoved\", message)\n );\n }\n\n /**\n * Unique name of the conversation.\n */\n public get uniqueName(): string | null {\n return this._internalState.uniqueName;\n }\n\n /**\n * Status of the conversation.\n */\n public get status(): ConversationStatus {\n return this._internalState.status;\n }\n\n /**\n * Name of the conversation.\n */\n public get friendlyName(): string | null {\n return this._internalState.friendlyName;\n }\n\n /**\n * Date this conversation was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this._internalState.dateUpdated;\n }\n\n /**\n * Date this conversation was created on.\n */\n public get dateCreated(): Date | null {\n return this._internalState.dateCreated;\n }\n\n /**\n * Identity of the user that created this conversation.\n */\n public get createdBy(): string {\n return this._internalState.createdBy ?? \"\";\n }\n\n /**\n * Custom attributes of the conversation.\n */\n public get attributes(): JSONValue {\n return this._internalState.attributes;\n }\n\n /**\n * Index of the last message the user has read in this conversation.\n */\n public get lastReadMessageIndex(): number | null {\n return this._internalState.lastReadMessageIndex;\n }\n\n /**\n * Last message sent to this conversation.\n */\n public get lastMessage(): LastMessage | undefined {\n return this._internalState.lastMessage ?? undefined;\n }\n\n /**\n * User notification level for this conversation.\n */\n public get notificationLevel(): NotificationLevel {\n return this._internalState.notificationLevel ?? \"default\";\n }\n\n /**\n * Conversation bindings. Undocumented feature (for now).\n * @internal\n */\n public get bindings(): ConversationBindings {\n return this._internalState.bindings;\n }\n\n /**\n * Current conversation limits.\n */\n public get limits(): ConversationLimits {\n return this._configuration.limits;\n }\n\n /**\n * State of the conversation.\n */\n public get state(): ConversationState | undefined {\n return this._internalState.state;\n }\n\n /**\n * Source of the conversation update.\n * @internal\n */\n public get _statusSource(): ConversationsDataSource {\n return this._dataSource;\n }\n\n /**\n * Preprocess the update object.\n * @param update The update object received from Sync.\n * @param conversationSid The SID of the conversation in question.\n */\n private static preprocessUpdate(update, conversationSid: string) {\n try {\n if (typeof update.attributes === \"string\") {\n update.attributes = JSON.parse(update.attributes);\n } else if (update.attributes) {\n JSON.stringify(update.attributes);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed attributes from the server for conversation: \" +\n conversationSid\n );\n update.attributes = {};\n }\n\n try {\n if (update.dateCreated) {\n update.dateCreated = new Date(update.dateCreated);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateCreated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateCreated;\n }\n\n try {\n if (update.dateUpdated) {\n update.dateUpdated = new Date(update.dateUpdated);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateUpdated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateUpdated;\n }\n\n try {\n if (update.lastMessage && update.lastMessage.timestamp) {\n update.lastMessage.timestamp = new Date(update.lastMessage.timestamp);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed lastMessage.timestamp from the server for conversation: \" +\n conversationSid\n );\n delete update.lastMessage.timestamp;\n }\n }\n\n /**\n * Add a participant to the conversation by its identity.\n * @param identity Identity of the Client to add.\n * @param attributes Attributes to be attached to the participant.\n * @returns The added participant.\n */\n @validateTypesAsync(nonEmptyString, optionalAttributesValidator)\n public async add(\n identity: string,\n attributes?: JSONValue\n ): Promise<Participant> {\n return this._participantsEntity.add(identity, attributes ?? {});\n }\n\n /**\n * Add a non-chat participant to the conversation.\n * @param proxyAddress Proxy (Twilio) address of the participant.\n * @param address User address of the participant.\n * @param attributes Attributes to be attached to the participant.\n * @param bindingOptions Options for adding email participants - name and\n * CC/To level.\n * @returns The added participant.\n */\n @validateTypesAsync(\n nonEmptyString,\n nonEmptyString,\n optionalAttributesValidator\n )\n public async addNonChatParticipant(\n proxyAddress: string,\n address: string,\n attributes: JSONValue = {},\n bindingOptions: ParticipantBindingOptions = {}\n ): Promise<Participant> {\n return this._participantsEntity.addNonChatParticipant(\n proxyAddress,\n address,\n attributes ?? {},\n bindingOptions ?? {}\n );\n }\n\n /**\n * Advance the conversation's last read message index to the current read\n * horizon. Rejects if the user is not a participant of the conversation. Last\n * read message index is updated only if the new index value is higher than\n * the previous.\n * @param index Message index to advance to.\n * @return Resulting unread messages count in the conversation.\n */\n @validateTypesAsync(nonNegativeInteger)\n public async advanceLastReadMessageIndex(index: number): Promise<number> {\n await this._subscribeStreams();\n\n if (index < (this.lastReadMessageIndex ?? 0)) {\n return await this._setLastReadMessageIndex(this.lastReadMessageIndex);\n }\n\n return await this._setLastReadMessageIndex(index);\n }\n\n /**\n * Delete the conversation and unsubscribe from its events.\n */\n public async delete(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n this._links.self\n );\n\n return this;\n }\n\n /**\n * Get the custom attributes of this Conversation.\n */\n public async getAttributes(): Promise<JSONValue> {\n await this._subscribe();\n return this.attributes;\n }\n\n /**\n * Returns messages from the conversation using the paginator interface.\n * @param pageSize Number of messages to return in a single chunk. Default is\n * 30.\n * @param anchor Index of the newest message to fetch. Default is from the\n * end.\n * @param direction Query direction. By default, it queries backwards\n * from newer to older. The `\"forward\"` value will query in the opposite\n * direction.\n * @return A page of messages.\n */\n @validateTypesAsync(\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", literal(\"backwards\", \"forward\")]\n )\n public async getMessages(\n pageSize?: number,\n anchor?: number,\n direction?: \"backwards\" | \"forward\"\n ): Promise<Paginator<Message>> {\n await this._subscribeStreams();\n return this._messagesEntity.getMessages(pageSize, anchor, direction);\n }\n\n /**\n * Get a list of all the participants who are joined to this conversation.\n */\n public async getParticipants(): Promise<Participant[]> {\n await this._subscribeStreams();\n return this._participantsEntity.getParticipants();\n }\n\n /**\n * Get conversation participants count.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getParticipantsCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n // todo: remove any after the release of new Twilsock\n const response: any =\n await this._services.network.get<ConversationResponse>(url);\n\n return response.body.participants_count ?? 0;\n }\n\n /**\n * Get a participant by its SID.\n * @param participantSid Participant SID.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantBySid(\n participantSid: string\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantBySid(participantSid);\n }\n\n /**\n * Get a participant by its identity.\n * @param identity Participant identity.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantByIdentity(\n identity: string | null = \"\"\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantByIdentity(identity ?? \"\");\n }\n\n /**\n * Get the total message count in the conversation.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getMessagesCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n // todo: remove any after the release of new Twilsock\n const response: any =\n await this._services.network.get<ConversationResponse>(url);\n\n return response.body.messages_count ?? 0;\n }\n\n /**\n * Get count of unread messages for the user if they are a participant of this\n * conversation. Rejects if the user is not a participant of the conversation.\n *\n * Use this method to obtain the number of unread messages together with\n * {@link Conversation.updateLastReadMessageIndex} instead of relying on the\n * message indices which may have gaps. See {@link Message.index} for details.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but it will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n *\n * If the read horizon is not set, this function will return null. This could mean\n * that all messages in the conversation are unread, or that the read horizon system\n * is not being used. How to interpret this `null` value is up to the customer application.\n *\n * @return Number of unread messages based on the current read horizon set for\n * the user or `null` if the read horizon is not set.\n */\n public async getUnreadMessagesCount(): Promise<number | null> {\n const url = new UriBuilder(this._configuration.links.myConversations)\n .path(this.sid)\n .build();\n // todo: remove any after the release of new Twilsock\n const response: any =\n await this._services.network.get<ConversationResponse>(url);\n\n if (response.body.conversation_sid !== this.sid) {\n throw new Error(\n \"Conversation was not found in the user conversations list\"\n );\n }\n\n const unreadMessageCount = response.body.unread_messages_count;\n\n if (typeof unreadMessageCount === \"number\") {\n return unreadMessageCount;\n }\n\n return null;\n }\n\n /**\n * Join the conversation and subscribe to its events.\n */\n public async join(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n AddParticipantRequest,\n ParticipantResponse\n >(\"post\", this._links.participants, {\n identity: this._configuration.userIdentity,\n });\n\n return this;\n }\n\n /**\n * Leave the conversation.\n */\n public async leave(): Promise<Conversation> {\n if (this._internalState.status === \"joined\") {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n `${this._links.participants}/${this._configuration.userIdentity}`\n );\n }\n\n return this;\n }\n\n /**\n * Remove a participant from the conversation. When a string is passed as the\n * argument, it will assume that the string is an identity or SID.\n * @param participant Identity, SID or the participant object to remove.\n */\n @validateTypesAsync([nonEmptyString, Participant])\n public async removeParticipant(\n participant: string | Participant\n ): Promise<void> {\n await this._participantsEntity.remove(\n typeof participant === \"string\" ? participant : participant.sid\n );\n }\n\n /**\n * Send a message to the conversation.\n * @param message Message body for the text message,\n * `FormData` or {@link SendMediaOptions} for media content. Sending FormData\n * is supported only with the browser engine.\n * @param messageAttributes Attributes for the message.\n * @param emailOptions Email options for the message.\n * @return Index of the new message.\n */\n @validateTypesAsync(\n [\n \"string\",\n FormData,\n literal(null),\n objectSchema(\"media options\", {\n contentType: nonEmptyString,\n media: custom((value) => {\n let isValid =\n (typeof value === \"string\" && value.length > 0) ||\n value instanceof Uint8Array ||\n value instanceof ArrayBuffer;\n\n if (typeof Blob === \"function\") {\n isValid = isValid || value instanceof Blob;\n }\n\n return [\n isValid,\n \"a non-empty string, an instance of Buffer or an instance of Blob\",\n ];\n }),\n }),\n ],\n optionalAttributesValidator,\n [\n \"undefined\",\n literal(null),\n objectSchema(\"email attributes\", {\n subject: [nonEmptyString, \"undefined\"],\n }),\n ]\n )\n public async sendMessage(\n message: null | string | FormData | SendMediaOptions,\n messageAttributes?: JSONValue,\n emailOptions?: SendEmailOptions\n ): Promise<Message> {\n const response: MessageResponse =\n typeof message === \"string\" || message === null\n ? await this._messagesEntity.send(\n message,\n messageAttributes,\n emailOptions\n )\n : await this._messagesEntity.sendMedia(\n message,\n messageAttributes,\n emailOptions\n );\n const type: MessageType =\n typeof message === \"string\" || message === null ? \"text\" : \"media\";\n\n let responseAttributes;\n try {\n responseAttributes = JSON.parse(response.attributes);\n } catch (e) {}\n\n const messageData = {\n sid: response.sid,\n text: response.body,\n type,\n author: response.author,\n subject: response.subject,\n lastUpdatedBy: response.participant_sid,\n attributes: responseAttributes,\n dateUpdated: response.date_updated,\n timestamp: response.date_created,\n memberSid: response.participant_sid,\n medias: Array.isArray(response.media)\n ? response.media.map((media) => ({\n sid: media[\"sid\"],\n size: Number(media[\"size\"]),\n category: media[\"category\"] as MediaCategory,\n filename: media[\"filename\"],\n contentType: media[\"content_type\"],\n }))\n : null,\n media:\n response.media &&\n typeof response.media === \"object\" &&\n !Array.isArray(response.media)\n ? {\n sid: response.media[\"sid\"],\n size: Number(response.media[\"size\"]),\n category: response.media[\"category\"] as MediaCategory,\n filename: response.media[\"filename\"],\n contentType: response.media[\"content_type\"],\n }\n : null,\n };\n\n return this._messagesEntity._upsertMessage(response.index, messageData);\n }\n\n /**\n * New interface to prepare for sending a message.\n * Use this instead of {@link Message.sendMessage}.\n * @return A MessageBuilder to help set all message sending options.\n */\n public prepareMessage(): MessageBuilder {\n return new MessageBuilder(this.limits, this._messagesEntity);\n }\n\n /**\n * Set last read message index of the conversation to the index of the last\n * known message.\n * @return Resulting unread messages count in the conversation.\n */\n public async setAllMessagesRead(): Promise<number> {\n await this._subscribeStreams();\n\n const messagesPage = await this.getMessages(1);\n\n if (messagesPage.items.length > 0) {\n return this.advanceLastReadMessageIndex(messagesPage.items[0].index);\n }\n\n return 0;\n }\n\n /**\n * Set all messages in the conversation unread.\n * @returns New count of unread messages after this update.\n */\n public async setAllMessagesUnread(): Promise<number> {\n await this._subscribeStreams();\n return await this._setLastReadMessageIndex(null);\n }\n\n /**\n * Set user notification level for this conversation.\n * @param notificationLevel New user notification level.\n */\n @validateTypesAsync(literal(\"default\", \"muted\"))\n public async setUserNotificationLevel(\n notificationLevel: NotificationLevel\n ): Promise<void> {\n await this._services.commandExecutor.mutateResource<EditNotificationLevelRequest>(\n \"post\",\n `${this._configuration.links.myConversations}/${this.sid}`,\n {\n notification_level: notificationLevel,\n }\n );\n }\n\n /**\n * Send a notification to the server indicating that this client is currently\n * typing in this conversation. Typing ended notification is sent after a\n * while automatically, but by calling this method again you ensure that\n * typing ended is not received.\n */\n public typing(): Promise<void> {\n return this._services.typingIndicator.send(this.sid);\n }\n\n /**\n * Update the attributes of the conversation.\n * @param attributes New attributes.\n */\n @validateTypesAsync(attributesValidator)\n public async updateAttributes(attributes: JSONValue): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n attributes:\n attributes !== undefined ? JSON.stringify(attributes) : undefined,\n });\n\n return this;\n }\n\n /**\n * Update the friendly name of the conversation.\n * @param friendlyName New friendly name.\n */\n @validateTypesAsync(\"string\")\n public async updateFriendlyName(friendlyName: string): Promise<Conversation> {\n if (this._internalState.friendlyName !== friendlyName) {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, { friendly_name: friendlyName });\n }\n\n return this;\n }\n\n /**\n * Set the last read message index to the current read horizon.\n * @param index Message index to set as last read. If null is provided, then\n * the behavior is identical to {@link Conversation.setAllMessagesUnread}.\n * @returns New count of unread messages after this update.\n */\n @validateTypesAsync([literal(null), nonNegativeInteger])\n public async updateLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n await this._subscribeStreams();\n return this._setLastReadMessageIndex(index);\n }\n\n /**\n * Update the unique name of the conversation.\n * @param uniqueName New unique name for the conversation. Setting unique name\n * to null removes it.\n */\n @validateTypesAsync([\"string\", literal(null)])\n public async updateUniqueName(\n uniqueName: string | null\n ): Promise<Conversation> {\n if (this._internalState.uniqueName !== uniqueName) {\n uniqueName ||= \"\";\n\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n unique_name: uniqueName,\n });\n }\n\n return this;\n }\n\n /**\n * Load and subscribe to this conversation and do not subscribe to its\n * participants and messages. This or _subscribeStreams will need to be called\n * before any events on conversation will fire.\n * @internal\n */\n public async _subscribe(): Promise<SyncDocument> {\n if (this._entityPromise) {\n return this._entityPromise;\n }\n\n this._entityPromise = this._services.syncClient.document({\n id: this._entityName,\n mode: \"open_existing\",\n });\n\n try {\n this._entity = await this._entityPromise;\n this._entity.on(\"updated\", (args) => this._update(args.data));\n this._entity.on(\"removed\", () => this.emit(\"removed\", this));\n this._update(this._entity.data);\n\n return this._entity;\n } catch (err) {\n this._entity = null;\n this._entityPromise = null;\n\n if (this._services.syncClient.connectionState != \"disconnected\") {\n Conversation._logger.error(\"Failed to get conversation object\", err);\n }\n Conversation._logger.debug(\n \"ERROR: Failed to get conversation object\",\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Fetch participants and messages of the conversation. This method needs to\n * be called during conversation initialization to catch broken conversations\n * (broken conversations are conversations that have essential Sync entities\n * missing, i.e. the conversation document, the messages list or the\n * participant map). In case of this conversation being broken, the method\n * will throw an exception that will be caught and handled gracefully.\n * @internal\n */\n public async _fetchStreams() {\n await this._subscribe();\n Conversation._logger.trace(\n \"_streamsAvailable, this.entity.data=\",\n this._entity?.data\n );\n\n const data = this._entity?.data as Record<string, string>;\n this._messagesList = await this._services.syncClient.list({\n id: data.messages,\n mode: \"open_existing\",\n });\n this._participantsMap = await this._services.syncClient.map({\n id: data.roster,\n mode: \"open_existing\",\n });\n }\n\n /**\n * Load the attributes of this conversation and instantiate its participants\n * and messages. This or _subscribe will need to be called before any events\n * on the conversation will fire. This will need to be called before any\n * events on participants or messages will fire\n * @internal\n */\n public async _subscribeStreams() {\n try {\n await this._subscribe();\n Conversation._logger.trace(\n \"_subscribeStreams, this.entity.data=\",\n this._entity?.data\n );\n\n const data = this._entity?.data as Record<string, string>;\n const messagesObjectName = data.messages;\n const rosterObjectName = data.roster;\n\n await Promise.all([\n this._messagesEntity.subscribe(\n this._messagesList ?? messagesObjectName\n ),\n this._participantsEntity.subscribe(\n this._participantsMap ?? rosterObjectName\n ),\n ]);\n } catch (err) {\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n Conversation._logger.error(\n \"Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n }\n Conversation._logger.debug(\n \"ERROR: Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Stop listening for and firing events on this conversation.\n * @internal\n */\n public async _unsubscribe() {\n if (this._entity) {\n await this._entity.close();\n this._entity = null;\n this._entityPromise = null;\n }\n\n return Promise.all([\n this._participantsEntity.unsubscribe(),\n this._messagesEntity.unsubscribe(),\n ]);\n }\n\n /**\n * Set conversation status.\n * @internal\n */\n public _setStatus(\n status: ConversationStatus,\n source: ConversationsDataSource\n ) {\n this._dataSource = source;\n\n if (this._internalState.status === status) {\n return;\n }\n\n this._internalState.status = status;\n\n if (status === \"joined\") {\n this._subscribeStreams().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n return;\n }\n\n if (this._entityPromise) {\n this._unsubscribe().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n }\n }\n\n /**\n * Update the local conversation object with new values.\n * @internal\n */\n public _update(update) {\n Conversation._logger.trace(\"_update\", update);\n\n Conversation.preprocessUpdate(update, this.sid);\n const updateReasons = new Set<ConversationUpdateReason>();\n\n for (const key of Object.keys(update)) {\n const localKey = fieldMappings[key];\n\n if (!localKey) {\n continue;\n }\n\n switch (localKey) {\n case fieldMappings.status:\n if (\n !update.status ||\n update.status === \"unknown\" ||\n this._internalState.status === update.status\n ) {\n break;\n }\n\n this._internalState.status = update.status;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.attributes:\n if (isEqual(this._internalState.attributes, update.attributes)) {\n break;\n }\n\n this._internalState.attributes = update.attributes;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.lastConsumedMessageIndex:\n if (\n update.lastConsumedMessageIndex === undefined ||\n update.lastConsumedMessageIndex ===\n this._internalState.lastReadMessageIndex\n ) {\n break;\n }\n\n this._internalState.lastReadMessageIndex =\n update.lastConsumedMessageIndex;\n updateReasons.add(\"lastReadMessageIndex\");\n\n break;\n case fieldMappings.lastMessage:\n if (this._internalState.lastMessage && !update.lastMessage) {\n delete this._internalState.lastMessage;\n updateReasons.add(localKey);\n\n break;\n }\n\n this._internalState.lastMessage =\n this._internalState.lastMessage || {};\n\n if (\n update.lastMessage?.index !== undefined &&\n update.lastMessage.index !== this._internalState.lastMessage.index\n ) {\n this._internalState.lastMessage.index = update.lastMessage.index;\n updateReasons.add(localKey);\n }\n\n if (\n update.lastMessage?.timestamp !== undefined &&\n this._internalState.lastMessage?.dateCreated?.getTime() !==\n update.lastMessage.timestamp.getTime()\n ) {\n this._internalState.lastMessage.dateCreated =\n update.lastMessage.timestamp;\n updateReasons.add(localKey);\n }\n\n if (isEqual(this._internalState.lastMessage, {})) {\n delete this._internalState.lastMessage;\n }\n\n break;\n case fieldMappings.state:\n const state = update.state || undefined;\n\n if (state !== undefined) {\n state.dateUpdated = new Date(state.dateUpdated);\n }\n\n if (isEqual(this._internalState.state, state)) {\n break;\n }\n\n this._internalState.state = state;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.bindings:\n if (isEqual(this._internalState.bindings, update.bindings)) {\n break;\n }\n\n this._internalState.bindings = update.bindings;\n updateReasons.add(localKey);\n\n break;\n default:\n const isDate = update[key] instanceof Date;\n const keysMatchAsDates =\n isDate &&\n this._internalState[localKey]?.getTime() === update[key].getTime();\n const keysMatchAsNonDates = !isDate && this[localKey] === update[key];\n\n if (keysMatchAsDates || keysMatchAsNonDates) {\n break;\n }\n\n this._internalState[localKey] = update[key];\n updateReasons.add(localKey);\n }\n }\n\n if (updateReasons.size > 0) {\n this.emit(\"updated\", {\n conversation: this,\n updateReasons: [...updateReasons],\n });\n }\n }\n\n /**\n * Handle onMessageAdded event.\n */\n private _onMessageAdded(message) {\n for (const participant of this._participants.values()) {\n if (participant.identity === message.author) {\n participant._endTyping();\n break;\n }\n }\n this.emit(\"messageAdded\", message);\n }\n\n /**\n * Set last read message index.\n * @param index New index to set.\n */\n private async _setLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n const result = await this._services.commandExecutor.mutateResource<\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse\n >(\"post\", `${this._configuration.links.myConversations}/${this.sid}`, {\n last_read_message_index: index,\n });\n\n return result.unread_messages_count;\n }\n}\n\nexport {\n ConversationDescriptor,\n Conversation,\n ConversationServices,\n ConversationUpdateReason,\n ConversationStatus,\n NotificationLevel,\n ConversationState,\n ConversationUpdatedEventArgs,\n SendMediaOptions,\n SendEmailOptions,\n LastMessage,\n ConversationBindings,\n ConversationEmailBinding,\n};\n"],"names":["ReplayEventEmitter","parseTime","Participants","Messages","UriBuilder","MessageBuilder","isEqual","Logger","__decorate","validateTypesAsync","nonEmptyString","optionalAttributesValidator","nonNegativeInteger","literal","Participant","objectSchema","custom","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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