Table of Contents

How to manage channel invitations in Sendbird Chat

How to manage channel invitations in Sendbird Chat

Jason Allshorn
Solution Engineer
Tutorial Type: Basic Tutorial Reading Time: 10 mins Building Time: 2-4 Hours
ChatAndroidiOSJSSDK

The channel invitations feature and its accompanying options allow users or your backend to control the membership of private and public group chats, and allows users to inquire about their own channel membership. This blog post dives deep into channel invitations and all of the available options and events, and is broken down into four sections: general information about channel invitations, channel creation, private group channel invitations, and manual accept/decline invitations.

Channel invitations: general information

You can implement channel invitations either through a Sendbird Chat SDK or through the Platform API. This guide explores both options.

The channel invitations feature governs channel membership. Users become members of a private group channel in a couple ways:

  • At the time of channel creation, it is possible to pass in an array of up to 100 user IDs to become members of the channel
  • After channel creation, it is also possible to invite up to 100 users per request
Invitation approachPlatformMethod
Upon private group channel creationAndroidgroupChannelParams
GroupChannel.createChannel(groupchannelParams)
iOSgroupChannelParams
GroupChannel.createChannelWithParams(groupchannelParams)
JavaScriptgroupChannelParams
GroupChannel.createChannel(groupchannelParams)
Platform APIPOST v3/group_channels/
After private group channel creationAndroidgroupchannel.inviteWithUserIds()
iOSgroupchannel.inviteUserIds()
JavaScriptgroupchannel.inviteWithUserIds()
Platform APIPOST v3/groups_channels/CHANNEL_URL/invite

Users can inquire about their membership status in private and public group channels in a couple ways:

  • A user can retrieve a list of channels they were automatically joined to by invitation (default behavior)
  • A user can retrieve a list of channels to which they’ve been invited by creating a channel list query instance
Invited status approachPlatformMethod
Fetch channels I’m a member ofAndroidGroupChannel.createMyGroupChannelListQuery()
iOSSBDGroupChannel.createMyGroupChannelListQuery()
JavaScriptsb.GroupChannel.createMyGroupChannelListQuery()
Platform APIGET /v3/users/{user_id}/my_group_channels
Fetch channels where my membership status is filteredAndroidGroupChannelListQuery + setMemberStateFilter
iOSSBDGroupChannelListQuery + SBDMemberStateFilter
JavaScriptGroupChannelListQuery + MemberStateFilter
Platform APImember_state_filter
FiltersReturned channels
INVITED Invitations have been sent to the current User (but not accepted yet)
INVITED_BY_FRIENDInvitations from a friend has been sent to the current User (but not accepted yet)
INVITED_BY_NON_FRIENDInvitations by non friend has been sent to the current User (but not accepted yet)
JOINEDChannels the current User is already a member of
Check my membership status within the current channelAndroidGroupChannel.getMyMemberState()
iOSSBDGroupChannel.myMemberState
JavaScriptN/A

Creating channels in Sendbird using an SDK or Platform API

Creating private group channels with either the Sendbird SDK or Platform API boils down to one main difference:

    • With channels created via the SDK, users have the freedom to chat and send channel invitations to whomever they like
    • Using the Platform API, your backend controls which users chat to whom

Batches of up to 100 users can be invited to a private group channel at the point of creation or batches of up to 100 users can be invited at a later point, up to a maximum channel membership of 100 members. The maximum channel membership size can be increased upon request to Sendbird.

Creating channels using a Sendbird Chat SDK

By default, creating a channel via a Sendbird SDK gives users the freedom to start a chat with any other user so long as they know that user’s ID. Apps that are social in nature, build community, or depend on a user’s freedom to engage socially with other users will likely implement channel invitations through the SDK.

Note: The option to auto-accept invitations is “on” by default for Sendbird’s private group channels. For Sendbird’s public group channels no invitation is needed.

If auto-accept invitations is “on,” then the created channel will appear in the invited user’s channel list by default (if there are no messages, the invited user will need to add the filter to include empty channels). The invited user will also begin to receive notifications and messages from the created channel.

Events

Creating a channel with the SDK automatically triggers the following events:

Event typeEventNote
Channel event handler (event delegate in iOS)onUserJoined()One event for each user in the member list
onMessageReceived()If auto-generated admin messages are turned on (default: off)
Webhooksgroup_channel:create

group_channel:join

If auto-accept invitations is turned on (default: on)
group_channel:createIf auto-accept invitations is turned off
Auto-generated admin messages (if: “on”)Message is sent.The channel is created.The message contains channel details and the user objects of each member

How to block channel creation through the SDK

Sendbird provides an ACL setting that prevents channel creation from all Sendbird SDKs.

Creating channels via Platform API

Creating a channel using the Platform API gives your backend full control to determine when to create a channel and which users belong to that channel.

As a result, users in the SDK may not start a chat with other users until you create a channel containing other users. Using the Platform API enables you to fully control which users chat with whom. Apps that coordinate conversations according to discrete transactions, tasks, support tickets, or consultations will likely implement channel invitations through the Platform API.

Note: Creating a channel using a Platform API call will always add users to the channel that were invited at the channel’s creation, regardless of the global invitation acceptance settings.

Events

Creating a channel with the Platform API automatically triggers the following events:

