Channels

Our channels enable developers to implement different types of chat messaging capabilities into their applications easily

Users can create and join channels where they will be able to participate and chat with other users. A channel can support up to 300,000 members and can contain an unlimited number of messages. Any message exchanged in the channels will be pushed to all other members of the channel in real-time.

Amity's Chat SDK supports the creations of 4 types of chat channels. Each type is designed to match a particular use-case for chat channels. Here's a table showing what features each channel offers:

Channel Types

Channel Type

Discoverable by

Message sending privileges

Moderation access

Community

All users and admins

Users and admins

All Moderation tools

Live

Only members and admins

Users and admins

All Moderation tools

Broadcast

All users and admins

Admins

Admin Moderation tools

Conversation

Only members

Users

No Moderation tools

Community

All community channels are visible on the Amity Social Cloud Console.

The community channel is our default channel type and can be discovered by all users and admins. It acts as a public chat channel that showcases all of the features that our SDK's have to offer.

Typical use cases:

  • Team collaboration

  • Online gaming

  • Celebrity fan club

  • Live streaming

  • Any type of public chat

Live

All live channels are visible on the Amity Social Cloud Console.

Live channels offers the ability for users and admins to create channels with exclusive memberships. The live channel is identical to our Community channel in features with the caveat that users will not be able to discover the channel when querying for all channels unless they are already a member of it. However users and admins can still invite other users to join the channel.

Typical use cases:

  • Healthcare

  • Project Discussion

  • Any type of private chat

Community and Live channel types can use our SDK moderation tools:

  • Message and user flagging

  • Muting/Unmuting users

  • Banning/Unbanning users from channel

  • Profanity filters

  • Whitelisted URLs

  • User rate-limiting

Broadcast

All broadcast channels are visible on the Amity Social Cloud Console.

The Broadcast channel is heavily adopted by corporate users who constantly promote or advertise their products, or make the announcement to drive awareness. Unlink other channel types, broadcast channels only allow admin users to send messages from Console, and everyone else in the channel will be under read-only mode.

Since this is a one-way communication channel, a tailored moderation tools are provided as well, for instance, users won't be able to flag message / user in the channel.

Typical use cases:

  • Marketing & Advertising

  • School / Government Announcements

Conversation

Conversation channels are NOT visible on the Amity Social Cloud Console.

The Conversation channel is our solution to 1-on-1 messaging. Unlike the other channel types, a Conversation channel can be created simply by knowing the userId of the user we want to converse with. Users can start conversations with any other user and only they will be able to see their conversation.

There are no moderation tools for Conversation channels, users will be able to converse freely with no oversight!

Typical use cases:

  • Hospitality

  • Financial Consultancy

  • Customer Support

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

Community

All users and admins

Users and admins

All Moderation tools

Live

Only members and admins

Users and admins

All Moderation tools

Broadcast

All users and admins

Admins

Admin Moderation tools

Conversation

Only members

Users

No Moderation tools

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 1. Community: a channel that is discoverable by all users. 2. Live: a channel that is discoverable only if user is already added as a member. 3. Broadcast: a channel that limits message creation to only Admin user. Message can only be created from Admin panel. 4. Conversation: a one-to-one chat that once created will not be available on Admin panel.

There are three ways of obtaining an EkoChannel object: via create, join, or get methods. EkoChannel management methods are all contained in the EkoChannelRepository class. To get an instance of EkoChannelRepository:

val channelRepository = EkoClient.newChannelRepository();

Create Channel

The SDK provides 2 typical ways of channel creation.

  1. Channel creation with specific channelId.

  2. 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 EkoExceptionwith 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 channel by specifying channelId
channelRepository.createChannel()
                .communityType()
                .withChannelId("Weekly-promo")
                .displayName("Weekly promo") // optional
                .metadata(jsonObject) // optional
                .tags("promotions") // optional
                .build()
                .create()
                .subscribe()

// let SDK handle channelId generation                               
channelRepository.createChannel()
                .communityType()
                .withDisplayName("Weekly promo")
                .metadata(jsonObject) // optional
                .tags("promotions") // optional
                .build()
                .create()
                .subscribe()

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.

// let SDK handle channelId generation                               
channelRepository.createChannel()
                .conversationType()
                .withUserId(userId)
                .displayName("BFF") // optional
                .metadata(jsonObject) // optional
                .tags("friends") // optional
                .build()
                .create()
                .subscribe()

Conversation channel is unique based on its membership. When creating conversation the system will check if channel with the same membership already exists, if such channel already exists the system will return 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 time as needed. If the channel has already been joined, a "success" result will be returned, ie., going into doOnSuccess{}block.

channelRepository.joinChannel(channelId)
                .subscribe()

Get Channel

In the case where you only want to fetch a channel's data without joining, you can use the getChannel() method:

channelRepository.getChanel(channelId)
                .subscribe( { ekoChannel -> ... } )

Channel Query

The EkoChannelRepository provides the getChannelCollection() method which initiates channel query method chain. The query returns Flowable<PagedList<EkoChannel>> representing all matching channels available.

// Query for Community type
channelRepository.getChannelCollection()
                .communityType()
                .build()
                .query()        
                .subscribe( { adapter.submitList(it)} )

