Moderation

Moderation consists of features that you can use to moderate a channel by detecting unwanted content and restricting the users that create the unwanted content. Several actions are supported, such as banning, flagging, muting and shadow banning. More information about the available low-level client moderation tools can be found here.

Moderation Configuration

We have a dedicated documentation for Moderation now. Please refer to dedicated Chat Moderation guide for details.

Moderated Messages

You can check if a message was moderated by checking the moderation property of Message. It is null for regular messages. For moderated messages, it contains:

  • originalText - the original text of the message.
  • action - the moderation action that was applied, for example ModerationAction.bounce or ModerationAction.remove.
  • textHarms, imageHarms, blocklistMatched, semanticFilterMatched and platformCircumvented - the reasons the message was moderated.
val moderation = message.moderation
if (moderation != null) {
    Log.d("Moderation", "action: ${moderation.action.value}, original: ${moderation.originalText}")
}
Note:

Apps on the previous moderation API receive the same information through the moderationDetails property, which holds a MessageModerationDetails with originalText, action (a MessageModerationAction) and errorMsg. The SDK reads both properties.

The two actions use different vocabularies: ModerationAction.bounce is "bounce", while MessageModerationAction.bounce is "MESSAGE_RESPONSE_ACTION_BOUNCE". Compare against the constants rather than the raw strings, so a check that covers both is:

val isBounced = message.moderation?.action == ModerationAction.bounce ||
    message.moderationDetails?.action == MessageModerationAction.bounce

Bounced Messages

A bounced message is a message that was rejected by the moderation policy and was not delivered to the other channel members. Only its author can see it, and they can decide to send it anyway, edit it or delete it.

A bounced message has the error type and a moderation action of bounce. Use isModerationError to check for it:

if (message.isModerationError(currentUserId = chatClient.getCurrentUser()?.id)) {
    // The message was bounced and only the author can see it.
}

Bounced messages are never persisted on the server. Deleting one only removes the local copy, and sending it again goes through the regular send path, so the moderation policy is evaluated a second time.

The UI components handle bounced messages for you and show the Send anyway, Edit message and Delete message options. See the Compose and XML message moderation pages for how to customize them.

Flagging Messages

Flagging a message sends it to the moderation queue of your app, where a moderator can review it. Flag a message with the low-level client:

chatClient.flagMessage(
    messageId = message.id,
    reason = "inappropriate",
    customData = emptyMap(),
).enqueue { result ->
    when (result) {
        is Result.Success -> {
            // The message was sent to the moderation queue.
        }
        is Result.Failure -> {
            // Handle error
        }
    }
}

By default, users can flag messages sent by other users, as long as the channel grants them the flag-message capability. Both UI component libraries add a Flag message action to the message options for messages from other users, when that capability is present.