Event typeEventNote
Channel event handler (event delegate in iOS)onUserJoined()One event for each user in the member list
onMessageReceived()If auto-generated admin messages are turned on (default: off)
Webhooksgroup_channel:create

group_channel:join

If auto-accept invitations is turned on (default: on). Whether auto-accept invitations is turned off or on, calls to create a channel using the Platform API will always add users to the channel that were invited at the channel’s creation.
Auto-generated admin messages (if: “on”)Message is sent.The channel is created.The message contains channel details and the user objects of each member

Private group channels: Post-channel creation invitations explained

Whether invitations are accepted automatically or accepted and declined manually greatly determines the behavior of channel invitations and how a user joins a channel. This section explains both options: auto-accept invitation and manual accept/decline invitation.

Auto-accept invitation

The following provides details about events that occur when the auto-accept invitations option is turned “on.”

By default, in Sendbird, if User A invites User B to a channel (groupChannel.invite()), at the moment of invitation User B automatically accepts the invitation and becomes a member of that channel. At channel creation in both the Sendbird SDK and Platform API, you can pass a list of up to 100 user IDs to invite to a group channel. All invitations are automatically created and accepted by the list of invited users. By default, auto-accept invitations is “true” if the invitation is sent through the SDK invite method or the Platform API endpoint (v3/groups_channels/CHANNEL_URL/invite).

Events

Making an invitation and automatically accepting the invitation creates these events that trigger at the same time (Note: Sendbird’s default behavior is to automatically accept invitations).

Event typeEventNote
Channel event handler (event delegate in iOS)onUserReceivedInvitation()
onUserJoined()
Webhooksgroup_channel:invite
group_channel:joinContains a list of joined users
Auto-generated admin messages (if: “on”)USER_JOINEDContains a list of joining users

Manual accept/decline invitation

This section provides details about events that occur when the auto-accept invitations option is turned “off.”

By default, users are automatically added to private group channels when they are invited. You can alter this default behavior for individual users or globally via the Platform API.

The global setting determines a user’s individual invitation preference when the user is created. It’s important to note that a user’s individual preference does not change when the global setting changes. To apply the global setting change to all current users, update all current user profiles individually.

When the auto-accept invitations option is turned “off” the following occurs: When User A invites User B, User B can decide to accept or decline the invitation.

Even when the auto-accept invitations option is turned “off,” invitations are automatically created for the passed list of user IDs when a group channel is created either via Sendbird SDK or Platform API.

Note: Users will automatically become members of a channel if the channel is created via the Platform API with a passed list of user IDs. That is to say there will be no invitations. If invitations are required, create the channel first and then invite the users in bulk.

Once User A invites User B, then User B will be added to a private channel’s member list with the status of “invited” in the member list object of the group channel.

  • As an invited member they will be able to see the channel, but not take any action on it aside from being able to call:
  • If User B accepts the invitation, then User B becomes a member of the channel
  • If User B declines the invitation, then the invitation is revoked
  • User B is able to fetch their invited channels using a myChannelListQuery and applying MemberStateFilter

Events

Creating a Sendbird group channel and passing in an array of user IDs will trigger these events:

Event typeEvent
Channel event handler (event delegate in iOS)N/A
Webhooksgroup_channel:create
Auto-generated admin messages (if: “on”)Type: CHANNEL_CREATE

Making an invitation from a Sendbird SDK using groupChannel.invite() with the auto-accept option turned “off” triggers these events:

Event typeEvent
Channel event handler (event delegate in iOS)onUserReceivedInvitation()
Webhooksgroup_channel:invite
Auto-generated admin messages (if: “on”)N/A

Accept/decline invitation

Once an invitation has been sent, then expect individual invitations to be accepted or declined. One event is triggered for each user accepting or declining invitations.

Event typeEvent
Channel event handler (event delegate in iOS)onUserAcceptedInvitation()
onUserDeclinedInvitation()
Webhooksgroup_channel:join
group_channel:decline_invite
Auto-generated admin messages (if: “on”)Type: USER_JOINED

Public group channels and open channels

Public group channels are used mostly for cases where one user shares a channel with another user and the chat is transparent and public. Although a passphrase can be applied, if needed.

Open channels are ideal for live events where massive membership is needed, but there is no need to maintain membership.

Sendbird’s public group channels and open channels do not require invitations to join. Public group channels maintain membership once joined. Open channels have an ephemeral transient membership which is maintained for an individual user so long as they have entered the open channel and remain online, and have not exited the channel.

Example scenario for a manual accept/decline invitation

The auto-accept invitations option has been turned “off” globally. User A creates a new Sendbird group channel in your app, or User A is already a member of a group channel, and wants to invite other users to that channel in your app. In this example, User A shares the group channel link in WhatsApp.

  • Given
    • User A has copied a deep link to a Sendbird channel
    • The deep link contains information to open your app
    • The deep link contains a channel URL to which User B is invited
    • User A has sent the link in WhatsApp
    • User B is already a user of your app but not a member of the group channel
  • Then

Conclusion

The channel invitations feature essentially determines how your users will interact with each other and with your company: Will users freely and socially interact with others or will your app set up key conversations among users?

Given the practical repercussions of this crucial feature, Sendbird ensures that channel invitations are as flexible as possible: from channel creation invitations to auto accept and manual accept to implementation with a Sendbird Chat SDK or Platform API.

Feel free to reach out to us if you need technical help with your app, and share with us what you’re building.