Chat / Unreal
Current version: v3
Chat Unreal v3
Chat Unreal
Chat
Unreal
Home
/
Chat
/
Unreal
/
Messages

Send a message in an open channel

A user can send messages of the following types once they enter the channel:

Message typeDescription

UserMessage

A text message sent by a user.

FileMessage

A binary file message sent by a user.

You can further subclassify a message by specifying its custom type in addition to the message types listed above. This custom type takes on the form of a std::wstring and can be used to search or filter messages. It allows you to append information to your message and customize message categorization.

The following code shows several types of parameters that you can configure to customize text messages by using SBDUserMessageParams. Under the SBDUserMessageParams object, you can assign specific values to message, data and other properties. By assigning arbitrary string to the data property, you can set custom font size, font type or JSON object. To send your messages, you need to pass the SBDUserMessageParams object as an argument to the parameter in the SendUserMessage() method.

Through the handler callback function of the SendUserMessage() method, the Sendbird server always notifies whether your message has been successfully sent to the channel. When there is a delivery failure due to network issues, an exception is returned through the callback method.

std::vector<std::wstring> userIDsToMention;
userIDsToMention.push_back(L"Jeff");
userIDsToMention.push_back(L"Julia");

std::vector<std::wstring> targetLanguages;
targetLanguages.push_back(L"fr");   // French
targetLanguages.push_back(L"de");   // German

std::vector<std::wstring> metaArrayKeys = { L"key1", L"key2" };

SBDUserMessageParams params = SBDUserMessageParams()
        .SetMessage(TEXT_MESSAGE)
        .SetData(DATA)
        .SetCustomType(CUSTOM_TYPE)
        .SetTargetLanguages(targetLanguages)
        .SetMentionType(SBDMentionType.Users)   // Either Channel or Users
        .SetMentionedUserIds(userIDsToMention)
        .SetPushNotificationDeliveryOption(SBDPushNotificationDeliveryOption.Default);  // Either Default or Suppress
        .SetMetaArrayKeys(metaArrayKeys);

openChannel->SendUserMessage(params, [](SBDUserMessage* userMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }

    // A text message with detailed configuration is successfully sent to the channel.
    // By using userMessage->message_id, userMessage->message, userMessage->custom_type, and so on,
    // you can access the result object from the Sendbird server to check your SBDUserMessageParams configuration.
    // The current user can receive messages from other users through the MessageReceived() method of a channel event handler.
});

A user can also send binary files through the Chat SDK. The two ways to send a binary file are: sending the file itself, or sending a URL.

Sending a raw file means you're uploading it to the Sendbird server where it can be downloaded in client apps. When you upload a file directly to the server, there is a size limit imposed on the file depending on your plan. You can see the limit on your dashboard and adjust it with our sales team.

The other option is to send a file hosted on your server. You can pass the file's URL, which represents its location, as an argument to a parameter. In this case, your file is not hosted on the Sendbird server and it can only be downloaded from your own server. When you send a file message with a URL, there is no limit on the file size since it's not directly uploaded to the Sendbird server.

Note: Use SendFileMessages() which is another method that allows you to send up to 20 file messages per one method call.

The following code shows several types of parameters that you can configure to customize file messages by using SBDFileMessageParams. Under the SBDFileMessageParams object, you can assign specific values to custom_type and other properties. To send your messages, you need to pass the SBDFileMessageParams object as an argument to the parameter in the SendFileMessage() method.

Through the handler callback function of the SendFileMessage() method, the Sendbird server always notifies whether your message has been successfully sent to the channel. When there is a delivery failure due to network issues, an exception is returned through the callback method.

// Sending a file message with a file url
std::vector<SBDThumbnailSize> thumbnailSizes;   // Allowed number of thumbnail images: 3
thumbnailSizes.push_back(SBDThumbnailSize(100, 100));
thumbnailSizes.push_back(SBDThumbnailSize(200, 200));

SBDFileMessageParams params = SBDFileMessageParams()
        .SetFileUrl(FILE_URL)
        .SetFileName(FILE_NAME)
        .SetMimeType(MIME_TYPE)
        .SetFileSize(FILE_SIZE)
        .SetThumbnailSizes(thumbnailSizes)
        .SetData(DATA)
        .SetCustomType(CUSTOM_TYPE);

openChannel->SendFileMessage(params, [](SBDFileMessage* fileMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }

    // A file message with detailed configuration is successfully sent to the channel.
    // By using fileMessage->message_id, fileMessage->name, fileMessage->custom_type and so on,
    // you can access the result object from the Sendbird server to check your SBDFileMessageParams configuration.
    // The current user can receive messages from other users through the MessageReceived() method of a channel event handler.
});

// Sending a file message with a raw file
openChannel->SendFileMessage(FILE_BUF, FILE_NAME, FILE_SIZE, FILE_TYPE, thumbnailSizes, DATA, CUSTOM_TYPE, [](SBDFileMessage* fileMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }
});