/ SDKs / Unity
SDKs
Chat SDKs Unity v4
Chat SDKs Unity
Chat SDKs
Unity
Version 4

Send a message

Copy link

For both open and group channels, users can send messages of the following types to the channel they are in.

Message typeClassDescription

Text

SbUserMessage

A text message sent by a user

File

SbFileMessage

A binary file message sent by a user

Additionally, you can also subclassify a message by specifying its custom type. This custom type takes on the form of string and can be used to search or filter messages. It allows you to append information to your message and customize message categorization.


User message

Copy link

The following code shows several types of parameters that you can configure to customize text messages using SbUserMessageCreateParams. Under the SbUserMessageCreateParams 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 SbUserMessageCreateParams object as an argument to the parameter in the SendUserMessage() method.

Through the callback handler 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.

SbUserMessageCreateParams userMessageCreateParams = new SbUserMessageCreateParams(TEXT_MESSAGE)
{
    CustomType = CUSTOM_TYPE,
    Data = DATA,
    MentionType = SbMentionType.Users,
    MentionedUserIds = new List<string> { "Jeff", "Julia" },
    MetaArrays = new List<SbMessageMetaArray> 
    {
        new SbMessageMetaArray("ItemType", new List<string> { "tablet" })
    },
    TranslationTargetLanguages = new List<string> { "fe", "de" },
    PushNotificationDeliveryOption = SbPushNotificationDeliveryOption.Default
};

channel.SendUserMessage(userMessageCreateParams, (inUserMessage, inError) =>
{
    if (inError != null)
        return; // Handle error.

    // A text message with detailed configuration is successfully sent to the channel.
    // By using inUserMessage.MessageId, inUserMessage.Message, inUserMessage.CustomType, and so on,
    // you can access the result object from the Sendbird server to check your SbUserMessageCreateParams configuration.
    // The current user can receive messages from other users through the OnMessageReceived() method of an event handler.
});

File message

Copy link

A user can also send a binary file through the Chat SDK as the file itself or through sending a URL.

Sending a raw file means you're uploading it to the Sendbird server where it can be downloaded on 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 contact our sales team to change the limit.

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 isn't 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 isn't directly uploaded to the Sendbird server.

Note: You can use SendFileMessage(), 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 a SbFileMessageCreateParams. Under the SbFileMessageCreateParams object, you can assign specific values to CustomType and other properties. To send your messages, you need to pass the SbFileMessageCreateParams object as an argument to the parameter in the SendFileMessage() method.

Through the callback handler 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.

SbFileMessageCreateParams fileMessageCreateParams = new SbFileMessageCreateParams(FILE)
{
    CustomType = CUSTOM_TYPE,
    Data = DATA,
    MentionType = SbMentionType.Users,
    MentionedUserIds = new List<string> { "Jeff", "Julia" },
    MetaArrays = new List<SbMessageMetaArray> 
    {
        new SbMessageMetaArray("ItemType", new List<string> { "tablet" })
    },
    PushNotificationDeliveryOption = SbPushNotificationDeliveryOption.Default
};

channel.SendFileMessage(fileMessageCreateParams, (inFileMessage, inError) =>
{
    if (inError != null)
        return; // Handle error.

    // A file message with detailed configuration is successfully sent to the channel.
    // By using inFileMessage.MessageId, inFileMessage.FileName, inFileMessage.CustomType, and so on,
    // you can access the result object from the Sendbird server to check your SbFileMessageCreateParams configuration.
    // The current user can receive messages from other users through the OnMessageReceived() method of an event handler.
});