/ SDKs / .NET
SDKs
Chat SDKs .NET v4
Chat SDKs .NET
Chat SDKs
.NET
Version 4

Add or remove a channel event handler

Copy link

To receive and retrieve information about events happening in channels from the Sendbird server, you can add a channel event handler with its UNIQUE_HANDLER_ID by calling SendbirdChat.GroupChannel.AddGroupChannelHandler() for group channel events and SendbirdChat.OpenChannel.AddOpenChannelHandler() for open channel events.

You should declare UNIQUE_HANDLER_ID when registering multiple concurrent handlers.

There are three types of channel handlers: SbBaseChannelHandler, SbGroupChannelHandler and SbOpenChannelHandler. SbGroupChannelHandler and SbOpenChannelHandler extend SbBaseChannelHandler. The following tables show a list of events for each channel event handler.

If you want to stay informed of changes related to channels and notify other users' client apps of those changes, define and register multiple channel event handlers to each view controller.


Channel event types

Copy link

List of base channel events

Copy link
MethodInvoked whenNotified devices

OnMessageReceived()

A message has been received in an open channel.

All devices where client apps with the channel are in the foreground, except the device that sent the message.

OnMessageUpdated()

A message has been updated in an open channel.

All devices where client apps with the channel are in the foreground, except the device where the message was updated.

OnMessageDeleted()

A message has been deleted in an open channel.

All devices where client apps with the channel are in the foreground, including the device where the message was deleted.

OnMentionReceived()

A user has been mentioned in a message sent in an open channel.

All devices of mentioned users (up to 10) in the channel, including the device that was used to mention other users.

OnChannelChanged()

One of the following open channel properties has been changed: name, cover image, data, custom type, or operators.

All devices that are connected to the changed channel, including the device where the channel was changed.

OnChannelDeleted()

An open channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the channel was deleted.

OnReactionUpdated()

A message reaction has been updated in a group channel.

All devices where client apps with the channel are in the foreground, including the device that reacted to the message.

OnUserMuted()

A user has been muted in an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was muted.

OnUserUnmuted()

A user has been unmuted in an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was unmuted.

OnUserBanned()

A user has been banned from an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was banned.

OnUserUnbanned()

A user has been unbanned from an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was unbanned.

OnChannelFrozen()

An open channel has been frozen.

All devices where client apps with the channel are in the foreground, including the device where the channel was frozen.

OnChannelUnfrozen()

An open channel has been unfrozen.

All devices where client apps with the channel are in the foreground, including the device where the channel was unfrozen.

OnMetaDataCreated()

A metadata for an open channel has been created.

All devices where client apps with the channel are in the foreground, including the device where the metadata was created.

OnMetaDataUpdated()

A metadata for an open channel has been updated.

All devices where client apps with the channel are in the foreground, including the device where the metadata was updated.

OnMetaDataDeleted()

A metadata for an open channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the metadata was deleted.

OnMetaCountersCreated()

A metacounter for an open channel has been created.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was created.

OnMetaCountersUpdated()

A metacounter for an open channel has been updated.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was updated.

OnMetaCountersDeleted()

A metacounter for an open channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was deleted.

OnOperatorUpdated()

An operator has been updated.

All devices where client apps with the channel are in the foreground, including the device where the operator was updated.

OnThreadInfoUpdated()

A reply message has been created or deleted from a thread.

All devices where client apps with the channel are in the foreground, including devices of all users who are in the message thread, and except the device of the user who created or deleted the reply message.

List of open channel events

Copy link
MethodInvoked whenNotified devices

OnUserEntered()

A user has entered an open channel.

All devices where client apps with the channel are in the foreground, including the device that the user entered that channel.

OnUserExited()

A user has exited an open channel.

All devices where client apps with the channel are in the foreground, except the device that the user exited that channel.

OnChannelParticipantCountChanged()

The participant count of one or more open channels has changed.

All connected devices where client apps have the affected open channels in their channel list.

List of group channel events

Copy link
MethodInvoked whenNotified devices

OnReadStatusUpdated()

A user has read a specific unread message in a group channel.

All devices where client apps with the channel are in the foreground, including all devices of the users who are invited to the channel, and except the device of the user who read the unread message.

OnDeliveryStatusUpdated()

A message has been delivered in a group channel.

All devices where client apps with the channel are in the foreground, and except the device where the message was marked as delivered and has invoked this event.

OnTypingStatusUpdated()

A user starts typing a message to a group channel.

All devices where client apps with the channel are in the foreground, except the devices of the users who are invited to the channel, and except all devices of the user who typed a message.

OnUserReceivedInvitation()

A user has been invited to a group channel.

All devices where client apps with the channel are in the foreground, including the device of a user who received an invitation.

OnUserDeclinedInvitation()

A user has declined an invitation to a group channel.

All devices where client apps with the channel are in the foreground, including the device of a user who declined an invitation.

OnUserJoined()

A user has joined a group channel.

All devices where client apps with the channel are in the foreground, including all devices of the user who joined the channel, and except the devices of users who haven't accepted invitations.

OnUserLeft()

A user has left a group channel.

All devices where client apps with the channel are in the foreground, including all devices of the user who left the channel, and except the devices of users who haven't accepted invitations.

OnChannelHidden()

A group channel has been hidden from the list.

All devices of a user who hid the channel.

OnChannelMemberCountChanged()

The member count of one or more group channels has changed.

All connected devices where client apps have the affected group channels in their channel list.

OnPinnedMessageUpdated()

A message has been pinned or unpinned.

All connected devices where client apps have the affected group channels in their channel list.


Add a channel event handler

Copy link

The following code shows a supported event callback with their parameters and how to add a channel event handler to the SendbirdChat.

 // for OpenChannel
  SbOpenChannelHandler openChannelHandler = new SbOpenChannelHandler
  {
      OnMessageReceived = (inBaseChannel, inBaseMessage) => { /* Received a new message. */ }
  };
  SendbirdChat.OpenChannel.AddOpenChannelHandler("UNIQUE_HANDLER_ID", openChannelHandler); 
  
  // for GroupChannel
  SbGroupChannelHandler groupChannelHandler = new SbGroupChannelHandler
  {
      OnMessageReceived = (inBaseChannel, inBaseMessage) => { /* Received a new message. */ }
  };
  SendbirdChat.GroupChannel.AddGroupChannelHandler("UNIQUE_HANDLER_ID", groupChannelHandler);

Remove a channel event handler

Copy link

The following code shows how to remove the channel event handler.

// for OpenChannel
SendbirdChat.OpenChannel.RemoveOpenChannelHandler("UNIQUE_HANDLER_ID");

// for GroupChannel
SendbirdChat.GroupChannel.RemoveGroupChannelHandler("UNIQUE_HANDLER_ID");