/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Add extra data to a message

Copy link

You can add extra data, such as metadata and metaarray, 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, call getMetaArrays().

Note: To learn more about the different options for storing additional information about a user, channel, or message, go to the overview page under Channel.

// When a message has been successfully sent to a channel, create items with keys.
val itemKeysToCreate = listOf("referees", "games")
channel.createMessageMetaArrayKeys(message, itemKeysToCreate) { message, e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

// Adding values to specific items by their keys.
val valuesToAdd = listOf(
    MessageMetaArray("referees", listOf("John", "Brandon", "Harry", "Jay")),
    MessageMetaArray("games", listOf("soccer", "baseball", "basketball"))
)
channel.addMessageMetaArrayValues(message, valuesToAdd) { message, e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

// Removing existing values of specific items by their keys.
val valuesToRemove = listOf(MessageMetaArray("referees", listOf("Brandon", "Jay")))
channel.removeMessageMetaArrayValues(message, valuesToRemove) { message, e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

// Deleting items by their keys.
val keysToDelete = listOf("referees", "games")
channel.deleteMessageMetaArrayKeys(message, keysToDelete) { message, e ->
    if (e != null) {
        // 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.