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

Receive messages in a channel

Copy link

Messages sent from other participants or members in open and group channels can be received through the OnMessageReceived() method in the channel event handler. A SbBaseMessage object for each received message is one of the following three message types.

Message typeClassDescription

Text

SbUserMessage

A text message sent by a user.

File

SbFileMessage

A binary file message sent by a user.

Admin

SbAdminMessage

A text message sent by an admin through the Chat Platform API.

In cases where multiple handlers need to be registered concurrently, pass the handler's unique ID for the UNIQUE_HANDLER_ID argument in AddOpenChannelHandler() or AddGroupChannelHandler().

// For open channel
SbOpenChannelHandler openChannelHandler = new SbOpenChannelHandler
{
    OnMessageReceived = (inGroupChannel, inMessage) => { }
};
SendbirdChat.OpenChannel.AddOpenChannelHandler(UNIQUE_HANDLER_ID, openChannelHandler);

// For group channel
SbGroupChannelHandler groupChannelHandler = new SbGroupChannelHandler
{
    OnMessageReceived = (inGroupChannel, inMessage) => { }
};
SendbirdChat.GroupChannel.AddGroupChannelHandler(UNIQUE_HANDLER_ID, groupChannelHandler);

If you no longer need to listen to the event handler and receive messages, remove the channel event handler by following the implementation below.

// For open channel
SendbirdChat.OpenChannel.RemoveOpenChannelHandler(UNIQUE_HANDLER_ID);

// For group channel
SendbirdChat.GroupChannel.RemoveGroupChannelHandler(UNIQUE_HANDLER_ID);

Receive a reply in a message thread

Copy link

Once a reply is created or deleted from a thread, the OnThreadInfoUpdated() method of channel event handlers is invoked. The method returns a SbThreadInfoUpdateEvent object that has the latest information about the thread. This object needs to be applied to the parent message object.

Note: Like other messages, when a reply is created in a channel, the OnMessageReceived() method of the channel event handler in client apps will be called.

SbGroupChannelHandler groupChannelHandler = new SbGroupChannelHandler
{
    OnThreadInfoUpdated = (inChannel, inThreadInfoUpdateEvent) =>
    {
        message.ApplyThreadInfoUpdateEvent(inThreadInfoUpdateEvent);
    }
};

SendbirdChat.GroupChannel.AddGroupChannelHandler(UNIQUE_HANDLER_ID, groupChannelHandler);

List of parameters

Copy link
Parameter nameTypeDescription

inChannel

SbBaseChannel

Specifies the channel that has the message thread.

inThreadInfoUpdateEvent

ThreadInfoUpdateEvent

Specifies a SbThreadInfoUpdateEvent object that has the latest information about the thread.


Receive callbacks for delivery receipts

Copy link

When a message is delivered to group channel members who are online, it is automatically marked as delivered and channel members are also notified of the successful message delivery through the OnDeliveryStatusUpdated() method in the channel event handler.

SbGroupChannelHandler groupChannelHandler = new SbGroupChannelHandler
{
    OnDeliveryStatusUpdated = (inChannel) => { }
};

SendbirdChat.GroupChannel.AddGroupChannelHandler(UNIQUE_HANDLER_ID, groupChannelHandler);