Channel Management
Channel Members
When a user joins a channel, they can watch and chat with other users in that channel. They are also automatically considered a member of that channel. With the Chat SDK, you can see which users are currently in the channel and 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 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 Community Channel
Create Live Channel
Create Conversation Channel
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 adds 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 is returned, ie, going into doOnSuccess{}
block.
Leave Channel
The leaveChannel()
method removes the active user as a member of the channel. When a user leaves a channel, they can no longer receive messages from that channel.
Get Channel
In case you only want to retrieve the data of a channel without connecting it, you can use the method getChannel()
:
Channel Query
The AmityChannelRepository
provides the getChannels()
method, which initiates the channel query method chain. The query returns <Flowable<PagedList<AmityChannel>
, which represents all matching available channels.
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:
Search Channel User
Last updated