A channel represents a remote channel of communication between multiple Programmable Chat clients.

### Hierarchy

- ReplayEventEmitter<ChannelEvents>
  - Channel

## Index

### Events

- memberJoined
- memberLeft
- memberUpdated
- messageAdded
- messageRemoved
- messageUpdated
- removed
- typingEnded
- typingStarted
- updated

### Properties

- sid

### Accessors

- attributes
- createdBy
- dateCreated
- dateUpdated
- friendlyName
- isPrivate
- lastConsumedMessageIndex
- lastMessage
- notificationLevel
- state
- status
- type
- uniqueName

### Methods

- add
- advanceLastConsumedMessageIndex
- decline
- delete
- getAttributes
- getMemberByIdentity
- getMemberBySid
- getMembers
- getMembersCount
- getMessages
- getMessagesCount
- getUnconsumedMessagesCount
- getUserDescriptors
- invite
- join
- leave
- removeMember
- sendMessage
- setAllMessagesConsumed
- setNoMessagesConsumed
- setUserNotificationLevel
- typing
- updateAttributes
- updateFriendlyName
- updateLastConsumedMessageIndex
- updateUniqueName

## Events

### Static Readonly memberJoined

memberJoined: "memberJoined" = 'memberJoined'

Fired when a member has joined the channel.

Parameters:

1. Member `member` - member that joined the channel

### Static Readonly memberLeft

memberLeft: "memberLeft" = 'memberLeft'

Fired when a member has left the channel.

Parameters:

1. Member `member` - member that left the channel

### Static Readonly memberUpdated

memberUpdated: "memberUpdated" = 'memberUpdated'

Fired when data of a member has been updated.

Parameters:

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

### Static Readonly messageAdded

messageAdded: "messageAdded" = 'messageAdded'

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

Parameters:

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

### Static Readonly messageRemoved

messageRemoved: "messageRemoved" = 'messageRemoved'

Fired when message is removed from the channel'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 update

### Static Readonly removed

removed: "removed" = 'removed'

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

Parameters:

1. Channel `channel` - channel that has been removed

### Static Readonly typingEnded

typingEnded: "typingEnded" = 'typingEnded'

Fired when a member has stopped typing.

Parameters:

1. Member `member` - the member that has stopped typing

### Static Readonly typingStarted

typingStarted: "typingStarted" = 'typingStarted'

Fired when a member has started typing.

Parameters:

1. Member `member` - the member that has started typing

### Static Readonly updated

updated: "updated" = 'updated'

Fired when the data of the message has been updated.

Parameters:

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

## Properties

### Readonly sid

sid: string

Unique system identifier of the channel.

## Accessors

### attributes

- get attributes(): Object

- Custom attributes of the channel.

  #### Returns Object

### createdBy

- get createdBy(): string

- Identity of the user that created this channel.

  #### Returns string

### dateCreated

- get dateCreated(): any

- Date this channel was created on.

  #### Returns any

### dateUpdated

- get dateUpdated(): any

- Date this channel was last updated on.

  #### Returns any

### friendlyName

- get friendlyName(): string

- Name of the channel.

  #### Returns string

### isPrivate

- get isPrivate(): boolean

- Signifies whether the channel is private.

  #### Returns boolean

### lastConsumedMessageIndex

- get lastConsumedMessageIndex(): number

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

  #### Returns number

### lastMessage

- get lastMessage(): LastMessage

- Last message sent to this channel.

  #### Returns LastMessage

### notificationLevel

- get notificationLevel(): NotificationLevel

- User notification level for this channel.

  #### Returns NotificationLevel

### state

- get state(): ChannelState

- State of the channel.

  #### Returns ChannelState

### status

- get status(): ChannelStatus

- Delivery status of the channel.

  #### Returns ChannelStatus

### type

- get type(): ChannelType

- MemberType of the channel.

  #### Returns ChannelType

### uniqueName

- get uniqueName(): string

- Unique name of the channel.

  #### Returns string

## Methods

### add

- add(identity: string): Promise<void>

- Add a member to the channel by its identity.

  #### Parameters

  - ##### identity: string

    Identity of the Client to add.

  #### Returns Promise<void>

