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

Add extra data to a message

Copy link

You can add extra data to a message in an open or group channel. By storing one or more key-value items to a message, you can use the data to implement various actions in a channel. Based on the items, you can measure user engagement in conversations or count how many times a message has been copied by users in the channel. As shown in the code below, you can add, update, or delete these key-value items anytime. To retrieve the key-values items of a message, use the MetaArrays property. When implementing the code below, channel can be openChannel or groupChannel.

Note: To learn more about the types of additional information you can add to a message, see the information types page.

// When a message has been successfully sent to a channel, create items with keys.
List itemKeyToCreate = new List { "referees", "games" };
channel.CreateMessageMetaArrayKeys(message, itemKeyToCreate, (inMessage, inError) =>
{
    if (inError != null)
    {
        return; //Handle error.
    }
});

// Adding values to specific items by their keys.
List<SbMessageMetaArray> valuesToAdd = new List<SbMessageMetaArray>
{
    new SbMessageMetaArray("referees", new List<string> { "John", "Brandon", "Harry", "Jay" }),
    new SbMessageMetaArray("games", new List<string> { "soccer", "baseball", "basketball" })
};
channel.AddMessageMetaArrayValues(message, valuesToAdd, (inMessage, inError) =>
{
    if (inError != null)
    {
        return; //Handle error.
    }
});

// Removing existing values of specific items by their keys.
List<SbMessageMetaArray> valuesToRemove = new List<SbMessageMetaArray>
{
    new SbMessageMetaArray("referees", new List<string> { "Brandon", "Jay" })
};
channel.RemoveMessageMetaArrayValues(message, valuesToRemove, (inMessage, inError) =>
{
    if (inError != null)
    {
        return; //Handle error.
    }
});

// Deleting items by their keys.
List<string> keysToDelete = new List<string> { "referees", "games" };
channel.DeleteMessageMetaArrayKeys(message, keysToDelete, (inMessage, inError) =>
{
    if (inError != null)
    {
        return; //Handle error.
    }
});

Note: Every Sendbird application has a different limit on how many key-value items you can add to a single message, as well as the maximum number of values an item can have. If you wish to learn more about these limits, contact our sales team.