Options
All
  • Public
  • Public/Protected
  • All
Menu

A conversation represents communication between multiple Conversations clients

Hierarchy

  • ReplayEventEmitter<ConversationEvents>
    • Conversation

Index

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:

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:

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:

Properties

Readonly sid

sid: string

Unique system identifier of the conversation.

Accessors

attributes

  • get attributes(): any
  • Custom attributes of the conversation.

    Returns any

createdBy

  • get createdBy(): string
  • Identity of the user that created this conversation.

    Returns string

dateCreated

  • get dateCreated(): any
  • Date this conversation was created on.

    Returns any

dateUpdated

  • get dateUpdated(): any
  • Date this conversation was last updated on.

    Returns any

friendlyName

  • get friendlyName(): string
  • Name of the conversation.

    Returns string

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

notificationLevel

state

status

uniqueName

  • get uniqueName(): string
  • Unique name of the conversation.

    Returns string

Methods

add

  • add(identity: string, attributes?: any): Promise<void>
  • Add a participant to the conversation by its identity.

    Parameters

    • identity: string

      Identity of the Client to add.

    • Optional attributes: any

      Attributes to be attached to the participant.

    Returns Promise<void>

addNonChatParticipant

  • addNonChatParticipant(proxyAddress: string, address: string, attributes?: any): Promise<void>
  • Add a non-chat participant to the conversation.

    Parameters

    • proxyAddress: string

      Proxy (Twilio) address of the participant.

    • address: string

      User address of the participant.

    • Optional attributes: any

      Attributes to be attached to the participant.

    Returns Promise<void>

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 the conversation and unsubscribe from its events.

    Returns Promise<Conversation>

getAttributes

  • getAttributes(): Promise<any>
  • Get the custom attributes of this Conversation.

    Returns Promise<any>

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

  • 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 unread messages count 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 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>

join

  • Join the conversation and subscribe to its events.

    Returns Promise<Conversation>

leave

prepareMessage

  • New interface to prepare for sending a message. Use instead of sendMessage.

    Returns MessageBuilder

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

  • 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: any

      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>

    Resulting unread messages count in the conversation.

setUserNotificationLevel

  • Set user notification level for this conversation.

    Parameters

    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

  • Update the attributes of the conversation.

    Parameters

    • attributes: any

      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

    Returns Promise<number>

    Resulting unread messages count in the conversation.

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>