/ SDKs / Unreal
SDKs
Chat SDKs Unreal v3
Chat SDKs Unreal
Chat SDKs
Unreal
Version 3

Receive messages through a channel event handler

Copy link

Members can receive each other's messages through the MessageReceived() method of a channel event handler. A SBDBaseMessage object for each received message is one of the following three message types.

Message typeClassDescription

Text

SBDUserMessage

A text message sent by a user

File

SBDFileMessage

A binary file message sent by a user

Admin

AdminMessage

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

UNIQUE_HANDLER_ID is a unique identifier to register multiple concurrent handlers.

class MyChannelHandler : public SBDChannelHandler {
    void MessageReceived(SBDBaseChannel* channel, SBDBaseMessage* message) {
        // You can customize how to display the different types of messages with the result object in the message parameter.
        if (message->message_type == SBDMessageType::User) {
            // ...
        }
        else if (message->message_type == SBDMessageType::File) {
            // ...
        }
        else if (message->message_type == SBDMessageType::Admin) {
            // ...
        }
    }
});

SBDMain::AddChannelHandler(UNIQUE_HANDLER_ID, new MyChannelHandler());

If the UI isn't valid anymore, remove the channel event handler.

// You can remove a specific channel handler.
SBDMain::RemoveChannelHandler(UNIQUE_HANDLER_ID);

// You can remove all registered channel handlers.
SBDMain::RemoveAllChannelHandlers();