Channel Management
Channel Members
When a user joins a channel, they are able to observe and chat with other users in that channel. They are also automatically considered a member of that channel. The Chat SDK provides the ability to view which users are currently in the channel as well as invite other users to join the channel.
Channel Type | Discoverable by | Message sending privileges | Moderation access | SDK Supported |
Community | All users and admins | Users and admins | All Moderation tools | Yes |
Live | Only members and admins | Users and admins | All Moderation tools | Yes |
Broadcast | All users and admins | Admins | Admin Moderation tools | No |
Conversation | Only members | Users | No Moderation tools | Yes |
Each channel is identified by a unique channelId
, which is any string that uniquely identifies the channel and is immutable through its lifetime. When creating channels, you can specify your own channelId
, or leave it to Amity to automatically generate one for you.
There are 4 channel types:
Community: a channel that is discoverable by all users
Live: a channel that is discoverable only if user is already added as a member
Broadcast: a channel that limits message creation to only Admin user. Message can only be created from Console
Conversation: a one-to-one chat that once created will not be available on Admin panel
There are three ways of obtaining an AmityChannel
object: via,
create method
join method
get method
AmityChannel
management methods are all contained in the AmityChannelRepository
class. To get an instance of AmityChannelRepository
:
Create Community Channel
The SDK provides 2 typical ways of channel creation.
Channel creation with specific channelId.
Channel creation with auto-generation of channelId.
The channel creation API guarantees that the requested channel is a new channel. If the channel already exists, the error will be an AmityException
with code 400900
The createChannel()
method initiates channel creation method chain and let you choose which channel type to be created.
To let SDK handle channelId generation, uses withDisplayName()
method to skip channelId specification.
Create Live Channel
The SDK provides 2 typical ways of channel creation.
Channel creation with specific channelId.
Channel creation with auto-generation of channelId.
The channel creation API guarantees that the requested channel is a new channel. If the channel already exists, the error will be an AmityException
with code 400900
The createChannel()
method initiates channel creation method chain and let you choose which channel type to be created.
To let SDK handle channelId generation, uses withDisplayName()
method to skip channelId specification.
Create Conversation
Channel of type Conversation
can also be created with createChannel()
method chain. However, the channelId is always being generated by SDK.
To create a conversation channel with a user, pass the user's userId to withUserId()
method.
Conversation channel is unique based on its membership. When creating conversation, the system will check if a channel with the same membership already exists. If such channel already exists, the system will return the existing channel instead of creating a new one.
Join Channel
The joinChannel()
method will add the active user as a member of the channel.
This API can be called as many times as needed. If the channel has already been joined, a "success" result will be returned, ie., going into doOnSuccess{}
block.
Get Channel
In the case where you only want to fetch a channel's data without joining, you can use the getChannel()
method:
Channel Query
The AmityChannelRepository
provides the getChannels()
method which initiates channel query method chain. The query returns Flowable<PagedList<AmityChannel>>
representing all matching channels available.
Channel Filtering
the
filter()
method lets you filter channels based on the current user membership statusthe
includingTags()
andexcludingTags()
methods let you filter channels based on the tags set (or not set) in each channel
Edit Channel
All channels have the following properties:
Channel display name
Channel Avatar
Tags
Metada
Edit Data
Every channel contains an optional displayName
, avatar
and tags
property with the following method:
Edit Metadata
Metadata is a general purpose data store that is automatically synchronized to all users of a channel. It is designed to store contextual information about a specific channel. The metadata is a JSON object which can store any number of JSON key-value pairs up to 100 kb. Example use cases include:
Conversation title or cover photo
Global conversation settings
Metadata is implemented with last writer wins semantics on the entire store. This means that multiple mutations by independent users to the metadata object will result in a single stored value. The metadata object set by last user overrides any previous values. No locking, merging, or other coordination is performed across participants.
To set metadata, simply call the following method:
Leave Channel
The leaveChannel()
method will remove the active user as a member of the channel. If a user leaves a channel, the user can't receive messages from the channel anymore.
Delete Channel
Deleting a channel is not supported in SDK. Refer to this section for the instructions on how to delete a channel via API.
Last updated