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

Add extra data to a message

You have the option to create further actions in a channel by using extra data in a message. You can add one or more key-values items to a message which you can save, update, or remove, when necessary. Based on those items, you can design and implement several different actions such as measuring user engagement within a chosen time limit through polls or counting how many times a message has been copied by members.

Note: For the quality of performance, every Sendbird application has its own limits to how many key-values items you can add to a single message, as well as the maximum number of values an item can have. If you would like more information on these limits, contact our sales team.

// When a message has been successfully sent to a channel, create items with keys.
std::vector<std::wstring> itemKeysToCreate;
itemKeysToCreate.push_back(L"referees");
itemKeysToCreate.push_back(L"games");

groupChannel->CreateMessageMetaArrayKeys(groupChannel->channel_url, MESSAGE_ID, itemKeysToCreate, [](SBDBaseMessage* baseMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }
});

// Adding values to specific items by their keys.
std::vector<std::wstring> people;
people.push_back(L"John");
people.push_back(L"Brandon");
people.push_back(L"Harry");
people.push_back(L"Jay");

std::vector<std::wstring> events;
events.push_back(L"soccer");
events.push_back(L"baseball");
events.push_back(L"basketball");

std::map<std::wstring, std::vector<std::wstring>> valuesToAdd;
valuesToAdd[L"referees"] = people;
valuesToAdd[L"games"] = events;

groupChannel->AddMessageMetaArrayValues(groupChannel->channel_url, MESSAGE_ID, valuesToAdd, [](SBDBaseMessage* baseMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }
});

// Removing existing values of specific items by their keys.
std::vector<std::wstring> notAvailablePeople;
notAvailablePeople.push_back(L"Brandon");
notAvailablePeople.push_back(L"Jay");

std::map<std::wstring, std::vector<std::wstring>> valuesToRemove;
valuesToRemove[L"referees"] = notAvailablePeople;

groupChannel->RemoveMessageMetaArrayValues(groupChannel->channel_url, MESSAGE_ID, valuesToRemove, [](SBDBaseMessage* baseMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }
});

// Deleting items by their keys.
std::vector<std::wstring> itemKeysToDelete;
itemKeysToDelete.push_back(L"referees");
itemKeysToDelete.push_back(L"games");

groupChannel->DeleteMessageMetaArrayKeys(groupChannel->channel_url, MESSAGE_ID, itemKeysToDelete, [](SBDBaseMessage* baseMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }
});

To get the key-values items of a message, use the message.meta_arrays property.