@twilio/conversations 2.0.1 → 2.1.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -0
- package/NOTICE.txt +679 -0
- package/builds/browser.js +889 -619
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +384 -129
- package/builds/lib.js +889 -619
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +1065 -939
- package/builds/twilio-conversations.min.js +2 -14
- package/dist/aggregated-delivery-receipt.js +6 -1
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +165 -142
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +16 -14
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +14 -10
- package/dist/configuration.js.map +1 -1
- package/dist/conversation.js +232 -159
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +82 -78
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +43 -39
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +100 -78
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +24 -22
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +1 -1
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/interfaces/attributes.js +147 -0
- package/dist/interfaces/attributes.js.map +1 -0
- package/dist/interfaces/notification-types.js +5 -5
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/logger.js +36 -15
- package/dist/logger.js.map +1 -1
- package/dist/media.js +21 -9
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +56 -3
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +157 -78
- package/dist/message.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js +101 -50
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +16 -6
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +18 -14
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +20 -17
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +87 -60
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +3 -1
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +6 -6
- package/dist/util/index.js.map +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +0 -102
- package/docs/classes/Client.html +24 -132
- package/docs/classes/Conversation.html +37 -132
- package/docs/classes/DetailedDeliveryReceipt.html +1 -103
- package/docs/classes/Media.html +0 -102
- package/docs/classes/Message.html +73 -109
- package/docs/classes/MessageBuilder.html +78 -104
- package/docs/classes/Participant.html +37 -110
- package/docs/classes/PushNotification.html +0 -102
- package/docs/classes/RestPaginator.html +0 -102
- package/docs/classes/UnsentMessage.html +0 -102
- package/docs/classes/User.html +7 -109
- package/docs/index.html +93 -3
- package/docs/interfaces/ClientOptions.html +0 -102
- package/docs/interfaces/ConversationBindings.html +3001 -0
- package/docs/interfaces/ConversationEmailBinding.html +3001 -0
- package/docs/interfaces/ConversationState.html +0 -102
- package/docs/interfaces/CreateConversationOptions.html +1 -103
- package/docs/interfaces/LastMessage.html +0 -102
- package/docs/interfaces/Paginator.html +0 -102
- package/docs/interfaces/ParticipantBindings.html +3001 -0
- package/docs/interfaces/ParticipantEmailBinding.html +3001 -0
- package/docs/interfaces/PushNotificationData.html +0 -102
- package/docs/interfaces/SendEmailOptions.html +0 -102
- package/docs/interfaces/SendMediaOptions.html +0 -102
- package/docs/modules.html +93 -3
- package/package.json +23 -17
package/dist/message.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"message.js","sources":["../src/message.ts"],"sourcesContent":["import { parseAttributes, UriBuilder } from './util';\nimport { Logger } from './logger';\nimport { Conversation } from './conversation';\nimport { McsClient, MediaCategory } from '@twilio/mcs-client';\nimport { Media } from './media';\nimport { Participant } from './participant';\nimport { AggregatedDeliveryReceipt } from './aggregated-delivery-receipt';\nimport { validateTypesAsync, literal, custom } from '@twilio/declarative-type-validator';\nimport { Network } from './services/network';\nimport { RestPaginator } from './rest-paginator';\nimport { DetailedDeliveryReceipt } from './detailed-delivery-receipt';\nimport { Paginator } from './interfaces/paginator';\nimport { Configuration } from './configuration';\nimport { CommandExecutor } from './command-executor';\nimport { EditMessageRequest } from './interfaces/commands/edit-message';\nimport { MessageResponse } from './interfaces/commands/message-response';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\nimport isEqual from 'lodash.isequal';\n\ntype MessageEvents = {\n updated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[]\n }) => void;\n};\n\nconst log = Logger.scope('Message');\n\ninterface MessageState {\n sid: string;\n index: number;\n author?: string;\n subject?: string;\n body: string;\n dateUpdated: Date;\n lastUpdatedBy: string;\n attributes: Object;\n timestamp: Date;\n type: MessageType;\n media?: Media;\n medias?: Media[];\n participantSid?: string;\n aggregatedDeliveryReceipt?: AggregatedDeliveryReceipt;\n}\n\ninterface MessageServices {\n mcsClient: McsClient;\n network: Network;\n commandExecutor: CommandExecutor;\n}\n\ninterface MessageLinks {\n self: string;\n conversation: string;\n messages_receipts: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a message.\n */\ntype MessageUpdateReason =\n | 'body'\n | 'lastUpdatedBy'\n | 'dateCreated'\n | 'dateUpdated'\n | 'attributes'\n | 'author'\n | 'deliveryReceipt'\n | 'subject';\n\n/**\n * Type of a message.\n */\ntype MessageType = 'text' | 'media';\n\ninterface MessageUpdatedEventArgs {\n message: Message;\n updateReasons: MessageUpdateReason[];\n}\n\n/**\n * A message in a conversation.\n */\nclass Message extends ReplayEventEmitter<MessageEvents> {\n /**\n * Conversation that the message is in.\n */\n public readonly conversation: Conversation;\n\n private readonly links: MessageLinks;\n private readonly configuration: Configuration;\n private readonly services: MessageServices;\n\n private state: MessageState;\n\n /**\n * @internal\n */\n constructor(\n index: number,\n data: any,\n conversation: Conversation,\n links: MessageLinks,\n configuration: Configuration,\n services: MessageServices,\n ) {\n super();\n\n this.conversation = conversation;\n\n this.links = links;\n this.configuration = configuration;\n this.services = services;\n\n this.state = {\n sid: data.sid,\n index: index,\n author: data.author ?? null,\n subject: data.subject ?? null,\n body: data.text,\n timestamp: data.timestamp ? new Date(data.timestamp) : null,\n dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,\n lastUpdatedBy: data.lastUpdatedBy ?? null,\n attributes: parseAttributes(data.attributes, `Got malformed attributes for the message ${data.sid}`, log),\n type: data.type ?? 'text',\n media: (data.type && data.type === 'media' && data.media)\n ? new Media(data.media, this.services) : null,\n medias: (data.type && data.type === 'media' && data.medias)\n ? data.medias.map((m) => new Media(m, this.services)) : null,\n participantSid: data.memberSid ?? null,\n aggregatedDeliveryReceipt: data.delivery ? new AggregatedDeliveryReceipt(data.delivery) : null\n };\n }\n\n /**\n * Fired when the properties or the body of the message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Message} message - the message in question\n * * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update\n */\n static readonly updated = 'updated';\n\n /**\n * The server-assigned unique identifier for the message.\n */\n public get sid(): string { return this.state.sid; }\n\n /**\n * Name of the user that sent the message.\n */\n public get author(): string { return this.state.author; }\n\n /**\n * Message subject. Used only in email conversations.\n */\n public get subject(): string | null { return this.state.subject; }\n\n /**\n * Body of the message.\n */\n public get body(): string { return this.state.body; }\n\n /**\n * Date this message was last updated on.\n */\n public get dateUpdated(): Date { return this.state.dateUpdated; }\n\n /**\n * Index of the message in the conversation's messages list.\n * By design of the Conversations system, the message indices may have arbitrary gaps between them,\n * that does not necessarily mean they were deleted or otherwise modified - just that\n * messages may have some non-contiguous indices even if they are being sent immediately one after another.\n *\n * Trying to use indices for some calculations is going to be unreliable.\n *\n * To calculate the number of unread messages it is better to use the read horizon API.\n * See {@link Conversation.getUnreadMessagesCount} for details.\n */\n public get index(): number { return this.state.index; }\n\n /**\n * Identity of the last user that updated the message.\n */\n public get lastUpdatedBy(): string { return this.state.lastUpdatedBy; }\n\n /**\n * Date this message was created on.\n */\n public get dateCreated(): Date { return this.state.timestamp; }\n\n /**\n * Custom attributes of the message.\n */\n public get attributes(): Object { return this.state.attributes; }\n\n /**\n * Push notification type of the message.\n */\n public get type(): MessageType { return this.state.type; }\n\n /**\n * One of the attached media.\n * @deprecated Use attachedMedia instead. Note that the latter is now an array.\n */\n public get media(): Media { return this.state.media; }\n\n /**\n * Return all media attachments, except email body/history attachments, without temporary urls.\n */\n public get attachedMedia(): Array<Media> | null { return this.getMediaByCategory(['media']); }\n\n /**\n * The server-assigned unique identifier of the authoring participant.\n */\n public get participantSid(): string { return this.state.participantSid; }\n\n /**\n * Aggregated information about the message delivery statuses across all participants of a conversation..\n */\n public get aggregatedDeliveryReceipt(): AggregatedDeliveryReceipt | null {\n return this.state.aggregatedDeliveryReceipt;\n }\n\n /**\n * Return a (possibly empty) array of media matching a specific set of categories.\n * Allowed category is so far only 'media'.\n * @param categories Array of categories to match.\n * @returns Array of media descriptors matching given categories.\n */\n public getMediaByCategory(categories: Array<MediaCategory>): Array<Media> | null {\n return this.state.medias?.filter((m) => categories.includes(m.category));\n }\n\n _update(data) {\n let updateReasons: MessageUpdateReason[] = [];\n\n if ((data.text || ((typeof data.text) === 'string')) && data.text !== this.state.body) {\n this.state.body = data.text;\n updateReasons.push('body');\n }\n\n if (data.subject && data.subject !== this.state.subject) {\n this.state.subject = data.subject;\n updateReasons.push('subject');\n }\n\n if (data.lastUpdatedBy && data.lastUpdatedBy !== this.state.lastUpdatedBy) {\n this.state.lastUpdatedBy = data.lastUpdatedBy;\n updateReasons.push('lastUpdatedBy');\n }\n\n if (data.author && data.author !== this.state.author) {\n this.state.author = data.author;\n updateReasons.push('author');\n }\n\n if (data.dateUpdated &&\n new Date(data.dateUpdated).getTime() !== (this.state.dateUpdated && this.state.dateUpdated.getTime())) {\n this.state.dateUpdated = new Date(data.dateUpdated);\n updateReasons.push('dateUpdated');\n }\n\n if (data.timestamp &&\n new Date(data.timestamp).getTime() !== (this.state.timestamp && this.state.timestamp.getTime())) {\n this.state.timestamp = new Date(data.timestamp);\n updateReasons.push('dateCreated');\n }\n\n let updatedAttributes = parseAttributes(data.attributes, `Got malformed attributes for the message ${this.sid}`, log);\n if (!isEqual(this.state.attributes, updatedAttributes)) {\n this.state.attributes = updatedAttributes;\n updateReasons.push('attributes');\n }\n\n let updatedAggregatedDelivery = data.delivery;\n let currentAggregatedDelivery = this.state.aggregatedDeliveryReceipt;\n let isUpdatedAggregateDeliveryValid = !!updatedAggregatedDelivery && !!updatedAggregatedDelivery.total &&\n !!updatedAggregatedDelivery.delivered && !!updatedAggregatedDelivery.failed && !!updatedAggregatedDelivery.read &&\n !!updatedAggregatedDelivery.sent && !!updatedAggregatedDelivery.undelivered;\n if (isUpdatedAggregateDeliveryValid) {\n if (!currentAggregatedDelivery) {\n this.state.aggregatedDeliveryReceipt = new AggregatedDeliveryReceipt(updatedAggregatedDelivery);\n updateReasons.push('deliveryReceipt');\n } else if (!currentAggregatedDelivery._isEquals(updatedAggregatedDelivery)) {\n currentAggregatedDelivery._update(updatedAggregatedDelivery);\n updateReasons.push('deliveryReceipt');\n }\n }\n\n if (updateReasons.length > 0) {\n this.emit('updated', { message: this, updateReasons: updateReasons });\n }\n }\n\n /**\n * Get the participant who is the author of the message.\n */\n public async getParticipant(): Promise<Participant> {\n let participant: Participant = null;\n if (this.state.participantSid) {\n participant = await this.conversation.getParticipantBySid(this.participantSid)\n .catch(() => {\n log.debug(`Participant with sid \"${this.participantSid}\" not found for message ${this.sid}`);\n return null;\n });\n }\n if (!participant && this.state.author) {\n participant = await this.conversation.getParticipantByIdentity(this.state.author)\n .catch(() => {\n log.debug(`Participant with identity \"${this.author}\" not found for message ${this.sid}`);\n return null;\n });\n }\n if (participant) {\n return participant;\n }\n let errorMesage = 'Participant with ';\n if (this.state.participantSid) {\n errorMesage += 'SID \\'' + this.state.participantSid + '\\' ';\n }\n if (this.state.author) {\n if (this.state.participantSid) {\n errorMesage += 'or ';\n }\n errorMesage += 'identity \\'' + this.state.author + '\\' ';\n }\n if (errorMesage === 'Participant with ') {\n errorMesage = 'Participant ';\n }\n errorMesage += 'was not found';\n throw new Error(errorMesage);\n }\n\n /**\n * Get the delivery receipts of the message.\n */\n public async getDetailedDeliveryReceipts(): Promise<DetailedDeliveryReceipt[]> {\n let paginator: Paginator<DetailedDeliveryReceipt> = await this._getDetailedDeliveryReceiptsPaginator();\n let detailedDeliveryReceipts: DetailedDeliveryReceipt[] = [];\n\n while (true) {\n detailedDeliveryReceipts = [...detailedDeliveryReceipts, ...paginator.items];\n\n if (!paginator.hasNextPage) {\n break;\n }\n\n paginator = await paginator.nextPage();\n }\n\n return detailedDeliveryReceipts;\n }\n\n /**\n * Remove the message.\n */\n public async remove(): Promise<Message> {\n await this.services.commandExecutor.mutateResource(\n 'delete',\n this.links.self\n );\n\n return this;\n }\n\n /**\n * Edit the message body.\n * @param body New body of the message.\n */\n @validateTypesAsync('string')\n public async updateBody(body: string): Promise<Message> {\n await this.services.commandExecutor.mutateResource<EditMessageRequest, MessageResponse>(\n 'post',\n this.links.self,\n {\n body\n }\n );\n\n return this;\n }\n\n /**\n * Edit the message attributes.\n * @param attributes New attributes.\n */\n @validateTypesAsync(['string', 'number', 'boolean', 'object', literal(null)])\n public async updateAttributes(attributes: any): Promise<Message> {\n await this.services.commandExecutor.mutateResource<EditMessageRequest, MessageResponse>(\n 'post',\n this.links.self,\n {\n attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined\n }\n );\n\n return this;\n }\n\n /**\n * Get content URLs for all media attachments in the given set using single operation.\n * @param contentSet Set of media attachments to query for content URL.\n */\n @validateTypesAsync(custom(value => [\n value instanceof Array && value.length > 0 && value.reduce((a, c) => a && c instanceof Media),\n 'a non-empty array of Media'\n ]))\n public async attachTemporaryUrlsFor(contentSet: Media[]): Promise<Media[]> {\n // We ignore existing mcsMedia members of each of the media entries.\n // Instead we just collect their sids and pull new descriptors from a mediaSet GET endpoint.\n const sids = contentSet.map((m) => m.sid);\n if (this.services.mcsClient) {\n return (await this.services.mcsClient.mediaSetGet(sids)).map((item) => { return new Media(item, this.services); });\n } else {\n throw new Error('Media Content Service is unavailable');\n }\n }\n\n private async _getDetailedDeliveryReceiptsPaginator(options?: {\n pageToken?: string;\n pageSize?: number;\n }): Promise<Paginator<DetailedDeliveryReceipt>> {\n const messagesReceiptsUrl = this.configuration.links.messagesReceipts\n .replace('%s', this.conversation.sid)\n .replace('%s', this.sid);\n const url = new UriBuilder(messagesReceiptsUrl)\n .arg('PageToken', options?.pageToken)\n .arg('PageSize', options?.pageSize)\n .build();\n const response = await this.services.network.get(url);\n\n return new RestPaginator<DetailedDeliveryReceipt>(\n response.body.delivery_receipts.map(\n (x) => new DetailedDeliveryReceipt(x)\n ),\n (pageToken, pageSize) =>\n this._getDetailedDeliveryReceiptsPaginator({ pageToken, pageSize }),\n response.body.meta.previous_token,\n response.body.meta.next_token\n );\n }\n}\n\nexport {\n Message,\n MessageServices,\n MessageType,\n MessageUpdateReason,\n MessageUpdatedEventArgs\n};\n"],"names":["Logger","ReplayEventEmitter","index","parseAttributes","Media","AggregatedDeliveryReceipt","isEqual","UriBuilder","RestPaginator","DetailedDeliveryReceipt","__decorate","validateTypesAsync","literal","custom"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAsDpC;;;AAGA,MAAM,OAAQ,SAAQC,qCAAiC;;;;IAerD,YACEC,OAAa,EACb,IAAS,EACT,YAA0B,EAC1B,KAAmB,EACnB,aAA4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CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,YAAYT,WAAK,CAAC;QAC7F,4BAA4B;KAC7B,CAAC,CAAC;;;;qDAUF;;;;"}
|
1
|
+
{"version":3,"file":"message.js","sources":["../src/message.ts"],"sourcesContent":["import { parseAttributes, UriBuilder } from \"./util\";\nimport { Logger } from \"./logger\";\nimport { Conversation } from \"./conversation\";\nimport { McsClient, MediaCategory } from \"@twilio/mcs-client\";\nimport { Media } from \"./media\";\nimport { Participant } from \"./participant\";\nimport {\n AggregatedDeliveryDescriptor,\n AggregatedDeliveryReceipt,\n} from \"./aggregated-delivery-receipt\";\nimport {\n validateTypes,\n validateTypesAsync,\n nonEmptyString,\n custom,\n} from \"@twilio/declarative-type-validator\";\nimport { attributesValidator } from \"./interfaces/attributes\";\nimport { Network } from \"./services/network\";\nimport { RestPaginator } from \"./rest-paginator\";\nimport { DetailedDeliveryReceipt } from \"./detailed-delivery-receipt\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { EditMessageRequest } from \"./interfaces/commands/edit-message\";\nimport { MessageResponse } from \"./interfaces/commands/message-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\nimport { ResponseMeta } from \"./interfaces/commands/response-meta\";\nimport { DeliveryReceiptResponse } from \"./interfaces/commands/delivery-receipt-response\";\n\ntype MessageEvents = {\n updated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Message\");\n\ninterface MessageState {\n sid: string;\n index: number;\n author: string | null;\n subject: string | null;\n body: string | null;\n dateUpdated: Date | null;\n lastUpdatedBy: string | null;\n attributes: JSONValue;\n timestamp: Date | null;\n type: MessageType;\n media: Media | null;\n medias: Media[] | null;\n participantSid: string | null;\n aggregatedDeliveryReceipt: AggregatedDeliveryReceipt | null;\n}\n\ninterface MessageServices {\n mcsClient: McsClient;\n network: Network;\n commandExecutor: CommandExecutor;\n}\n\ninterface MessageLinks {\n self: string;\n conversation: string;\n messages_receipts: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a message.\n */\ntype MessageUpdateReason =\n | \"body\"\n | \"lastUpdatedBy\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"attributes\"\n | \"author\"\n | \"deliveryReceipt\"\n | \"subject\";\n\n/**\n * Type of a message.\n */\ntype MessageType = \"text\" | \"media\";\n\ninterface MessageUpdatedEventArgs {\n message: Message;\n updateReasons: MessageUpdateReason[];\n}\n\nexport interface MessageData {\n sid: string;\n text?: string;\n type?: MessageType;\n author: string | null;\n subject: string | null;\n lastUpdatedBy?: string | null;\n attributes?: JSONValue;\n dateUpdated: string;\n timestamp?: string;\n medias?: Media[];\n media?: Media;\n memberSid?: string;\n delivery?: AggregatedDeliveryDescriptor;\n}\n\n/**\n * A message in a conversation.\n */\nclass Message extends ReplayEventEmitter<MessageEvents> {\n /**\n * Conversation that the message is in.\n */\n public readonly conversation: Conversation;\n\n private readonly links: MessageLinks;\n private readonly configuration: Configuration;\n private readonly services: MessageServices;\n\n private state: MessageState;\n\n /**\n * @internal\n */\n constructor(\n index: number,\n data: MessageData,\n conversation: Conversation,\n links: MessageLinks,\n configuration: Configuration,\n services: MessageServices\n ) {\n super();\n\n this.conversation = conversation;\n\n this.links = links;\n this.configuration = configuration;\n this.services = services;\n\n this.state = {\n sid: data.sid,\n index: index,\n author: data.author,\n subject: data.subject,\n body: data.text ?? null,\n timestamp: data.timestamp ? new Date(data.timestamp) : null,\n dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,\n lastUpdatedBy: data.lastUpdatedBy ?? null,\n attributes: parseAttributes(\n data.attributes,\n `Got malformed attributes for the message ${data.sid}`,\n log\n ),\n type: data.type ?? \"text\",\n media:\n data.type && data.type === \"media\" && data.media\n ? new Media(data.media, this.services)\n : null,\n medias:\n data.type && data.type === \"media\" && data.medias\n ? data.medias.map((m) => new Media(m, this.services))\n : null,\n participantSid: data.memberSid ?? null,\n aggregatedDeliveryReceipt: data.delivery\n ? new AggregatedDeliveryReceipt(data.delivery)\n : null,\n };\n }\n\n /**\n * Fired when the properties or the body of the message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Message} message - the message in question\n * * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update\n */\n static readonly updated = \"updated\";\n\n /**\n * The server-assigned unique identifier for the message.\n */\n public get sid(): string {\n return this.state.sid;\n }\n\n /**\n * Name of the user that sent the message.\n */\n public get author(): string | null {\n return this.state.author;\n }\n\n /**\n * Message subject. Used only in email conversations.\n */\n public get subject(): string | null {\n return this.state.subject;\n }\n\n /**\n * Body of the message.\n */\n public get body(): string | null {\n return this.state.body;\n }\n\n /**\n * Date this message was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this.state.dateUpdated;\n }\n\n /**\n * Index of the message in the conversation's messages list.\n * By design of the Conversations system, the message indices may have arbitrary gaps between them,\n * that does not necessarily mean they were deleted or otherwise modified - just that\n * messages may have some non-contiguous indices even if they are being sent immediately one after another.\n *\n * Trying to use indices for some calculations is going to be unreliable.\n *\n * To calculate the number of unread messages it is better to use the read horizon API.\n * See {@link Conversation.getUnreadMessagesCount} for details.\n */\n public get index(): number {\n return this.state.index;\n }\n\n /**\n * Identity of the last user that updated the message.\n */\n public get lastUpdatedBy(): string | null {\n return this.state.lastUpdatedBy;\n }\n\n /**\n * Date this message was created on.\n */\n public get dateCreated(): Date | null {\n return this.state.timestamp;\n }\n\n /**\n * Custom attributes of the message.\n */\n public get attributes(): JSONValue {\n return this.state.attributes;\n }\n\n /**\n * Type of the message.\n */\n public get type(): MessageType {\n return this.state.type;\n }\n\n /**\n * One of the attached media (if present).\n * @deprecated Use attachedMedia instead. Note that the latter is now an array.\n */\n public get media(): Media | null {\n return this.state.media;\n }\n\n /**\n * Return all media attachments, except email body/history attachments, without temporary urls.\n */\n public get attachedMedia(): Array<Media> | null {\n return this.getMediaByCategory([\"media\"]);\n }\n\n /**\n * The server-assigned unique identifier of the authoring participant.\n */\n public get participantSid(): string | null {\n return this.state.participantSid;\n }\n\n /**\n * Aggregated information about the message delivery statuses across all participants of a conversation..\n */\n public get aggregatedDeliveryReceipt(): AggregatedDeliveryReceipt | null {\n return this.state.aggregatedDeliveryReceipt;\n }\n\n /**\n * Return a (possibly empty) array of media matching a specific set of categories.\n * Allowed category is so far only 'media'.\n * @param categories Array of categories to match.\n * @returns Array of media descriptors matching given categories.\n */\n public getMediaByCategory(\n categories: Array<MediaCategory>\n ): Array<Media> | null {\n return (this.state.medias ?? []).filter((m) =>\n categories.includes(m.category)\n );\n }\n\n /**\n * Get a media descriptor for an email body attachment of a provided type.\n * Allowed body types are returned in the Conversation.limits().emailBodiesAllowedMimeTypes array.\n * @param type Type of email body to request, defaults to `text/plain`.\n */\n @validateTypes(nonEmptyString)\n public getEmailBody(type = \"text/plain\"): Media | null {\n return (\n this.getMediaByCategory([\"body\"])\n ?.filter((m) => m.contentType == type)\n .shift() ?? null\n );\n }\n\n /**\n * Get a media descriptor for an email history attachment of a provided type.\n * Allowed body types are returned in the Conversation.limits().emailHistoriesAllowedMimeTypes array.\n * @param type Type of email history to request, defaults to `text/plain`.\n */\n @validateTypes(nonEmptyString)\n public getEmailHistory(type = \"text/plain\"): Media | null {\n return (\n this.getMediaByCategory([\"history\"])\n ?.filter((m) => m.contentType == type)\n .shift() ?? null\n );\n }\n\n _update(data) {\n const updateReasons: MessageUpdateReason[] = [];\n\n if (\n (data.text || typeof data.text === \"string\") &&\n data.text !== this.state.body\n ) {\n this.state.body = data.text;\n updateReasons.push(\"body\");\n }\n\n if (data.subject && data.subject !== this.state.subject) {\n this.state.subject = data.subject;\n updateReasons.push(\"subject\");\n }\n\n if (data.lastUpdatedBy && data.lastUpdatedBy !== this.state.lastUpdatedBy) {\n this.state.lastUpdatedBy = data.lastUpdatedBy;\n updateReasons.push(\"lastUpdatedBy\");\n }\n\n if (data.author && data.author !== this.state.author) {\n this.state.author = data.author;\n updateReasons.push(\"author\");\n }\n\n if (\n data.dateUpdated &&\n new Date(data.dateUpdated).getTime() !==\n (this.state.dateUpdated && this.state.dateUpdated.getTime())\n ) {\n this.state.dateUpdated = new Date(data.dateUpdated);\n updateReasons.push(\"dateUpdated\");\n }\n\n if (\n data.timestamp &&\n new Date(data.timestamp).getTime() !==\n (this.state.timestamp && this.state.timestamp.getTime())\n ) {\n this.state.timestamp = new Date(data.timestamp);\n updateReasons.push(\"dateCreated\");\n }\n\n const updatedAttributes = parseAttributes(\n data.attributes,\n `Got malformed attributes for the message ${this.sid}`,\n log\n );\n if (!isEqual(this.state.attributes, updatedAttributes)) {\n this.state.attributes = updatedAttributes;\n updateReasons.push(\"attributes\");\n }\n\n const updatedAggregatedDelivery = data.delivery;\n const currentAggregatedDelivery = this.state.aggregatedDeliveryReceipt;\n const isUpdatedAggregateDeliveryValid =\n !!updatedAggregatedDelivery &&\n !!updatedAggregatedDelivery.total &&\n !!updatedAggregatedDelivery.delivered &&\n !!updatedAggregatedDelivery.failed &&\n !!updatedAggregatedDelivery.read &&\n !!updatedAggregatedDelivery.sent &&\n !!updatedAggregatedDelivery.undelivered;\n if (isUpdatedAggregateDeliveryValid) {\n if (!currentAggregatedDelivery) {\n this.state.aggregatedDeliveryReceipt = new AggregatedDeliveryReceipt(\n updatedAggregatedDelivery\n );\n updateReasons.push(\"deliveryReceipt\");\n } else if (\n !currentAggregatedDelivery._isEquals(updatedAggregatedDelivery)\n ) {\n currentAggregatedDelivery._update(updatedAggregatedDelivery);\n updateReasons.push(\"deliveryReceipt\");\n }\n }\n\n if (updateReasons.length > 0) {\n this.emit(\"updated\", { message: this, updateReasons: updateReasons });\n }\n }\n\n /**\n * Get the participant who is the author of the message.\n */\n public async getParticipant(): Promise<Participant> {\n let participant: Participant | null = null;\n if (this.state.participantSid) {\n participant = await this.conversation\n .getParticipantBySid(this.state.participantSid)\n .catch(() => {\n log.debug(\n `Participant with sid \"${this.participantSid}\" not found for message ${this.sid}`\n );\n return null;\n });\n }\n if (!participant && this.state.author) {\n participant = await this.conversation\n .getParticipantByIdentity(this.state.author)\n .catch(() => {\n log.debug(\n `Participant with identity \"${this.author}\" not found for message ${this.sid}`\n );\n return null;\n });\n }\n if (participant) {\n return participant;\n }\n let errorMesage = \"Participant with \";\n if (this.state.participantSid) {\n errorMesage += \"SID '\" + this.state.participantSid + \"' \";\n }\n if (this.state.author) {\n if (this.state.participantSid) {\n errorMesage += \"or \";\n }\n errorMesage += \"identity '\" + this.state.author + \"' \";\n }\n if (errorMesage === \"Participant with \") {\n errorMesage = \"Participant \";\n }\n errorMesage += \"was not found\";\n throw new Error(errorMesage);\n }\n\n /**\n * Get the delivery receipts of the message.\n */\n public async getDetailedDeliveryReceipts(): Promise<\n DetailedDeliveryReceipt[]\n > {\n let paginator: Paginator<DetailedDeliveryReceipt> =\n await this._getDetailedDeliveryReceiptsPaginator();\n let detailedDeliveryReceipts: DetailedDeliveryReceipt[] = [];\n\n while (true) {\n detailedDeliveryReceipts = [\n ...detailedDeliveryReceipts,\n ...paginator.items,\n ];\n\n if (!paginator.hasNextPage) {\n break;\n }\n\n paginator = await paginator.nextPage();\n }\n\n return detailedDeliveryReceipts;\n }\n\n /**\n * Remove the message.\n */\n public async remove(): Promise<Message> {\n await this.services.commandExecutor.mutateResource(\n \"delete\",\n this.links.self\n );\n\n return this;\n }\n\n /**\n * Edit the message body.\n * @param body New body of the message.\n */\n @validateTypesAsync(\"string\")\n public async updateBody(body: string): Promise<Message> {\n await this.services.commandExecutor.mutateResource<\n EditMessageRequest,\n MessageResponse\n >(\"post\", this.links.self, {\n body,\n });\n\n return this;\n }\n\n /**\n * Edit the message attributes.\n * @param attributes New attributes.\n */\n @validateTypesAsync(attributesValidator)\n public async updateAttributes(attributes: JSONValue): Promise<Message> {\n await this.services.commandExecutor.mutateResource<\n EditMessageRequest,\n MessageResponse\n >(\"post\", this.links.self, {\n attributes:\n typeof attributes !== \"undefined\"\n ? JSON.stringify(attributes)\n : undefined,\n });\n\n return this;\n }\n\n /**\n * Get content URLs for all media attachments in the given set using single operation.\n * @param contentSet Set of media attachments to query for content URL.\n */\n @validateTypesAsync(\n custom((value) => [\n value instanceof Array &&\n value.length > 0 &&\n value.reduce((a, c) => a && c instanceof Media, true),\n \"a non-empty array of Media\",\n ])\n )\n public async attachTemporaryUrlsFor(\n contentSet: Media[] | null\n ): Promise<Media[]> {\n // We ignore existing mcsMedia members of each of the media entries.\n // Instead we just collect their sids and pull new descriptors from a mediaSet GET endpoint.\n const sids = contentSet?.map((m) => m.sid);\n if (this.services.mcsClient && sids) {\n return (await this.services.mcsClient.mediaSetGet(sids)).map((item) => {\n return new Media(item, this.services);\n });\n } else {\n throw new Error(\"Media Content Service is unavailable\");\n }\n }\n\n private async _getDetailedDeliveryReceiptsPaginator(options?: {\n pageToken?: string;\n pageSize?: number;\n }): Promise<Paginator<DetailedDeliveryReceipt>> {\n const messagesReceiptsUrl = this.configuration.links.messagesReceipts\n .replace(\"%s\", this.conversation.sid)\n .replace(\"%s\", this.sid);\n const url = new UriBuilder(messagesReceiptsUrl)\n .arg(\"PageToken\", options?.pageToken as string)\n .arg(\"PageSize\", options?.pageSize as number)\n .build();\n const response = await this.services.network.get<\n { delivery_receipts: DeliveryReceiptResponse[] } & ResponseMeta\n >(url);\n\n return new RestPaginator<DetailedDeliveryReceipt>(\n response.body.delivery_receipts.map(\n (x) => new DetailedDeliveryReceipt(x)\n ),\n (pageToken, pageSize) =>\n this._getDetailedDeliveryReceiptsPaginator({ pageToken, pageSize }),\n response.body.meta.previous_token,\n response.body.meta.next_token\n );\n }\n}\n\nexport {\n Message,\n MessageServices,\n MessageType,\n MessageUpdateReason,\n MessageUpdatedEventArgs,\n};\n"],"names":["Logger","ReplayEventEmitter","index","parseAttributes","Media","AggregatedDeliveryReceipt","isEqual","UriBuilder","RestPaginator","DetailedDeliveryReceipt","__decorate","validateTypes","non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AAC;aAC5C,KAAK,EAAE,CAAC;QACX,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAE9C,GAAG,CAAC,CAAC;QAEP,OAAO,IAAIC,2BAAa,CACtB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CACjC,CAAC,CAAC,KAAK,IAAIC,+CAAuB,CAAC,CAAC,CAAC,CACtC,EACD,CAAC,SAAS,EAAE,QAAQ,KAClB,IAAI,CAAC,qCAAqC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EACrE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EACjC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAC9B,CAAC;KACH;;AA3ZD;;;;;;;;AAQgB,eAAO,GAAG,SAAS,CAAC;AAiIpCC;IADCC,sCAAa,CAACC,uCAAc,CAAC;;;8CACYR,WAAK;2CAM9C;AAQDM;IADCC,sCAAa,CAACC,uCAAc,CAAC;;;8CACeR,WAAK;8CAMjD;AA6KDM;IADCG,2CAAkB,CAAC,QAAQ,CAAC;;;;yCAU5B;AAODH;IADCG,2CAAkB,CAACC,8BAAmB,CAAC;;;;+CAavC;AAcDJ;IARCG,2CAAkB,CACjBE,+BAAM,CAAC,CAAC,KAAK,KAAK;QAChB,KAAK,YAAY,KAAK;YACpB,KAAK,CAAC,MAAM,GAAG,CAAC;YAChB,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,YAAYX,WAAK,EAAE,IAAI,CAAC;QACvD,4BAA4B;KAC7B,CAAC,CACH;;;;qDAcA;;;;"}
|
@@ -130,7 +130,7 @@ This software includes platform.js under the following license.
|
|
130
130
|
|
131
131
|
Object.defineProperty(exports, '__esModule', { value: true });
|
132
132
|
|
133
|
-
var version = "2.0.
|
133
|
+
var version = "2.1.0-rc.6";
|
134
134
|
|
135
135
|
exports.version = version;
|
136
136
|
//# sourceMappingURL=package.json.js.map
|
package/dist/participant.js
CHANGED
@@ -133,6 +133,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
133
133
|
var tslib_es6 = require('./node_modules/tslib/tslib.es6.js');
|
134
134
|
var index = require('./util/index.js');
|
135
135
|
var logger = require('./logger.js');
|
136
|
+
var attributes = require('./interfaces/attributes.js');
|
136
137
|
var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
137
138
|
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
138
139
|
var isEqual = require('lodash.isequal');
|
@@ -141,7 +142,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
141
142
|
|
142
143
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
143
144
|
|
144
|
-
const log = logger.Logger.scope(
|
145
|
+
const log = logger.Logger.scope("Participant");
|
145
146
|
/**
|
146
147
|
* A participant represents a remote client in a conversation.
|
147
148
|
*/
|
@@ -150,78 +151,120 @@ class Participant extends replayEventEmitter.ReplayEventEmitter {
|
|
150
151
|
* @internal
|
151
152
|
*/
|
152
153
|
constructor(data, sid, conversation, links, services) {
|
154
|
+
var _a, _b;
|
153
155
|
super();
|
154
156
|
this.conversation = conversation;
|
155
157
|
this.links = links;
|
156
158
|
this.services = services;
|
157
159
|
this.state = {
|
158
|
-
attributes: index.parseAttributes(data.attributes,
|
160
|
+
attributes: index.parseAttributes(data.attributes, "Retrieved malformed attributes from the server for participant: " +
|
161
|
+
sid, log),
|
159
162
|
dateCreated: data.dateCreated ? index.parseTime(data.dateCreated) : null,
|
160
163
|
dateUpdated: data.dateCreated ? index.parseTime(data.dateUpdated) : null,
|
161
164
|
sid: sid,
|
162
165
|
typingTimeout: null,
|
163
166
|
isTyping: false,
|
164
|
-
identity: data.identity
|
165
|
-
roleSid: data.roleSid
|
166
|
-
lastReadMessageIndex: Number.isInteger(data.lastConsumedMessageIndex)
|
167
|
-
|
168
|
-
|
169
|
-
|
167
|
+
identity: data.identity,
|
168
|
+
roleSid: (_a = data.roleSid) !== null && _a !== void 0 ? _a : "",
|
169
|
+
lastReadMessageIndex: Number.isInteger(data.lastConsumedMessageIndex)
|
170
|
+
? data.lastConsumedMessageIndex
|
171
|
+
: null,
|
172
|
+
lastReadTimestamp: data.lastConsumptionTimestamp
|
173
|
+
? index.parseTime(data.lastConsumptionTimestamp)
|
174
|
+
: null,
|
175
|
+
type: data.type || "chat",
|
176
|
+
userInfo: data.userInfo,
|
177
|
+
bindings: (_b = data.bindings) !== null && _b !== void 0 ? _b : {},
|
170
178
|
};
|
171
179
|
if (!data.identity && !data.type) {
|
172
|
-
throw new Error(
|
180
|
+
throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");
|
173
181
|
}
|
174
182
|
}
|
175
183
|
/**
|
176
184
|
* The server-assigned unique identifier for the participant.
|
177
185
|
*/
|
178
|
-
get sid() {
|
186
|
+
get sid() {
|
187
|
+
return this.state.sid;
|
188
|
+
}
|
179
189
|
/**
|
180
190
|
* Custom attributes of the participant.
|
181
191
|
*/
|
182
|
-
get attributes() {
|
192
|
+
get attributes() {
|
193
|
+
return this.state.attributes;
|
194
|
+
}
|
183
195
|
/**
|
184
196
|
* Date this participant was created on.
|
185
197
|
*/
|
186
|
-
get dateCreated() {
|
198
|
+
get dateCreated() {
|
199
|
+
return this.state.dateCreated;
|
200
|
+
}
|
187
201
|
/**
|
188
202
|
* Date this participant was last updated on.
|
189
203
|
*/
|
190
|
-
get dateUpdated() {
|
204
|
+
get dateUpdated() {
|
205
|
+
return this.state.dateUpdated;
|
206
|
+
}
|
191
207
|
/**
|
192
208
|
* Identity of the participant.
|
193
209
|
*/
|
194
|
-
get identity() {
|
210
|
+
get identity() {
|
211
|
+
return this.state.identity;
|
212
|
+
}
|
195
213
|
/**
|
196
214
|
* Indicates whether the participant is currently typing.
|
197
215
|
*/
|
198
|
-
get isTyping() {
|
216
|
+
get isTyping() {
|
217
|
+
return this.state.isTyping;
|
218
|
+
}
|
199
219
|
/**
|
200
220
|
* The index of the last read message by the participant.
|
201
221
|
* Note that retrieving messages on a client endpoint does not mean that messages are read,
|
202
222
|
* please consider reading about the [Read Horizon feature](https://www.twilio.com/docs/api/chat/guides/consumption-horizon)
|
203
223
|
* to find out about the proper way to mark messages as read.
|
204
224
|
*/
|
205
|
-
get lastReadMessageIndex() {
|
225
|
+
get lastReadMessageIndex() {
|
226
|
+
return this.state.lastReadMessageIndex;
|
227
|
+
}
|
206
228
|
/**
|
207
229
|
* Date of the most recent read horizon update.
|
208
230
|
*/
|
209
|
-
get lastReadTimestamp() {
|
210
|
-
|
231
|
+
get lastReadTimestamp() {
|
232
|
+
return this.state.lastReadTimestamp;
|
233
|
+
}
|
234
|
+
get roleSid() {
|
235
|
+
return this.state.roleSid;
|
236
|
+
}
|
211
237
|
/**
|
212
|
-
*
|
238
|
+
* Type of the participant.
|
213
239
|
*/
|
214
|
-
get type() {
|
240
|
+
get type() {
|
241
|
+
return this.state.type;
|
242
|
+
}
|
243
|
+
/**
|
244
|
+
* Get the bindings mapping for the current participant.
|
245
|
+
* Available binding depends on the participant type.
|
246
|
+
* You could access it as `participant.bindings.sms?.address` or
|
247
|
+
* using the type dynamically `participant.bindings[participant.type]`
|
248
|
+
* just be aware that the binding information has different structure for
|
249
|
+
* each participant type.
|
250
|
+
* See also {ParticipantEmailBinding}, the only available currently binding descriptor.
|
251
|
+
*/
|
252
|
+
get bindings() {
|
253
|
+
var _a;
|
254
|
+
return (_a = this.state.bindings) !== null && _a !== void 0 ? _a : {};
|
255
|
+
}
|
215
256
|
/**
|
216
257
|
* Internal method used to start or reset the typing indicator timeout (with event emitting).
|
217
258
|
* @internal
|
218
259
|
*/
|
219
260
|
_startTyping(timeout) {
|
220
|
-
|
261
|
+
if (this.state.typingTimeout) {
|
262
|
+
clearTimeout(this.state.typingTimeout);
|
263
|
+
}
|
221
264
|
this.state.isTyping = true;
|
222
|
-
this.emit(
|
223
|
-
this.conversation.emit(
|
224
|
-
this.state.typingTimeout = setTimeout(() => this._endTyping(), timeout);
|
265
|
+
this.emit("typingStarted", this);
|
266
|
+
this.conversation.emit("typingStarted", this);
|
267
|
+
this.state.typingTimeout = Number(setTimeout(() => this._endTyping(), timeout));
|
225
268
|
return this;
|
226
269
|
}
|
227
270
|
/**
|
@@ -233,8 +276,8 @@ class Participant extends replayEventEmitter.ReplayEventEmitter {
|
|
233
276
|
return;
|
234
277
|
}
|
235
278
|
this.state.isTyping = false;
|
236
|
-
this.emit(
|
237
|
-
this.conversation.emit(
|
279
|
+
this.emit("typingEnded", this);
|
280
|
+
this.conversation.emit("typingEnded", this);
|
238
281
|
clearInterval(this.state.typingTimeout);
|
239
282
|
this.state.typingTimeout = null;
|
240
283
|
}
|
@@ -243,43 +286,51 @@ class Participant extends replayEventEmitter.ReplayEventEmitter {
|
|
243
286
|
* @internal
|
244
287
|
*/
|
245
288
|
_update(data) {
|
246
|
-
|
247
|
-
|
289
|
+
const updateReasons = [];
|
290
|
+
const updateAttributes = index.parseAttributes(data.attributes, "Retrieved malformed attributes from the server for participant: " +
|
291
|
+
this.state.sid, log);
|
248
292
|
if (data.attributes && !isEqual__default['default'](this.state.attributes, updateAttributes)) {
|
249
293
|
this.state.attributes = updateAttributes;
|
250
|
-
updateReasons.push(
|
294
|
+
updateReasons.push("attributes");
|
251
295
|
}
|
252
|
-
|
296
|
+
const updatedDateUpdated = index.parseTime(data.dateUpdated);
|
253
297
|
if (data.dateUpdated &&
|
254
|
-
updatedDateUpdated
|
298
|
+
(updatedDateUpdated === null || updatedDateUpdated === void 0 ? void 0 : updatedDateUpdated.getTime()) !==
|
299
|
+
(this.state.dateUpdated && this.state.dateUpdated.getTime())) {
|
255
300
|
this.state.dateUpdated = updatedDateUpdated;
|
256
|
-
updateReasons.push(
|
301
|
+
updateReasons.push("dateUpdated");
|
257
302
|
}
|
258
|
-
|
303
|
+
const updatedDateCreated = index.parseTime(data.dateCreated);
|
259
304
|
if (data.dateCreated &&
|
260
|
-
updatedDateCreated
|
305
|
+
(updatedDateCreated === null || updatedDateCreated === void 0 ? void 0 : updatedDateCreated.getTime()) !==
|
306
|
+
(this.state.dateCreated && this.state.dateCreated.getTime())) {
|
261
307
|
this.state.dateCreated = updatedDateCreated;
|
262
|
-
updateReasons.push(
|
308
|
+
updateReasons.push("dateCreated");
|
263
309
|
}
|
264
310
|
if (data.roleSid && this.state.roleSid !== data.roleSid) {
|
265
311
|
this.state.roleSid = data.roleSid;
|
266
|
-
updateReasons.push(
|
312
|
+
updateReasons.push("roleSid");
|
267
313
|
}
|
268
|
-
if ((Number.isInteger(data.lastConsumedMessageIndex) ||
|
269
|
-
|
314
|
+
if ((Number.isInteger(data.lastConsumedMessageIndex) ||
|
315
|
+
data.lastConsumedMessageIndex === null) &&
|
316
|
+
this.state.lastReadMessageIndex !== data.lastConsumedMessageIndex) {
|
270
317
|
this.state.lastReadMessageIndex = data.lastConsumedMessageIndex;
|
271
|
-
updateReasons.push(
|
318
|
+
updateReasons.push("lastReadMessageIndex");
|
272
319
|
}
|
273
320
|
if (data.lastConsumptionTimestamp) {
|
274
|
-
|
321
|
+
const lastReadTimestamp = new Date(data.lastConsumptionTimestamp);
|
275
322
|
if (!this.state.lastReadTimestamp ||
|
276
323
|
this.state.lastReadTimestamp.getTime() !== lastReadTimestamp.getTime()) {
|
277
324
|
this.state.lastReadTimestamp = lastReadTimestamp;
|
278
|
-
updateReasons.push(
|
325
|
+
updateReasons.push("lastReadTimestamp");
|
279
326
|
}
|
280
327
|
}
|
328
|
+
if (data.bindings && !isEqual__default['default'](this.state.bindings, data.bindings)) {
|
329
|
+
this.state.bindings = data.bindings;
|
330
|
+
updateReasons.push("bindings");
|
331
|
+
}
|
281
332
|
if (updateReasons.length > 0) {
|
282
|
-
this.emit(
|
333
|
+
this.emit("updated", { participant: this, updateReasons: updateReasons });
|
283
334
|
}
|
284
335
|
return this;
|
285
336
|
}
|
@@ -287,8 +338,8 @@ class Participant extends replayEventEmitter.ReplayEventEmitter {
|
|
287
338
|
* Get the user for this participant and subscribes to it. Supported only for participants of type `chat`.
|
288
339
|
*/
|
289
340
|
async getUser() {
|
290
|
-
if (this.type !=
|
291
|
-
throw new Error(
|
341
|
+
if (this.type != "chat") {
|
342
|
+
throw new Error("Getting User is not supported for this Participant type: " + this.type);
|
292
343
|
}
|
293
344
|
return this.services.users.getUser(this.state.identity, this.state.userInfo);
|
294
345
|
}
|
@@ -303,8 +354,8 @@ class Participant extends replayEventEmitter.ReplayEventEmitter {
|
|
303
354
|
* @param attributes New attributes.
|
304
355
|
*/
|
305
356
|
async updateAttributes(attributes) {
|
306
|
-
await this.services.commandExecutor.mutateResource(
|
307
|
-
attributes: JSON.stringify(attributes)
|
357
|
+
await this.services.commandExecutor.mutateResource("post", this.links.self, {
|
358
|
+
attributes: JSON.stringify(attributes),
|
308
359
|
});
|
309
360
|
return this;
|
310
361
|
}
|
@@ -316,7 +367,7 @@ class Participant extends replayEventEmitter.ReplayEventEmitter {
|
|
316
367
|
* 1. {@link Participant} `participant` - the participant in question
|
317
368
|
* @event
|
318
369
|
*/
|
319
|
-
Participant.typingStarted =
|
370
|
+
Participant.typingStarted = "typingStarted";
|
320
371
|
/**
|
321
372
|
* Fired when the participant has stopped typing.
|
322
373
|
*
|
@@ -324,7 +375,7 @@ Participant.typingStarted = 'typingStarted';
|
|
324
375
|
* 1. {@link Participant} `participant` - the participant in question
|
325
376
|
* @event
|
326
377
|
*/
|
327
|
-
Participant.typingEnded =
|
378
|
+
Participant.typingEnded = "typingEnded";
|
328
379
|
/**
|
329
380
|
* Fired when the fields of the participant have been updated.
|
330
381
|
*
|
@@ -334,9 +385,9 @@ Participant.typingEnded = 'typingEnded';
|
|
334
385
|
* * {@link ParticipantUpdateReason}[] updateReasons - array of reasons for the update
|
335
386
|
* @event
|
336
387
|
*/
|
337
|
-
Participant.updated =
|
388
|
+
Participant.updated = "updated";
|
338
389
|
tslib_es6.__decorate([
|
339
|
-
declarativeTypeValidator.validateTypesAsync(
|
390
|
+
declarativeTypeValidator.validateTypesAsync(attributes.attributesValidator),
|
340
391
|
tslib_es6.__metadata("design:type", Function),
|
341
392
|
tslib_es6.__metadata("design:paramtypes", [Object]),
|
342
393
|
tslib_es6.__metadata("design:returntype", Promise)
|
package/dist/participant.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"participant.js","sources":["../src/participant.ts"],"sourcesContent":["import { Users } from './data/users';\nimport { User } from './user';\nimport { parseTime, parseAttributes } from './util';\nimport { Logger } from './logger';\nimport { Conversation } from './conversation';\nimport { validateTypesAsync, literal } from '@twilio/declarative-type-validator';\nimport { CommandExecutor } from './command-executor';\nimport { EditParticipantRequest } from './interfaces/commands/edit-participant';\nimport { ParticipantResponse } from './interfaces/commands/participant-response';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\nimport isEqual from 'lodash.isequal';\n\ntype ParticipantEvents = {\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope('Participant');\n\ninterface ParticipantDescriptor {\n attributes?: Object;\n dateCreated: any;\n dateUpdated: any;\n identity: string;\n roleSid?: string;\n lastConsumedMessageIndex: number;\n lastConsumptionTimestamp: number;\n type: ParticipantType;\n userInfo: string;\n}\n\ninterface ParticipantState {\n attributes: any;\n dateCreated: Date;\n dateUpdated: Date;\n identity: string;\n isTyping: boolean;\n lastReadMessageIndex: number | null;\n lastReadTimestamp: Date;\n roleSid: string;\n sid: string;\n type: ParticipantType;\n typingTimeout: any;\n userInfo: string;\n}\n\ninterface ParticipantServices {\n users: Users;\n commandExecutor: CommandExecutor;\n}\n\ninterface ParticipantLinks {\n self: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a participant.\n */\ntype ParticipantUpdateReason =\n | 'attributes'\n | 'dateCreated'\n | 'dateUpdated'\n | 'roleSid'\n | 'lastReadMessageIndex'\n | 'lastReadTimestamp';\n\n/**\n * Type of a participant.\n */\ntype ParticipantType = 'chat' | 'sms' | 'whatsapp';\n\ninterface ParticipantUpdatedEventArgs {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n}\n\n/**\n * A participant represents a remote client in a conversation.\n */\nclass Participant extends ReplayEventEmitter<ParticipantEvents> {\n private state: ParticipantState;\n private readonly links: ParticipantLinks;\n private readonly services: ParticipantServices;\n\n /**\n * Conversation that the remote client is a participant of.\n */\n public readonly conversation: Conversation;\n\n /**\n * The server-assigned unique identifier for the participant.\n */\n public get sid(): string { return this.state.sid; }\n\n /**\n * Custom attributes of the participant.\n */\n public get attributes(): Object { return this.state.attributes; }\n\n /**\n * Date this participant was created on.\n */\n public get dateCreated(): Date { return this.state.dateCreated; }\n\n /**\n * Date this participant was last updated on.\n */\n public get dateUpdated(): Date { return this.state.dateUpdated; }\n\n /**\n * Identity of the participant.\n */\n public get identity(): string { return this.state.identity; }\n\n /**\n * Indicates whether the participant is currently typing.\n */\n public get isTyping(): boolean { return this.state.isTyping; }\n\n /**\n * The index of the last read message by the participant.\n * Note that retrieving messages on a client endpoint does not mean that messages are read,\n * please consider reading about the [Read Horizon feature](https://www.twilio.com/docs/api/chat/guides/consumption-horizon)\n * to find out about the proper way to mark messages as read.\n */\n public get lastReadMessageIndex(): number | null { return this.state.lastReadMessageIndex; }\n\n /**\n * Date of the most recent read horizon update.\n */\n public get lastReadTimestamp(): Date { return this.state.lastReadTimestamp; }\n\n public get roleSid(): string { return this.state.roleSid; }\n\n /**\n * Message type of the participant.\n */\n public get type(): ParticipantType { return this.state.type; }\n\n /**\n * @internal\n */\n constructor(\n data: ParticipantDescriptor,\n sid: string,\n conversation: Conversation,\n links: ParticipantLinks,\n services: ParticipantServices,\n ) {\n super();\n\n this.conversation = conversation;\n this.links = links;\n this.services = services;\n this.state = {\n attributes: parseAttributes(data.attributes,\n 'Retrieved malformed attributes from the server for participant: ' + sid,\n log),\n dateCreated: data.dateCreated ? parseTime(data.dateCreated) : null,\n dateUpdated: data.dateCreated ? parseTime(data.dateUpdated) : null,\n sid: sid,\n typingTimeout: null,\n isTyping: false,\n identity: data.identity || null,\n roleSid: data.roleSid || null,\n lastReadMessageIndex: Number.isInteger(data.lastConsumedMessageIndex) ? data.lastConsumedMessageIndex : null,\n lastReadTimestamp: data.lastConsumptionTimestamp ? parseTime(data.lastConsumptionTimestamp) : null,\n type: data.type || 'chat',\n userInfo: data.userInfo\n };\n\n if (!data.identity && !data.type) {\n throw new Error('Received invalid Participant object from server: Missing identity or type of Participant.');\n }\n }\n\n /**\n * Fired when the participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingStarted = 'typingStarted';\n\n /**\n * Fired when the participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingEnded = 'typingEnded';\n\n /**\n * Fired when the fields of the participant have been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Participant} participant - the participant in question\n * * {@link ParticipantUpdateReason}[] updateReasons - array of reasons for the update\n * @event\n */\n static readonly updated = 'updated';\n\n /**\n * Internal method used to start or reset the typing indicator timeout (with event emitting).\n * @internal\n */\n _startTyping(timeout) {\n clearTimeout(this.state.typingTimeout);\n\n this.state.isTyping = true;\n this.emit('typingStarted', this);\n this.conversation.emit('typingStarted', this);\n\n this.state.typingTimeout = setTimeout(() => this._endTyping(), timeout);\n return this;\n }\n\n /**\n * Internal method function used to stop the typing indicator timeout (with event emitting).\n * @internal\n */\n _endTyping() {\n if (!this.state.typingTimeout) { return; }\n\n this.state.isTyping = false;\n this.emit('typingEnded', this);\n this.conversation.emit('typingEnded', this);\n\n clearInterval(this.state.typingTimeout);\n this.state.typingTimeout = null;\n }\n\n /**\n * Internal method function used update local object's property roleSid with a new value.\n * @internal\n */\n _update(data) {\n let updateReasons: ParticipantUpdateReason[] = [];\n\n let updateAttributes =\n parseAttributes(\n data.attributes,\n 'Retrieved malformed attributes from the server for participant: ' + this.state.sid,\n log);\n\n if (data.attributes && !isEqual(this.state.attributes, updateAttributes)) {\n this.state.attributes = updateAttributes;\n updateReasons.push('attributes');\n }\n\n let updatedDateUpdated = parseTime(data.dateUpdated);\n if (data.dateUpdated &&\n updatedDateUpdated.getTime() !== (this.state.dateUpdated && this.state.dateUpdated.getTime())) {\n this.state.dateUpdated = updatedDateUpdated;\n updateReasons.push('dateUpdated');\n }\n\n let updatedDateCreated = parseTime(data.dateCreated);\n if (data.dateCreated &&\n updatedDateCreated.getTime() !== (this.state.dateCreated && this.state.dateCreated.getTime())) {\n this.state.dateCreated = updatedDateCreated;\n updateReasons.push('dateCreated');\n }\n\n if (data.roleSid && this.state.roleSid !== data.roleSid) {\n this.state.roleSid = data.roleSid;\n updateReasons.push('roleSid');\n }\n\n if ((Number.isInteger(data.lastConsumedMessageIndex) || data.lastConsumedMessageIndex === null)\n && this.state.lastReadMessageIndex !== data.lastConsumedMessageIndex) {\n this.state.lastReadMessageIndex = data.lastConsumedMessageIndex;\n updateReasons.push('lastReadMessageIndex');\n }\n\n if (data.lastConsumptionTimestamp) {\n let lastReadTimestamp = new Date(data.lastConsumptionTimestamp);\n if (!this.state.lastReadTimestamp ||\n this.state.lastReadTimestamp.getTime() !== lastReadTimestamp.getTime()) {\n this.state.lastReadTimestamp = lastReadTimestamp;\n updateReasons.push('lastReadTimestamp');\n }\n }\n\n if (updateReasons.length > 0) {\n this.emit('updated', { participant: this, updateReasons: updateReasons });\n }\n\n return this;\n }\n\n /**\n * Get the user for this participant and subscribes to it. Supported only for participants of type `chat`.\n */\n async getUser(): Promise<User> {\n if (this.type != 'chat') {\n throw new Error('Getting User is not supported for this Participant type: ' + this.type);\n }\n\n return this.services.users.getUser(this.state.identity, this.state.userInfo);\n }\n\n /**\n * Remove the participant from the conversation.\n */\n async remove() {\n return this.conversation.removeParticipant(this);\n }\n\n /**\n * Update the attributes of the participant.\n * @param attributes New attributes.\n */\n @validateTypesAsync(['string', 'number', 'boolean', 'object', literal(null)])\n async updateAttributes(attributes: any): Promise<Participant> {\n await this.services.commandExecutor.mutateResource<EditParticipantRequest, ParticipantResponse>(\n 'post',\n this.links.self,\n {\n attributes: JSON.stringify(attributes)\n }\n );\n\n return this;\n }\n}\n\nexport {\n ParticipantDescriptor,\n ParticipantServices,\n Participant,\n ParticipantUpdateReason,\n ParticipantType,\n ParticipantUpdatedEventArgs\n};\n"],"names":["Logger","ReplayEventEmitter","parseAttributes","parseTime","isEqual","__decorate","validateTypesAsync","literal"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AA2DxC;;;AAGA,MAAM,WAAY,SAAQC,qCAAqC;;;;IA+D7D,YACE,IAA2B,EAC3B,GAAW,EACX,YAA0B,EAC1B,KAAuB,EACvB,QAA6B;QAE7B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG;YACX,UAAU,EAAEC,qBAAe,CAAC,IAAI,CAAC,UAAU,EACzC,kEAAkE,GAAG,GAAG,EACxE,GAAG,CAAC;YACN,WAAW,EAAE,IAAI,CAAC,WAAW,GAAGC,eAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI;YAClE,WAAW,EAAE,IAAI,CAAC,WAAW,GAAGA,eAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI;YAClE,GAAG,EAAE,GAAG;YACR,aAAa,EAAE,IAAI;YACnB,QAAQ,EAAE,KAAK;YACf,Q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CAAC,UAAU,CAAC;SACvC,CACF,CAAC;QAEF,OAAO,IAAI,CAAC;KACb;;AAvJD;;;;;;;AAOgB,yBAAa,GAAG,eAAe,CAAC;AAEhD;;;;;;;AAOgB,uBAAW,GAAG,aAAa,CAAC;AAE5C;;;;;;;;;AASgB,mBAAO,GAAG,SAAS,CAAC;AAkHpCE;IADCC,2CAAkB,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAEC,gCAAO,CAAC,IAAI,CAAC,CAAC,CAAC;;;;mDAW5E;;;;"}
|
1
|
+
{"version":3,"file":"participant.js","sources":["../src/participant.ts"],"sourcesContent":["import { Users } from \"./data/users\";\nimport { User } from \"./user\";\nimport { parseTime, parseAttributes } from \"./util\";\nimport { Logger } from \"./logger\";\nimport { Conversation } from \"./conversation\";\nimport { attributesValidator } from \"./interfaces/attributes\";\nimport { validateTypesAsync } from \"@twilio/declarative-type-validator\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { EditParticipantRequest } from \"./interfaces/commands/edit-participant\";\nimport { ParticipantResponse } from \"./interfaces/commands/participant-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\n\ntype ParticipantEvents = {\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Participant\");\n\ninterface ParticipantDescriptor {\n attributes?: JSONValue;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n identity: string;\n roleSid?: string;\n lastConsumedMessageIndex: number | null;\n lastConsumptionTimestamp: number;\n type: ParticipantType;\n userInfo: string;\n bindings?: ParticipantBindings;\n}\n\ninterface ParticipantState {\n attributes: JSONValue;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n identity: string;\n isTyping: boolean;\n lastReadMessageIndex: number | null;\n lastReadTimestamp: Date | null;\n roleSid: string;\n sid: string;\n type: ParticipantType;\n typingTimeout: number | null;\n userInfo: string;\n bindings?: ParticipantBindings;\n}\n\ninterface ParticipantServices {\n users: Users;\n commandExecutor: CommandExecutor;\n}\n\ninterface ParticipantLinks {\n self: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a participant.\n */\ntype ParticipantUpdateReason =\n | \"attributes\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"roleSid\"\n | \"lastReadMessageIndex\"\n | \"lastReadTimestamp\"\n | \"bindings\";\n\n/**\n * Type of a participant.\n */\ntype ParticipantType = \"chat\" | \"sms\" | \"whatsapp\" | \"email\";\n\ninterface ParticipantUpdatedEventArgs {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n}\n\n/**\n * Bindings for conversation participant.\n */\ninterface ParticipantBindings {\n email?: ParticipantEmailBinding;\n}\n\n/**\n * Email participation level.\n * to = to/from\n * cc = cc\n */\ntype ParticipantEmailLevel = \"to\" | \"cc\";\n\n/**\n * Bindings for email participant.\n */\ninterface ParticipantEmailBinding {\n name: string;\n address: string;\n level: ParticipantEmailLevel;\n}\n\n/**\n * A participant represents a remote client in a conversation.\n */\nclass Participant extends ReplayEventEmitter<ParticipantEvents> {\n private state: ParticipantState;\n private readonly links: ParticipantLinks;\n private readonly services: ParticipantServices;\n\n /**\n * Conversation that the remote client is a participant of.\n */\n public readonly conversation: Conversation;\n\n /**\n * The server-assigned unique identifier for the participant.\n */\n public get sid(): string {\n return this.state.sid;\n }\n\n /**\n * Custom attributes of the participant.\n */\n public get attributes(): JSONValue {\n return this.state.attributes;\n }\n\n /**\n * Date this participant was created on.\n */\n public get dateCreated(): Date | null {\n return this.state.dateCreated;\n }\n\n /**\n * Date this participant was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this.state.dateUpdated;\n }\n\n /**\n * Identity of the participant.\n */\n public get identity(): string | null {\n return this.state.identity;\n }\n\n /**\n * Indicates whether the participant is currently typing.\n */\n public get isTyping(): boolean {\n return this.state.isTyping;\n }\n\n /**\n * The index of the last read message by the participant.\n * Note that retrieving messages on a client endpoint does not mean that messages are read,\n * please consider reading about the [Read Horizon feature](https://www.twilio.com/docs/api/chat/guides/consumption-horizon)\n * to find out about the proper way to mark messages as read.\n */\n public get lastReadMessageIndex(): number | null {\n return this.state.lastReadMessageIndex;\n }\n\n /**\n * Date of the most recent read horizon update.\n */\n public get lastReadTimestamp(): Date | null {\n return this.state.lastReadTimestamp;\n }\n\n public get roleSid(): string {\n return this.state.roleSid;\n }\n\n /**\n * Type of the participant.\n */\n public get type(): ParticipantType {\n return this.state.type;\n }\n\n /**\n * Get the bindings mapping for the current participant.\n * Available binding depends on the participant type.\n * You could access it as `participant.bindings.sms?.address` or\n * using the type dynamically `participant.bindings[participant.type]`\n * just be aware that the binding information has different structure for\n * each participant type.\n * See also {ParticipantEmailBinding}, the only available currently binding descriptor.\n */\n public get bindings(): ParticipantBindings {\n return this.state.bindings ?? {};\n }\n\n /**\n * @internal\n */\n constructor(\n data: ParticipantDescriptor,\n sid: string,\n conversation: Conversation,\n links: ParticipantLinks,\n services: ParticipantServices\n ) {\n super();\n\n this.conversation = conversation;\n this.links = links;\n this.services = services;\n this.state = {\n attributes: parseAttributes(\n data.attributes,\n \"Retrieved malformed attributes from the server for participant: \" +\n sid,\n log\n ),\n dateCreated: data.dateCreated ? parseTime(data.dateCreated) : null,\n dateUpdated: data.dateCreated ? parseTime(data.dateUpdated) : null,\n sid: sid,\n typingTimeout: null,\n isTyping: false,\n identity: data.identity,\n roleSid: data.roleSid ?? \"\",\n lastReadMessageIndex: Number.isInteger(data.lastConsumedMessageIndex)\n ? data.lastConsumedMessageIndex\n : null,\n lastReadTimestamp: data.lastConsumptionTimestamp\n ? parseTime(data.lastConsumptionTimestamp)\n : null,\n type: data.type || \"chat\",\n userInfo: data.userInfo,\n bindings: data.bindings ?? {},\n };\n\n if (!data.identity && !data.type) {\n throw new Error(\n \"Received invalid Participant object from server: Missing identity or type of Participant.\"\n );\n }\n }\n\n /**\n * Fired when the participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingStarted = \"typingStarted\";\n\n /**\n * Fired when the participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingEnded = \"typingEnded\";\n\n /**\n * Fired when the fields of the participant have been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Participant} participant - the participant in question\n * * {@link ParticipantUpdateReason}[] updateReasons - array of reasons for the update\n * @event\n */\n static readonly updated = \"updated\";\n\n /**\n * Internal method used to start or reset the typing indicator timeout (with event emitting).\n * @internal\n */\n _startTyping(timeout) {\n if (this.state.typingTimeout) {\n clearTimeout(this.state.typingTimeout);\n }\n\n this.state.isTyping = true;\n this.emit(\"typingStarted\", this);\n\n this.conversation.emit(\"typingStarted\", this);\n\n this.state.typingTimeout = Number(\n setTimeout(() => this._endTyping(), timeout)\n );\n return this;\n }\n\n /**\n * Internal method function used to stop the typing indicator timeout (with event emitting).\n * @internal\n */\n _endTyping() {\n if (!this.state.typingTimeout) {\n return;\n }\n\n this.state.isTyping = false;\n this.emit(\"typingEnded\", this);\n\n this.conversation.emit(\"typingEnded\", this);\n\n clearInterval(this.state.typingTimeout);\n this.state.typingTimeout = null;\n }\n\n /**\n * Internal method function used update local object's property roleSid with a new value.\n * @internal\n */\n _update(data) {\n const updateReasons: ParticipantUpdateReason[] = [];\n\n const updateAttributes = parseAttributes(\n data.attributes,\n \"Retrieved malformed attributes from the server for participant: \" +\n this.state.sid,\n log\n );\n\n if (data.attributes && !isEqual(this.state.attributes, updateAttributes)) {\n this.state.attributes = updateAttributes;\n updateReasons.push(\"attributes\");\n }\n\n const updatedDateUpdated = parseTime(data.dateUpdated);\n if (\n data.dateUpdated &&\n updatedDateUpdated?.getTime() !==\n (this.state.dateUpdated && this.state.dateUpdated.getTime())\n ) {\n this.state.dateUpdated = updatedDateUpdated;\n updateReasons.push(\"dateUpdated\");\n }\n\n const updatedDateCreated = parseTime(data.dateCreated);\n if (\n data.dateCreated &&\n updatedDateCreated?.getTime() !==\n (this.state.dateCreated && this.state.dateCreated.getTime())\n ) {\n this.state.dateCreated = updatedDateCreated;\n updateReasons.push(\"dateCreated\");\n }\n\n if (data.roleSid && this.state.roleSid !== data.roleSid) {\n this.state.roleSid = data.roleSid;\n updateReasons.push(\"roleSid\");\n }\n\n if (\n (Number.isInteger(data.lastConsumedMessageIndex) ||\n data.lastConsumedMessageIndex === null) &&\n this.state.lastReadMessageIndex !== data.lastConsumedMessageIndex\n ) {\n this.state.lastReadMessageIndex = data.lastConsumedMessageIndex;\n updateReasons.push(\"lastReadMessageIndex\");\n }\n\n if (data.lastConsumptionTimestamp) {\n const lastReadTimestamp = new Date(data.lastConsumptionTimestamp);\n if (\n !this.state.lastReadTimestamp ||\n this.state.lastReadTimestamp.getTime() !== lastReadTimestamp.getTime()\n ) {\n this.state.lastReadTimestamp = lastReadTimestamp;\n updateReasons.push(\"lastReadTimestamp\");\n }\n }\n\n if (data.bindings && !isEqual(this.state.bindings, data.bindings)) {\n this.state.bindings = data.bindings;\n updateReasons.push(\"bindings\");\n }\n\n if (updateReasons.length > 0) {\n this.emit(\"updated\", { participant: this, updateReasons: updateReasons });\n }\n\n return this;\n }\n\n /**\n * Get the user for this participant and subscribes to it. Supported only for participants of type `chat`.\n */\n async getUser(): Promise<User> {\n if (this.type != \"chat\") {\n throw new Error(\n \"Getting User is not supported for this Participant type: \" + this.type\n );\n }\n\n return this.services.users.getUser(\n this.state.identity,\n this.state.userInfo\n );\n }\n\n /**\n * Remove the participant from the conversation.\n */\n async remove() {\n return this.conversation.removeParticipant(this);\n }\n\n /**\n * Update the attributes of the participant.\n * @param attributes New attributes.\n */\n @validateTypesAsync(attributesValidator)\n async updateAttributes(attributes: JSONValue): Promise<Participant> {\n await this.services.commandExecutor.mutateResource<\n EditParticipantRequest,\n ParticipantResponse\n >(\"post\", this.links.self, {\n attributes: JSON.stringify(attributes),\n });\n\n return this;\n }\n}\n\nexport {\n ParticipantDescriptor,\n ParticipantServices,\n Participant,\n ParticipantUpdateReason,\n ParticipantType,\n ParticipantUpdatedEventArgs,\n ParticipantBindings,\n ParticipantEmailBinding,\n ParticipantEmailLevel,\n};\n"],"names":["Logger","ReplayEventEmitter","parseAttributes","parseTime","isEqual","__decorate","validateTypesAsync","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAqFxC;;;AAGA,MAAM,WAAY,SAAQC,qCAAqC;;;;IAgG7D,YACE,IAA2B,EAC3B,GAAW,EACX,YAA0B,EAC1B,KAAuB,EACvB,QAA6B;;QAE7B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG;YACX,UAAU,EAAEC,qBAAe,CACzB,IAAI,CAAC,UAAU,EACf,kEAAkE;gBAChE,GAAG,EACL,GAAG,CACJ;YACD,WAAW,EAAE,IAAI,CAAC,WAAW,GAAGC,eAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI;YAClE,WAAW,EAAE,IAAI,CAAC,WAAW,GAAGA,eAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI;YAClE,GAAG,EAAE,GAAG;YACR,aAAa,EAAE,IAAI;YACnB,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,MAAA,IAAI,CAAC,OA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,2DAA2D,GAAG,IAAI,CAAC,IAAI,CACxE,CAAC;SACH;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAChC,IAAI,CAAC,KAAK,CAAC,QAAQ,EACnB,IAAI,CAAC,KAAK,CAAC,QAAQ,CACpB,CAAC;KACH;;;;IAKD,MAAM,MAAM;QACV,OAAO,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;KAClD;;;;;IAOD,MAAM,gBAAgB,CAAC,UAAqB;QAC1C,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,CAGhD,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YACzB,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;SACvC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;KACb;;AApLD;;;;;;;AAOgB,yBAAa,GAAG,eAAe,CAAC;AAEhD;;;;;;;AAOgB,uBAAW,GAAG,aAAa,CAAC;AAE5C;;;;;;;;;AASgB,mBAAO,GAAG,SAAS,CAAC;AAgJpCC;IADCC,2CAAkB,CAACC,8BAAmB,CAAC;;;;mDAUvC;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"push-notification.js","sources":["../src/push-notification.ts"],"sourcesContent":["/**\n * Push notification type.\n */\ntype PushNotificationType =\n |
|
1
|
+
{"version":3,"file":"push-notification.js","sources":["../src/push-notification.ts"],"sourcesContent":["/**\n * Push notification type.\n */\ntype PushNotificationType =\n | \"twilio.conversations.new_message\"\n | \"twilio.conversations.added_to_conversation\"\n | \"twilio.conversations.removed_from_conversation\";\n\ninterface PushNotificationDescriptor {\n title: string | null;\n body: string | null;\n sound: string | null;\n badge: number | null;\n action: string | null;\n type: PushNotificationType;\n data: Record<string, unknown>;\n}\n\n/**\n * Additional data for a given push notification.\n */\ninterface PushNotificationData {\n /**\n * SID of the conversation.\n */\n conversationSid?: string;\n\n /**\n * Index of the message in the conversation.\n */\n messageIndex?: number;\n\n /**\n * SID of the message in the conversation.\n */\n messageSid?: string;\n}\n\n/**\n * Push notification for a Conversations client.\n */\nclass PushNotification {\n /**\n * Title of the notification.\n */\n public readonly title: string | null;\n\n /**\n * Text of the notification.\n */\n public readonly body: string | null;\n\n /**\n * Sound of the notification.\n */\n public readonly sound: string | null;\n\n /**\n * Number of the badge.\n */\n public readonly badge: number | null;\n\n /**\n * Notification action (`click_action` in FCM terms and `category` in APN terms).\n */\n public readonly action: string | null;\n\n /**\n * Type of the notification.\n */\n public readonly type: PushNotificationType;\n\n /**\n * Additional data of the conversation.\n */\n public readonly data: PushNotificationData;\n\n /**\n * @internal\n */\n constructor(data: PushNotificationDescriptor) {\n this.title = data.title || null;\n this.body = data.body || null;\n this.sound = data.sound || null;\n this.badge = data.badge || null;\n this.action = data.action || null;\n this.type = data.type || null;\n this.data = data.data || {};\n }\n}\n\nexport {\n PushNotification,\n PushNotificationType,\n PushNotificationDescriptor,\n PushNotificationData,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA;;;AAGA,MAAM,gBAAgB;;;;IAuCpB,YAAY,IAAgC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;KAC7B;;;;;"}
|
package/dist/rest-paginator.js
CHANGED
@@ -142,32 +142,42 @@ class RestPaginator {
|
|
142
142
|
prevToken,
|
143
143
|
nextToken,
|
144
144
|
source,
|
145
|
-
items
|
145
|
+
items,
|
146
146
|
};
|
147
147
|
}
|
148
148
|
/**
|
149
149
|
* Indicates the existence of the next page.
|
150
150
|
*/
|
151
|
-
get hasNextPage() {
|
151
|
+
get hasNextPage() {
|
152
|
+
return !!this.state.nextToken;
|
153
|
+
}
|
152
154
|
/**
|
153
155
|
* Indicates the existence of the previous page
|
154
156
|
*/
|
155
|
-
get hasPrevPage() {
|
157
|
+
get hasPrevPage() {
|
158
|
+
return !!this.state.prevToken;
|
159
|
+
}
|
156
160
|
/**
|
157
161
|
* Array of elements on the current page.
|
158
162
|
*/
|
159
|
-
get items() {
|
163
|
+
get items() {
|
164
|
+
return this.state.items;
|
165
|
+
}
|
160
166
|
/**
|
161
167
|
* Request the next page. Does not modify the existing object.
|
162
168
|
*/
|
163
169
|
nextPage() {
|
164
|
-
return this.hasNextPage
|
170
|
+
return this.hasNextPage
|
171
|
+
? this.state.source(this.state.nextToken)
|
172
|
+
: Promise.reject(new Error("No next page"));
|
165
173
|
}
|
166
174
|
/**
|
167
175
|
* Request the previous page. Does not modify the existing object.
|
168
176
|
*/
|
169
177
|
prevPage() {
|
170
|
-
return this.hasPrevPage
|
178
|
+
return this.hasPrevPage
|
179
|
+
? this.state.source(this.state.prevToken)
|
180
|
+
: Promise.reject(new Error("No previous page"));
|
171
181
|
}
|
172
182
|
}
|
173
183
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rest-paginator.js","sources":["../src/rest-paginator.ts"],"sourcesContent":["import { Paginator } from
|
1
|
+
{"version":3,"file":"rest-paginator.js","sources":["../src/rest-paginator.ts"],"sourcesContent":["import { Paginator } from \"./interfaces/paginator\";\n\ninterface PaginatorState<T> {\n source: (token: string) => Promise<RestPaginator<T>>;\n nextToken: string;\n prevToken: string;\n items: T[];\n}\n\n/**\n * Pagination helper class.\n */\nclass RestPaginator<T> implements Paginator<T> {\n private state: PaginatorState<T>;\n\n /**\n * Indicates the existence of the next page.\n */\n public get hasNextPage(): boolean {\n return !!this.state.nextToken;\n }\n\n /**\n * Indicates the existence of the previous page\n */\n public get hasPrevPage(): boolean {\n return !!this.state.prevToken;\n }\n\n /**\n * Array of elements on the current page.\n */\n public get items(): T[] {\n return this.state.items;\n }\n\n /**\n * @internal\n */\n constructor(items, source, prevToken, nextToken) {\n this.state = {\n prevToken,\n nextToken,\n source,\n items,\n };\n }\n\n /**\n * Request the next page. Does not modify the existing object.\n */\n nextPage(): Promise<RestPaginator<T>> {\n return this.hasNextPage\n ? this.state.source(this.state.nextToken)\n : Promise.reject(new Error(\"No next page\"));\n }\n\n /**\n * Request the previous page. Does not modify the existing object.\n */\n prevPage(): Promise<RestPaginator<T>> {\n return this.hasPrevPage\n ? this.state.source(this.state.prevToken)\n : Promise.reject(new Error(\"No previous page\"));\n }\n}\n\nexport { RestPaginator };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;;AAGA,MAAM,aAAa;;;;IA2BjB,YAAY,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS;QAC7C,IAAI,CAAC,KAAK,GAAG;YACX,SAAS;YACT,SAAS;YACT,MAAM;YACN,KAAK;SACN,CAAC;KACH;;;;IA5BD,IAAW,WAAW;QACpB,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;KAC/B;;;;IAKD,IAAW,WAAW;QACpB,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;KAC/B;;;;IAKD,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;KACzB;;;;IAiBD,QAAQ;QACN,OAAO,IAAI,CAAC,WAAW;cACnB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;cACvC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;KAC/C;;;;IAKD,QAAQ;QACN,OAAO,IAAI,CAAC,WAAW;cACnB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;cACvC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;KACnD;;;;;"}
|