Android
Open Channel Advanced

Open Channel: Advanced

This page explains the advanced features for open channels. Some of them are the premium features available only to a paying user.


Send an admin message

If you are using the Custom Plan, you can send an admin message to an open channel using the SendBird Dashboard or the Platform API. To send the admin message through your dashboard, on the Moderation > Open Channels panel, select an open channel, find a message box below, click the Admin Message tab, and then write your message in the box. An admin message is limited to 1,000 characters.

Note: For clients using the Free Plan, a suggesting message to upgrade to the Custom Plan will be returned when attempting to send an admin message using the Platform API.


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 participants.

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 engineering team.

Light Color Skin
Copy
// When a message has been successfully sent to a channel, create items with keys.
List<String> itemKeysToCreate = new ArrayList<>();
itemKeysToCreate.add("referees");
itemKeysToCreate.add("games");

openChannel.createMessageMetaArrayKeys(BASE_MESSAGE, itemKeysToCreate, new BaseChannel.MessageMetaArrayHandler() {
    @Override
    public void onResult(BaseMessage baseMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

// Add values to specific items by their keys.
List<String> people = new ArrayList<>();
people.add("John");
people.add("Brandon");
people.add("Harry");
people.add("Jay");

List<String> event = new ArrayList<>();
events.add("soccer");
events.add("baseball");
events.add("basketball");

Map<String, List<String>> valuesToAdd = new HashMap<>();
valuesToAdd.put("referees", people);
valuesToAdd.put("games", events);

openChannel.addMessageMetaArrayValues(BASE_MESSAGE, valuesToAdd, new BaseChannel.MessageMetaArrayHandler() {
    @Override
    public void onResult(BaseMessage baseMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

// Remove existing values of specific items by their keys.
List<String> notAvailablePeople = new ArrayList<>();
notAvailablePeople.add("Brandon");
notAvailablePeople.add("Jay");

Map<String, List<String>> valuesToRemove = new HashMap<>();
valuesToRemove.put("referees", notAvailablePeople);

openChannel.removeMessageMetaArrayValues(BASE_MESSAGE, valuesToRemove, new BaseChannel.MessageMetaArrayHandler() {
    @Override
    public void onResult(BaseMessage baseMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});


// Delete items by their keys.
List<String> itemKeysToDelete = new ArrayList<>();
itemKeysToDelete.add("referees");
itemKeysToDelete.add("games");

openChannel.deleteMessageMetaArrayKeys(BASE_MESSAGE, itemKeysToDelete, new BaseChannel.MessageMetaArrayHandler() {
    @Override
    public void onResult(BaseMessage baseMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

To get the key-values items of a message, use the message.getAllMetaArrays() method.


Categorize channels by custom type

When creating a channel, you can additionally specify a custom channel type for further channel grouping. This custom type takes on the form of a String, and can be handy in searching or filtering channels.

Note: The DATA and CUSTOM_TYPE are both String fields that allow you to append information to your channels. As mentioned above, a common use case for the CUSTOM_TYPE is to contain information for channel grouping (for example, categorizing into School and Work channels). However, both these fields can be flexibly utilized.

Light Color Skin
Copy
OpenChannel.createChannel(NAME, COVER_IMAGE_OR_URL, DATA, OPERATOR_USERS, CUSTOM_TYPE, new OpenChannel.OpenChannelCreateHandler() {
    @Override
    public void onResult(OpenChannel openChannel, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

To get a channel's custom type, use the openChannel.getCustomType() method.


Categorize messages by custom type

When sending a message, you can additionally specify a custom message type for further message grouping. This custom type takes on the form of a String, and can be useful in searching or filtering messages.

Note: The DATA and CUSTOM_TYPE are both String fields that allow you to append information to your messages. As mentioned above, a common use case for the CUSTOM_TYPE is to contain information for message grouping (for example, categorizing into Notes and Contacts messages). However, both these fields can be flexibly utilized.

To embed a custom type into a message, set a value of the type to a UserMessageParams or FileMessageParams object with other values, and then pass the object as a parameter to the sendUserMessage() or sendFileMessage() methods.

Light Color Skin
Copy
UserMessageParams params = new UserMessageParams()
    .setMessage(TEXT_MESSAGE)
    .setCustomType(CUSTOM_TYPE)
    ...

openChannel.sendUserMessage(params, new BaseChannel.SendUserMessageHandler() {
    @Override
    public void onSent(UserMessage userMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

To get a message's custom type, use the message.getCustomType() method.


Search channels by name, URL, or custom type

You can search for specific open channels by adding keywords to an OpenChannelListQuery instance. There are two types of keywords: a Name and a URL. The code sample below shows the query instance which returns a list of open channels that partially match the specified Name keyword in the names of the channels.

Light Color Skin
Copy
channelListQuery = OpenChannel.createOpenChannelListQuery();
channelListQuery.setNameKeyword("SendBird");

channelListQuery.next(new OpenChannelListQuery.OpenChannelListQueryResultHandler() {
    @Override
    public void onResult(List<OpenChannel> openChannels, SendBirdException e) {
        if (e != null) {    // Error!
            return;
        }
        // Returns a list of open channels that have "SendBird" in their names.
    }
});

The following shows the query instance which returns a list of open channels that partially match the specified URL keyword in the URLs of the channels.

Light Color Skin
Copy
channelListQuery = OpenChannel.createOpenChannelListQuery();
channelListQuery.setUrlKeyword("seminar");

channelListQuery.next(new OpenChannelListQuery.OpenChannelListQueryResultHandler() {
    @Override
    public void onResult(List<OpenChannel> openChannels, SendBirdException e) {
        if (e != null) {    // Error!
            return;
        }
        // Returns a list of open channels that have "seminar" in their URLs.
    }
});

Using the setCustomTypeFilter() like the following, you can also search for open channels with a specific custom type.

Light Color Skin
Copy
channelListQuery = OpenChannel.createOpenChannelListQuery();
channelListQuery.setCustomTypeFilter("movie");

channelListQuery.next(new OpenChannelListQuery.OpenChannelListQueryResultHandler() {
    @Override
    public void onResult(List<OpenChannel> openChannels, SendBirdException e) {
        if (e != null) {        // Error!
            return;
        }
        // Returns a list of open channels with a "movie" custom type.
    }
});

Generate thumbnails of a file message

When sending an image file, you can determine whether to create thumbnails of the image to fetch and render into your UI. You can specify up to 3 different dimensions to generate thumbnail images in for supporting various display densities.

Note: Supported file types are files whose media type is image/* or video/*. The SDK doesn't support creating thumbnails when sending a file message via a file URL.

The sendFileMessage() method requires that you pass a FileMessageParams object as a parameter, containing an array of items which each specify the maximum values of width and height of a thumbnail image. The callback function subsequently returns a list of Thumbnail items that each contain the URL of the generated thumbnail image file.

Light Color Skin
Copy
// Create and add a ThumbnailSize object (allowed number of thumbnail images: 3).
List<FileMessage.ThumbnailSize> thumbnailSizes = new ArrayList<>();
thumbnailSizes.add(new ThumbnailSize(100,100));
thumbnailSizes.add(new ThumbnailSize(200,200));

FileMessageParams params = new FileMessageParams()
        ... 
        .setFile(FILE)
        .setFileName(FILE_NAME)
        .setFileSize(FILE_SIZE)
        .setMimeType(MIME_TYPE)
        .setThumbnailSizes(thumbnailSizes);

openChannel.sendFileMessage(params, new BaseChannel.SendFileMessageHandler() {
    @Override
    public void onSent(FileMessage fileMessage, SendBirdException e) {
        if (e != null) {    // Error!
            return;
        }

        Thumbnail first = fileMessage.getThumbnails.get(0);
        Thumbnail second = fileMessage.getThumbnails.get(1);

        int maxHeightFirst = first.getMaxHeight(); // 100
        int maxHeightSecond = second.getMaxHeight(); // 200

        String urlFirst = first.getUrl(); // URL of first thumbnail file.
        String urlSecond = second.getUrl(); // URL of second thumbnail file.
    }
});

A thumbnail image is generated evenly to fit within the bounds of (maxWidth, maxHeight), which are provided through the ThumbnailSize constructor. Note that if the original image is smaller than the specified dimensions, the thumbnail isn't resized. getUrl() returns the location of the generated thumbnail file within SendBird server.

This is one of SendBird's premium features, contact our sales team for further assistance.


Share an encrypted file with other participants

This file encryption feature prevents users without access from opening and reading encrypted files that have been shared within a group of users. When this feature is turned on, all types of sent files and thumbnail images will be first uploaded to SendBird server, and then encrypted by AES256.

In an open channel, encrypted files and thumbnail images will be decrypted and accessed securely only by the participants. Anyone outside of the channel and application will not have access to those files and thumbnail images. The following explains how this data security works and what to do at the SDK level to apply it to your client apps.

The SendBird system enables secure encryption and decryption of files by generating and distributing an opaque and unique encryption key for each user. An encryption key is managed internally by the system, and is valid for 3 days. It is generated every time the user logs in to SendBird server through the SDK, which then gets delivered to the SDK from the server.

When the SDK requests an encrypted file by its URL, the parameter auth should be added to the URL to access the file, which is specified with an encryption key of the user such as ?auth=RW5jb2RlIHaXMgdGV4eA==. With the specified key in the auth, SendBird server first decrypts the file, then checks if the user is participating in the open channel, and finally, allows the user to access and open the file in the channel.

This can be easily done by using the fileMessage.getUrl() method, which automatically adds the parameter auth with an encryption key of the current user to the file URL, and returns the unique URL for the user.

This is one of SendBird's premium features, contact our sales team for further assistance. This feature will also require customized implementation efforts from your side.


Spam flood protection

This feature allows you to customize the number of messages a participant can send in an open channel per second. By doing so, all excess messages from a paricipant will be deleted and only the number of messages allowed to be sent per participant per second will be delivered. This feature protects your app from some participants spamming others in the channel with the same messages.

Note: Our default system setting is 5 messages per second. This limit can be manually adjusted only by our side. You can contact our engineering team about this setting. This is one of SendBird's premium features, first contact our sales team for further assistance.


Smart throttling

You can use this feature to customize the number of messages displayed in an open channel per second. By doing so, you can adjust the pace of the conversation in a chat so that the participants can read the messages more clearly. In fact, each participant's channel will display the messages they have sent and those that other participants have sent up to this limit in chronological order.

Note: Our default system setting is 5 messages per second. This limit can be manually adjusted only by our side. You can contact our engineering team on this setting. This is one of SendBird's premium features, first contact our sales team for further assistance.


Message auto-translation

It is possible for text messages to be sent in different languages through the SendBird's auto-translation feature. When sending a text message, set a List of language codes to a UserMessageParams object and then pass the object as a parameter to the sendUserMessage() method to request translated messages in the corresponding languages.

Note: This message auto-translation feature is powered by Google Cloud Translation API recognition engine and Microsoft Translator engine. It is by default that Google's Cloud Translation API recognition engine is used for message auto-translation, whereas if your SendBird application has been created before June 26, 2019, Microsoft Translator engine is used.

Light Color Skin
Copy
List<String> translationTargetLanguages = new ArrayList<>();
translationTargetLanguages.add("es");   // Spanish 
translationTargetLanguages.add("ko");   // Korean 

UserMessageParams params = new UserMessageParams()
        .setMessage(TEXT_MESSAGE)
        .setCustomType(CUSTOM_TYPE)
        .setData(DATA)
        ...
        .setTranslationTargetLanguages(translationTargetLanguages);

openChannel.sendUserMessage(params, new BaseChannel.SendUserMessageHandler() {
    @Override
    public void onSent(UserMessage userMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

You can retrieve translations of a text message using the userMessage.getTranslations() method which returns a Map object containing the language codes and translations.

Note: The two translation engines support a wide variety of languages, and you can see their language code tables in the Miscellaneous > Language support section.

Light Color Skin
Copy
SendBird.addChannelHandler(UNIQUE_HANDLER_ID, new SendBird.ChannelHandler() {
    @Override
    public void onMessageReceived(BaseChannel channel, BaseMessage message) {
        Map<String, String> map = ((UserMessage) message).getTranslations();
        String esTranslation = map.get("es");       // Spanish
        
        ...
        // Display translation in UI.
    }
}

Using the openChannel.translateUserMessage() method, you can also translate an already sent text message into other languages for your specific needs.

Light Color Skin
Copy
List<String> translationTargetLanguages = new ArrayList<>();
translationTargetLanguages.add("es");   // Spanish
translationTargetLanguages.add("de");   // German

// The USER_MESSAGE below indicates a UserMessage object which represents an already sent text message.
openChannel.translateUserMessage(USER_MESSAGE, translationTargetLanguages, new BaseChannel.TranslateUserMessageHandler() {
    @Override
    public void onTranslated(UserMessage userMessage, SendBirdException e) {
        Map<String, String> map = userMessage.getTranslations();
        String esTranslatedMessage = map.get("es");     // Spanish
        String deTranslatedMessage = map.get("de");     // German
        ...
        // Display translation in UI.
    }
}

Note: This is one of SendBird's premium features, contact our sales team for further assistance.