CometChat Pro Documentation

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Profanity Filter

Learn how to mask or hide profanity in messages.

The Profanity Filter Extension helps you to mask or hide profanity in a message. We check for words from a blacklist (which you can customize) and then mask them.

Recipients will receive metadata with the filtered message. Here is a sample response:

"@injected": {
  "extensions": {
    "profanity-filter": {
      "profanity": "yes",
      "message_clean": "This is *********"
    }
  }
}

By checking if profanity is set to yes, you can also consider showing a warning before reading the message or dropping the message altogether.

At the recipients' end, from the message object, you can fetch the metadata by calling the getMetadata() method. Using this metadata, you can fetch the masked message.

JSONObject metadata = message.getMetadata();
if (metadata != null) {
  JSONObject injectedObject = metadata.getJSONObject("@injected");
  if (injectedObject != null && injectedObject.has("extensions")) {
    JSONObject extensionsObject = injectedObject.getJSONObject("extensions");
    if (extensionsObject != null && extensionsObject.has("profanity-filter"))
        {
          JSONObject profanityFilterObject = extensionsObject.getJSONObject("profanity-filter");
          String profanity = profanityFilterObject.getString("profanity");
          String cleanMessage = profanityFilterObject.getString("message_clean");

        }
    }
}
if (metadata != null) {
  if (metadata.has("@injected")) {
   val injectedJSONObject = metadata.getJSONObject("@injected")
   if (injectedJSONObject != null && injectedJSONObject.has("extensions")) {
   val extensionsObject = injectedJSONObject.getJSONObject("extensions")

   if (extensionsObject != null && extensionsObject.has("profanity-filter")) {
   val profanityFilterObject = extensionsObject.getJSONObject("profanity-filter")
   val dataObject = profanityFilterObject.getJSONObject("data")
      if (dataObject.has("profanity"))
         val profanity = dataObject.getString("profanity")
      if (dataObject.has("message_clean"))
        val message_clean= dataObject.getString("message_clean"))
         }     
       }
     }
   }

Profanity Filter


Learn how to mask or hide profanity in messages.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.