A conversation represents communication between multiple Conversations clients.

### Hierarchy

- ReplayEventEmitter<ConversationEvents>
  - Conversation

## Index

### Events

- messageAdded
- messageRemoved
- messageUpdated
- participantJoined
- participantLeft
- participantUpdated
- removed
- typingEnded
- typingStarted
- updated

### Properties

- sid

### Accessors

- attributes
- createdBy
- dateCreated
- dateUpdated
- friendlyName
- lastMessage
- lastReadMessageIndex
- limits
- notificationLevel
- state
- status
- uniqueName

### Methods

- add
- addNonChatParticipant
- advanceLastReadMessageIndex
- delete
- getAttributes
- getMessageRecipients
- getMessages
- getMessagesCount
- getParticipantByIdentity
- getParticipantBySid
- getParticipants
- getParticipantsCount
- getUnreadMessagesCount
- join
- leave
- prepareMessage
- removeParticipant
- sendMessage
- setAllMessagesRead
- setAllMessagesUnread
- setUserNotificationLevel
- typing
- updateAttributes
- updateFriendlyName
- updateLastReadMessageIndex
- updateUniqueName

## Events

### Static Readonly messageAdded

messageAdded: "messageAdded" = "messageAdded"

Fired when a new message has been added to the conversation.

Parameters:

1. Message `message` - message that has been added

### Static Readonly messageRemoved

messageRemoved: "messageRemoved" = "messageRemoved"

Fired when message is removed from the conversation's message list.

Parameters:

1. Message `message` - message that has been removed

### Static Readonly messageUpdated

messageUpdated: "messageUpdated" = "messageUpdated"

Fired when data of a message has been updated.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - Message `message` - message that has received the update
   - MessageUpdateReason[] `updateReasons` - array of reasons for the update

### Static Readonly participantJoined

participantJoined: "participantJoined" = "participantJoined"

Fired when a participant has joined the conversation.

Parameters:

1. Participant `participant` - participant that joined the conversation

### Static Readonly participantLeft

participantLeft: "participantLeft" = "participantLeft"

Fired when a participant has left the conversation.

Parameters:

1. Participant `participant` - participant that left the conversation

### Static Readonly participantUpdated

participantUpdated: "participantUpdated" = "participantUpdated"

Fired when data of a participant has been updated.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - Participant `participant` - participant that has received the update
   - ParticipantUpdateReason[] `updateReasons` - array of reasons for the update

### Static Readonly removed

removed: "removed" = "removed"

Fired when the conversation was destroyed or the currently-logged-in user has left private conversation.

Parameters:

1. Conversation `conversation` - conversation that has been removed

### Static Readonly typingEnded

typingEnded: "typingEnded" = "typingEnded"

Fired when a participant has stopped typing.

Parameters:

1. Participant `participant` - the participant that has stopped typing

### Static Readonly typingStarted

typingStarted: "typingStarted" = "typingStarted"

Fired when a participant has started typing.

Parameters:

1. Participant `participant` - the participant that has started typing

### Static Readonly updated

updated: "updated" = "updated"

Fired when the data of the conversation has been updated.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - Conversation `conversation` - conversation that has received the update
   - ConversationUpdateReason[] `updateReasons` - array of reasons for the update

## Properties

### Readonly sid

sid: string

Unique system identifier of the conversation.

## Accessors

### attributes

- get attributes(): JSONValue

- Custom attributes of the conversation.

  #### Returns JSONValue

### createdBy

- get createdBy(): string

- Identity of the user that created this conversation.

  #### Returns string

### dateCreated

- get dateCreated(): Date

- Date this conversation was created on.

  #### Returns Date

### dateUpdated

- get dateUpdated(): Date

- Date this conversation was last updated on.

  #### Returns Date

### friendlyName

- get friendlyName(): string

- Name of the conversation.

  #### Returns string

### lastMessage

- get lastMessage(): LastMessage

- Last message sent to this conversation.

  #### Returns LastMessage

### lastReadMessageIndex

- get lastReadMessageIndex(): number

- Index of the last message the user has read in this conversation.

  #### Returns number

### limits

- get limits(): ConversationLimits

- Current conversation limits.

  #### Returns ConversationLimits

### notificationLevel

- get notificationLevel(): NotificationLevel

- User notification level for this conversation.

  #### Returns NotificationLevel

### state

- get state(): ConversationState

