Open Channel: Advanced

This section explains the advanced features of Open Channel. Some of them are the premium features available only to a paying user.


Send admin messages to an open channel

You can send an admin message to users in a channel using the SendBird Dashboard or the Platform API. To send the admin message via the Dashboard, in the Open Channels panel, select an open channel, find a message box below, click the Admin Message tab, and write a message in the box. The admin message is limited to 1000 characters.

Note: If you are currently developing under the Free Plan and therefore cannot use the Moderation Tools from the Dashboard, you must send the admin messages through the Platform API.


Categorize open channels by custom types

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

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

channel.createChannel(NAME, COVER_URL, DATA, 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, call channel.getCustomType().


Categorize messages in an open channel by custom types

Likewise, you can specify a custom type for messages to categorize them into more specific groups. This custom type takes on the form of a String, and can be useful in searching or filtering messages.

Note: DATA and CUSTOM_TYPE are both String fields that allow you to append information to your messages. The intended use case is for CUSTOM_TYPE to contain information that can subclassify the message (for example, categorizing into FILE_IMAGE and FILE_AUDIO type messages). However, both these fields can be flexibly utilized.

To embed a custom type into a message, pass a String parameter to sendUserMessage() or sendFileMessage().

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

To get a message's custom type, call message.getCustomType().


Search for open channels by name and URL

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

channelListQuery = OpenChannel.createOpenChannelListQuery();
channelListQuery.setNameKeyword("SendBird");

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

A query returns a list of open channels that partially match the specified URL keyword in the urls of the channels.

channelListQuery = OpenChannel.createOpenChannelListQuery();
channelListQuery.setUrlKeyword("seminar");

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

Generate thumbnails of a file message

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

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

Create a list of FileMessage.ThumbnailSize objects to pass to channel.sendFileMessage(). A ThumbnailSize can be created with the constructor ThumbnailSize(int maxWidth, int maxHeight), where the values specify pixels. The onSent() callback subsequently returns a list of Thumbnail objects that each contain the URL of the generated thumbnail image file.

List<FileMessage.ThumbnailSize> thumbnailSizes = new ArrayList<>();
// Create and add ThumbnailSizes (Max: 3 ThumbnailSizes).
thumbnailSizes.add(new ThumbnailSize(100, 100));
thumbnailSizes.add(new ThumbnailSize(200, 200));

channel.sendFileMessage(FILE, NAME, TYPE, SIZE, DATA, CUSTOM_TYPE, thumbnailSizes, new BaseChannel.SendFileMessageHandler() {
    public void onSent(FileMessage fileMessage, SendBirdException e) {
        if (e != null) {    // Error!
        }

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

maxWidth and maxHeight specify the maximum dimensions of the thumbnail. Your image is resized evenly to fit within the bounds of (maxWidth, maxHeight). 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 the SendBird servers.

As this is one of SendBird's Premium Features, please contact our sales team for further assistance.


Share an encrypted file with other participants

This feature encrypts all file messages sent by a channel participant with a master key when saved on SendBird server. This encrypted file has its own access URL, and only participants with the master key can decrypt the file and open it.

As this is one of SendBird's Premium Features, please 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 will be deleted and only the number of messages allowed to be sent per participant per second will be delivered. This feature protects your application 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 for further assistance on this setting. As this is one of SendBird's Premium Features, please 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 (s)he has 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. If you are using this feature, you can adjust the limit from our Dashboard: Settings > Messages > Smart Throttling. As this is one of SendBird's Premium Features, please contact our sales team for further assistance.


Message auto-translation

SendBird makes it possible for messages to be sent in different languages through its auto-translation feature. Pass in a List of language codes to sendUserMessage() to request translated messages in the corresponding languages.

ArrayList targetLangList = new ArrayList<String>();
targetLangList.add("es");
targetLangList.add("ko");

channel.sendUserMessage(MESSAGE, DATA, CUSTOM_TYPE, targetLangList, new BaseChannel.SendUserMessageHandler() {
    @Override
    public void onSent(UserMessage userMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

You can obtain translations of a message using userMessage.getTranslations(). This method returns a Map containing the language codes and translations.

SendBird.addChannelHandler(UNIQUE_CHANNEL_ID, new SendBird.ChannelHandler() {
    @Override
    public void onMessageReceived(BaseChannel baseChannel, BaseMessage baseMessage) {
        Map<String, String> map = ((UserMessage) baseMessage).getTranslations();
        String esTranslation = map.get("es");
        ...
        // Display translation in UI.
    }
}

Note: The message auto-translation supports 53 languages. For the language code table, see the Miscellaneous > Supported Languages. As this is one of SendBird's Premium Features, please contact our sales team for further assistance.