Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Accept or decline an invitation from other user

A user who is invited to a private group channel can accept or decline the invitation. If the user accepts the invitation, they join the channel as a new member and can start chatting with other members. If the user declines the invitation, the invitation will no longer be valid.

Users can join up to 2,000 group channels and when the number of group channels a user can join reaches the maximum number, any new invitation will automatically be declined.

// Accept an invitation.
await channel.acceptInvitation();

// Decline an invitation.
await channel.declineInvitation();

You can set the channel invitation preference for your Sendbird application. The preference determines whether a user can automatically accept a private group channel invitation or manually accept invitations. If the value of setChannelInvitationPreference() is set to true, invitations will be automatically accepted. If the value is false, users can either accept or decline invitations. By default, the value is set to true.

// The default value of true means that a user will automatically join
// a group channel without the user's action.
const autoAccept = false;
await sb.setChannelInvitationPreference(autoAccept);

If the client app is in the foreground, the members of the group channel will be notified of whether the newly invited user has accepted or declined the invitation. To do so, implement onUserReceivedInvitation() and onUserDeclinedInvitation() in the channel event handler. For more information, see the event handler page.