### advanceLastConsumedMessageIndex

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

- Advance the channel's last consumed message index to the current read horizon. Rejects if the user is not a member of the channel. Last consumed 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 channel.

### decline

- decline(): Promise<Channel>

- Decline an invitation to the channel and unsubscribe from its events.

  #### Returns Promise<Channel>

### delete

- delete(): Promise<Channel>

- Delete the channel and unsubscribe from its events.

  #### Returns Promise<Channel>

### getAttributes

- getAttributes(): Promise<any>

- Get the custom attributes of this Channel.

  Note: Channel.attributes will be empty for public channels until this function is called.

  #### Returns Promise<any>

### getMemberByIdentity

- getMemberByIdentity(identity: string): Promise<Member>

- Get a member by its identity.

  #### Parameters

  - ##### identity: string

    Member identity.

  #### Returns Promise<Member>

### getMemberBySid

- getMemberBySid(memberSid: string): Promise<Member>

- Get a member by its SID.

  #### Parameters

  - ##### memberSid: string

    Member SID.

  #### Returns Promise<Member>

### getMembers

- getMembers(): Promise<Member[]>

- Get a list of all the members who are joined to this channel.

  #### Returns Promise<Member[]>

### getMembersCount

- getMembersCount(): Promise<number>

- Get channel members 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 Programmable Chat 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>

### getMessages

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

- Return messages from the channel 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 channel.

  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 Programmable Chat 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>

### getUnconsumedMessagesCount

- getUnconsumedMessagesCount(): Promise<number>

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

  Use this method to obtain the number of unread messages together with Channel.updateLastConsumedMessageIndex 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 Programmable Chat 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>

### getUserDescriptors

- getUserDescriptors(): Promise<Paginator<UserDescriptor>>

- Get user descriptors of this channel.

  #### Returns Promise<Paginator<UserDescriptor>>

### invite

- invite(identity: string): Promise<void>

- Invite a user to the channel by their identity.

  #### Parameters

  - ##### identity: string

    Identity of the user.

  #### Returns Promise<void>

### join

- join(): Promise<Channel>

- Join the channel and subscribe to its events.

  #### Returns Promise<Channel>

### leave

- leave(): Promise<Channel>

- Leave the channel.

  #### Returns Promise<Channel>

### removeMember

- removeMember(member: string | Member): Promise<void>

- Remove a member from the channel. When a string is passed as the argument, it will assume that the string is an identity.

  #### Parameters

  - ##### member: string | Member

    Identity or the member object to remove.

  #### Returns Promise<void>

### sendMessage

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

- Send a message to the channel.

  #### Parameters

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

    Message body for the text message, `FormData` or {@link Channel.MediaOptions) for media content. Sending FormData is supported only with the browser engine.

  - ##### Optional messageAttributes: any

    Attributes for the message.

  #### Returns Promise<number>

  Index of the new message.

### setAllMessagesConsumed

- setAllMessagesConsumed(): Promise<number>

- Set last consumed message index of the channel to the index of the last known message.

  #### Returns Promise<number>

  Resulting unread messages count in the channel.

### setNoMessagesConsumed

- setNoMessagesConsumed(): Promise<number>

- Set all messages in the channel unread.

  #### Returns Promise<number>

  Resulting unread messages count in the channel.

### setUserNotificationLevel

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

- Set user notification level for this channel.

  #### 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 channel. 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: any): Promise<Channel>

- Update the attributes of the channel.

  #### Parameters

  - ##### attributes: any

    New attributes.

  #### Returns Promise<Channel>

### updateFriendlyName

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

- Update the friendly name of the channel.

  #### Parameters

  - ##### friendlyName: string

    New friendly name.

  #### Returns Promise<Channel>

### updateLastConsumedMessageIndex

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

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

  #### Parameters

  - ##### index: number

    Message index to set as last consumed. If null is provided, then the behavior is identical to Channel.setNoMessagesConsumed.

  #### Returns Promise<number>

  Resulting unread messages count in the channel.

### updateUniqueName

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

- Update the unique name of the channel.

  #### Parameters

  - ##### uniqueName: string

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

  #### Returns Promise<Channel>