@twilio/conversations 2.2.1-rc.0 → 3.0.0-canary.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builds/browser.js +888 -2159
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +18 -100
- package/builds/lib.js +888 -2159
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +24296 -26232
- package/builds/twilio-conversations.min.js +1 -1
- package/dist/client.js +56 -90
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +30 -12
- package/dist/command-executor.js.map +1 -1
- package/dist/conversation.js +44 -6
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +4 -1
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +3 -13
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +4 -2
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +4 -2
- package/dist/data/users.js.map +1 -1
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +1 -41
- package/dist/message.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js.map +1 -1
- package/dist/services/network.js +38 -15
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +7 -5
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js.map +1 -1
- package/dist/util/index.js.map +1 -1
- package/package.json +14 -12
- package/CHANGELOG.md +0 -705
- package/docs/assets/css/main.css +0 -2660
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +0 -3184
- package/docs/classes/CancellablePromise.html +0 -3213
- package/docs/classes/Client.html +0 -4254
- package/docs/classes/Conversation.html +0 -4359
- package/docs/classes/DetailedDeliveryReceipt.html +0 -3163
- package/docs/classes/Media.html +0 -3167
- package/docs/classes/Message.html +0 -3732
- package/docs/classes/MessageBuilder.html +0 -3277
- package/docs/classes/Participant.html +0 -3444
- package/docs/classes/PushNotification.html +0 -3130
- package/docs/classes/RestPaginator.html +0 -3160
- package/docs/classes/UnsentMessage.html +0 -3042
- package/docs/classes/User.html +0 -3349
- package/docs/index.html +0 -3513
- package/docs/interfaces/ClientOptions.html +0 -3034
- package/docs/interfaces/ConversationBindings.html +0 -3001
- package/docs/interfaces/ConversationEmailBinding.html +0 -3001
- package/docs/interfaces/ConversationLimits.html +0 -3098
- package/docs/interfaces/ConversationState.html +0 -3050
- package/docs/interfaces/ConversationUpdatedEventArgs.html +0 -3001
- package/docs/interfaces/CreateConversationOptions.html +0 -3066
- package/docs/interfaces/LastMessage.html +0 -3050
- package/docs/interfaces/Paginator.html +0 -3141
- package/docs/interfaces/ParticipantBindings.html +0 -3001
- package/docs/interfaces/ParticipantEmailBinding.html +0 -3001
- package/docs/interfaces/PushNotificationData.html +0 -3114
- package/docs/interfaces/SendEmailOptions.html +0 -3034
- package/docs/interfaces/SendMediaOptions.html +0 -3068
- package/docs/modules.html +0 -3514
package/dist/command-executor.js
CHANGED
@@ -130,11 +130,11 @@ This software includes platform.js under the following license.
|
|
130
130
|
|
131
131
|
Object.defineProperty(exports, '__esModule', { value: true });
|
132
132
|
|
133
|
-
var uuid = require('uuid');
|
134
133
|
var operationRetrier = require('@twilio/operation-retrier');
|
134
|
+
var nanoid = require('nanoid');
|
135
135
|
|
136
136
|
const trimSlashes = (url) => url.replace(/(^\/+|\/+$)/g, "");
|
137
|
-
const isMutationConflictResponse = (response) => response.
|
137
|
+
const isMutationConflictResponse = (response) => response.statusCode === 202;
|
138
138
|
class CommandExecutor {
|
139
139
|
constructor(_serviceUrl, _services, _productId) {
|
140
140
|
this._serviceUrl = _serviceUrl;
|
@@ -159,45 +159,63 @@ class CommandExecutor {
|
|
159
159
|
getUrl +=
|
160
160
|
"?" +
|
161
161
|
Object.entries(requestBody)
|
162
|
-
.map((entry) => entry
|
162
|
+
.map((entry) => entry
|
163
|
+
.map((component) => encodeURIComponent(String(component)))
|
164
|
+
.join("="))
|
163
165
|
.join("&");
|
164
166
|
}
|
165
|
-
response = await this._services.transport.get(
|
167
|
+
response = await this._services.transport.get({
|
168
|
+
url: getUrl,
|
169
|
+
headers: finalHeaders,
|
170
|
+
grant: this._productId,
|
171
|
+
});
|
166
172
|
break;
|
167
173
|
case "post":
|
168
|
-
response = await this._services.transport.post(
|
174
|
+
response = await this._services.transport.post({
|
175
|
+
url: preProcessedUrl,
|
176
|
+
headers: finalHeaders,
|
177
|
+
body: JSON.stringify(requestBody),
|
178
|
+
grant: this._productId,
|
179
|
+
});
|
169
180
|
break;
|
170
181
|
case "delete":
|
171
|
-
response = await this._services.transport.delete(
|
182
|
+
response = await this._services.transport.delete({
|
183
|
+
url: preProcessedUrl,
|
184
|
+
headers: finalHeaders,
|
185
|
+
grant: this._productId,
|
186
|
+
});
|
172
187
|
break;
|
173
188
|
}
|
174
|
-
if (response.
|
175
|
-
throw new Error(`Request responded with a non-success code ${response.
|
189
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
190
|
+
throw new Error(`Request responded with a non-success code ${response.statusCode}`);
|
176
191
|
}
|
177
192
|
return response;
|
178
193
|
}
|
179
194
|
async fetchResource(url, requestBody) {
|
180
195
|
const maxAttemptsCount = 6;
|
181
196
|
try {
|
197
|
+
// todo: remove any after the release of new Twilsock
|
182
198
|
const result = await new operationRetrier.AsyncRetrier({
|
183
199
|
min: 50,
|
184
200
|
max: 1600,
|
185
201
|
maxAttemptsCount,
|
186
202
|
}).run(() => this._makeRequest("get", url, requestBody));
|
187
|
-
return result.
|
203
|
+
return JSON.parse(result.payload);
|
188
204
|
}
|
189
205
|
catch (_a) {
|
190
206
|
throw new Error(`Fetch resource from "${url}" failed.`);
|
191
207
|
}
|
192
208
|
}
|
193
209
|
async mutateResource(method, url, requestBody) {
|
210
|
+
// todo: remove any after the release of new Twilsock
|
194
211
|
const result = await this._makeRequest(method, url, requestBody, {
|
195
|
-
"X-Twilio-Mutation-Id":
|
212
|
+
"X-Twilio-Mutation-Id": nanoid.nanoid(),
|
196
213
|
});
|
214
|
+
const parsedPayload = JSON.parse(result.payload);
|
197
215
|
if (isMutationConflictResponse(result)) {
|
198
|
-
return await this.fetchResource(
|
216
|
+
return await this.fetchResource(parsedPayload.resource_url);
|
199
217
|
}
|
200
|
-
return
|
218
|
+
return parsedPayload;
|
201
219
|
}
|
202
220
|
}
|
203
221
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"command-executor.js","sources":["../src/command-executor.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"file":"command-executor.js","sources":["../src/command-executor.ts"],"sourcesContent":["import { TwilsockClient, HttpResponse } from \"twilsock\";\nimport { AsyncRetrier } from \"@twilio/operation-retrier\";\nimport { nanoid } from \"nanoid\";\n\nexport interface CommandExecutorServices {\n transport: TwilsockClient;\n}\n\nconst trimSlashes = (url: string): string => url.replace(/(^\\/+|\\/+$)/g, \"\");\n\nconst isMutationConflictResponse = (response: HttpResponse): boolean =>\n response.statusCode === 202;\n\nclass CommandExecutor {\n constructor(\n private _serviceUrl: string,\n private _services: CommandExecutorServices,\n private _productId?: string\n ) {}\n\n private _preProcessUrl(url: string): string {\n const trimmedUrl = trimSlashes(url);\n\n if (/^https?:\\/\\//.test(url)) {\n return trimmedUrl;\n }\n\n return `${trimSlashes(this._serviceUrl)}/${trimmedUrl}`;\n }\n\n private async _makeRequest<REQ = void, RESP = void>(\n method: \"get\" | \"post\" | \"delete\",\n url: string,\n requestBody?: REQ,\n headers?: Record<string, string>\n ): Promise<HttpResponse> {\n const preProcessedUrl = this._preProcessUrl(url);\n const finalHeaders = {\n \"Content-Type\": \"application/json; charset=utf-8\",\n ...(headers || {}),\n };\n let response: HttpResponse;\n\n switch (method) {\n case \"get\":\n let getUrl = preProcessedUrl;\n\n if (requestBody) {\n getUrl +=\n \"?\" +\n Object.entries(requestBody)\n .map((entry) =>\n entry\n .map((component) => encodeURIComponent(String(component)))\n .join(\"=\")\n )\n .join(\"&\");\n }\n\n response = await this._services.transport.get({\n url: getUrl,\n headers: finalHeaders,\n grant: this._productId,\n });\n break;\n case \"post\":\n response = await this._services.transport.post({\n url: preProcessedUrl,\n headers: finalHeaders,\n body: JSON.stringify(requestBody),\n grant: this._productId,\n });\n break;\n case \"delete\":\n response = await this._services.transport.delete({\n url: preProcessedUrl,\n headers: finalHeaders,\n grant: this._productId,\n });\n break;\n }\n\n if (response.statusCode < 200 || response.statusCode >= 300) {\n throw new Error(\n `Request responded with a non-success code ${response.statusCode}`\n );\n }\n\n return response;\n }\n\n public async fetchResource<REQ = void, RESP = void>(\n url: string,\n requestBody?: REQ\n ): Promise<RESP> {\n const maxAttemptsCount = 6;\n try {\n // todo: remove any after the release of new Twilsock\n const result = await new AsyncRetrier({\n min: 50,\n max: 1600,\n maxAttemptsCount,\n }).run(() => this._makeRequest<REQ, RESP>(\"get\", url, requestBody));\n return JSON.parse(result.payload);\n } catch {\n throw new Error(`Fetch resource from \"${url}\" failed.`);\n }\n }\n\n public async mutateResource<REQ = void, RESP = void>(\n method: \"post\" | \"delete\",\n url: string,\n requestBody?: REQ\n ): Promise<RESP> {\n // todo: remove any after the release of new Twilsock\n const result = await this._makeRequest<REQ, RESP>(\n method,\n url,\n requestBody,\n {\n \"X-Twilio-Mutation-Id\": nanoid(),\n }\n );\n\n const parsedPayload = JSON.parse(result.payload);\n\n if (isMutationConflictResponse(result)) {\n return await this.fetchResource<undefined, RESP>(\n parsedPayload.resource_url\n );\n }\n\n return parsedPayload;\n }\n}\n\nexport { CommandExecutor };\n"],"names":["AsyncRetrier","nanoid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;KACjB;AAEM,IAAA,MAAM,aAAa,CACxB,GAAW,EACX,WAAiB,EAAA;QAEjB,MAAM,gBAAgB,GAAG,CAAC,CAAC;QAC3B,IAAI;;AAEF,YAAA,MAAM,MAAM,GAAG,MAAM,IAAIA,6BAAY,CAAC;AACpC,gBAAA,GAAG,EAAE,EAAE;AACP,gBAAA,GAAG,EAAE,IAAI;gBACT,gBAAgB;AACjB,aAAA,CAAC,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAY,KAAK,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;YACpE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACnC,SAAA;QAAC,OAAM,EAAA,EAAA;AACN,YAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,CAAA,SAAA,CAAW,CAAC,CAAC;AACzD,SAAA;KACF;AAEM,IAAA,MAAM,cAAc,CACzB,MAAyB,EACzB,GAAW,EACX,WAAiB,EAAA;;AAGjB,QAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CACpC,MAAM,EACN,GAAG,EACH,WAAW,EACX;YACE,sBAAsB,EAAEC,aAAM,EAAE;AACjC,SAAA,CACF,CAAC;QAEF,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAEjD,QAAA,IAAI,0BAA0B,CAAC,MAAM,CAAC,EAAE;YACtC,OAAO,MAAM,IAAI,CAAC,aAAa,CAC7B,aAAa,CAAC,YAAY,CAC3B,CAAC;AACH,SAAA;AAED,QAAA,OAAO,aAAa,CAAC;KACtB;AACF;;;;"}
|
package/dist/conversation.js
CHANGED
@@ -443,6 +443,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
443
443
|
const url = new index.UriBuilder(this._configuration.links.conversations)
|
444
444
|
.path(this.sid)
|
445
445
|
.build();
|
446
|
+
// todo: remove any after the release of new Twilsock
|
446
447
|
const response = await this._services.network.get(url);
|
447
448
|
return (_a = response.body.participants_count) !== null && _a !== void 0 ? _a : 0;
|
448
449
|
}
|
@@ -476,6 +477,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
476
477
|
const url = new index.UriBuilder(this._configuration.links.conversations)
|
477
478
|
.path(this.sid)
|
478
479
|
.build();
|
480
|
+
// todo: remove any after the release of new Twilsock
|
479
481
|
const response = await this._services.network.get(url);
|
480
482
|
return (_a = response.body.messages_count) !== null && _a !== void 0 ? _a : 0;
|
481
483
|
}
|
@@ -506,6 +508,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
506
508
|
const url = new index.UriBuilder(this._configuration.links.myConversations)
|
507
509
|
.path(this.sid)
|
508
510
|
.build();
|
511
|
+
// todo: remove any after the release of new Twilsock
|
509
512
|
const response = await this._services.network.get(url);
|
510
513
|
if (response.body.conversation_sid !== this.sid) {
|
511
514
|
throw new Error("Conversation was not found in the user conversations list");
|
@@ -552,13 +555,48 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
|
|
552
555
|
* @return Index of the new message.
|
553
556
|
*/
|
554
557
|
async sendMessage(message, messageAttributes, emailOptions) {
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
558
|
+
const response = typeof message === "string" || message === null
|
559
|
+
? await this._messagesEntity.send(message, messageAttributes, emailOptions)
|
560
|
+
: await this._messagesEntity.sendMedia(message, messageAttributes, emailOptions);
|
561
|
+
const type = typeof message === "string" || message === null ? "text" : "media";
|
562
|
+
let responseAttributes;
|
563
|
+
try {
|
564
|
+
responseAttributes = JSON.parse(response.attributes);
|
559
565
|
}
|
560
|
-
|
561
|
-
|
566
|
+
catch (e) { }
|
567
|
+
const messageData = {
|
568
|
+
sid: response.sid,
|
569
|
+
text: response.body,
|
570
|
+
type,
|
571
|
+
author: response.author,
|
572
|
+
subject: response.subject,
|
573
|
+
lastUpdatedBy: response.participant_sid,
|
574
|
+
attributes: responseAttributes,
|
575
|
+
dateUpdated: response.date_updated,
|
576
|
+
timestamp: response.date_created,
|
577
|
+
memberSid: response.participant_sid,
|
578
|
+
medias: Array.isArray(response.media)
|
579
|
+
? response.media.map((media) => ({
|
580
|
+
sid: media["sid"],
|
581
|
+
size: Number(media["size"]),
|
582
|
+
category: media["category"],
|
583
|
+
filename: media["filename"],
|
584
|
+
contentType: media["content_type"],
|
585
|
+
}))
|
586
|
+
: null,
|
587
|
+
media: response.media &&
|
588
|
+
typeof response.media === "object" &&
|
589
|
+
!Array.isArray(response.media)
|
590
|
+
? {
|
591
|
+
sid: response.media["sid"],
|
592
|
+
size: Number(response.media["size"]),
|
593
|
+
category: response.media["category"],
|
594
|
+
filename: response.media["filename"],
|
595
|
+
contentType: response.media["content_type"],
|
596
|
+
}
|
597
|
+
: null,
|
598
|
+
};
|
599
|
+
return this._messagesEntity._upsertMessage(response.index, messageData);
|
562
600
|
}
|
563
601
|
/**
|
564
602
|
* New interface to prepare for sending a message.
|
package/dist/conversation.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"conversation.js","sources":["../src/conversation.ts"],"sourcesContent":["import \"isomorphic-form-data\";\nimport { Logger } from \"./logger\";\nimport { ParticipantBindingOptions, Participants } from \"./data/participants\";\nimport {\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason,\n} from \"./participant\";\nimport { Messages } from \"./data/messages\";\nimport {\n Message,\n MessageUpdatedEventArgs,\n MessageUpdateReason,\n} from \"./message\";\nimport { UriBuilder, parseToNumber, parseTime } from \"./util\";\nimport { Users } from \"./data/users\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { ConversationsDataSource } from \"./data/conversations\";\nimport { McsClient } from \"@twilio/mcs-client\";\nimport { SyncClient, SyncDocument, SyncList, SyncMap } from \"twilio-sync\";\nimport { TypingIndicator } from \"./services/typing-indicator\";\nimport { Network } from \"./services/network\";\nimport {\n validateTypesAsync,\n custom,\n literal,\n nonEmptyString,\n nonNegativeInteger,\n objectSchema,\n} from \"@twilio/declarative-type-validator\";\nimport {\n attributesValidator,\n optionalAttributesValidator,\n} from \"./interfaces/attributes\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { AddParticipantRequest } from \"./interfaces/commands/add-participant\";\nimport { EditConversationRequest } from \"./interfaces/commands/edit-conversation\";\nimport { ConversationResponse } from \"./interfaces/commands/conversation-response\";\nimport { ParticipantResponse } from \"./interfaces/commands/participant-response\";\nimport { EditNotificationLevelRequest } from \"./interfaces/commands/edit-notification-level\";\nimport {\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse,\n} from \"./interfaces/commands/edit-last-read-message-index\";\nimport { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { MessageBuilder } from \"./message-builder\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\n\n/**\n * Conversation events.\n */\ntype ConversationEvents = {\n participantJoined: (participant: Participant) => void;\n participantLeft: (participant: Participant) => void;\n participantUpdated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n }) => void;\n removed: (conversation: Conversation) => void;\n};\n\n/**\n * Reason for the `updated` event emission by a conversation.\n */\ntype ConversationUpdateReason =\n | \"attributes\"\n | \"createdBy\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"friendlyName\"\n | \"lastReadMessageIndex\"\n | \"state\"\n | \"status\"\n | \"uniqueName\"\n | \"lastMessage\"\n | \"notificationLevel\"\n | \"bindings\";\n\n/**\n * Status of the conversation, relative to the client: whether the conversation\n * has been `joined` or the client is `notParticipating` in the conversation.\n */\ntype ConversationStatus = \"notParticipating\" | \"joined\";\n\n/**\n * User's notification level for the conversation. Determines\n * whether the currently logged-in user will receive pushes for events\n * in this conversation. Can be either `muted` or `default`, where\n * `default` defers to the global service push configuration.\n */\ntype NotificationLevel = \"default\" | \"muted\";\n\n/**\n * State of the conversation.\n */\ninterface ConversationState {\n /**\n * Current state.\n */\n current: \"active\" | \"inactive\" | \"closed\";\n\n /**\n * Date at which the latest conversation state update happened.\n */\n dateUpdated: Date;\n}\n\n/**\n * Event arguments for the `updated` event.\n */\ninterface ConversationUpdatedEventArgs {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationBindings {\n email?: ConversationEmailBinding;\n sms?: ConversationSmsBinding;\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationEmailBinding {\n name?: string;\n projected_address: string;\n}\n\n/**\n * Binding for SMS conversation.\n */\ninterface ConversationSmsBinding {\n address?: string;\n}\n\n/**\n * Configuration for attaching a media file to a message.\n * These options can be passed to {@link Conversation.sendMessage} and\n * {@link MessageBuilder.addMedia}.\n */\ninterface SendMediaOptions {\n /**\n * Content type of media.\n */\n contentType: null | string;\n\n /**\n * Optional filename.\n */\n filename?: string;\n\n /**\n * Content to post.\n */\n media: null | string | Buffer | Blob;\n}\n\n/**\n * These options can be passed to {@link Conversation.sendMessage}.\n */\ninterface SendEmailOptions {\n /**\n * Message subject. Ignored for media messages.\n */\n subject?: string;\n}\n\n/**\n * Information about the last message of a conversation.\n */\ninterface LastMessage {\n /**\n * Message's index.\n */\n index?: number;\n\n /**\n * Message's creation date.\n */\n dateCreated?: Date;\n}\n\n/**\n * Conversation services.\n */\ninterface ConversationServices {\n users: Users;\n typingIndicator: TypingIndicator;\n network: Network;\n mcsClient: McsClient;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Internal (private) state of the conversation.\n */\ninterface ConversationInternalState {\n uniqueName: string | null;\n status: ConversationStatus;\n attributes: JSONValue;\n createdBy?: string;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n friendlyName: string | null;\n lastReadMessageIndex: number | null;\n lastMessage?: LastMessage;\n notificationLevel?: NotificationLevel;\n state?: ConversationState;\n bindings: ConversationBindings;\n}\n\n/**\n * Conversation descriptor.\n */\ninterface ConversationDescriptor {\n channel: string;\n entityName: string;\n uniqueName: string;\n attributes: JSONValue;\n createdBy?: string;\n friendlyName?: string;\n lastConsumedMessageIndex: number;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n notificationLevel?: NotificationLevel;\n bindings?: ConversationBindings;\n}\n\n/**\n * Conversation links.\n */\ninterface ConversationLinks {\n self: string;\n messages: string;\n participants: string;\n}\n\n/**\n * Map of the fields that will be processed with update messages.\n */\nconst fieldMappings = {\n lastMessage: \"lastMessage\",\n attributes: \"attributes\",\n createdBy: \"createdBy\",\n dateCreated: \"dateCreated\",\n dateUpdated: \"dateUpdated\",\n friendlyName: \"friendlyName\",\n lastConsumedMessageIndex: \"lastConsumedMessageIndex\",\n notificationLevel: \"notificationLevel\",\n sid: \"sid\",\n status: \"status\",\n uniqueName: \"uniqueName\",\n state: \"state\",\n bindings: \"bindings\",\n};\n\n/**\n * A conversation represents communication between multiple Conversations\n * clients.\n */\nclass Conversation extends ReplayEventEmitter<ConversationEvents> {\n /**\n * Fired when a participant has joined the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that joined the\n * conversation\n * @event\n */\n public static readonly participantJoined = \"participantJoined\";\n\n /**\n * Fired when a participant has left the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that left the\n * conversation\n * @event\n */\n public static readonly participantLeft = \"participantLeft\";\n\n /**\n * Fired when data of a participant has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Participant} `participant` - participant that has received the\n * update\n * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly participantUpdated = \"participantUpdated\";\n\n /**\n * Fired when a new message has been added to the conversation.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been added\n * @event\n */\n public static readonly messageAdded = \"messageAdded\";\n\n /**\n * Fired when message is removed from the conversation's message list.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been removed\n * @event\n */\n public static readonly messageRemoved = \"messageRemoved\";\n\n /**\n * Fired when data of a message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Message} `message` - message that has received the update\n * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for\n * the update\n * @event\n */\n public static readonly messageUpdated = \"messageUpdated\";\n\n /**\n * Fired when a participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has stopped\n * typing\n * @event\n */\n public static readonly typingEnded = \"typingEnded\";\n\n /**\n * Fired when a participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has started\n * typing\n * @event\n */\n public static readonly typingStarted = \"typingStarted\";\n\n /**\n * Fired when the data of the conversation has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Conversation} `conversation` - conversation that has received\n * the update\n * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly updated = \"updated\";\n\n /**\n * Fired when the conversation was destroyed or the currently-logged-in user\n * has left private conversation.\n *\n * Parameters:\n * 1. {@link Conversation} `conversation` - conversation that has been removed\n * @event\n */\n public static readonly removed = \"removed\";\n\n /**\n * Logger instance.\n */\n private static readonly _logger = Logger.scope(\"Conversation\");\n\n /**\n * Unique system identifier of the conversation.\n */\n public readonly sid: string;\n\n /**\n * Conversation links for REST requests.\n * @internal\n */\n public readonly _links: ConversationLinks;\n\n /**\n * Map of participants.\n * @internal\n */\n public readonly _participants: Map<string, Participant>;\n\n /**\n * Configuration of the client that the conversation belongs to.\n */\n private readonly _configuration: Configuration;\n\n /**\n * Conversation service objects.\n */\n private readonly _services: ConversationServices;\n\n /**\n * Internal state of the conversation.\n */\n private readonly _internalState: ConversationInternalState;\n\n /**\n * Name of the conversation entity document.\n */\n private readonly _entityName: string;\n\n /**\n * Messages entity.\n */\n private readonly _messagesEntity: Messages;\n\n /**\n * Sync list containing messages.\n */\n private _messagesList?: SyncList;\n\n /**\n * Participants entity.\n */\n private readonly _participantsEntity: Participants;\n\n /**\n * Sync map containing participants.\n */\n private _participantsMap?: SyncMap;\n\n /**\n * Source of the most recent update.\n */\n private _dataSource!: ConversationsDataSource;\n\n /**\n * Promise for the conversation entity document.\n */\n private _entityPromise!: Promise<SyncDocument> | null;\n\n /**\n * Conversation entity document.\n */\n private _entity!: SyncDocument | null;\n\n /**\n * @param descriptor Conversation descriptor.\n * @param sid Conversation SID.\n * @param links Conversation links for REST requests.\n * @param configuration Client configuration.\n * @param services Conversation services.\n * @internal\n */\n public constructor(\n descriptor: ConversationDescriptor,\n sid: string,\n links: ConversationLinks,\n configuration: Configuration,\n services: ConversationServices\n ) {\n super();\n\n this.sid = sid;\n this._links = links;\n this._configuration = configuration;\n this._services = services;\n this._entityName = descriptor.channel;\n this._internalState = {\n uniqueName: descriptor.uniqueName || null,\n status: \"notParticipating\",\n attributes: descriptor.attributes ?? {},\n createdBy: descriptor.createdBy,\n dateCreated: parseTime(descriptor.dateCreated),\n dateUpdated: parseTime(descriptor.dateUpdated),\n friendlyName: descriptor.friendlyName || null,\n lastReadMessageIndex: Number.isInteger(\n descriptor.lastConsumedMessageIndex\n )\n ? descriptor.lastConsumedMessageIndex\n : null,\n bindings: descriptor.bindings ?? {},\n };\n\n if (descriptor.notificationLevel) {\n this._internalState.notificationLevel = descriptor.notificationLevel;\n }\n\n const participantsLinks = {\n participants: this._links.participants,\n };\n\n this._participants = new Map();\n this._participantsEntity = new Participants(\n this,\n this._participants,\n participantsLinks,\n this._configuration,\n this._services\n );\n this._participantsEntity.on(\"participantJoined\", (participant) =>\n this.emit(\"participantJoined\", participant)\n );\n this._participantsEntity.on(\"participantLeft\", (participant) =>\n this.emit(\"participantLeft\", participant)\n );\n this._participantsEntity.on(\n \"participantUpdated\",\n (args: ParticipantUpdatedEventArgs) =>\n this.emit(\"participantUpdated\", args)\n );\n\n this._messagesEntity = new Messages(this, configuration, services);\n this._messagesEntity.on(\"messageAdded\", (message) =>\n this._onMessageAdded(message)\n );\n this._messagesEntity.on(\"messageUpdated\", (args: MessageUpdatedEventArgs) =>\n this.emit(\"messageUpdated\", args)\n );\n this._messagesEntity.on(\"messageRemoved\", (message) =>\n this.emit(\"messageRemoved\", message)\n );\n }\n\n /**\n * Unique name of the conversation.\n */\n public get uniqueName(): string | null {\n return this._internalState.uniqueName;\n }\n\n /**\n * Status of the conversation.\n */\n public get status(): ConversationStatus {\n return this._internalState.status;\n }\n\n /**\n * Name of the conversation.\n */\n public get friendlyName(): string | null {\n return this._internalState.friendlyName;\n }\n\n /**\n * Date this conversation was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this._internalState.dateUpdated;\n }\n\n /**\n * Date this conversation was created on.\n */\n public get dateCreated(): Date | null {\n return this._internalState.dateCreated;\n }\n\n /**\n * Identity of the user that created this conversation.\n */\n public get createdBy(): string {\n return this._internalState.createdBy ?? \"\";\n }\n\n /**\n * Custom attributes of the conversation.\n */\n public get attributes(): JSONValue {\n return this._internalState.attributes;\n }\n\n /**\n * Index of the last message the user has read in this conversation.\n */\n public get lastReadMessageIndex(): number | null {\n return this._internalState.lastReadMessageIndex;\n }\n\n /**\n * Last message sent to this conversation.\n */\n public get lastMessage(): LastMessage | undefined {\n return this._internalState.lastMessage ?? undefined;\n }\n\n /**\n * User notification level for this conversation.\n */\n public get notificationLevel(): NotificationLevel {\n return this._internalState.notificationLevel ?? \"default\";\n }\n\n /**\n * Conversation bindings. Undocumented feature (for now).\n * @internal\n */\n public get bindings(): ConversationBindings {\n return this._internalState.bindings;\n }\n\n /**\n * Current conversation limits.\n */\n public get limits(): ConversationLimits {\n return this._configuration.limits;\n }\n\n /**\n * State of the conversation.\n */\n public get state(): ConversationState | undefined {\n return this._internalState.state;\n }\n\n /**\n * Source of the conversation update.\n * @internal\n */\n public get _statusSource(): ConversationsDataSource {\n return this._dataSource;\n }\n\n /**\n * Preprocess the update object.\n * @param update The update object received from Sync.\n * @param conversationSid The SID of the conversation in question.\n */\n private static preprocessUpdate(update, conversationSid: string) {\n try {\n if (typeof update.attributes === \"string\") {\n update.attributes = JSON.parse(update.attributes);\n } else if (update.attributes) {\n JSON.stringify(update.attributes);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed attributes from the server for conversation: \" +\n conversationSid\n );\n update.attributes = {};\n }\n\n try {\n if (update.dateCreated) {\n update.dateCreated = new Date(update.dateCreated);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateCreated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateCreated;\n }\n\n try {\n if (update.dateUpdated) {\n update.dateUpdated = new Date(update.dateUpdated);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateUpdated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateUpdated;\n }\n\n try {\n if (update.lastMessage && update.lastMessage.timestamp) {\n update.lastMessage.timestamp = new Date(update.lastMessage.timestamp);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed lastMessage.timestamp from the server for conversation: \" +\n conversationSid\n );\n delete update.lastMessage.timestamp;\n }\n }\n\n /**\n * Add a participant to the conversation by its identity.\n * @param identity Identity of the Client to add.\n * @param attributes Attributes to be attached to the participant.\n * @returns The added participant.\n */\n @validateTypesAsync(nonEmptyString, optionalAttributesValidator)\n public async add(\n identity: string,\n attributes?: JSONValue\n ): Promise<ParticipantResponse> {\n return this._participantsEntity.add(identity, attributes ?? {});\n }\n\n /**\n * Add a non-chat participant to the conversation.\n * @param proxyAddress Proxy (Twilio) address of the participant.\n * @param address User address of the participant.\n * @param attributes Attributes to be attached to the participant.\n * @param bindingOptions Options for adding email participants - name and\n * CC/To level.\n * @returns The added participant.\n */\n @validateTypesAsync(\n nonEmptyString,\n nonEmptyString,\n optionalAttributesValidator\n )\n public async addNonChatParticipant(\n proxyAddress: string,\n address: string,\n attributes: JSONValue = {},\n bindingOptions: ParticipantBindingOptions = {}\n ): Promise<ParticipantResponse> {\n return this._participantsEntity.addNonChatParticipant(\n proxyAddress,\n address,\n attributes ?? {},\n bindingOptions ?? {}\n );\n }\n\n /**\n * Advance the conversation's last read message index to the current read\n * horizon. Rejects if the user is not a participant of the conversation. Last\n * read message index is updated only if the new index value is higher than\n * the previous.\n * @param index Message index to advance to.\n * @return Resulting unread messages count in the conversation.\n */\n @validateTypesAsync(nonNegativeInteger)\n public async advanceLastReadMessageIndex(index: number): Promise<number> {\n await this._subscribeStreams();\n\n if (index < (this.lastReadMessageIndex ?? 0)) {\n return await this._setLastReadMessageIndex(this.lastReadMessageIndex);\n }\n\n return await this._setLastReadMessageIndex(index);\n }\n\n /**\n * Delete the conversation and unsubscribe from its events.\n */\n public async delete(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n this._links.self\n );\n\n return this;\n }\n\n /**\n * Get the custom attributes of this Conversation.\n */\n public async getAttributes(): Promise<JSONValue> {\n await this._subscribe();\n return this.attributes;\n }\n\n /**\n * Returns messages from the conversation using the paginator interface.\n * @param pageSize Number of messages to return in a single chunk. Default is\n * 30.\n * @param anchor Index of the newest message to fetch. Default is from the\n * end.\n * @param direction Query direction. By default, it queries backwards\n * from newer to older. The `\"forward\"` value will query in the opposite\n * direction.\n * @return A page of messages.\n */\n @validateTypesAsync(\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", literal(\"backwards\", \"forward\")]\n )\n public async getMessages(\n pageSize?: number,\n anchor?: number,\n direction?: \"backwards\" | \"forward\"\n ): Promise<Paginator<Message>> {\n await this._subscribeStreams();\n return this._messagesEntity.getMessages(pageSize, anchor, direction);\n }\n\n /**\n * Get a list of all the participants who are joined to this conversation.\n */\n public async getParticipants(): Promise<Participant[]> {\n await this._subscribeStreams();\n return this._participantsEntity.getParticipants();\n }\n\n /**\n * Get conversation participants count.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getParticipantsCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n const response = await this._services.network.get<ConversationResponse>(\n url\n );\n\n return response.body.participants_count ?? 0;\n }\n\n /**\n * Get a participant by its SID.\n * @param participantSid Participant SID.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantBySid(\n participantSid: string\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantBySid(participantSid);\n }\n\n /**\n * Get a participant by its identity.\n * @param identity Participant identity.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantByIdentity(\n identity: string | null = \"\"\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantByIdentity(identity ?? \"\");\n }\n\n /**\n * Get the total message count in the conversation.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getMessagesCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n const response = await this._services.network.get<ConversationResponse>(\n url\n );\n\n return response.body.messages_count ?? 0;\n }\n\n /**\n * Get count of unread messages for the user if they are a participant of this\n * conversation. Rejects if the user is not a participant of the conversation.\n *\n * Use this method to obtain the number of unread messages together with\n * {@link Conversation.updateLastReadMessageIndex} instead of relying on the\n * message indices which may have gaps. See {@link Message.index} for details.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but it will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n *\n * If the read horizon is not set, this function will return null. This could mean\n * that all messages in the conversation are unread, or that the read horizon system\n * is not being used. How to interpret this `null` value is up to the customer application.\n *\n * @return Number of unread messages based on the current read horizon set for\n * the user or `null` if the read horizon is not set.\n */\n public async getUnreadMessagesCount(): Promise<number | null> {\n const url = new UriBuilder(this._configuration.links.myConversations)\n .path(this.sid)\n .build();\n const response = await this._services.network.get<ConversationResponse>(\n url\n );\n\n if (response.body.conversation_sid !== this.sid) {\n throw new Error(\n \"Conversation was not found in the user conversations list\"\n );\n }\n\n const unreadMessageCount = response.body.unread_messages_count;\n\n if (typeof unreadMessageCount === \"number\") {\n return unreadMessageCount;\n }\n\n return null;\n }\n\n /**\n * Join the conversation and subscribe to its events.\n */\n public async join(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n AddParticipantRequest,\n ParticipantResponse\n >(\"post\", this._links.participants, {\n identity: this._configuration.userIdentity,\n });\n\n return this;\n }\n\n /**\n * Leave the conversation.\n */\n public async leave(): Promise<Conversation> {\n if (this._internalState.status === \"joined\") {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n `${this._links.participants}/${this._configuration.userIdentity}`\n );\n }\n\n return this;\n }\n\n /**\n * Remove a participant from the conversation. When a string is passed as the\n * argument, it will assume that the string is an identity or SID.\n * @param participant Identity, SID or the participant object to remove.\n */\n @validateTypesAsync([nonEmptyString, Participant])\n public async removeParticipant(\n participant: string | Participant\n ): Promise<void> {\n await this._participantsEntity.remove(\n typeof participant === \"string\" ? participant : participant.sid\n );\n }\n\n /**\n * Send a message to the conversation.\n * @param message Message body for the text message,\n * `FormData` or {@link SendMediaOptions} for media content. Sending FormData\n * is supported only with the browser engine.\n * @param messageAttributes Attributes for the message.\n * @param emailOptions Email options for the message.\n * @return Index of the new message.\n */\n @validateTypesAsync(\n [\n \"string\",\n FormData,\n literal(null),\n objectSchema(\"media options\", {\n contentType: nonEmptyString,\n media: custom((value) => {\n let isValid =\n (typeof value === \"string\" && value.length > 0) ||\n value instanceof Uint8Array ||\n value instanceof ArrayBuffer;\n\n if (typeof Blob === \"function\") {\n isValid = isValid || value instanceof Blob;\n }\n\n return [\n isValid,\n \"a non-empty string, an instance of Buffer or an instance of Blob\",\n ];\n }),\n }),\n ],\n optionalAttributesValidator,\n [\n \"undefined\",\n literal(null),\n objectSchema(\"email attributes\", {\n subject: [nonEmptyString, \"undefined\"],\n }),\n ]\n )\n public async sendMessage(\n message: null | string | FormData | SendMediaOptions,\n messageAttributes?: JSONValue,\n emailOptions?: SendEmailOptions\n ): Promise<number> {\n if (typeof message === \"string\" || message === null) {\n const response = await this._messagesEntity.send(\n message,\n messageAttributes,\n emailOptions\n );\n return parseToNumber(response.index) ?? 0;\n }\n\n const response = await this._messagesEntity.sendMedia(\n message,\n messageAttributes,\n emailOptions\n );\n return parseToNumber(response.index) ?? 0;\n }\n\n /**\n * New interface to prepare for sending a message.\n * Use this instead of {@link Message.sendMessage}.\n * @return A MessageBuilder to help set all message sending options.\n */\n public prepareMessage(): MessageBuilder {\n return new MessageBuilder(this.limits, this._messagesEntity);\n }\n\n /**\n * Set last read message index of the conversation to the index of the last\n * known message.\n * @return Resulting unread messages count in the conversation.\n */\n public async setAllMessagesRead(): Promise<number> {\n await this._subscribeStreams();\n\n const messagesPage = await this.getMessages(1);\n\n if (messagesPage.items.length > 0) {\n return this.advanceLastReadMessageIndex(messagesPage.items[0].index);\n }\n\n return 0;\n }\n\n /**\n * Set all messages in the conversation unread.\n * @returns New count of unread messages after this update.\n */\n public async setAllMessagesUnread(): Promise<number> {\n await this._subscribeStreams();\n return await this._setLastReadMessageIndex(null);\n }\n\n /**\n * Set user notification level for this conversation.\n * @param notificationLevel New user notification level.\n */\n @validateTypesAsync(literal(\"default\", \"muted\"))\n public async setUserNotificationLevel(\n notificationLevel: NotificationLevel\n ): Promise<void> {\n await this._services.commandExecutor.mutateResource<EditNotificationLevelRequest>(\n \"post\",\n `${this._configuration.links.myConversations}/${this.sid}`,\n {\n notification_level: notificationLevel,\n }\n );\n }\n\n /**\n * Send a notification to the server indicating that this client is currently\n * typing in this conversation. Typing ended notification is sent after a\n * while automatically, but by calling this method again you ensure that\n * typing ended is not received.\n */\n public typing(): Promise<void> {\n return this._services.typingIndicator.send(this.sid);\n }\n\n /**\n * Update the attributes of the conversation.\n * @param attributes New attributes.\n */\n @validateTypesAsync(attributesValidator)\n public async updateAttributes(attributes: JSONValue): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n attributes:\n attributes !== undefined ? JSON.stringify(attributes) : undefined,\n });\n\n return this;\n }\n\n /**\n * Update the friendly name of the conversation.\n * @param friendlyName New friendly name.\n */\n @validateTypesAsync(\"string\")\n public async updateFriendlyName(friendlyName: string): Promise<Conversation> {\n if (this._internalState.friendlyName !== friendlyName) {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, { friendly_name: friendlyName });\n }\n\n return this;\n }\n\n /**\n * Set the last read message index to the current read horizon.\n * @param index Message index to set as last read. If null is provided, then\n * the behavior is identical to {@link Conversation.setAllMessagesUnread}.\n * @returns New count of unread messages after this update.\n */\n @validateTypesAsync([literal(null), nonNegativeInteger])\n public async updateLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n await this._subscribeStreams();\n return this._setLastReadMessageIndex(index);\n }\n\n /**\n * Update the unique name of the conversation.\n * @param uniqueName New unique name for the conversation. Setting unique name\n * to null removes it.\n */\n @validateTypesAsync([\"string\", literal(null)])\n public async updateUniqueName(\n uniqueName: string | null\n ): Promise<Conversation> {\n if (this._internalState.uniqueName !== uniqueName) {\n uniqueName ||= \"\";\n\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n unique_name: uniqueName,\n });\n }\n\n return this;\n }\n\n /**\n * Load and subscribe to this conversation and do not subscribe to its\n * participants and messages. This or _subscribeStreams will need to be called\n * before any events on conversation will fire.\n * @internal\n */\n public async _subscribe(): Promise<SyncDocument> {\n if (this._entityPromise) {\n return this._entityPromise;\n }\n\n this._entityPromise = this._services.syncClient.document({\n id: this._entityName,\n mode: \"open_existing\",\n });\n\n try {\n this._entity = await this._entityPromise;\n this._entity.on(\"updated\", (args) => this._update(args.data));\n this._entity.on(\"removed\", () => this.emit(\"removed\", this));\n this._update(this._entity.data);\n\n return this._entity;\n } catch (err) {\n this._entity = null;\n this._entityPromise = null;\n\n if (this._services.syncClient.connectionState != \"disconnected\") {\n Conversation._logger.error(\"Failed to get conversation object\", err);\n }\n Conversation._logger.debug(\n \"ERROR: Failed to get conversation object\",\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Fetch participants and messages of the conversation. This method needs to\n * be called during conversation initialization to catch broken conversations\n * (broken conversations are conversations that have essential Sync entities\n * missing, i.e. the conversation document, the messages list or the\n * participant map). In case of this conversation being broken, the method\n * will throw an exception that will be caught and handled gracefully.\n * @internal\n */\n public async _fetchStreams() {\n await this._subscribe();\n Conversation._logger.trace(\n \"_streamsAvailable, this.entity.data=\",\n this._entity?.data\n );\n\n const data = this._entity?.data as Record<string, string>;\n this._messagesList = await this._services.syncClient.list({\n id: data.messages,\n mode: \"open_existing\",\n });\n this._participantsMap = await this._services.syncClient.map({\n id: data.roster,\n mode: \"open_existing\",\n });\n }\n\n /**\n * Load the attributes of this conversation and instantiate its participants\n * and messages. This or _subscribe will need to be called before any events\n * on the conversation will fire. This will need to be called before any\n * events on participants or messages will fire\n * @internal\n */\n public async _subscribeStreams() {\n try {\n await this._subscribe();\n Conversation._logger.trace(\n \"_subscribeStreams, this.entity.data=\",\n this._entity?.data\n );\n\n const data = this._entity?.data as Record<string, string>;\n const messagesObjectName = data.messages;\n const rosterObjectName = data.roster;\n\n await Promise.all([\n this._messagesEntity.subscribe(\n this._messagesList ?? messagesObjectName\n ),\n this._participantsEntity.subscribe(\n this._participantsMap ?? rosterObjectName\n ),\n ]);\n } catch (err) {\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n Conversation._logger.error(\n \"Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n }\n Conversation._logger.debug(\n \"ERROR: Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Stop listening for and firing events on this conversation.\n * @internal\n */\n public async _unsubscribe() {\n if (this._entity) {\n await this._entity.close();\n this._entity = null;\n this._entityPromise = null;\n }\n\n return Promise.all([\n this._participantsEntity.unsubscribe(),\n this._messagesEntity.unsubscribe(),\n ]);\n }\n\n /**\n * Set conversation status.\n * @internal\n */\n public _setStatus(\n status: ConversationStatus,\n source: ConversationsDataSource\n ) {\n this._dataSource = source;\n\n if (this._internalState.status === status) {\n return;\n }\n\n this._internalState.status = status;\n\n if (status === \"joined\") {\n this._subscribeStreams().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n return;\n }\n\n if (this._entityPromise) {\n this._unsubscribe().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n }\n }\n\n /**\n * Update the local conversation object with new values.\n * @internal\n */\n public _update(update) {\n Conversation._logger.trace(\"_update\", update);\n\n Conversation.preprocessUpdate(update, this.sid);\n const updateReasons = new Set<ConversationUpdateReason>();\n\n for (const key of Object.keys(update)) {\n const localKey = fieldMappings[key];\n\n if (!localKey) {\n continue;\n }\n\n switch (localKey) {\n case fieldMappings.status:\n if (\n !update.status ||\n update.status === \"unknown\" ||\n this._internalState.status === update.status\n ) {\n break;\n }\n\n this._internalState.status = update.status;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.attributes:\n if (isEqual(this._internalState.attributes, update.attributes)) {\n break;\n }\n\n this._internalState.attributes = update.attributes;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.lastConsumedMessageIndex:\n if (\n update.lastConsumedMessageIndex === undefined ||\n update.lastConsumedMessageIndex ===\n this._internalState.lastReadMessageIndex\n ) {\n break;\n }\n\n this._internalState.lastReadMessageIndex =\n update.lastConsumedMessageIndex;\n updateReasons.add(\"lastReadMessageIndex\");\n\n break;\n case fieldMappings.lastMessage:\n if (this._internalState.lastMessage && !update.lastMessage) {\n delete this._internalState.lastMessage;\n updateReasons.add(localKey);\n\n break;\n }\n\n this._internalState.lastMessage =\n this._internalState.lastMessage || {};\n\n if (\n update.lastMessage?.index !== undefined &&\n update.lastMessage.index !== this._internalState.lastMessage.index\n ) {\n this._internalState.lastMessage.index = update.lastMessage.index;\n updateReasons.add(localKey);\n }\n\n if (\n update.lastMessage?.timestamp !== undefined &&\n this._internalState.lastMessage?.dateCreated?.getTime() !==\n update.lastMessage.timestamp.getTime()\n ) {\n this._internalState.lastMessage.dateCreated =\n update.lastMessage.timestamp;\n updateReasons.add(localKey);\n }\n\n if (isEqual(this._internalState.lastMessage, {})) {\n delete this._internalState.lastMessage;\n }\n\n break;\n case fieldMappings.state:\n const state = update.state || undefined;\n\n if (state !== undefined) {\n state.dateUpdated = new Date(state.dateUpdated);\n }\n\n if (isEqual(this._internalState.state, state)) {\n break;\n }\n\n this._internalState.state = state;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.bindings:\n if (isEqual(this._internalState.bindings, update.bindings)) {\n break;\n }\n\n this._internalState.bindings = update.bindings;\n updateReasons.add(localKey);\n\n break;\n default:\n const isDate = update[key] instanceof Date;\n const keysMatchAsDates =\n isDate &&\n this._internalState[localKey]?.getTime() === update[key].getTime();\n const keysMatchAsNonDates = !isDate && this[localKey] === update[key];\n\n if (keysMatchAsDates || keysMatchAsNonDates) {\n break;\n }\n\n this._internalState[localKey] = update[key];\n updateReasons.add(localKey);\n }\n }\n\n if (updateReasons.size > 0) {\n this.emit(\"updated\", {\n conversation: this,\n updateReasons: [...updateReasons],\n });\n }\n }\n\n /**\n * Handle onMessageAdded event.\n */\n private _onMessageAdded(message) {\n for (const participant of this._participants.values()) {\n if (participant.identity === message.author) {\n participant._endTyping();\n break;\n }\n }\n this.emit(\"messageAdded\", message);\n }\n\n /**\n * Set last read message index.\n * @param index New index to set.\n */\n private async _setLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n const result = await this._services.commandExecutor.mutateResource<\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse\n >(\"post\", `${this._configuration.links.myConversations}/${this.sid}`, {\n last_read_message_index: index,\n });\n\n return result.unread_messages_count;\n }\n}\n\nexport {\n ConversationDescriptor,\n Conversation,\n ConversationServices,\n ConversationUpdateReason,\n ConversationStatus,\n NotificationLevel,\n ConversationState,\n ConversationUpdatedEventArgs,\n SendMediaOptions,\n SendEmailOptions,\n LastMessage,\n ConversationBindings,\n ConversationEmailBinding,\n};\n"],"names":["ReplayEventEmitter","parseTime","Participants","Messages","UriBuilder","parseToNumber","MessageBuilder","isEqual","Logger","__decorate","validateTypesAsync","nonEmptyString","optionalAttributesValidator","nonNegativeInteger","literal","Participant","objectSchema","custom","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgQA;;AAEG;AACH,MAAM,aAAa,GAAG;AACpB,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,wBAAwB,EAAE,0BAA0B;AACpD,IAAA,iBAAiB,EAAE,mBAAmB;AACtC,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,MAAM,E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,kBAAkB,EAAE;AAC/B,YAAA,OAAO,EAAE,CAACL,uCAAc,EAAE,WAAW,CAAC;SACvC,CAAC;KACH,CACF;;;;AAqBA,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,aAAA,EAAA,IAAA,CAAA,CAAA;AA0CDF,oBAAA,CAAA;AADC,IAAAC,2CAAkB,CAACI,gCAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;;;;AAW/C,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,0BAAA,EAAA,IAAA,CAAA,CAAA;AAiBDL,oBAAA,CAAA;IADCC,2CAAkB,CAACQ,8BAAmB,CAAC;;;;AAWvC,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAODT,oBAAA,CAAA;IADCC,2CAAkB,CAAC,QAAQ,CAAC;;;;AAU5B,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA,CAAA;AASDD,oBAAA,CAAA;IADCC,2CAAkB,CAAC,CAACI,gCAAO,CAAC,IAAI,CAAC,EAAED,2CAAkB,CAAC,CAAC;;;;AAMvD,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,4BAAA,EAAA,IAAA,CAAA,CAAA;AAQDJ,oBAAA,CAAA;IADCC,2CAAkB,CAAC,CAAC,QAAQ,EAAEI,gCAAO,CAAC,IAAI,CAAC,CAAC,CAAC;;;;AAgB7C,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA;;;;"}
|
1
|
+
{"version":3,"file":"conversation.js","sources":["../src/conversation.ts"],"sourcesContent":["import \"isomorphic-form-data\";\nimport { Logger } from \"./logger\";\nimport { ParticipantBindingOptions, Participants } from \"./data/participants\";\nimport {\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason,\n} from \"./participant\";\nimport { Messages } from \"./data/messages\";\nimport {\n Message,\n MessageType,\n MessageUpdatedEventArgs,\n MessageUpdateReason,\n} from \"./message\";\nimport { UriBuilder, parseTime } from \"./util\";\nimport { Users } from \"./data/users\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { ConversationsDataSource } from \"./data/conversations\";\nimport { McsClient } from \"@twilio/mcs-client\";\nimport { SyncClient, SyncDocument, SyncList, SyncMap } from \"twilio-sync\";\nimport { TypingIndicator } from \"./services/typing-indicator\";\nimport { Network } from \"./services/network\";\nimport {\n validateTypesAsync,\n custom,\n literal,\n nonEmptyString,\n nonNegativeInteger,\n objectSchema,\n} from \"@twilio/declarative-type-validator\";\nimport {\n attributesValidator,\n optionalAttributesValidator,\n} from \"./interfaces/attributes\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { AddParticipantRequest } from \"./interfaces/commands/add-participant\";\nimport { EditConversationRequest } from \"./interfaces/commands/edit-conversation\";\nimport { ConversationResponse } from \"./interfaces/commands/conversation-response\";\nimport { ParticipantResponse } from \"./interfaces/commands/participant-response\";\nimport { EditNotificationLevelRequest } from \"./interfaces/commands/edit-notification-level\";\nimport {\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse,\n} from \"./interfaces/commands/edit-last-read-message-index\";\nimport { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { MessageBuilder } from \"./message-builder\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"@twilio/shared\";\nimport { MediaCategory } from \"./media\";\nimport { MessageResponse } from \"./interfaces/commands/message-response\";\n\n/**\n * Conversation events.\n */\ntype ConversationEvents = {\n participantJoined: (participant: Participant) => void;\n participantLeft: (participant: Participant) => void;\n participantUpdated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n }) => void;\n removed: (conversation: Conversation) => void;\n};\n\n/**\n * Reason for the `updated` event emission by a conversation.\n */\ntype ConversationUpdateReason =\n | \"attributes\"\n | \"createdBy\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"friendlyName\"\n | \"lastReadMessageIndex\"\n | \"state\"\n | \"status\"\n | \"uniqueName\"\n | \"lastMessage\"\n | \"notificationLevel\"\n | \"bindings\";\n\n/**\n * Status of the conversation, relative to the client: whether the conversation\n * has been `joined` or the client is `notParticipating` in the conversation.\n */\ntype ConversationStatus = \"notParticipating\" | \"joined\";\n\n/**\n * User's notification level for the conversation. Determines\n * whether the currently logged-in user will receive pushes for events\n * in this conversation. Can be either `muted` or `default`, where\n * `default` defers to the global service push configuration.\n */\ntype NotificationLevel = \"default\" | \"muted\";\n\n/**\n * State of the conversation.\n */\ninterface ConversationState {\n /**\n * Current state.\n */\n current: \"active\" | \"inactive\" | \"closed\";\n\n /**\n * Date at which the latest conversation state update happened.\n */\n dateUpdated: Date;\n}\n\n/**\n * Event arguments for the `updated` event.\n */\ninterface ConversationUpdatedEventArgs {\n conversation: Conversation;\n updateReasons: ConversationUpdateReason[];\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationBindings {\n email?: ConversationEmailBinding;\n sms?: ConversationSmsBinding;\n}\n\n/**\n * Binding for email conversation.\n */\ninterface ConversationEmailBinding {\n name?: string;\n projected_address: string;\n}\n\n/**\n * Binding for SMS conversation.\n */\ninterface ConversationSmsBinding {\n address?: string;\n}\n\n/**\n * Configuration for attaching a media file to a message.\n * These options can be passed to {@link Conversation.sendMessage} and\n * {@link MessageBuilder.addMedia}.\n */\ninterface SendMediaOptions {\n /**\n * Content type of media.\n */\n contentType: null | string;\n\n /**\n * Optional filename.\n */\n filename?: string;\n\n /**\n * Content to post.\n */\n media: null | string | Buffer | Blob;\n}\n\n/**\n * These options can be passed to {@link Conversation.sendMessage}.\n */\ninterface SendEmailOptions {\n /**\n * Message subject. Ignored for media messages.\n */\n subject?: string;\n}\n\n/**\n * Information about the last message of a conversation.\n */\ninterface LastMessage {\n /**\n * Message's index.\n */\n index?: number;\n\n /**\n * Message's creation date.\n */\n dateCreated?: Date;\n}\n\n/**\n * Conversation services.\n */\ninterface ConversationServices {\n users: Users;\n typingIndicator: TypingIndicator;\n network: Network;\n mcsClient: McsClient;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Internal (private) state of the conversation.\n */\ninterface ConversationInternalState {\n uniqueName: string | null;\n status: ConversationStatus;\n attributes: JSONValue;\n createdBy?: string;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n friendlyName: string | null;\n lastReadMessageIndex: number | null;\n lastMessage?: LastMessage;\n notificationLevel?: NotificationLevel;\n state?: ConversationState;\n bindings: ConversationBindings;\n}\n\n/**\n * Conversation descriptor.\n */\ninterface ConversationDescriptor {\n channel: string;\n entityName: string;\n uniqueName: string;\n attributes: JSONValue;\n createdBy?: string;\n friendlyName?: string;\n lastConsumedMessageIndex: number;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n notificationLevel?: NotificationLevel;\n bindings?: ConversationBindings;\n}\n\n/**\n * Conversation links.\n */\ninterface ConversationLinks {\n self: string;\n messages: string;\n participants: string;\n}\n\n/**\n * Map of the fields that will be processed with update messages.\n */\nconst fieldMappings = {\n lastMessage: \"lastMessage\",\n attributes: \"attributes\",\n createdBy: \"createdBy\",\n dateCreated: \"dateCreated\",\n dateUpdated: \"dateUpdated\",\n friendlyName: \"friendlyName\",\n lastConsumedMessageIndex: \"lastConsumedMessageIndex\",\n notificationLevel: \"notificationLevel\",\n sid: \"sid\",\n status: \"status\",\n uniqueName: \"uniqueName\",\n state: \"state\",\n bindings: \"bindings\",\n};\n\n/**\n * A conversation represents communication between multiple Conversations\n * clients.\n */\nclass Conversation extends ReplayEventEmitter<ConversationEvents> {\n /**\n * Fired when a participant has joined the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that joined the\n * conversation\n * @event\n */\n public static readonly participantJoined = \"participantJoined\";\n\n /**\n * Fired when a participant has left the conversation.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - participant that left the\n * conversation\n * @event\n */\n public static readonly participantLeft = \"participantLeft\";\n\n /**\n * Fired when data of a participant has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Participant} `participant` - participant that has received the\n * update\n * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly participantUpdated = \"participantUpdated\";\n\n /**\n * Fired when a new message has been added to the conversation.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been added\n * @event\n */\n public static readonly messageAdded = \"messageAdded\";\n\n /**\n * Fired when message is removed from the conversation's message list.\n *\n * Parameters:\n * 1. {@link Message} `message` - message that has been removed\n * @event\n */\n public static readonly messageRemoved = \"messageRemoved\";\n\n /**\n * Fired when data of a message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Message} `message` - message that has received the update\n * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for\n * the update\n * @event\n */\n public static readonly messageUpdated = \"messageUpdated\";\n\n /**\n * Fired when a participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has stopped\n * typing\n * @event\n */\n public static readonly typingEnded = \"typingEnded\";\n\n /**\n * Fired when a participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant that has started\n * typing\n * @event\n */\n public static readonly typingStarted = \"typingStarted\";\n\n /**\n * Fired when the data of the conversation has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the\n * following properties:\n * * {@link Conversation} `conversation` - conversation that has received\n * the update\n * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons\n * for the update\n * @event\n */\n public static readonly updated = \"updated\";\n\n /**\n * Fired when the conversation was destroyed or the currently-logged-in user\n * has left private conversation.\n *\n * Parameters:\n * 1. {@link Conversation} `conversation` - conversation that has been removed\n * @event\n */\n public static readonly removed = \"removed\";\n\n /**\n * Logger instance.\n */\n private static readonly _logger = Logger.scope(\"Conversation\");\n\n /**\n * Unique system identifier of the conversation.\n */\n public readonly sid: string;\n\n /**\n * Conversation links for REST requests.\n * @internal\n */\n public readonly _links: ConversationLinks;\n\n /**\n * Map of participants.\n * @internal\n */\n public readonly _participants: Map<string, Participant>;\n\n /**\n * Configuration of the client that the conversation belongs to.\n */\n private readonly _configuration: Configuration;\n\n /**\n * Conversation service objects.\n */\n private readonly _services: ConversationServices;\n\n /**\n * Internal state of the conversation.\n */\n private readonly _internalState: ConversationInternalState;\n\n /**\n * Name of the conversation entity document.\n */\n private readonly _entityName: string;\n\n /**\n * Messages entity.\n */\n private readonly _messagesEntity: Messages;\n\n /**\n * Sync list containing messages.\n */\n private _messagesList?: SyncList;\n\n /**\n * Participants entity.\n */\n private readonly _participantsEntity: Participants;\n\n /**\n * Sync map containing participants.\n */\n private _participantsMap?: SyncMap;\n\n /**\n * Source of the most recent update.\n */\n private _dataSource!: ConversationsDataSource;\n\n /**\n * Promise for the conversation entity document.\n */\n private _entityPromise!: Promise<SyncDocument> | null;\n\n /**\n * Conversation entity document.\n */\n private _entity!: SyncDocument | null;\n\n /**\n * @param descriptor Conversation descriptor.\n * @param sid Conversation SID.\n * @param links Conversation links for REST requests.\n * @param configuration Client configuration.\n * @param services Conversation services.\n * @internal\n */\n public constructor(\n descriptor: ConversationDescriptor,\n sid: string,\n links: ConversationLinks,\n configuration: Configuration,\n services: ConversationServices\n ) {\n super();\n\n this.sid = sid;\n this._links = links;\n this._configuration = configuration;\n this._services = services;\n this._entityName = descriptor.channel;\n this._internalState = {\n uniqueName: descriptor.uniqueName || null,\n status: \"notParticipating\",\n attributes: descriptor.attributes ?? {},\n createdBy: descriptor.createdBy,\n dateCreated: parseTime(descriptor.dateCreated),\n dateUpdated: parseTime(descriptor.dateUpdated),\n friendlyName: descriptor.friendlyName || null,\n lastReadMessageIndex: Number.isInteger(\n descriptor.lastConsumedMessageIndex\n )\n ? descriptor.lastConsumedMessageIndex\n : null,\n bindings: descriptor.bindings ?? {},\n };\n\n if (descriptor.notificationLevel) {\n this._internalState.notificationLevel = descriptor.notificationLevel;\n }\n\n const participantsLinks = {\n participants: this._links.participants,\n };\n\n this._participants = new Map();\n this._participantsEntity = new Participants(\n this,\n this._participants,\n participantsLinks,\n this._configuration,\n this._services\n );\n this._participantsEntity.on(\"participantJoined\", (participant) =>\n this.emit(\"participantJoined\", participant)\n );\n this._participantsEntity.on(\"participantLeft\", (participant) =>\n this.emit(\"participantLeft\", participant)\n );\n this._participantsEntity.on(\n \"participantUpdated\",\n (args: ParticipantUpdatedEventArgs) =>\n this.emit(\"participantUpdated\", args)\n );\n\n this._messagesEntity = new Messages(this, configuration, services);\n this._messagesEntity.on(\"messageAdded\", (message) =>\n this._onMessageAdded(message)\n );\n this._messagesEntity.on(\"messageUpdated\", (args: MessageUpdatedEventArgs) =>\n this.emit(\"messageUpdated\", args)\n );\n this._messagesEntity.on(\"messageRemoved\", (message) =>\n this.emit(\"messageRemoved\", message)\n );\n }\n\n /**\n * Unique name of the conversation.\n */\n public get uniqueName(): string | null {\n return this._internalState.uniqueName;\n }\n\n /**\n * Status of the conversation.\n */\n public get status(): ConversationStatus {\n return this._internalState.status;\n }\n\n /**\n * Name of the conversation.\n */\n public get friendlyName(): string | null {\n return this._internalState.friendlyName;\n }\n\n /**\n * Date this conversation was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this._internalState.dateUpdated;\n }\n\n /**\n * Date this conversation was created on.\n */\n public get dateCreated(): Date | null {\n return this._internalState.dateCreated;\n }\n\n /**\n * Identity of the user that created this conversation.\n */\n public get createdBy(): string {\n return this._internalState.createdBy ?? \"\";\n }\n\n /**\n * Custom attributes of the conversation.\n */\n public get attributes(): JSONValue {\n return this._internalState.attributes;\n }\n\n /**\n * Index of the last message the user has read in this conversation.\n */\n public get lastReadMessageIndex(): number | null {\n return this._internalState.lastReadMessageIndex;\n }\n\n /**\n * Last message sent to this conversation.\n */\n public get lastMessage(): LastMessage | undefined {\n return this._internalState.lastMessage ?? undefined;\n }\n\n /**\n * User notification level for this conversation.\n */\n public get notificationLevel(): NotificationLevel {\n return this._internalState.notificationLevel ?? \"default\";\n }\n\n /**\n * Conversation bindings. Undocumented feature (for now).\n * @internal\n */\n public get bindings(): ConversationBindings {\n return this._internalState.bindings;\n }\n\n /**\n * Current conversation limits.\n */\n public get limits(): ConversationLimits {\n return this._configuration.limits;\n }\n\n /**\n * State of the conversation.\n */\n public get state(): ConversationState | undefined {\n return this._internalState.state;\n }\n\n /**\n * Source of the conversation update.\n * @internal\n */\n public get _statusSource(): ConversationsDataSource {\n return this._dataSource;\n }\n\n /**\n * Preprocess the update object.\n * @param update The update object received from Sync.\n * @param conversationSid The SID of the conversation in question.\n */\n private static preprocessUpdate(update, conversationSid: string) {\n try {\n if (typeof update.attributes === \"string\") {\n update.attributes = JSON.parse(update.attributes);\n } else if (update.attributes) {\n JSON.stringify(update.attributes);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed attributes from the server for conversation: \" +\n conversationSid\n );\n update.attributes = {};\n }\n\n try {\n if (update.dateCreated) {\n update.dateCreated = new Date(update.dateCreated);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateCreated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateCreated;\n }\n\n try {\n if (update.dateUpdated) {\n update.dateUpdated = new Date(update.dateUpdated);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed dateUpdated from the server for conversation: \" +\n conversationSid\n );\n delete update.dateUpdated;\n }\n\n try {\n if (update.lastMessage && update.lastMessage.timestamp) {\n update.lastMessage.timestamp = new Date(update.lastMessage.timestamp);\n }\n } catch (e) {\n Conversation._logger.warn(\n \"Retrieved malformed lastMessage.timestamp from the server for conversation: \" +\n conversationSid\n );\n delete update.lastMessage.timestamp;\n }\n }\n\n /**\n * Add a participant to the conversation by its identity.\n * @param identity Identity of the Client to add.\n * @param attributes Attributes to be attached to the participant.\n * @returns The added participant.\n */\n @validateTypesAsync(nonEmptyString, optionalAttributesValidator)\n public async add(\n identity: string,\n attributes?: JSONValue\n ): Promise<Participant> {\n return this._participantsEntity.add(identity, attributes ?? {});\n }\n\n /**\n * Add a non-chat participant to the conversation.\n * @param proxyAddress Proxy (Twilio) address of the participant.\n * @param address User address of the participant.\n * @param attributes Attributes to be attached to the participant.\n * @param bindingOptions Options for adding email participants - name and\n * CC/To level.\n * @returns The added participant.\n */\n @validateTypesAsync(\n nonEmptyString,\n nonEmptyString,\n optionalAttributesValidator\n )\n public async addNonChatParticipant(\n proxyAddress: string,\n address: string,\n attributes: JSONValue = {},\n bindingOptions: ParticipantBindingOptions = {}\n ): Promise<Participant> {\n return this._participantsEntity.addNonChatParticipant(\n proxyAddress,\n address,\n attributes ?? {},\n bindingOptions ?? {}\n );\n }\n\n /**\n * Advance the conversation's last read message index to the current read\n * horizon. Rejects if the user is not a participant of the conversation. Last\n * read message index is updated only if the new index value is higher than\n * the previous.\n * @param index Message index to advance to.\n * @return Resulting unread messages count in the conversation.\n */\n @validateTypesAsync(nonNegativeInteger)\n public async advanceLastReadMessageIndex(index: number): Promise<number> {\n await this._subscribeStreams();\n\n if (index < (this.lastReadMessageIndex ?? 0)) {\n return await this._setLastReadMessageIndex(this.lastReadMessageIndex);\n }\n\n return await this._setLastReadMessageIndex(index);\n }\n\n /**\n * Delete the conversation and unsubscribe from its events.\n */\n public async delete(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n this._links.self\n );\n\n return this;\n }\n\n /**\n * Get the custom attributes of this Conversation.\n */\n public async getAttributes(): Promise<JSONValue> {\n await this._subscribe();\n return this.attributes;\n }\n\n /**\n * Returns messages from the conversation using the paginator interface.\n * @param pageSize Number of messages to return in a single chunk. Default is\n * 30.\n * @param anchor Index of the newest message to fetch. Default is from the\n * end.\n * @param direction Query direction. By default, it queries backwards\n * from newer to older. The `\"forward\"` value will query in the opposite\n * direction.\n * @return A page of messages.\n */\n @validateTypesAsync(\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", nonNegativeInteger],\n [\"undefined\", literal(\"backwards\", \"forward\")]\n )\n public async getMessages(\n pageSize?: number,\n anchor?: number,\n direction?: \"backwards\" | \"forward\"\n ): Promise<Paginator<Message>> {\n await this._subscribeStreams();\n return this._messagesEntity.getMessages(pageSize, anchor, direction);\n }\n\n /**\n * Get a list of all the participants who are joined to this conversation.\n */\n public async getParticipants(): Promise<Participant[]> {\n await this._subscribeStreams();\n return this._participantsEntity.getParticipants();\n }\n\n /**\n * Get conversation participants count.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getParticipantsCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n // todo: remove any after the release of new Twilsock\n const response: any =\n await this._services.network.get<ConversationResponse>(url);\n\n return response.body.participants_count ?? 0;\n }\n\n /**\n * Get a participant by its SID.\n * @param participantSid Participant SID.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantBySid(\n participantSid: string\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantBySid(participantSid);\n }\n\n /**\n * Get a participant by its identity.\n * @param identity Participant identity.\n */\n @validateTypesAsync(nonEmptyString)\n public async getParticipantByIdentity(\n identity: string | null = \"\"\n ): Promise<Participant | null> {\n return this._participantsEntity.getParticipantByIdentity(identity ?? \"\");\n }\n\n /**\n * Get the total message count in the conversation.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n */\n public async getMessagesCount(): Promise<number> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(this.sid)\n .build();\n // todo: remove any after the release of new Twilsock\n const response: any =\n await this._services.network.get<ConversationResponse>(url);\n\n return response.body.messages_count ?? 0;\n }\n\n /**\n * Get count of unread messages for the user if they are a participant of this\n * conversation. Rejects if the user is not a participant of the conversation.\n *\n * Use this method to obtain the number of unread messages together with\n * {@link Conversation.updateLastReadMessageIndex} instead of relying on the\n * message indices which may have gaps. See {@link Message.index} for details.\n *\n * This method is semi-realtime. This means that this data will be eventually\n * correct, but it will also be possibly incorrect for a few seconds. The\n * Conversations system does not provide real time events for counter values\n * changes.\n *\n * This is useful for any UI badges, but it is not recommended to build any\n * core application logic based on these counters being accurate in real time.\n *\n * If the read horizon is not set, this function will return null. This could mean\n * that all messages in the conversation are unread, or that the read horizon system\n * is not being used. How to interpret this `null` value is up to the customer application.\n *\n * @return Number of unread messages based on the current read horizon set for\n * the user or `null` if the read horizon is not set.\n */\n public async getUnreadMessagesCount(): Promise<number | null> {\n const url = new UriBuilder(this._configuration.links.myConversations)\n .path(this.sid)\n .build();\n // todo: remove any after the release of new Twilsock\n const response: any =\n await this._services.network.get<ConversationResponse>(url);\n\n if (response.body.conversation_sid !== this.sid) {\n throw new Error(\n \"Conversation was not found in the user conversations list\"\n );\n }\n\n const unreadMessageCount = response.body.unread_messages_count;\n\n if (typeof unreadMessageCount === \"number\") {\n return unreadMessageCount;\n }\n\n return null;\n }\n\n /**\n * Join the conversation and subscribe to its events.\n */\n public async join(): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n AddParticipantRequest,\n ParticipantResponse\n >(\"post\", this._links.participants, {\n identity: this._configuration.userIdentity,\n });\n\n return this;\n }\n\n /**\n * Leave the conversation.\n */\n public async leave(): Promise<Conversation> {\n if (this._internalState.status === \"joined\") {\n await this._services.commandExecutor.mutateResource(\n \"delete\",\n `${this._links.participants}/${this._configuration.userIdentity}`\n );\n }\n\n return this;\n }\n\n /**\n * Remove a participant from the conversation. When a string is passed as the\n * argument, it will assume that the string is an identity or SID.\n * @param participant Identity, SID or the participant object to remove.\n */\n @validateTypesAsync([nonEmptyString, Participant])\n public async removeParticipant(\n participant: string | Participant\n ): Promise<void> {\n await this._participantsEntity.remove(\n typeof participant === \"string\" ? participant : participant.sid\n );\n }\n\n /**\n * Send a message to the conversation.\n * @param message Message body for the text message,\n * `FormData` or {@link SendMediaOptions} for media content. Sending FormData\n * is supported only with the browser engine.\n * @param messageAttributes Attributes for the message.\n * @param emailOptions Email options for the message.\n * @return Index of the new message.\n */\n @validateTypesAsync(\n [\n \"string\",\n FormData,\n literal(null),\n objectSchema(\"media options\", {\n contentType: nonEmptyString,\n media: custom((value) => {\n let isValid =\n (typeof value === \"string\" && value.length > 0) ||\n value instanceof Uint8Array ||\n value instanceof ArrayBuffer;\n\n if (typeof Blob === \"function\") {\n isValid = isValid || value instanceof Blob;\n }\n\n return [\n isValid,\n \"a non-empty string, an instance of Buffer or an instance of Blob\",\n ];\n }),\n }),\n ],\n optionalAttributesValidator,\n [\n \"undefined\",\n literal(null),\n objectSchema(\"email attributes\", {\n subject: [nonEmptyString, \"undefined\"],\n }),\n ]\n )\n public async sendMessage(\n message: null | string | FormData | SendMediaOptions,\n messageAttributes?: JSONValue,\n emailOptions?: SendEmailOptions\n ): Promise<Message> {\n const response: MessageResponse =\n typeof message === \"string\" || message === null\n ? await this._messagesEntity.send(\n message,\n messageAttributes,\n emailOptions\n )\n : await this._messagesEntity.sendMedia(\n message,\n messageAttributes,\n emailOptions\n );\n const type: MessageType =\n typeof message === \"string\" || message === null ? \"text\" : \"media\";\n\n let responseAttributes;\n try {\n responseAttributes = JSON.parse(response.attributes);\n } catch (e) {}\n\n const messageData = {\n sid: response.sid,\n text: response.body,\n type,\n author: response.author,\n subject: response.subject,\n lastUpdatedBy: response.participant_sid,\n attributes: responseAttributes,\n dateUpdated: response.date_updated,\n timestamp: response.date_created,\n memberSid: response.participant_sid,\n medias: Array.isArray(response.media)\n ? response.media.map((media) => ({\n sid: media[\"sid\"],\n size: Number(media[\"size\"]),\n category: media[\"category\"] as MediaCategory,\n filename: media[\"filename\"],\n contentType: media[\"content_type\"],\n }))\n : null,\n media:\n response.media &&\n typeof response.media === \"object\" &&\n !Array.isArray(response.media)\n ? {\n sid: response.media[\"sid\"],\n size: Number(response.media[\"size\"]),\n category: response.media[\"category\"] as MediaCategory,\n filename: response.media[\"filename\"],\n contentType: response.media[\"content_type\"],\n }\n : null,\n };\n\n return this._messagesEntity._upsertMessage(response.index, messageData);\n }\n\n /**\n * New interface to prepare for sending a message.\n * Use this instead of {@link Message.sendMessage}.\n * @return A MessageBuilder to help set all message sending options.\n */\n public prepareMessage(): MessageBuilder {\n return new MessageBuilder(this.limits, this._messagesEntity);\n }\n\n /**\n * Set last read message index of the conversation to the index of the last\n * known message.\n * @return Resulting unread messages count in the conversation.\n */\n public async setAllMessagesRead(): Promise<number> {\n await this._subscribeStreams();\n\n const messagesPage = await this.getMessages(1);\n\n if (messagesPage.items.length > 0) {\n return this.advanceLastReadMessageIndex(messagesPage.items[0].index);\n }\n\n return 0;\n }\n\n /**\n * Set all messages in the conversation unread.\n * @returns New count of unread messages after this update.\n */\n public async setAllMessagesUnread(): Promise<number> {\n await this._subscribeStreams();\n return await this._setLastReadMessageIndex(null);\n }\n\n /**\n * Set user notification level for this conversation.\n * @param notificationLevel New user notification level.\n */\n @validateTypesAsync(literal(\"default\", \"muted\"))\n public async setUserNotificationLevel(\n notificationLevel: NotificationLevel\n ): Promise<void> {\n await this._services.commandExecutor.mutateResource<EditNotificationLevelRequest>(\n \"post\",\n `${this._configuration.links.myConversations}/${this.sid}`,\n {\n notification_level: notificationLevel,\n }\n );\n }\n\n /**\n * Send a notification to the server indicating that this client is currently\n * typing in this conversation. Typing ended notification is sent after a\n * while automatically, but by calling this method again you ensure that\n * typing ended is not received.\n */\n public typing(): Promise<void> {\n return this._services.typingIndicator.send(this.sid);\n }\n\n /**\n * Update the attributes of the conversation.\n * @param attributes New attributes.\n */\n @validateTypesAsync(attributesValidator)\n public async updateAttributes(attributes: JSONValue): Promise<Conversation> {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n attributes:\n attributes !== undefined ? JSON.stringify(attributes) : undefined,\n });\n\n return this;\n }\n\n /**\n * Update the friendly name of the conversation.\n * @param friendlyName New friendly name.\n */\n @validateTypesAsync(\"string\")\n public async updateFriendlyName(friendlyName: string): Promise<Conversation> {\n if (this._internalState.friendlyName !== friendlyName) {\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, { friendly_name: friendlyName });\n }\n\n return this;\n }\n\n /**\n * Set the last read message index to the current read horizon.\n * @param index Message index to set as last read. If null is provided, then\n * the behavior is identical to {@link Conversation.setAllMessagesUnread}.\n * @returns New count of unread messages after this update.\n */\n @validateTypesAsync([literal(null), nonNegativeInteger])\n public async updateLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n await this._subscribeStreams();\n return this._setLastReadMessageIndex(index);\n }\n\n /**\n * Update the unique name of the conversation.\n * @param uniqueName New unique name for the conversation. Setting unique name\n * to null removes it.\n */\n @validateTypesAsync([\"string\", literal(null)])\n public async updateUniqueName(\n uniqueName: string | null\n ): Promise<Conversation> {\n if (this._internalState.uniqueName !== uniqueName) {\n uniqueName ||= \"\";\n\n await this._services.commandExecutor.mutateResource<\n EditConversationRequest,\n ConversationResponse\n >(\"post\", this._links.self, {\n unique_name: uniqueName,\n });\n }\n\n return this;\n }\n\n /**\n * Load and subscribe to this conversation and do not subscribe to its\n * participants and messages. This or _subscribeStreams will need to be called\n * before any events on conversation will fire.\n * @internal\n */\n public async _subscribe(): Promise<SyncDocument> {\n if (this._entityPromise) {\n return this._entityPromise;\n }\n\n this._entityPromise = this._services.syncClient.document({\n id: this._entityName,\n mode: \"open_existing\",\n });\n\n try {\n this._entity = await this._entityPromise;\n this._entity.on(\"updated\", (args) => this._update(args.data));\n this._entity.on(\"removed\", () => this.emit(\"removed\", this));\n this._update(this._entity.data);\n\n return this._entity;\n } catch (err) {\n this._entity = null;\n this._entityPromise = null;\n\n if (this._services.syncClient.connectionState != \"disconnected\") {\n Conversation._logger.error(\"Failed to get conversation object\", err);\n }\n Conversation._logger.debug(\n \"ERROR: Failed to get conversation object\",\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Fetch participants and messages of the conversation. This method needs to\n * be called during conversation initialization to catch broken conversations\n * (broken conversations are conversations that have essential Sync entities\n * missing, i.e. the conversation document, the messages list or the\n * participant map). In case of this conversation being broken, the method\n * will throw an exception that will be caught and handled gracefully.\n * @internal\n */\n public async _fetchStreams() {\n await this._subscribe();\n Conversation._logger.trace(\n \"_streamsAvailable, this.entity.data=\",\n this._entity?.data\n );\n\n const data = this._entity?.data as Record<string, string>;\n this._messagesList = await this._services.syncClient.list({\n id: data.messages,\n mode: \"open_existing\",\n });\n this._participantsMap = await this._services.syncClient.map({\n id: data.roster,\n mode: \"open_existing\",\n });\n }\n\n /**\n * Load the attributes of this conversation and instantiate its participants\n * and messages. This or _subscribe will need to be called before any events\n * on the conversation will fire. This will need to be called before any\n * events on participants or messages will fire\n * @internal\n */\n public async _subscribeStreams() {\n try {\n await this._subscribe();\n Conversation._logger.trace(\n \"_subscribeStreams, this.entity.data=\",\n this._entity?.data\n );\n\n const data = this._entity?.data as Record<string, string>;\n const messagesObjectName = data.messages;\n const rosterObjectName = data.roster;\n\n await Promise.all([\n this._messagesEntity.subscribe(\n this._messagesList ?? messagesObjectName\n ),\n this._participantsEntity.subscribe(\n this._participantsMap ?? rosterObjectName\n ),\n ]);\n } catch (err) {\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n Conversation._logger.error(\n \"Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n }\n Conversation._logger.debug(\n \"ERROR: Failed to subscribe on conversation objects\",\n this.sid,\n err\n );\n\n throw err;\n }\n }\n\n /**\n * Stop listening for and firing events on this conversation.\n * @internal\n */\n public async _unsubscribe() {\n if (this._entity) {\n await this._entity.close();\n this._entity = null;\n this._entityPromise = null;\n }\n\n return Promise.all([\n this._participantsEntity.unsubscribe(),\n this._messagesEntity.unsubscribe(),\n ]);\n }\n\n /**\n * Set conversation status.\n * @internal\n */\n public _setStatus(\n status: ConversationStatus,\n source: ConversationsDataSource\n ) {\n this._dataSource = source;\n\n if (this._internalState.status === status) {\n return;\n }\n\n this._internalState.status = status;\n\n if (status === \"joined\") {\n this._subscribeStreams().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n return;\n }\n\n if (this._entityPromise) {\n this._unsubscribe().catch((err) => {\n Conversation._logger.debug(\n \"ERROR while setting conversation status \" + status,\n err\n );\n if (this._services.syncClient.connectionState !== \"disconnected\") {\n throw err;\n }\n });\n }\n }\n\n /**\n * Update the local conversation object with new values.\n * @internal\n */\n public _update(update) {\n Conversation._logger.trace(\"_update\", update);\n\n Conversation.preprocessUpdate(update, this.sid);\n const updateReasons = new Set<ConversationUpdateReason>();\n\n for (const key of Object.keys(update)) {\n const localKey = fieldMappings[key];\n\n if (!localKey) {\n continue;\n }\n\n switch (localKey) {\n case fieldMappings.status:\n if (\n !update.status ||\n update.status === \"unknown\" ||\n this._internalState.status === update.status\n ) {\n break;\n }\n\n this._internalState.status = update.status;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.attributes:\n if (isEqual(this._internalState.attributes, update.attributes)) {\n break;\n }\n\n this._internalState.attributes = update.attributes;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.lastConsumedMessageIndex:\n if (\n update.lastConsumedMessageIndex === undefined ||\n update.lastConsumedMessageIndex ===\n this._internalState.lastReadMessageIndex\n ) {\n break;\n }\n\n this._internalState.lastReadMessageIndex =\n update.lastConsumedMessageIndex;\n updateReasons.add(\"lastReadMessageIndex\");\n\n break;\n case fieldMappings.lastMessage:\n if (this._internalState.lastMessage && !update.lastMessage) {\n delete this._internalState.lastMessage;\n updateReasons.add(localKey);\n\n break;\n }\n\n this._internalState.lastMessage =\n this._internalState.lastMessage || {};\n\n if (\n update.lastMessage?.index !== undefined &&\n update.lastMessage.index !== this._internalState.lastMessage.index\n ) {\n this._internalState.lastMessage.index = update.lastMessage.index;\n updateReasons.add(localKey);\n }\n\n if (\n update.lastMessage?.timestamp !== undefined &&\n this._internalState.lastMessage?.dateCreated?.getTime() !==\n update.lastMessage.timestamp.getTime()\n ) {\n this._internalState.lastMessage.dateCreated =\n update.lastMessage.timestamp;\n updateReasons.add(localKey);\n }\n\n if (isEqual(this._internalState.lastMessage, {})) {\n delete this._internalState.lastMessage;\n }\n\n break;\n case fieldMappings.state:\n const state = update.state || undefined;\n\n if (state !== undefined) {\n state.dateUpdated = new Date(state.dateUpdated);\n }\n\n if (isEqual(this._internalState.state, state)) {\n break;\n }\n\n this._internalState.state = state;\n updateReasons.add(localKey);\n\n break;\n case fieldMappings.bindings:\n if (isEqual(this._internalState.bindings, update.bindings)) {\n break;\n }\n\n this._internalState.bindings = update.bindings;\n updateReasons.add(localKey);\n\n break;\n default:\n const isDate = update[key] instanceof Date;\n const keysMatchAsDates =\n isDate &&\n this._internalState[localKey]?.getTime() === update[key].getTime();\n const keysMatchAsNonDates = !isDate && this[localKey] === update[key];\n\n if (keysMatchAsDates || keysMatchAsNonDates) {\n break;\n }\n\n this._internalState[localKey] = update[key];\n updateReasons.add(localKey);\n }\n }\n\n if (updateReasons.size > 0) {\n this.emit(\"updated\", {\n conversation: this,\n updateReasons: [...updateReasons],\n });\n }\n }\n\n /**\n * Handle onMessageAdded event.\n */\n private _onMessageAdded(message) {\n for (const participant of this._participants.values()) {\n if (participant.identity === message.author) {\n participant._endTyping();\n break;\n }\n }\n this.emit(\"messageAdded\", message);\n }\n\n /**\n * Set last read message index.\n * @param index New index to set.\n */\n private async _setLastReadMessageIndex(\n index: number | null\n ): Promise<number> {\n const result = await this._services.commandExecutor.mutateResource<\n EditLastReadMessageIndexRequest,\n EditLastReadMessageIndexResponse\n >(\"post\", `${this._configuration.links.myConversations}/${this.sid}`, {\n last_read_message_index: index,\n });\n\n return result.unread_messages_count;\n }\n}\n\nexport {\n ConversationDescriptor,\n Conversation,\n ConversationServices,\n ConversationUpdateReason,\n ConversationStatus,\n NotificationLevel,\n ConversationState,\n ConversationUpdatedEventArgs,\n SendMediaOptions,\n SendEmailOptions,\n LastMessage,\n ConversationBindings,\n ConversationEmailBinding,\n};\n"],"names":["ReplayEventEmitter","parseTime","Participants","Messages","UriBuilder","MessageBuilder","isEqual","Logger","__decorate","validateTypesAsync","nonEmptyString","optionalAttributesValidator","nonNegativeInteger","literal","Participant","objectSchema","custom","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmQA;;AAEG;AACH,MAAM,aAAa,GAAG;AACpB,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,wBAAwB,EAAE,0BAA0B;AACpD,IAAA,iBAAiB,EAAE,mBAAmB;AACtC,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEF;;;AAGG;AACH,MAAM,YAAa,SAAQA,qCAAsC,CAAA;AA2L/D;;;;;;;AAOG;IACH,WACE,CAAA,UAAkC,EAClC,GAAW,EACX,KA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AAE;AAC/B,YAAA,OAAO,EAAE,CAACL,uCAAc,EAAE,WAAW,CAAC;SACvC,CAAC;KACH,CACF;;;;AA6DA,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,aAAA,EAAA,IAAA,CAAA,CAAA;AA0CYF,oBAAA,CAAA;AADZ,IAAAC,2CAAkB,CAACI,gCAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;;;;AAW/C,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,0BAAA,EAAA,IAAA,CAAA,CAAA;AAiBYL,oBAAA,CAAA;IADZC,2CAAkB,CAACQ,8BAAmB,CAAC;;;;AAWvC,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAOYT,oBAAA,CAAA;IADZC,2CAAkB,CAAC,QAAQ,CAAC;;;;AAU5B,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA,CAAA;AASYD,oBAAA,CAAA;IADZC,2CAAkB,CAAC,CAACI,gCAAO,CAAC,IAAI,CAAC,EAAED,2CAAkB,CAAC,CAAC;;;;AAMvD,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,4BAAA,EAAA,IAAA,CAAA,CAAA;AAQYJ,oBAAA,CAAA;IADZC,2CAAkB,CAAC,CAAC,QAAQ,EAAEI,gCAAO,CAAC,IAAI,CAAC,CAAC,CAAC;;;;AAgB7C,CAAA,EAAA,YAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA;;;;"}
|
@@ -260,7 +260,8 @@ class Conversations extends replayEventEmitter.ReplayEventEmitter {
|
|
260
260
|
.path(uniqueName)
|
261
261
|
.build();
|
262
262
|
const response = await this.services.network.get(url);
|
263
|
-
|
263
|
+
// todo: remove any after the release of new Twilsock
|
264
|
+
const body = JSON.parse(response.payload);
|
264
265
|
const sid = body.conversation_sid;
|
265
266
|
const data = {
|
266
267
|
entityName: null,
|
@@ -282,6 +283,7 @@ class Conversations extends replayEventEmitter.ReplayEventEmitter {
|
|
282
283
|
const url = new index.UriBuilder(this.configuration.links.conversations)
|
283
284
|
.path(sid)
|
284
285
|
.build();
|
286
|
+
// todo: remove any after the release of new Twilsock
|
285
287
|
const response = await this.services.network.get(url);
|
286
288
|
const body = response.body;
|
287
289
|
const data = {
|
@@ -417,6 +419,7 @@ class Conversations extends replayEventEmitter.ReplayEventEmitter {
|
|
417
419
|
if (pageToken) {
|
418
420
|
url.arg("PageToken", pageToken);
|
419
421
|
}
|
422
|
+
// todo: remove any after the release of new Twilsock
|
420
423
|
const response = await this.services.network.get(url.build());
|
421
424
|
const receivedConversations = (_a = response.body) === null || _a === void 0 ? void 0 : _a.conversations.map((conversationDescriptor) => ({
|
422
425
|
descriptor: conversationDescriptor,
|