- State of the conversation.

  #### Returns ConversationState

### status

- get status(): ConversationStatus

- Status of the conversation.

  #### Returns ConversationStatus

### uniqueName

- get uniqueName(): string

- Unique name of the conversation.

  #### Returns string

## Methods

### add

- add(identity: string, attributes?: JSONValue): Promise<ParticipantResponse>

- Add a participant to the conversation by its identity.

  #### Parameters

  - ##### identity: string

    Identity of the Client to add.

  - ##### Optional attributes: JSONValue

    Attributes to be attached to the participant.

  #### Returns Promise<ParticipantResponse>

  The added participant.

### addNonChatParticipant

- addNonChatParticipant(proxyAddress: string, address: string, attributes?: JSONValue, bindingOptions?: ParticipantBindingOptions): Promise<ParticipantResponse>

- Add a non-chat participant to the conversation.

  #### Parameters

  - ##### proxyAddress: string

    Proxy (Twilio) address of the participant.

  - ##### address: string

    User address of the participant.

  - ##### attributes: JSONValue = {}

    Attributes to be attached to the participant.

  - ##### bindingOptions: ParticipantBindingOptions = {}

    Options for adding email participants - name and CC/To level.

  #### Returns Promise<ParticipantResponse>

  The added participant.

### advanceLastReadMessageIndex

- advanceLastReadMessageIndex(index: number): Promise<number>

- Advance the conversation's last read message index to the current read horizon. Rejects if the user is not a participant of the conversation. Last read message index is updated only if the new index value is higher than the previous.

  #### Parameters

  - ##### index: number

    Message index to advance to.

  #### Returns Promise<number>

  Resulting unread messages count in the conversation.

### delete

- delete(): Promise<Conversation>

- Delete the conversation and unsubscribe from its events.

  #### Returns Promise<Conversation>

### getAttributes

- getAttributes(): Promise<JSONValue>

- Get the custom attributes of this Conversation.

  #### Returns Promise<JSONValue>

### getMessageRecipients

- getMessageRecipients(options?: PaginatorOptions): Promise<Paginator<RecipientDescriptor>>

- Get recipients of all messages in the conversation.

  #### Parameters

  - ##### Optional options: PaginatorOptions

    Optional configuration, set pageSize to request a specific pagination page size. Page size specifies a number of messages to include in a single batch. Each message may include multiple recipients.

  #### Returns Promise<Paginator<RecipientDescriptor>>

### getMessages

- getMessages(pageSize?: number, anchor?: number, direction?: "backwards" | "forward"): Promise<Paginator<Message>>

- Returns messages from the conversation using the paginator interface.

  #### Parameters

  - ##### Optional pageSize: number

    Number of messages to return in a single chunk. Default is 30.

  - ##### Optional anchor: number

    Index of the newest message to fetch. Default is from the end.

  - ##### Optional direction: "backwards" | "forward"

    Query direction. By default, it queries backwards from newer to older. The `"forward"` value will query in the opposite direction.

  #### Returns Promise<Paginator<Message>>

  A page of messages.

### getMessagesCount

- getMessagesCount(): Promise<number>

- Get the total message count in the conversation.

  This method is semi-realtime. This means that this data will be eventually correct, but will also be possibly incorrect for a few seconds. The Conversations system does not provide real time events for counter values changes.

  This is useful for any UI badges, but it is not recommended to build any core application logic based on these counters being accurate in real time.

  #### Returns Promise<number>

### getParticipantByIdentity

- getParticipantByIdentity(identity?: string): Promise<Participant>

- Get a participant by its identity.

  #### Parameters

  - ##### identity: string = ""

    Participant identity.

  #### Returns Promise<Participant>

### getParticipantBySid

- getParticipantBySid(participantSid: string): Promise<Participant>

- Get a participant by its SID.

  #### Parameters

  - ##### participantSid: string

    Participant SID.

  #### Returns Promise<Participant>

### getParticipants

- getParticipants(): Promise<Participant[]>

- Get a list of all the participants who are joined to this conversation.

  #### Returns Promise<Participant[]>

### getParticipantsCount

- getParticipantsCount(): Promise<number>

- Get conversation participants count.

  This method is semi-realtime. This means that this data will be eventually correct, but will also be possibly incorrect for a few seconds. The Conversations system does not provide real time events for counter values changes.

  This is useful for any UI badges, but it is not recommended to build any core application logic based on these counters being accurate in real time.

  #### Returns Promise<number>

