@twilio/conversations 2.0.1-rc.9 → 2.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/builds/browser.js +248 -64
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +86 -9
- package/builds/lib.js +248 -64
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +246 -63
- package/builds/twilio-conversations.min.js +3 -3
- package/dist/conversation.js +24 -10
- package/dist/conversation.js.map +1 -1
- package/dist/data/messages.js +1 -1
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +7 -3
- package/dist/data/participants.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/attributes.js +147 -0
- package/dist/interfaces/attributes.js.map +1 -0
- package/dist/message-builder.js +52 -0
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +35 -4
- package/dist/message.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js +20 -3
- package/dist/participant.js.map +1 -1
- package/dist/user.js +2 -1
- package/dist/user.js.map +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +15 -0
- package/docs/classes/Client.html +15 -0
- package/docs/classes/Conversation.html +24 -2
- package/docs/classes/DetailedDeliveryReceipt.html +15 -0
- package/docs/classes/Media.html +15 -0
- package/docs/classes/Message.html +83 -2
- package/docs/classes/MessageBuilder.html +91 -0
- package/docs/classes/Participant.html +45 -1
- package/docs/classes/PushNotification.html +15 -0
- package/docs/classes/RestPaginator.html +15 -0
- package/docs/classes/UnsentMessage.html +15 -0
- package/docs/classes/User.html +15 -0
- package/docs/index.html +37 -3
- package/docs/interfaces/ClientOptions.html +15 -0
- package/docs/interfaces/ConversationBindings.html +3118 -0
- package/docs/interfaces/ConversationEmailBinding.html +3118 -0
- package/docs/interfaces/ConversationState.html +15 -0
- package/docs/interfaces/CreateConversationOptions.html +15 -0
- package/docs/interfaces/LastMessage.html +15 -0
- package/docs/interfaces/Paginator.html +15 -0
- package/docs/interfaces/ParticipantBindings.html +3118 -0
- package/docs/interfaces/ParticipantEmailBinding.html +3118 -0
- package/docs/interfaces/PushNotificationData.html +15 -0
- package/docs/interfaces/SendEmailOptions.html +15 -0
- package/docs/interfaces/SendMediaOptions.html +15 -0
- package/docs/modules.html +37 -3
- package/package.json +2 -2
package/dist/conversation.js
CHANGED
@@ -137,6 +137,7 @@ var participant = require('./participant.js');
|
|
137
137
|
var messages = require('./data/messages.js');
|
138
138
|
var index = require('./util/index.js');
|
139
139
|
var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
140
|
+
var attributes = require('./interfaces/attributes.js');
|
140
141
|
var messageBuilder = require('./message-builder.js');
|
141
142
|
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
142
143
|
var isEqual = require('lodash.isequal');
|
@@ -158,7 +159,8 @@ const fieldMappings = {
|
|
158
159
|
sid: 'sid',
|
159
160
|
status: 'status',
|
160
161
|
uniqueName: 'uniqueName',
|
161
|
-
state: 'state'
|
162
|
+
state: 'state',
|
163
|
+
bindings: 'bindings'
|
162
164
|
};
|
163
165
|
function parseTime(timeString) {
|
164
166
|
try {
|
@@ -176,6 +178,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
176
178
|
* @internal
|
177
179
|
*/
|
178
180
|
constructor(descriptor, sid, links, configuration, services) {
|
181
|
+
var _a;
|
179
182
|
super();
|
180
183
|
this.sid = sid;
|
181
184
|
this.links = links;
|
@@ -203,7 +206,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
203
206
|
dateCreated,
|
204
207
|
dateUpdated,
|
205
208
|
friendlyName,
|
206
|
-
lastReadMessageIndex
|
209
|
+
lastReadMessageIndex,
|
210
|
+
bindings: (_a = descriptor.bindings) !== null && _a !== void 0 ? _a : {},
|
207
211
|
};
|
208
212
|
if (descriptor.notificationLevel) {
|
209
213
|
this.channelState.notificationLevel = descriptor.notificationLevel;
|
@@ -261,6 +265,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
261
265
|
* User notification level for this conversation.
|
262
266
|
*/
|
263
267
|
get notificationLevel() { return this.channelState.notificationLevel; }
|
268
|
+
get bindings() { return this.channelState.bindings; }
|
264
269
|
get limits() { return this.configuration.limits; }
|
265
270
|
/**
|
266
271
|
* State of the conversation.
|
@@ -477,6 +482,13 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
477
482
|
this.channelState.state = state;
|
478
483
|
updateReasons.add(localKey);
|
479
484
|
break;
|
485
|
+
case fieldMappings.bindings:
|
486
|
+
if (isEqual__default['default'](this.channelState.bindings, update.bindings)) {
|
487
|
+
break;
|
488
|
+
}
|
489
|
+
this.channelState.bindings = update.bindings;
|
490
|
+
updateReasons.add(localKey);
|
491
|
+
break;
|
480
492
|
default:
|
481
493
|
const isDate = update[key] instanceof Date;
|
482
494
|
const keysMatchAsDates = isDate && ((_e = this.channelState[localKey]) === null || _e === void 0 ? void 0 : _e.getTime()) === update[key].getTime();
|
@@ -516,16 +528,17 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
516
528
|
* @param attributes Attributes to be attached to the participant.
|
517
529
|
*/
|
518
530
|
async add(identity, attributes) {
|
519
|
-
return this.participantsEntity.add(identity, attributes);
|
531
|
+
return this.participantsEntity.add(identity, attributes !== null && attributes !== void 0 ? attributes : {});
|
520
532
|
}
|
521
533
|
/**
|
522
534
|
* Add a non-chat participant to the conversation.
|
523
535
|
* @param proxyAddress Proxy (Twilio) address of the participant.
|
524
536
|
* @param address User address of the participant.
|
525
537
|
* @param attributes Attributes to be attached to the participant.
|
538
|
+
* @param bindingOptions Options for adding email participants - name and CC/To level.
|
526
539
|
*/
|
527
|
-
async addNonChatParticipant(proxyAddress, address, attributes) {
|
528
|
-
return this.participantsEntity.addNonChatParticipant(proxyAddress, address, attributes);
|
540
|
+
async addNonChatParticipant(proxyAddress, address, attributes = {}, bindingOptions = {}) {
|
541
|
+
return this.participantsEntity.addNonChatParticipant(proxyAddress, address, attributes !== null && attributes !== void 0 ? attributes : {}, bindingOptions !== null && bindingOptions !== void 0 ? bindingOptions : {});
|
529
542
|
}
|
530
543
|
/**
|
531
544
|
* Advance the conversation's last read message index to the current read horizon.
|
@@ -698,6 +711,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
698
711
|
/**
|
699
712
|
* New interface to prepare for sending a message.
|
700
713
|
* Use instead of `sendMessage`.
|
714
|
+
* @return A MessageBuilder to help set all message sending options.
|
701
715
|
*/
|
702
716
|
prepareMessage() {
|
703
717
|
return new messageBuilder.MessageBuilder(this.limits, this.messagesEntity);
|
@@ -871,15 +885,15 @@ Conversation.updated = 'updated';
|
|
871
885
|
*/
|
872
886
|
Conversation.removed = 'removed';
|
873
887
|
tslib_es6.__decorate([
|
874
|
-
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString,
|
888
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, attributes.optionalAttributesValidator),
|
875
889
|
tslib_es6.__metadata("design:type", Function),
|
876
890
|
tslib_es6.__metadata("design:paramtypes", [String, Object]),
|
877
891
|
tslib_es6.__metadata("design:returntype", Promise)
|
878
892
|
], Conversation.prototype, "add", null);
|
879
893
|
tslib_es6.__decorate([
|
880
|
-
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString,
|
894
|
+
declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString, attributes.optionalAttributesValidator),
|
881
895
|
tslib_es6.__metadata("design:type", Function),
|
882
|
-
tslib_es6.__metadata("design:paramtypes", [String, String, Object]),
|
896
|
+
tslib_es6.__metadata("design:paramtypes", [String, String, Object, Object]),
|
883
897
|
tslib_es6.__metadata("design:returntype", Promise)
|
884
898
|
], Conversation.prototype, "addNonChatParticipant", null);
|
885
899
|
tslib_es6.__decorate([
|
@@ -931,7 +945,7 @@ tslib_es6.__decorate([
|
|
931
945
|
];
|
932
946
|
})
|
933
947
|
})
|
934
|
-
],
|
948
|
+
], attributes.optionalAttributesValidator, ['undefined', declarativeTypeValidator.literal(null), declarativeTypeValidator.objectSchema('email attributes', {
|
935
949
|
subject: [declarativeTypeValidator.nonEmptyString, 'undefined']
|
936
950
|
})]),
|
937
951
|
tslib_es6.__metadata("design:type", Function),
|
@@ -945,7 +959,7 @@ tslib_es6.__decorate([
|
|
945
959
|
tslib_es6.__metadata("design:returntype", Promise)
|
946
960
|
], Conversation.prototype, "setUserNotificationLevel", null);
|
947
961
|
tslib_es6.__decorate([
|
948
|
-
declarativeTypeValidator.validateTypesAsync(
|
962
|
+
declarativeTypeValidator.validateTypesAsync(attributes.attributesValidator),
|
949
963
|
tslib_es6.__metadata("design:type", Function),
|
950
964
|
tslib_es6.__metadata("design:paramtypes", [Object]),
|
951
965
|
tslib_es6.__metadata("design:returntype", Promise)
|
package/dist/conversation.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"conversation.js","sources":["../src/conversation.ts"],"sourcesContent":["import { Logger } from './logger';\n\nimport { Participants } from './data/participants';\nimport {\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason\n} from './participant';\nimport { Messages } from './data/messages';\nimport { Message, MessageUpdatedEventArgs, MessageUpdateReason } from './message';\n\nimport { UriBuilder, parseToNumber } from './util';\nimport { Users } from './data/users';\nimport { Paginator } from './interfaces/paginator';\nimport { ConversationsDataSource } from './data/conversations';\nimport { McsClient } from '@twilio/mcs-client';\n\nimport { SyncClient } from 'twilio-sync';\nimport { TypingIndicator } from './services/typing-indicator';\nimport { Network } from './services/network';\nimport {\n validateTypesAsync, custom, literal, nonEmptyString, nonNegativeInteger, objectSchema\n} from '@twilio/declarative-type-validator';\nimport { Configuration } from './configuration';\nimport { CommandExecutor } from './command-executor';\nimport {\n AddParticipantRequest\n} 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 { Limits } from './interfaces/limits';\nimport { MessageBuilder } from './message-builder';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\nimport isEqual from 'lodash.isequal';\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\nconst log = Logger.scope('Conversation');\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};\n\nfunction parseTime(timeString) {\n try {\n return new Date(timeString);\n } catch (e) {\n return null;\n }\n}\n\nexport interface ConversationServices {\n users: Users;\n typingIndicator: TypingIndicator;\n network: Network;\n mcsClient: McsClient;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\ninterface ConversationInternalState {\n uniqueName: string;\n status: ConversationStatus;\n attributes: any;\n createdBy?: string;\n dateCreated: Date;\n dateUpdated: Date;\n friendlyName?: string;\n lastReadMessageIndex: number | null;\n lastMessage?: LastMessage;\n notificationLevel?: NotificationLevel;\n state?: ConversationState;\n}\n\ninterface ConversationDescriptor {\n channel: string;\n entityName: string;\n uniqueName: string;\n attributes: any;\n createdBy?: string;\n friendlyName?: string;\n lastConsumedMessageIndex: number;\n dateCreated: any;\n dateUpdated: any;\n notificationLevel?: NotificationLevel;\n}\n\ninterface ConversationLinks {\n self: string;\n messages: string;\n participants: string;\n}\n\n/**\n * The reason for the `updated` event being emitted 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\n/**\n * The status of the conversation, relative to the client: whether\n * the conversation has been `joined` or the client is\n * `notParticipating` in the conversation.\n */\ntype ConversationStatus = 'notParticipating' | 'joined';\n\n/**\n * The 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 * The state of the conversation.\n */\ninterface ConversationState {\n /**\n * The 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\ninterface ConversationUpdatedEventArgs {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\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: string;\n\n /**\n * Optional filename.\n */\n filename?: string;\n\n /**\n * Content to post.\n */\n media: 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 * A conversation represents communication between multiple Conversations clients\n */\nclass Conversation extends ReplayEventEmitter<ConversationEvents> {\n /**\n * Unique system identifier of the conversation.\n */\n public readonly sid: string;\n public readonly links: ConversationLinks;\n\n private readonly configuration: Configuration;\n private readonly services: ConversationServices;\n private channelState: ConversationInternalState;\n private statusSource: ConversationsDataSource;\n\n private entityPromise: Promise<any>;\n private entityName: string;\n private entity: any;\n private messagesEntity: any;\n private participantsEntity: Participants;\n private readonly participants: any;\n\n /**\n * @internal\n */\n 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\n let attributes = descriptor.attributes || {};\n let createdBy = descriptor.createdBy;\n let dateCreated = parseTime(descriptor.dateCreated);\n let dateUpdated = parseTime(descriptor.dateUpdated);\n let friendlyName = descriptor.friendlyName || null;\n let lastReadMessageIndex =\n Number.isInteger(descriptor.lastConsumedMessageIndex) ? descriptor.lastConsumedMessageIndex : null;\n let uniqueName = descriptor.uniqueName || null;\n\n try {\n JSON.stringify(attributes);\n } catch (e) {\n throw new Error('Attributes must be a valid JSON object.');\n }\n\n this.entityName = descriptor.channel;\n this.channelState = {\n uniqueName,\n status: 'notParticipating',\n attributes,\n createdBy,\n dateCreated,\n dateUpdated,\n friendlyName,\n lastReadMessageIndex: lastReadMessageIndex\n };\n\n if (descriptor.notificationLevel) {\n this.channelState.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', this.emit.bind(this, 'participantJoined'));\n this.participantsEntity.on('participantLeft', this.emit.bind(this, 'participantLeft'));\n this.participantsEntity.on('participantUpdated',\n (args: ParticipantUpdatedEventArgs) => this.emit('participantUpdated', args));\n\n this.messagesEntity = new Messages(this, configuration, services);\n this.messagesEntity.on('messageAdded', message => this._onMessageAdded(message));\n this.messagesEntity.on('messageUpdated',\n (args: MessageUpdatedEventArgs) => this.emit('messageUpdated', args));\n this.messagesEntity.on('messageRemoved', this.emit.bind(this, 'messageRemoved'));\n }\n\n /**\n * Fired when a participant has joined the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that joined the conversation\n * @event\n */\n 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 conversation\n * @event\n */\n 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 following properties:\n * * {@link Participant} `participant` - participant that has received the update\n * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons for update\n * @event\n */\n 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 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 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 following properties:\n * * {@link Message} `message` - message that has received the update\n * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for update\n * @event\n */\n 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 typing\n * @event\n */\n 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 typing\n * @event\n */\n 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 following properties:\n * * {@link Conversation} `conversation` - conversation that has received the update\n * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons for update\n * @event\n */\n static readonly updated = 'updated';\n\n /**\n * Fired when the conversation was destroyed or the currently-logged-in user has left private conversation.\n *\n * Parameters:\n * 1. {@link Conversation} `conversation` - conversation that has been removed\n * @event\n */\n static readonly removed = 'removed';\n\n /**\n * Unique name of the conversation.\n */\n public get uniqueName(): string { return this.channelState.uniqueName; }\n\n /**\n * Status of the conversation.\n */\n public get status(): ConversationStatus { return this.channelState.status; }\n\n /**\n * Name of the conversation.\n */\n public get friendlyName(): string { return this.channelState.friendlyName; }\n\n /**\n * Date this conversation was last updated on.\n */\n public get dateUpdated(): any { return this.channelState.dateUpdated; }\n\n /**\n * Date this conversation was created on.\n */\n public get dateCreated(): any { return this.channelState.dateCreated; }\n\n /**\n * Identity of the user that created this conversation.\n */\n public get createdBy(): string { return this.channelState.createdBy; }\n\n /**\n * Custom attributes of the conversation.\n */\n public get attributes(): any { return this.channelState.attributes; }\n\n /**\n * Index of the last message the user has read in this conversation.\n */\n public get lastReadMessageIndex(): number | null { return this.channelState.lastReadMessageIndex; }\n\n /**\n * Last message sent to this conversation.\n */\n public get lastMessage(): LastMessage { return this.channelState.lastMessage; }\n\n /**\n * User notification level for this conversation.\n */\n public get notificationLevel(): NotificationLevel { return this.channelState.notificationLevel; }\n\n public get limits(): Limits { return this.configuration.limits; }\n\n /**\n * State of the conversation.\n */\n public get state(): ConversationState | undefined { return this.channelState.state; }\n\n /**\n * Load and subscribe to this conversation and do not subscribe to its participants and messages.\n * This or _subscribeStreams will need to be called before any events on conversation will fire.\n * @internal\n */\n _subscribe() {\n return this.entityPromise = this.entityPromise ??\n this.services.syncClient.document({ id: this.entityName, mode: 'open_existing' })\n .then(entity => {\n this.entity = entity;\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 return entity;\n })\n .catch(err => {\n this.entity = null;\n this.entityPromise = null;\n if (this.services.syncClient.connectionState != 'disconnected') {\n log.error('Failed to get conversation object', err);\n }\n log.debug('ERROR: Failed to get conversation object', err);\n throw err;\n });\n }\n\n /**\n * Load the attributes of this conversation and instantiate its participants and messages.\n * This or _subscribe will need to be called before any events on the conversation will fire.\n * This will need to be called before any events on participants or messages will fire\n * @internal\n */\n async _subscribeStreams() {\n try {\n await this._subscribe();\n log.trace('_subscribeStreams, this.entity.data=', this.entity.data);\n const messagesObjectName = this.entity.data.messages;\n const rosterObjectName = this.entity.data.roster;\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 log.error('Failed to subscribe on conversation objects', this.sid, err);\n }\n log.debug('ERROR: Failed to subscribe on conversation objects', this.sid, err);\n throw err;\n }\n }\n\n /**\n * Stop listening for and firing events on this conversation.\n * @internal\n */\n 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 _setStatus(status: ConversationStatus, source: ConversationsDataSource) {\n this.statusSource = source;\n\n if (this.channelState.status === status) { return; }\n\n this.channelState.status = status;\n\n if (status === 'joined') {\n this._subscribeStreams()\n .catch(err => {\n log.debug('ERROR while setting conversation status ' + status, err);\n if (this.services.syncClient.connectionState !== 'disconnected') {\n throw err;\n }\n });\n } else if (this.entityPromise) {\n this._unsubscribe().catch(err => {\n log.debug('ERROR while setting conversation status ' + status, err);\n if (this.services.syncClient.connectionState !== 'disconnected') {\n throw err;\n }\n });\n }\n }\n\n /**\n * Get the source of the conversation update.\n * @internal\n */\n _statusSource(): ConversationsDataSource {\n return this.statusSource;\n }\n\n private static preprocessUpdate(update, conversationSid) {\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 log.warn('Retrieved malformed attributes from the server for conversation: ' + conversationSid);\n update.attributes = {};\n }\n\n try {\n if (update.dateCreated) {\n update.dateCreated = new Date(update.dateCreated);\n }\n } catch (e) {\n log.warn('Retrieved malformed dateCreated from the server for conversation: ' + conversationSid);\n delete update.dateCreated;\n }\n\n try {\n if (update.dateUpdated) {\n update.dateUpdated = new Date(update.dateUpdated);\n }\n } catch (e) {\n log.warn('Retrieved malformed dateUpdated from the server for conversation: ' + conversationSid);\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 log.warn('Retrieved malformed lastMessage.timestamp from the server for conversation: ' + conversationSid);\n delete update.lastMessage.timestamp;\n }\n }\n\n /**\n * Update the local conversation object with new values.\n * @internal\n */\n _update(update) {\n log.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 (!update.status || update.status === 'unknown'\n || this.channelState.status === update.status) {\n break;\n }\n\n this.channelState.status = update.status;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.attributes:\n if (isEqual(this.channelState.attributes, update.attributes)) {\n break;\n }\n\n this.channelState.attributes = update.attributes;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.lastConsumedMessageIndex:\n if (update.lastConsumedMessageIndex === undefined\n || update.lastConsumedMessageIndex === this.channelState.lastReadMessageIndex) {\n break;\n }\n\n this.channelState.lastReadMessageIndex = update.lastConsumedMessageIndex;\n updateReasons.add('lastReadMessageIndex');\n\n break;\n case fieldMappings.lastMessage:\n if (this.channelState.lastMessage && !update.lastMessage) {\n delete this.channelState.lastMessage;\n updateReasons.add(localKey);\n\n break;\n }\n\n this.channelState.lastMessage = this.channelState.lastMessage || {};\n\n if (update.lastMessage?.index !== undefined\n && update.lastMessage.index !== this.channelState.lastMessage.index) {\n this.channelState.lastMessage.index = update.lastMessage.index;\n updateReasons.add(localKey);\n }\n\n if (update.lastMessage?.timestamp !== undefined\n && this.channelState.lastMessage?.dateCreated?.getTime() !== update.lastMessage.timestamp.getTime()) {\n this.channelState.lastMessage.dateCreated = update.lastMessage.timestamp;\n updateReasons.add(localKey);\n }\n\n if (isEqual(this.channelState.lastMessage, {})) {\n delete this.channelState.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.channelState.state, state)) {\n break;\n }\n\n this.channelState.state = state;\n updateReasons.add(localKey);\n\n break;\n default:\n const isDate = update[key] instanceof Date;\n const keysMatchAsDates = isDate && this.channelState[localKey]?.getTime() === update[key].getTime();\n const keysMatchAsNonDates = !isDate && this[localKey] === update[key];\n\n if (keysMatchAsDates || keysMatchAsNonDates) {\n break;\n }\n\n this.channelState[localKey] = update[key];\n updateReasons.add(localKey);\n }\n }\n\n if (updateReasons.size > 0) {\n this.emit('updated', { conversation: this, updateReasons: [...updateReasons] });\n }\n }\n\n /**\n * @internal\n */\n private _onMessageAdded(message) {\n for (let 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 private async _setLastReadMessageIndex(index: number | null): Promise<number> {\n const result = await this.services.commandExecutor.mutateResource<\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse\n >(\n 'post',\n `${this.configuration.links.myConversations}/${this.sid}`,\n {\n last_read_message_index: index\n }\n );\n\n return result.unread_messages_count;\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 */\n @validateTypesAsync(\n nonEmptyString,\n ['undefined', 'string', 'number', 'boolean', 'object', literal(null)]\n )\n async add(identity: string, attributes?: any): Promise<void> {\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 */\n @validateTypesAsync(\n nonEmptyString,\n nonEmptyString,\n ['undefined', 'string', 'number', 'boolean', 'object', literal(null)]\n )\n async addNonChatParticipant(proxyAddress: string, address: string, attributes?: any): Promise<void> {\n return this.participantsEntity.addNonChatParticipant(proxyAddress, address, attributes);\n }\n\n /**\n * Advance the conversation's last read message index to the current read horizon.\n * Rejects if the user is not a participant of the conversation.\n * Last read message index is updated only if the new index value is higher than the previous.\n * @param index Message index to advance to.\n * @return Resulting unread messages count in the conversation.\n */\n @validateTypesAsync(nonNegativeInteger)\n async advanceLastReadMessageIndex(index: number): Promise<number> {\n await this._subscribeStreams();\n\n if (index < this.lastReadMessageIndex) {\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 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 async getAttributes(): Promise<any> {\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 30.\n * @param anchor Index of the newest message to fetch. Default is from the end.\n * @param direction Query direction. By default it queries backwards\n * from newer to older. The `\"forward\"` value will query in the opposite direction.\n * @return A page of messages.\n */\n @validateTypesAsync(\n ['undefined', nonNegativeInteger],\n ['undefined', nonNegativeInteger],\n ['undefined', literal('backwards', 'forward')]\n )\n async getMessages(pageSize?: number, anchor?: number, direction?: 'backwards' | 'forward'): 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 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 correct,\n * but will also be possibly incorrect for a few seconds. The Conversations system does not\n * provide real time events for counter values changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any core application\n * logic based on these counters being accurate in real time.\n */\n 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(url);\n\n return response.body.participants_count;\n }\n\n /**\n * Get a participant by its SID.\n * @param participantSid Participant SID.\n */\n @validateTypesAsync(nonEmptyString)\n async getParticipantBySid(participantSid: string): Promise<Participant> {\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 async getParticipantByIdentity(identity: string): Promise<Participant> {\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 correct,\n * but will also be possibly incorrect for a few seconds. The Conversations system does not\n * provide real time events for counter values changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any core application\n * logic based on these counters being accurate in real time.\n */\n 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(url);\n\n return response.body.messages_count;\n }\n\n /**\n * Get unread messages count for the user if they are a participant of this conversation.\n * 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 correct,\n * but will also be possibly incorrect for a few seconds. The Conversations system does not\n * provide real time events for counter values changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any core application\n * logic based on these counters being accurate in real time.\n */\n 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(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 async join(): Promise<Conversation> {\n await this.services.commandExecutor.mutateResource<AddParticipantRequest, ParticipantResponse>(\n 'post',\n this.links.participants,\n {\n identity: this.configuration.userIdentity\n }\n );\n\n return this;\n }\n\n /**\n * Leave the conversation.\n */\n async leave(): Promise<Conversation> {\n if (this.channelState.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 async removeParticipant(participant: string | Participant): Promise<void> {\n await this.participantsEntity.remove(\n typeof participant === 'string'\n ? participant\n : 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 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 literal(null),\n // Wrapping it into a custom rule is necessary because the FormData class is not available on initialization.\n custom((value) => [value instanceof FormData, 'an instance of FormData']),\n objectSchema('media options', {\n contentType: nonEmptyString,\n media: custom((value) => {\n let isValid = (typeof value === 'string' && value.length > 0) || value instanceof Uint8Array || 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 ['undefined', 'string', 'number', 'boolean', 'object', literal(null)],\n ['undefined', literal(null), objectSchema('email attributes', {\n subject: [nonEmptyString, 'undefined']\n })]\n )\n async sendMessage(message: string | FormData | SendMediaOptions | null, messageAttributes?: any,\n emailOptions?: SendEmailOptions): Promise<number> {\n if (typeof message === 'string' || message === null) {\n let response = await this.messagesEntity.send(message, messageAttributes, emailOptions);\n return parseToNumber(response.index);\n }\n\n let response = await this.messagesEntity.sendMedia(message, messageAttributes, emailOptions);\n return parseToNumber(response.index);\n }\n\n /**\n * New interface to prepare for sending a message.\n * Use instead of `sendMessage`.\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 known message.\n * @return Resulting unread messages count in the conversation.\n */\n public async setAllMessagesRead(): Promise<number> {\n await this._subscribeStreams();\n\n let messagesPage = await this.getMessages(1);\n\n if (messagesPage.items.length > 0) {\n return this.advanceLastReadMessageIndex(messagesPage.items[0].index);\n }\n\n return Promise.resolve(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 async setUserNotificationLevel(notificationLevel: NotificationLevel): 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 typing in this conversation.\n * Typing ended notification is sent after a while automatically, but by calling this method again you ensure that typing ended is not received.\n */\n 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(['string', 'number', 'boolean', 'object', literal(null)])\n async updateAttributes(attributes: any): Promise<Conversation> {\n await this.services.commandExecutor.mutateResource<EditConversationRequest, ConversationResponse>(\n 'post',\n this.links.self,\n {\n attributes: attributes !== undefined ? JSON.stringify(attributes) : undefined\n }\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 async updateFriendlyName(friendlyName: string): Promise<Conversation> {\n if (this.channelState.friendlyName !== friendlyName) {\n await this.services.commandExecutor.mutateResource<EditConversationRequest, ConversationResponse>(\n 'post',\n this.links.self,\n { friendly_name: friendlyName }\n );\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.\n * If null is provided, then the behavior is identical to {@link Conversation.setAllMessagesUnread}.\n * @returns Resulting unread messages count in the conversation.\n */\n @validateTypesAsync([literal(null), nonNegativeInteger])\n async updateLastReadMessageIndex(index: number | null): 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 to null removes it.\n */\n @validateTypesAsync(['string', literal(null)])\n async updateUniqueName(uniqueName: string | null): Promise<Conversation> {\n if (this.channelState.uniqueName !== uniqueName) {\n if (!uniqueName) {\n uniqueName = '';\n }\n\n await this.services.commandExecutor.mutateResource<EditConversationRequest, ConversationResponse>(\n 'post',\n this.links.self,\n {\n unique_name: uniqueName\n }\n );\n }\n\n return this;\n }\n}\n\nexport {\n ConversationDescriptor,\n Conversation,\n ConversationUpdateReason,\n ConversationStatus,\n NotificationLevel,\n ConversationState,\n ConversationUpdatedEventArgs,\n SendMediaOptions,\n SendEmailOptions,\n LastMessage\n};\n"],"names":["Logger","ReplayEventEmitter","Participants","Messages","isEqual","UriBuilder","parseToNumber","MessageBuilder","__decorate","validateTypesAsync","nonEmptyString","literal","nonNegativeInteger","Participant","custom","objectSchema"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAEzC,MAAM,aAAa,GAAG;IACpB,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,wBAAwB,EAAE,0BAA0B;IACpD,iBAAiB,EAAE,mBAAmB;IACtC,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,SAAS,SAAS,CAAC,UAAU;IAC3B,IAAI;QACF,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AA8ID;;;AAGA,MAAM,YAAa,SAAQC,qCAAsC;;;;IAsB/D,YACE,UAAkC,EAClC,GAAW,EACX,KAAwB,EACxB,aAA4B,EAC5B,QAA8B;QAE9B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,UAAU,GAAG,UAAU,CAAC,UAAU,IAAI,EAAE,CAA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IADCC,2CAAkB,CAACE,gCAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;;;;4DAS/C;AAeDH;IADCC,2CAAkB,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAEE,gCAAO,CAAC,IAAI,CAAC,CAAC,CAAC;;;;oDAW5E;AAODH;IADCC,2CAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC;;;;sDAW9B;AASDD;IADCC,2CAAkB,CAAC,CAACE,gCAAO,CAAC,IAAI,CAAC,EAAEC,2CAAkB,CAAC,CAAC;;;;8DAIvD;AAODJ;IADCC,2CAAkB,CAAC,CAAC,QAAQ,EAAEE,gCAAO,CAAC,IAAI,CAAC,CAAC,CAAC;;;;oDAiB7C;;;;"}
|
1
|
+
{"version":3,"file":"conversation.js","sources":["../src/conversation.ts"],"sourcesContent":["import { Logger } from './logger';\n\nimport { ParticipantBindingOptions, Participants } from './data/participants';\nimport {\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason\n} from './participant';\nimport { Messages } from './data/messages';\nimport { Message, MessageUpdatedEventArgs, MessageUpdateReason } from './message';\n\nimport { UriBuilder, parseToNumber } from './util';\nimport { Users } from './data/users';\nimport { Paginator } from './interfaces/paginator';\nimport { ConversationsDataSource } from './data/conversations';\nimport { McsClient } from '@twilio/mcs-client';\n\nimport { SyncClient } from 'twilio-sync';\nimport { TypingIndicator } from './services/typing-indicator';\nimport { Network } from './services/network';\nimport {\n validateTypesAsync, custom, literal, nonEmptyString, nonNegativeInteger, objectSchema\n} from '@twilio/declarative-type-validator';\nimport { attributesValidator, optionalAttributesValidator } from './interfaces/attributes';\nimport { Configuration } from './configuration';\nimport { CommandExecutor } from './command-executor';\nimport {\n AddParticipantRequest\n} 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 { Limits } from './interfaces/limits';\nimport { MessageBuilder } from './message-builder';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\nimport isEqual from 'lodash.isequal';\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\nconst log = Logger.scope('Conversation');\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\nfunction parseTime(timeString) {\n try {\n return new Date(timeString);\n } catch (e) {\n return null;\n }\n}\n\nexport interface ConversationServices {\n users: Users;\n typingIndicator: TypingIndicator;\n network: Network;\n mcsClient: McsClient;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\ninterface ConversationInternalState {\n uniqueName: string;\n status: ConversationStatus;\n attributes: any;\n createdBy?: string;\n dateCreated: Date;\n dateUpdated: Date;\n friendlyName?: string;\n lastReadMessageIndex: number | null;\n lastMessage?: LastMessage;\n notificationLevel?: NotificationLevel;\n state?: ConversationState;\n bindings: ConversationBindings;\n}\n\ninterface ConversationDescriptor {\n channel: string;\n entityName: string;\n uniqueName: string;\n attributes: any;\n createdBy?: string;\n friendlyName?: string;\n lastConsumedMessageIndex: number;\n dateCreated: any;\n dateUpdated: any;\n notificationLevel?: NotificationLevel;\n bindings?: ConversationBindings;\n}\n\ninterface ConversationLinks {\n self: string;\n messages: string;\n participants: string;\n}\n\n/**\n * The reason for the `updated` event being emitted 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 * The status of the conversation, relative to the client: whether\n * the conversation has been `joined` or the client is\n * `notParticipating` in the conversation.\n */\ntype ConversationStatus = 'notParticipating' | 'joined';\n\n/**\n * The 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 * The state of the conversation.\n */\ninterface ConversationState {\n /**\n * The 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\ninterface ConversationUpdatedEventArgs {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationBindings {\n email?: ConversationEmailBinding;\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationEmailBinding {\n name?: string;\n projected_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: string;\n\n /**\n * Optional filename.\n */\n filename?: string;\n\n /**\n * Content to post.\n */\n media: 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 * A conversation represents communication between multiple Conversations clients\n */\nclass Conversation extends ReplayEventEmitter<ConversationEvents> {\n /**\n * Unique system identifier of the conversation.\n */\n public readonly sid: string;\n public readonly links: ConversationLinks;\n\n private readonly configuration: Configuration;\n private readonly services: ConversationServices;\n private channelState: ConversationInternalState;\n private statusSource: ConversationsDataSource;\n\n private entityPromise: Promise<any>;\n private entityName: string;\n private entity: any;\n private messagesEntity: any;\n private participantsEntity: Participants;\n private readonly participants: any;\n\n /**\n * @internal\n */\n 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\n let attributes = descriptor.attributes || {};\n let createdBy = descriptor.createdBy;\n let dateCreated = parseTime(descriptor.dateCreated);\n let dateUpdated = parseTime(descriptor.dateUpdated);\n let friendlyName = descriptor.friendlyName || null;\n let lastReadMessageIndex =\n Number.isInteger(descriptor.lastConsumedMessageIndex) ? descriptor.lastConsumedMessageIndex : null;\n let uniqueName = descriptor.uniqueName || null;\n\n try {\n JSON.stringify(attributes);\n } catch (e) {\n throw new Error('Attributes must be a valid JSON object.');\n }\n\n this.entityName = descriptor.channel;\n this.channelState = {\n uniqueName,\n status: 'notParticipating',\n attributes,\n createdBy,\n dateCreated,\n dateUpdated,\n friendlyName,\n lastReadMessageIndex,\n bindings: descriptor.bindings ?? {},\n };\n\n if (descriptor.notificationLevel) {\n this.channelState.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', this.emit.bind(this, 'participantJoined'));\n this.participantsEntity.on('participantLeft', this.emit.bind(this, 'participantLeft'));\n this.participantsEntity.on('participantUpdated',\n (args: ParticipantUpdatedEventArgs) => this.emit('participantUpdated', args));\n\n this.messagesEntity = new Messages(this, configuration, services);\n this.messagesEntity.on('messageAdded', message => this._onMessageAdded(message));\n this.messagesEntity.on('messageUpdated',\n (args: MessageUpdatedEventArgs) => this.emit('messageUpdated', args));\n this.messagesEntity.on('messageRemoved', this.emit.bind(this, 'messageRemoved'));\n }\n\n /**\n * Fired when a participant has joined the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that joined the conversation\n * @event\n */\n 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 conversation\n * @event\n */\n 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 following properties:\n * * {@link Participant} `participant` - participant that has received the update\n * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons for update\n * @event\n */\n 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 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 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 following properties:\n * * {@link Message} `message` - message that has received the update\n * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for update\n * @event\n */\n 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 typing\n * @event\n */\n 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 typing\n * @event\n */\n 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 following properties:\n * * {@link Conversation} `conversation` - conversation that has received the update\n * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons for update\n * @event\n */\n static readonly updated = 'updated';\n\n /**\n * Fired when the conversation was destroyed or the currently-logged-in user has left private conversation.\n *\n * Parameters:\n * 1. {@link Conversation} `conversation` - conversation that has been removed\n * @event\n */\n static readonly removed = 'removed';\n\n /**\n * Unique name of the conversation.\n */\n public get uniqueName(): string { return this.channelState.uniqueName; }\n\n /**\n * Status of the conversation.\n */\n public get status(): ConversationStatus { return this.channelState.status; }\n\n /**\n * Name of the conversation.\n */\n public get friendlyName(): string { return this.channelState.friendlyName; }\n\n /**\n * Date this conversation was last updated on.\n */\n public get dateUpdated(): any { return this.channelState.dateUpdated; }\n\n /**\n * Date this conversation was created on.\n */\n public get dateCreated(): any { return this.channelState.dateCreated; }\n\n /**\n * Identity of the user that created this conversation.\n */\n public get createdBy(): string { return this.channelState.createdBy; }\n\n /**\n * Custom attributes of the conversation.\n */\n public get attributes(): any { return this.channelState.attributes; }\n\n /**\n * Index of the last message the user has read in this conversation.\n */\n public get lastReadMessageIndex(): number | null { return this.channelState.lastReadMessageIndex; }\n\n /**\n * Last message sent to this conversation.\n */\n public get lastMessage(): LastMessage { return this.channelState.lastMessage; }\n\n /**\n * User notification level for this conversation.\n */\n public get notificationLevel(): NotificationLevel { return this.channelState.notificationLevel; }\n\n public get bindings(): ConversationBindings { return this.channelState.bindings; }\n\n public get limits(): Limits { return this.configuration.limits; }\n\n /**\n * State of the conversation.\n */\n public get state(): ConversationState | undefined { return this.channelState.state; }\n\n /**\n * Load and subscribe to this conversation and do not subscribe to its participants and messages.\n * This or _subscribeStreams will need to be called before any events on conversation will fire.\n * @internal\n */\n _subscribe() {\n return this.entityPromise = this.entityPromise ??\n this.services.syncClient.document({ id: this.entityName, mode: 'open_existing' })\n .then(entity => {\n this.entity = entity;\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 return entity;\n })\n .catch(err => {\n this.entity = null;\n this.entityPromise = null;\n if (this.services.syncClient.connectionState != 'disconnected') {\n log.error('Failed to get conversation object', err);\n }\n log.debug('ERROR: Failed to get conversation object', err);\n throw err;\n });\n }\n\n /**\n * Load the attributes of this conversation and instantiate its participants and messages.\n * This or _subscribe will need to be called before any events on the conversation will fire.\n * This will need to be called before any events on participants or messages will fire\n * @internal\n */\n async _subscribeStreams() {\n try {\n await this._subscribe();\n log.trace('_subscribeStreams, this.entity.data=', this.entity.data);\n const messagesObjectName = this.entity.data.messages;\n const rosterObjectName = this.entity.data.roster;\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 log.error('Failed to subscribe on conversation objects', this.sid, err);\n }\n log.debug('ERROR: Failed to subscribe on conversation objects', this.sid, err);\n throw err;\n }\n }\n\n /**\n * Stop listening for and firing events on this conversation.\n * @internal\n */\n 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 _setStatus(status: ConversationStatus, source: ConversationsDataSource) {\n this.statusSource = source;\n\n if (this.channelState.status === status) { return; }\n\n this.channelState.status = status;\n\n if (status === 'joined') {\n this._subscribeStreams()\n .catch(err => {\n log.debug('ERROR while setting conversation status ' + status, err);\n if (this.services.syncClient.connectionState !== 'disconnected') {\n throw err;\n }\n });\n } else if (this.entityPromise) {\n this._unsubscribe().catch(err => {\n log.debug('ERROR while setting conversation status ' + status, err);\n if (this.services.syncClient.connectionState !== 'disconnected') {\n throw err;\n }\n });\n }\n }\n\n /**\n * Get the source of the conversation update.\n * @internal\n */\n _statusSource(): ConversationsDataSource {\n return this.statusSource;\n }\n\n private static preprocessUpdate(update, conversationSid) {\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 log.warn('Retrieved malformed attributes from the server for conversation: ' + conversationSid);\n update.attributes = {};\n }\n\n try {\n if (update.dateCreated) {\n update.dateCreated = new Date(update.dateCreated);\n }\n } catch (e) {\n log.warn('Retrieved malformed dateCreated from the server for conversation: ' + conversationSid);\n delete update.dateCreated;\n }\n\n try {\n if (update.dateUpdated) {\n update.dateUpdated = new Date(update.dateUpdated);\n }\n } catch (e) {\n log.warn('Retrieved malformed dateUpdated from the server for conversation: ' + conversationSid);\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 log.warn('Retrieved malformed lastMessage.timestamp from the server for conversation: ' + conversationSid);\n delete update.lastMessage.timestamp;\n }\n }\n\n /**\n * Update the local conversation object with new values.\n * @internal\n */\n _update(update) {\n log.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 (!update.status || update.status === 'unknown'\n || this.channelState.status === update.status) {\n break;\n }\n\n this.channelState.status = update.status;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.attributes:\n if (isEqual(this.channelState.attributes, update.attributes)) {\n break;\n }\n\n this.channelState.attributes = update.attributes;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.lastConsumedMessageIndex:\n if (update.lastConsumedMessageIndex === undefined\n || update.lastConsumedMessageIndex === this.channelState.lastReadMessageIndex) {\n break;\n }\n\n this.channelState.lastReadMessageIndex = update.lastConsumedMessageIndex;\n updateReasons.add('lastReadMessageIndex');\n\n break;\n case fieldMappings.lastMessage:\n if (this.channelState.lastMessage && !update.lastMessage) {\n delete this.channelState.lastMessage;\n updateReasons.add(localKey);\n\n break;\n }\n\n this.channelState.lastMessage = this.channelState.lastMessage || {};\n\n if (update.lastMessage?.index !== undefined\n && update.lastMessage.index !== this.channelState.lastMessage.index) {\n this.channelState.lastMessage.index = update.lastMessage.index;\n updateReasons.add(localKey);\n }\n\n if (update.lastMessage?.timestamp !== undefined\n && this.channelState.lastMessage?.dateCreated?.getTime() !== update.lastMessage.timestamp.getTime()) {\n this.channelState.lastMessage.dateCreated = update.lastMessage.timestamp;\n updateReasons.add(localKey);\n }\n\n if (isEqual(this.channelState.lastMessage, {})) {\n delete this.channelState.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.channelState.state, state)) {\n break;\n }\n\n this.channelState.state = state;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.bindings:\n if (isEqual(this.channelState.bindings, update.bindings)) {\n break;\n }\n\n this.channelState.bindings = update.bindings;\n updateReasons.add(localKey);\n\n break;\n default:\n const isDate = update[key] instanceof Date;\n const keysMatchAsDates = isDate && this.channelState[localKey]?.getTime() === update[key].getTime();\n const keysMatchAsNonDates = !isDate && this[localKey] === update[key];\n\n if (keysMatchAsDates || keysMatchAsNonDates) {\n break;\n }\n\n this.channelState[localKey] = update[key];\n updateReasons.add(localKey);\n }\n }\n\n if (updateReasons.size > 0) {\n this.emit('updated', { conversation: this, updateReasons: [...updateReasons] });\n }\n }\n\n /**\n * @internal\n */\n private _onMessageAdded(message) {\n for (let 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 private async _setLastReadMessageIndex(index: number | null): Promise<number> {\n const result = await this.services.commandExecutor.mutateResource<\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse\n >(\n 'post',\n `${this.configuration.links.myConversations}/${this.sid}`,\n {\n last_read_message_index: index\n }\n );\n\n return result.unread_messages_count;\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 */\n @validateTypesAsync(nonEmptyString, optionalAttributesValidator)\n async add(identity: string, attributes?: any): Promise<void> {\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 CC/To level.\n */\n @validateTypesAsync(nonEmptyString, nonEmptyString, optionalAttributesValidator)\n async addNonChatParticipant(proxyAddress: string, address: string, attributes: Record<string, any> = {},\n bindingOptions: ParticipantBindingOptions = {}): Promise<void> {\n return this.participantsEntity.addNonChatParticipant(proxyAddress, address, attributes ?? {},\n bindingOptions ?? {});\n }\n\n /**\n * Advance the conversation's last read message index to the current read horizon.\n * Rejects if the user is not a participant of the conversation.\n * Last read message index is updated only if the new index value is higher than the previous.\n * @param index Message index to advance to.\n * @return Resulting unread messages count in the conversation.\n */\n @validateTypesAsync(nonNegativeInteger)\n async advanceLastReadMessageIndex(index: number): Promise<number> {\n await this._subscribeStreams();\n\n if (index < this.lastReadMessageIndex) {\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 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 async getAttributes(): Promise<any> {\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 30.\n * @param anchor Index of the newest message to fetch. Default is from the end.\n * @param direction Query direction. By default it queries backwards\n * from newer to older. The `\"forward\"` value will query in the opposite direction.\n * @return A page of messages.\n */\n @validateTypesAsync(\n ['undefined', nonNegativeInteger],\n ['undefined', nonNegativeInteger],\n ['undefined', literal('backwards', 'forward')]\n )\n async getMessages(pageSize?: number, anchor?: number, direction?: 'backwards' | 'forward'): 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 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 correct,\n * but will also be possibly incorrect for a few seconds. The Conversations system does not\n * provide real time events for counter values changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any core application\n * logic based on these counters being accurate in real time.\n */\n 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(url);\n\n return response.body.participants_count;\n }\n\n /**\n * Get a participant by its SID.\n * @param participantSid Participant SID.\n */\n @validateTypesAsync(nonEmptyString)\n async getParticipantBySid(participantSid: string): Promise<Participant> {\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 async getParticipantByIdentity(identity: string): Promise<Participant> {\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 correct,\n * but will also be possibly incorrect for a few seconds. The Conversations system does not\n * provide real time events for counter values changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any core application\n * logic based on these counters being accurate in real time.\n */\n 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(url);\n\n return response.body.messages_count;\n }\n\n /**\n * Get unread messages count for the user if they are a participant of this conversation.\n * 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 correct,\n * but will also be possibly incorrect for a few seconds. The Conversations system does not\n * provide real time events for counter values changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any core application\n * logic based on these counters being accurate in real time.\n */\n 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(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 async join(): Promise<Conversation> {\n await this.services.commandExecutor.mutateResource<AddParticipantRequest, ParticipantResponse>(\n 'post',\n this.links.participants,\n {\n identity: this.configuration.userIdentity\n }\n );\n\n return this;\n }\n\n /**\n * Leave the conversation.\n */\n async leave(): Promise<Conversation> {\n if (this.channelState.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 async removeParticipant(participant: string | Participant): Promise<void> {\n await this.participantsEntity.remove(\n typeof participant === 'string'\n ? participant\n : 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 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 literal(null),\n // Wrapping it into a custom rule is necessary because the FormData class is not available on initialization.\n custom((value) => [value instanceof FormData, 'an instance of FormData']),\n objectSchema('media options', {\n contentType: nonEmptyString,\n media: custom((value) => {\n let isValid = (typeof value === 'string' && value.length > 0) || value instanceof Uint8Array || 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 ['undefined', literal(null), objectSchema('email attributes', {\n subject: [nonEmptyString, 'undefined']\n })]\n )\n async sendMessage(message: string | FormData | SendMediaOptions | null, messageAttributes?: any,\n emailOptions?: SendEmailOptions): Promise<number> {\n if (typeof message === 'string' || message === null) {\n let response = await this.messagesEntity.send(message, messageAttributes, emailOptions);\n return parseToNumber(response.index);\n }\n\n let response = await this.messagesEntity.sendMedia(message, messageAttributes, emailOptions);\n return parseToNumber(response.index);\n }\n\n /**\n * New interface to prepare for sending a message.\n * Use instead of `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 known message.\n * @return Resulting unread messages count in the conversation.\n */\n public async setAllMessagesRead(): Promise<number> {\n await this._subscribeStreams();\n\n let messagesPage = await this.getMessages(1);\n\n if (messagesPage.items.length > 0) {\n return this.advanceLastReadMessageIndex(messagesPage.items[0].index);\n }\n\n return Promise.resolve(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 async setUserNotificationLevel(notificationLevel: NotificationLevel): 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 typing in this conversation.\n * Typing ended notification is sent after a while automatically, but by calling this method again you ensure that typing ended is not received.\n */\n 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 async updateAttributes(attributes: any): Promise<Conversation> {\n await this.services.commandExecutor.mutateResource<EditConversationRequest, ConversationResponse>(\n 'post',\n this.links.self,\n {\n attributes: attributes !== undefined ? JSON.stringify(attributes) : undefined\n }\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 async updateFriendlyName(friendlyName: string): Promise<Conversation> {\n if (this.channelState.friendlyName !== friendlyName) {\n await this.services.commandExecutor.mutateResource<EditConversationRequest, ConversationResponse>(\n 'post',\n this.links.self,\n { friendly_name: friendlyName }\n );\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.\n * If null is provided, then the behavior is identical to {@link Conversation.setAllMessagesUnread}.\n * @returns Resulting unread messages count in the conversation.\n */\n @validateTypesAsync([literal(null), nonNegativeInteger])\n async updateLastReadMessageIndex(index: number | null): 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 to null removes it.\n */\n @validateTypesAsync(['string', literal(null)])\n async updateUniqueName(uniqueName: string | null): Promise<Conversation> {\n if (this.channelState.uniqueName !== uniqueName) {\n if (!uniqueName) {\n uniqueName = '';\n }\n\n await this.services.commandExecutor.mutateResource<EditConversationRequest, ConversationResponse>(\n 'post',\n this.links.self,\n {\n unique_name: uniqueName\n }\n );\n }\n\n return this;\n }\n}\n\nexport {\n ConversationDescriptor,\n Conversation,\n ConversationUpdateReason,\n ConversationStatus,\n NotificationLevel,\n ConversationState,\n ConversationUpdatedEventArgs,\n SendMediaOptions,\n SendEmailOptions,\n LastMessage,\n ConversationBindings,\n ConversationEmailBinding\n};\n"],"names":["Logger","ReplayEventEmitter","Participants","Messages","isEqual","UriBuilder","parseToNumber","MessageBuilder","__decorate","validateTypesAsync","nonEmptyString","optionalAttributesValidator","nonNegativeInteger","literal","Participant","custom","objectSchema","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAEzC,MAAM,aAAa,GAAG;IACpB,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,wBAAwB,EAAE,0BAA0B;IACpD,iBAAiB,EAAE,mBAAmB;IACtC,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEF,SAAS,SAAS,CAAC,UAAU;IAC3B,IAAI;QACF,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AAgKD;;;AAGA,MAAM,YAAa,SAAQC,qCAAsC;;;;IAsB/D,YACE,UAAkC,EAClC,GAAW,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B,KAAK,EAAEK,+BAAM,CAAC,CAAC,KAAK;gBAClB,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,KAAK,YAAY,UAAU,IAAI,KAAK,YAAY,WAAW,CAAC;gBAE7H,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;oBAC9B,OAAO,GAAG,OAAO,IAAI,KAAK,YAAY,IAAI,CAAC;iBAC5C;gBAED,OAAO;oBACL,OAAO;oBACP,kEAAkE;iBACnE,CAAC;aACH,CAAC;SACH,CAAC;KACH,EACDJ,sCAA2B,EAC3B,CAAC,WAAW,EAAEE,gCAAO,CAAC,IAAI,CAAC,EAAEG,qCAAY,CAAC,kBAAkB,EAAE;YAC5D,OAAO,EAAE,CAACN,uCAAc,EAAE,WAAW,CAAC;SACvC,CAAC,CAAC,CACJ;;;;+CAUA;AAyCDF;IADCC,2CAAkB,CAACI,gCAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;;;;4DAS/C;AAeDL;IADCC,2CAAkB,CAACQ,8BAAmB,CAAC;;;;oDAWvC;AAODT;IADCC,2CAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC;;;;sDAW9B;AASDD;IADCC,2CAAkB,CAAC,CAACI,gCAAO,CAAC,IAAI,CAAC,EAAED,2CAAkB,CAAC,CAAC;;;;8DAIvD;AAODJ;IADCC,2CAAkB,CAAC,CAAC,QAAQ,EAAEI,gCAAO,CAAC,IAAI,CAAC,CAAC,CAAC;;;;oDAiB7C;;;;"}
|
package/dist/data/messages.js
CHANGED
@@ -216,7 +216,7 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
|
|
216
216
|
/**
|
217
217
|
* Send Message to the conversation, message could include both text and multiple media attachments.
|
218
218
|
* @param message Message to post
|
219
|
-
* @returns Returns promise which can fail
|
219
|
+
* @returns Returns a promise which can fail
|
220
220
|
*/
|
221
221
|
async sendV2(message) {
|
222
222
|
var _a;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"messages.js","sources":["../../src/data/messages.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport { Logger } from '../logger';\n\nimport {\n Message,\n MessageUpdatedEventArgs,\n MessageUpdateReason\n} from '../message';\nimport {\n Conversation,\n SendEmailOptions,\n SendMediaOptions\n} from '../conversation';\nimport { UnsentMessage } from '../unsent-message';\n\nimport { SyncList, SyncClient } from 'twilio-sync';\nimport { SyncPaginator } from '../sync-paginator';\n\nimport { McsClient, McsMedia } from '@twilio/mcs-client';\nimport { Network } from '../services/network';\nimport { Configuration } from '../configuration';\nimport { CommandExecutor } from '../command-executor';\nimport { SendMessageRequest } from '../interfaces/commands/send-message';\nimport { MessageResponse } from '../interfaces/commands/message-response';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\n\ntype MessagesEvents = {\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope('Messages');\n\nexport interface MessagesServices {\n mcsClient: McsClient;\n network: Network;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Represents the collection of messages in a conversation\n */\nclass Messages extends ReplayEventEmitter<MessagesEvents> {\n public readonly conversation: Conversation;\n private readonly configuration: Configuration;\n private readonly services: MessagesServices;\n private readonly messagesByIndex: Map<number, Message>;\n private messagesListPromise: Promise<SyncList>;\n\n public constructor(\n conversation: Conversation,\n configuration: Configuration,\n services: MessagesServices\n ) {\n super();\n\n this.conversation = conversation;\n this.configuration = configuration;\n this.services = services;\n\n this.messagesByIndex = new Map();\n this.messagesListPromise = null;\n }\n\n /**\n * Subscribe to the Messages Event Stream\n * @param name - The name of Sync object for the Messages resource.\n */\n public async subscribe(name: string) {\n if (this.messagesListPromise) {\n return this.messagesListPromise;\n }\n\n this.messagesListPromise = this.services.syncClient.list({\n id: name,\n mode: 'open_existing',\n });\n\n try {\n const list = await this.messagesListPromise;\n\n list.on('itemAdded', (args) => {\n log.debug(`${this.conversation.sid} itemAdded: ${args.item.index}`);\n\n const links = {\n self: `${this.conversation.links.messages}/${args.item.data.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${args.item.data.sid}/Receipts`,\n };\n const message = new Message(\n args.item.index,\n args.item.data,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n if (this.messagesByIndex.has(message.index)) {\n log.debug(\n 'Message arrived, but is already known and ignored',\n this.conversation.sid,\n message.index\n );\n return;\n }\n\n this.messagesByIndex.set(message.index, message);\n\n message.on('updated', (args: MessageUpdatedEventArgs) =>\n this.emit('messageUpdated', args)\n );\n\n this.emit('messageAdded', message);\n });\n\n list.on('itemRemoved', (args) => {\n log.debug(`#{this.conversation.sid} itemRemoved: ${args.index}`);\n\n const index = args.index;\n\n if (this.messagesByIndex.has(index)) {\n let message = this.messagesByIndex.get(index);\n this.messagesByIndex.delete(message.index);\n message.removeAllListeners('updated');\n this.emit('messageRemoved', message);\n }\n });\n\n list.on('itemUpdated', (args) => {\n log.debug(`${this.conversation.sid} itemUpdated: ${args.item.index}`);\n\n const message = this.messagesByIndex.get(args.item.index);\n\n if (message) {\n message._update(args.item.data);\n }\n });\n\n return list;\n } catch (err) {\n this.messagesListPromise = null;\n\n if (this.services.syncClient.connectionState !== 'disconnected') {\n log.error(\n 'Failed to get messages object for conversation',\n this.conversation.sid,\n err\n );\n }\n\n log.debug(\n 'ERROR: Failed to get messages object for conversation',\n this.conversation.sid,\n err\n );\n\n throw err;\n }\n }\n\n public async unsubscribe() {\n if (!this.messagesListPromise) {\n return;\n }\n\n const entity = await this.messagesListPromise;\n entity.close();\n this.messagesListPromise = null;\n }\n\n /**\n * Send Message to the conversation, message could include both text and multiple media attachments.\n * @param message Message to post\n * @returns Returns promise which can fail\n */\n public async sendV2(message: UnsentMessage) {\n log.debug(\n 'Sending message V2',\n message.mediaContent,\n message.attributes,\n message.emailOptions\n );\n\n const media: McsMedia[] = [];\n\n for (const [category, mediaContent] of message.mediaContent) {\n log.debug(\n `Adding media to a message as ${\n mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'\n }`,\n mediaContent\n );\n\n media.push(\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent, category)\n : await this.services.mcsClient.post(\n mediaContent.contentType,\n mediaContent.media,\n category,\n mediaContent.filename\n )\n );\n }\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n body: message.text,\n subject: message.emailOptions?.subject,\n media_sids: media.map((m) => m.sid),\n attributes:\n typeof message.attributes !== 'undefined'\n ? JSON.stringify(message.attributes)\n : undefined,\n });\n }\n\n /**\n * Send Message to the conversation\n * @param message Message to post\n * @param attributes Message attributes\n * @param emailOptions Options that modify E-mail integration behaviors.\n * @returns Returns promise which can fail\n */\n public async send(\n message: string | null,\n attributes: any = {},\n emailOptions?: SendEmailOptions\n ): Promise<MessageResponse> {\n log.debug('Sending text message', message, attributes, emailOptions);\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n body: message ?? '',\n attributes:\n typeof attributes !== 'undefined'\n ? JSON.stringify(attributes)\n : undefined,\n subject: emailOptions?.subject,\n });\n }\n\n /**\n * Send Media Message to the conversation\n * @param mediaContent Media content to post\n * @param attributes Message attributes\n * @param emailOptions Email options\n * @returns Returns promise which can fail\n */\n public async sendMedia(\n mediaContent: FormData | SendMediaOptions,\n attributes: any = {},\n emailOptions?: SendEmailOptions\n ) {\n log.debug('Sending media message', mediaContent, attributes, emailOptions);\n log.debug(\n `Sending media message as ${\n mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'\n }`,\n mediaContent,\n attributes\n );\n\n const media: McsMedia =\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent)\n : await this.services.mcsClient.post(\n mediaContent.contentType,\n mediaContent.media,\n 'media',\n mediaContent.filename\n );\n\n // emailOptions are currently ignored for media messages.\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n media_sids: [media.sid],\n attributes:\n typeof attributes !== 'undefined'\n ? JSON.stringify(attributes)\n : undefined,\n });\n }\n\n /**\n * Returns messages from conversation using paginator interface\n * @param pageSize Number of messages to return in single chunk. By default it's 30.\n * @param anchor Most early message id which is already known, or 'end' by default\n * @param direction Pagination order 'backwards' or 'forward', 'forward' by default\n * @returns Last page of messages by default\n */\n public async getMessages(\n pageSize: number,\n anchor: number | 'end',\n direction: 'forward' | 'backwards' = 'backwards'\n ): Promise<SyncPaginator<Message>> {\n return this._getMessages(pageSize, anchor, direction);\n }\n\n private _wrapPaginator(order, page, op) {\n // Due to an inconsistency between Sync and Chat conventions, next and\n // previous pages should be swapped.\n const shouldReverse = order === 'desc';\n\n const nextPage = () =>\n page.nextPage().then((page) => this._wrapPaginator(order, page, op));\n const previousPage = () =>\n page.prevPage().then((page) => this._wrapPaginator(order, page, op));\n\n return op(page.items).then((items) => ({\n items: items.sort((x, y) => {\n return x.index - y.index;\n }),\n hasPrevPage: shouldReverse ? page.hasNextPage : page.hasPrevPage,\n hasNextPage: shouldReverse ? page.hasPrevPage : page.hasNextPage,\n prevPage: shouldReverse ? nextPage : previousPage,\n nextPage: shouldReverse ? previousPage : nextPage,\n }));\n }\n\n private _upsertMessage(index: number, value: any) {\n const cachedMessage = this.messagesByIndex.get(index);\n\n if (cachedMessage) {\n return cachedMessage;\n }\n\n const links = {\n self: `${this.conversation.links.messages}/${value.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${value.sid}/Receipts`,\n };\n const message = new Message(\n index,\n value,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n this.messagesByIndex.set(message.index, message);\n\n message.on('updated', (args: MessageUpdatedEventArgs) =>\n this.emit('messageUpdated', args)\n );\n\n return message;\n }\n\n /**\n * Returns last messages from conversation\n * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.\n * @param {String} [anchor] Most early message id which is already known, or 'end' by default\n * @param {String} [direction] Pagination order 'backwards' or 'forward', or 'forward' by default\n * @returns {Promise<SyncPaginator<Message>>} last page of messages by default\n * @private\n */\n private async _getMessages(\n pageSize = 30,\n anchor: number | 'end' = 'end',\n direction: 'forward' | 'backwards' = 'forward'\n ): Promise<SyncPaginator<Message>> {\n const order = direction === 'backwards' ? 'desc' : 'asc';\n const list = await this.messagesListPromise;\n const page = await list.getItems({\n from: anchor !== 'end' ? anchor : void 0,\n pageSize,\n order,\n limit: pageSize, // @todo Limit equals pageSize by default in Sync. This is probably not ideal.\n });\n\n return await this._wrapPaginator(order, page, (items) =>\n Promise.all(\n items.map((item) => this._upsertMessage(item.index, item.data))\n )\n );\n }\n}\n\nexport { Messages };\n"],"names":["Logger","ReplayEventEmitter","message","Message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AASrC;;;AAGA,MAAM,QAAS,SAAQC,qCAAkC;IAOvD,YACE,YAA0B,EAC1B,aAA4B,EAC5B,QAA0B;QAE1B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;KACjC;;;;;IAMM,MAAM,SAAS,CAAC,IAAY;QACjC,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,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AAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAA6B,KAClD,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAClC,CAAC;QAEF,OAAOA,SAAO,CAAC;KAChB;;;;;;;;;IAUO,MAAM,YAAY,CACxB,QAAQ,GAAG,EAAE,EACb,SAAyB,KAAK,EAC9B,YAAqC,SAAS;QAE9C,MAAM,KAAK,GAAG,SAAS,KAAK,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;QACzD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC;QAC5C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC;YAC/B,IAAI,EAAE,MAAM,KAAK,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;YACxC,QAAQ;YACR,KAAK;YACL,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;QAEH,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,KAClD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAChE,CACF,CAAC;KACH;;;;;"}
|
1
|
+
{"version":3,"file":"messages.js","sources":["../../src/data/messages.ts"],"sourcesContent":["import { Logger } from '../logger';\n\nimport {\n Message,\n MessageUpdatedEventArgs,\n MessageUpdateReason\n} from '../message';\nimport {\n Conversation,\n SendEmailOptions,\n SendMediaOptions,\n} from '../conversation';\nimport { UnsentMessage } from '../unsent-message';\n\nimport { SyncList, SyncClient } from 'twilio-sync';\nimport { SyncPaginator } from '../sync-paginator';\n\nimport { McsClient, McsMedia } from '@twilio/mcs-client';\nimport { Network } from '../services/network';\nimport { Configuration } from '../configuration';\nimport { CommandExecutor } from '../command-executor';\nimport { SendMessageRequest } from '../interfaces/commands/send-message';\nimport { MessageResponse } from '../interfaces/commands/message-response';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\n\ntype MessagesEvents = {\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope('Messages');\n\nexport interface MessagesServices {\n mcsClient: McsClient;\n network: Network;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Represents the collection of messages in a conversation\n */\nclass Messages extends ReplayEventEmitter<MessagesEvents> {\n public readonly conversation: Conversation;\n private readonly configuration: Configuration;\n private readonly services: MessagesServices;\n private readonly messagesByIndex: Map<number, Message>;\n private messagesListPromise: Promise<SyncList>;\n\n public constructor(\n conversation: Conversation,\n configuration: Configuration,\n services: MessagesServices\n ) {\n super();\n\n this.conversation = conversation;\n this.configuration = configuration;\n this.services = services;\n\n this.messagesByIndex = new Map();\n this.messagesListPromise = null;\n }\n\n /**\n * Subscribe to the Messages Event Stream\n * @param name - The name of Sync object for the Messages resource.\n */\n public async subscribe(name: string) {\n if (this.messagesListPromise) {\n return this.messagesListPromise;\n }\n\n this.messagesListPromise = this.services.syncClient.list({\n id: name,\n mode: 'open_existing',\n });\n\n try {\n const list = await this.messagesListPromise;\n\n list.on('itemAdded', (args) => {\n log.debug(`${this.conversation.sid} itemAdded: ${args.item.index}`);\n\n const links = {\n self: `${this.conversation.links.messages}/${args.item.data.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${args.item.data.sid}/Receipts`,\n };\n const message = new Message(\n args.item.index,\n args.item.data,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n if (this.messagesByIndex.has(message.index)) {\n log.debug(\n 'Message arrived, but is already known and ignored',\n this.conversation.sid,\n message.index\n );\n return;\n }\n\n this.messagesByIndex.set(message.index, message);\n\n message.on('updated', (args: MessageUpdatedEventArgs) =>\n this.emit('messageUpdated', args)\n );\n\n this.emit('messageAdded', message);\n });\n\n list.on('itemRemoved', (args) => {\n log.debug(`#{this.conversation.sid} itemRemoved: ${args.index}`);\n\n const index = args.index;\n\n if (this.messagesByIndex.has(index)) {\n let message = this.messagesByIndex.get(index);\n this.messagesByIndex.delete(message.index);\n message.removeAllListeners('updated');\n this.emit('messageRemoved', message);\n }\n });\n\n list.on('itemUpdated', (args) => {\n log.debug(`${this.conversation.sid} itemUpdated: ${args.item.index}`);\n\n const message = this.messagesByIndex.get(args.item.index);\n\n if (message) {\n message._update(args.item.data);\n }\n });\n\n return list;\n } catch (err) {\n this.messagesListPromise = null;\n\n if (this.services.syncClient.connectionState !== 'disconnected') {\n log.error(\n 'Failed to get messages object for conversation',\n this.conversation.sid,\n err\n );\n }\n\n log.debug(\n 'ERROR: Failed to get messages object for conversation',\n this.conversation.sid,\n err\n );\n\n throw err;\n }\n }\n\n public async unsubscribe() {\n if (!this.messagesListPromise) {\n return;\n }\n\n const entity = await this.messagesListPromise;\n entity.close();\n this.messagesListPromise = null;\n }\n\n /**\n * Send Message to the conversation, message could include both text and multiple media attachments.\n * @param message Message to post\n * @returns Returns a promise which can fail\n */\n public async sendV2(message: UnsentMessage): Promise<MessageResponse> {\n log.debug(\n 'Sending message V2',\n message.mediaContent,\n message.attributes,\n message.emailOptions\n );\n\n const media: McsMedia[] = [];\n\n for (const [category, mediaContent] of message.mediaContent) {\n log.debug(\n `Adding media to a message as ${\n mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'\n }`,\n mediaContent\n );\n\n media.push(\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent, category)\n : await this.services.mcsClient.post(\n mediaContent.contentType,\n mediaContent.media,\n category,\n mediaContent.filename\n )\n );\n }\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n body: message.text,\n subject: message.emailOptions?.subject,\n media_sids: media.map((m) => m.sid),\n attributes:\n typeof message.attributes !== 'undefined'\n ? JSON.stringify(message.attributes)\n : undefined,\n });\n }\n\n /**\n * Send Message to the conversation\n * @param message Message to post\n * @param attributes Message attributes\n * @param emailOptions Options that modify E-mail integration behaviors.\n * @returns Returns promise which can fail\n */\n public async send(\n message: string | null,\n attributes: any = {},\n emailOptions?: SendEmailOptions\n ): Promise<MessageResponse> {\n log.debug('Sending text message', message, attributes, emailOptions);\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n body: message ?? '',\n attributes:\n typeof attributes !== 'undefined'\n ? JSON.stringify(attributes)\n : undefined,\n subject: emailOptions?.subject,\n });\n }\n\n /**\n * Send Media Message to the conversation\n * @param mediaContent Media content to post\n * @param attributes Message attributes\n * @param emailOptions Email options\n * @returns Returns promise which can fail\n */\n public async sendMedia(\n mediaContent: FormData | SendMediaOptions,\n attributes: any = {},\n emailOptions?: SendEmailOptions\n ) {\n log.debug('Sending media message', mediaContent, attributes, emailOptions);\n log.debug(\n `Sending media message as ${\n mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'\n }`,\n mediaContent,\n attributes\n );\n\n const media: McsMedia =\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent)\n : await this.services.mcsClient.post(\n mediaContent.contentType,\n mediaContent.media,\n 'media',\n mediaContent.filename\n );\n\n // emailOptions are currently ignored for media messages.\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n media_sids: [media.sid],\n attributes:\n typeof attributes !== 'undefined'\n ? JSON.stringify(attributes)\n : undefined,\n });\n }\n\n /**\n * Returns messages from conversation using paginator interface\n * @param pageSize Number of messages to return in single chunk. By default it's 30.\n * @param anchor Most early message id which is already known, or 'end' by default\n * @param direction Pagination order 'backwards' or 'forward', 'forward' by default\n * @returns Last page of messages by default\n */\n public async getMessages(\n pageSize: number,\n anchor: number | 'end',\n direction: 'forward' | 'backwards' = 'backwards'\n ): Promise<SyncPaginator<Message>> {\n return this._getMessages(pageSize, anchor, direction);\n }\n\n private _wrapPaginator(order, page, op) {\n // Due to an inconsistency between Sync and Chat conventions, next and\n // previous pages should be swapped.\n const shouldReverse = order === 'desc';\n\n const nextPage = () =>\n page.nextPage().then((page) => this._wrapPaginator(order, page, op));\n const previousPage = () =>\n page.prevPage().then((page) => this._wrapPaginator(order, page, op));\n\n return op(page.items).then((items) => ({\n items: items.sort((x, y) => {\n return x.index - y.index;\n }),\n hasPrevPage: shouldReverse ? page.hasNextPage : page.hasPrevPage,\n hasNextPage: shouldReverse ? page.hasPrevPage : page.hasNextPage,\n prevPage: shouldReverse ? nextPage : previousPage,\n nextPage: shouldReverse ? previousPage : nextPage,\n }));\n }\n\n private _upsertMessage(index: number, value: any) {\n const cachedMessage = this.messagesByIndex.get(index);\n\n if (cachedMessage) {\n return cachedMessage;\n }\n\n const links = {\n self: `${this.conversation.links.messages}/${value.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${value.sid}/Receipts`,\n };\n const message = new Message(\n index,\n value,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n this.messagesByIndex.set(message.index, message);\n\n message.on('updated', (args: MessageUpdatedEventArgs) =>\n this.emit('messageUpdated', args)\n );\n\n return message;\n }\n\n /**\n * Returns last messages from conversation\n * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.\n * @param {String} [anchor] Most early message id which is already known, or 'end' by default\n * @param {String} [direction] Pagination order 'backwards' or 'forward', or 'forward' by default\n * @returns {Promise<SyncPaginator<Message>>} last page of messages by default\n * @private\n */\n private async _getMessages(\n pageSize = 30,\n anchor: number | 'end' = 'end',\n direction: 'forward' | 'backwards' = 'forward'\n ): Promise<SyncPaginator<Message>> {\n const order = direction === 'backwards' ? 'desc' : 'asc';\n const list = await this.messagesListPromise;\n const page = await list.getItems({\n from: anchor !== 'end' ? anchor : void 0,\n pageSize,\n order,\n limit: pageSize, // @todo Limit equals pageSize by default in Sync. This is probably not ideal.\n });\n\n return await this._wrapPaginator(order, page, (items) =>\n Promise.all(\n items.map((item) => this._upsertMessage(item.index, item.data))\n )\n );\n }\n}\n\nexport { Messages };\n"],"names":["Logger","ReplayEventEmitter","message","Message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AASrC;;;AAGA,MAAM,QAAS,SAAQC,qCAAkC;IAOvD,YACE,YAA0B,EAC1B,aAA4B,EAC5B,QAA0B;QAE1B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;KACjC;;;;;IAMM,MAAM,SAAS,CAAC,IAAY;QACjC,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC;SACjC;QAED,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;YACvD,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,eAAe;SACtB,CAAC,CAAC;QAEH,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAE5C,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI;gBACxB,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,eAAe,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;gBAE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IAAI,EAAE,MAAM,KAAK,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;YACxC,QAAQ;YACR,KAAK;YACL,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;QAEH,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,KAClD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAChE,CACF,CAAC;KACH;;;;;"}
|
@@ -219,7 +219,7 @@ class Participants extends replayEventEmitter.ReplayEventEmitter {
|
|
219
219
|
/**
|
220
220
|
* @returns {Promise<Array<Participant>>} returns list of participants {@see Participant}
|
221
221
|
*/
|
222
|
-
getParticipants() {
|
222
|
+
async getParticipants() {
|
223
223
|
return this.rosterEntityPromise.then(() => {
|
224
224
|
let participants = [];
|
225
225
|
this.participants.forEach(participant => participants.push(participant));
|
@@ -273,14 +273,18 @@ class Participants extends replayEventEmitter.ReplayEventEmitter {
|
|
273
273
|
* @param proxyAddress
|
274
274
|
* @param address
|
275
275
|
* @param attributes
|
276
|
+
* @param bindingOptions
|
276
277
|
* @returns {Promise<any>}
|
277
278
|
*/
|
278
|
-
addNonChatParticipant(proxyAddress, address, attributes) {
|
279
|
+
addNonChatParticipant(proxyAddress, address, attributes = {}, bindingOptions = {}) {
|
280
|
+
var _a, _b;
|
279
281
|
return this.services.commandExecutor.mutateResource('post', this.links.participants, {
|
280
282
|
attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined,
|
281
283
|
messaging_binding: {
|
282
284
|
address,
|
283
|
-
proxy_address: proxyAddress
|
285
|
+
proxy_address: proxyAddress,
|
286
|
+
name: (_a = bindingOptions === null || bindingOptions === void 0 ? void 0 : bindingOptions.email) === null || _a === void 0 ? void 0 : _a.name,
|
287
|
+
level: (_b = bindingOptions === null || bindingOptions === void 0 ? void 0 : bindingOptions.email) === null || _b === void 0 ? void 0 : _b.level,
|
284
288
|
}
|
285
289
|
});
|
286
290
|
}
|