// Query for Live type
channelRepository.getChannelCollection()
                .liveType()
                .build()
                .query()        
                .subscribe( { adapter.submitList(it)} )

// Query for Broadcast type
channelRepository.getChannelCollection()
                .broadcastType()
                .build()
                .query()        
                .subscribe( { adapter.submitList(it)} )

// Query for Conversation type
channelRepository.getChannelCollection()
                .conversationType()
                .build()
                .query()        
                .subscribe( { adapter.submitList(it)} )     

// Query for Multiple types
val types : List<EkoChannel.Type> = // create a list of your desired types

channelRepository.getChannelCollection()
                .types(types)
                .build()
                .query()        
                .subscribe( { adapter.submitList(it)} )

Channel Filtering

  • the filter() method lets you filter channels based on the current user membership status

  • the includingTags() and excludingTags() methods let you filter channels based on the tags set (or not set) in each channel

val includingTags = EkoTags()
includingTags.add("games")

// Query for Community channels where the user is member, tagged as "games"
channelRepository.getChannelCollection()
                .communityType()
                .filter(EkoChannelFilter.MEMBER)
                .includingTags(includingTags)
                .build()
                .query()
                .subscribe( { adapter.submitList(it)} )
val includingTags = EkoTags()
includingTags.add("games");

val excludingTags = EkoTags()
excludingTags.add("staff-only")

// Query for Community channels where the user is not member, tagged as "games", and not tagged as "staff-only"
channelRepository.getChannelCollection()
                .communityType()
                .filter(EkoChannelFilter.NOT_MEMBER)
                .includingTags(includingTags)
                .excludingTags(excludingTags)
                .build()
                .query()
                .subscribe( { adapter.submitList(it)} )

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 override any previous values. No locking, merging, or other coordination is performed across participants.

To set metadata, simply call the following method:

val metadata = channel.getMetadata()
metadata.addProperty("tutorial_url", "https://docs.ekomedia.technology/")

channelRepository.getChannelCollection()
                .updateChannel(channelId)
                .metadata(metadata)
                .build()
                .update()
                .subscribe()

Display Name

Every channel contains an optional displayName field. This field is mainly used to identify the channel in push notifications, but it is also exposed to the application via EkoChannel object.

You can set a channel's displayName with the following methods:

channelRepository.setDisplayName(channelId, "General Eko chat discussion");

Participation

All participation related methods in a channel falls under a separate EkoChannelParticipation model. You can access EkoChannelParticipation from EkoChannelRepository.membership() method as well as from EkoChannel.membership() method.

// Access from EkoChannelRepository
val membership = channelRepository.membership(channelId)

// EkoChannel object already knows its channelId
val membership = channel.membership();

Members Query

The EkoChannelParticipation provides a list of members in the given channel

membership.getCollection()
                .build()
                .query()
                .subscribe( { adapter.submitList()} )

Manage Members

You can add and remove members, as well as removing yourself as a member of a channel (leaving the channel) via EkoChannelParticipation model should you have appropriate privileges.

// Add 'user1' and 'user2' to this channel
membership.addUsers(listOf("user1", "user2")).subscribe()

// Remove 'user3' from this channel
membership.removeUsers(listOf("user3")).subscribe()

// Leave the channel
membership.leave().subscribe()

Role and Permission

Creator of the channel can add and remove the role of user via EkoChannelModeration.

Role

//Add role
EkoClient.newChannelRepository()
                .moderate(:channelId)
                .addRole(role = :roleName, userIds = listOf(:userId))
                .subscribe()

//Remove role
EkoClient.newChannelRepository()
                .moderate(:channelId)
                .removeRole(role = :roleName, userIds = listOf(:userId))
                .subscribe()

Query memberships by role

The EkoChannelParticipation provides a list of members by role in the given channel.

EkoClient.newChannelRepository()
                .membership(:channelId)
                .getCollection()
                .role(:roleName)
                .build()
                .query()
                .subscribe()

Permission

You can check your permission in channel by sending EkoPermission enums to EkoClient.hasPermission(:ekoPermission).

EkoClient.hasPermission(:ekoPermission)
         .atChannel(:channelId)
         .check()
         .subscribe()

Reading Status And Unread Count

The EkoChannelRepository provides getTotalUnreadCount() method. It's giving the flowable of the number of messages that the current user has yet to read. This count is the sum of all the unreadCount channels properties where the user is member of.

// total unread count
channelRepository.getTotalUnreadCount()
                .doOnNext( totalUnreadCount -> {

                })
                .subscribe();

// channel unread count
val unreadCount = channel.getUnreadCount()

To let the server know when the current user is reading one channel, hence resetting that channel unreadCount to zero, the participation membership exposes the EkoChannelParticipation.startReading() and EkoChannelParticipation.stopReading() methods.

You can call both methods as much as you want, the SDK takes care of multi-device management: therefore a user can read multiple channels, from one or multiple devices at once. In case of an abrupt disconnection (whether because the app was killed, or the internet went down etc) the SDK backend will automatically call the EkoChannelParticipation.stopReading() on the user behalf.

// Start reading a channel
membership.startReading()

// Stop reading a channel
membership.stopReading()

Last updated