### getUnreadMessagesCount

- getUnreadMessagesCount(): Promise<number>

- Get count of unread messages for the user if they are a participant of this conversation. Rejects if the user is not a participant of the conversation.

  Use this method to obtain the number of unread messages together with Conversation.updateLastReadMessageIndex instead of relying on the message indices which may have gaps. See Message.index for details.

  This method is semi-realtime. This means that this data will be eventually correct, but it will also be possibly incorrect for a few seconds. The Conversations system does not provide real time events for counter values changes.

  This is useful for any UI badges, but it is not recommended to build any core application logic based on these counters being accurate in real time.

  If the read horizon is not set, this function will return null. This could mean that all messages in the conversation are unread, or that the read horizon system is not being used. How to interpret this `null` value is up to the customer application.

  #### Returns Promise<number>

  Number of unread messages based on the current read horizon set for the user or `null` if the read horizon is not set.

### join

- join(): Promise<Conversation>

- Join the conversation and subscribe to its events.

  #### Returns Promise<Conversation>

### leave

- leave(): Promise<Conversation>

- Leave the conversation.

  #### Returns Promise<Conversation>

### prepareMessage

- prepareMessage(): MessageBuilder

- New interface to prepare for sending a message. Use this instead of Conversation.sendMessage.

  #### Returns MessageBuilder

  A MessageBuilder to help set all message sending options.

### removeParticipant

- removeParticipant(participant: string | Participant): Promise<void>

- Remove a participant from the conversation. When a string is passed as the argument, it will assume that the string is an identity or SID.

  #### Parameters

  - ##### participant: string | Participant

    Identity, SID or the participant object to remove.

  #### Returns Promise<void>

### sendMessage

- sendMessage(message: string | FormData | SendMediaOptions, messageAttributes?: JSONValue, emailOptions?: SendEmailOptions): Promise<number>

- Send a message to the conversation.

  #### Parameters

  - ##### message: string | FormData | SendMediaOptions

    Message body for the text message, `FormData` or SendMediaOptions for media content. Sending FormData is supported only with the browser engine.

  - ##### Optional messageAttributes: JSONValue

    Attributes for the message.

  - ##### Optional emailOptions: SendEmailOptions

    Email options for the message.

  #### Returns Promise<number>

  Index of the new message.

### setAllMessagesRead

- setAllMessagesRead(): Promise<number>

- Set last read message index of the conversation to the index of the last known message.

  #### Returns Promise<number>

  Resulting unread messages count in the conversation.

### setAllMessagesUnread

- setAllMessagesUnread(): Promise<number>

- Set all messages in the conversation unread.

  #### Returns Promise<number>

  New count of unread messages after this update.

### setUserNotificationLevel

- setUserNotificationLevel(notificationLevel: NotificationLevel): Promise<void>

- Set user notification level for this conversation.

  #### Parameters

  - ##### notificationLevel: NotificationLevel

    New user notification level.

  #### Returns Promise<void>

### typing

- typing(): Promise<void>

- Send a notification to the server indicating that this client is currently typing in this conversation. Typing ended notification is sent after a while automatically, but by calling this method again you ensure that typing ended is not received.

  #### Returns Promise<void>

### updateAttributes

- updateAttributes(attributes: JSONValue): Promise<Conversation>

- Update the attributes of the conversation.

  #### Parameters

  - ##### attributes: JSONValue

    New attributes.

  #### Returns Promise<Conversation>

### updateFriendlyName

- updateFriendlyName(friendlyName: string): Promise<Conversation>

- Update the friendly name of the conversation.

  #### Parameters

  - ##### friendlyName: string

    New friendly name.

  #### Returns Promise<Conversation>

### updateLastReadMessageIndex

- updateLastReadMessageIndex(index: number): Promise<number>

- Set the last read message index to the current read horizon.

  #### Parameters

  - ##### index: number

    Message index to set as last read. If null is provided, then the behavior is identical to Conversation.setAllMessagesUnread.

  #### Returns Promise<number>

  New count of unread messages after this update.

### updateUniqueName

- updateUniqueName(uniqueName: string): Promise<Conversation>

- Update the unique name of the conversation.

  #### Parameters

  - ##### uniqueName: string

    New unique name for the conversation. Setting unique name to null removes it.

  #### Returns Promise<Conversation>