Skip to main content

Profanity Filter

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.

Extension settings

  1. Login to the CometChat and select your app.
  2. Go to the Extensions section and enable the Profanity Filter extension.
  3. Open Settings and choose to Drop messages with Profanity.
  4. Also, you can provide the comma separated list of words that you would like to filter.

Support for filtering emojis

Apart from words, we have also added support for filtering Profane emojis along with words. The only thing that you need to keep in mind is, certain emojis have skin tones or other variations associated with them.

As part of the comma separated values, all the variations need to be covered.

For eg: In case of finger pointing left, you need to add: 👈🏿,👈🏾,👈🏽,👈🏼,👈🏻,👈. Please note that the yellow variant has to be entered at the end of the list.

Refer https://emojipedia.org/ for details.

How does it work?

The recipients will receive the normal message in the text field of the message object. Also, there will be a clean/filtered version of the message in the metadata section as shown below:

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

If the profanity-filter key is missing, it means that the extension is either not enabled or has timed out.

If there is some error inside the profanity-filter object, the list of bad words is probably empty. Save the settings with bad words to get the desired results.

Implementation

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

From the extension settings, you can also choose to drop 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.

var metadata = message.getMetadata();
if (metadata != null) {
var injectedObject = metadata["@injected"];
if (injectedObject != null && injectedObject.hasOwnProperty("extensions")) {
var extensionsObject = injectedObject["extensions"];
if (
extensionsObject != null &&
extensionsObject.hasOwnProperty("profanity-filter")
) {
var profanityFilterObject = extensionsObject["profanity-filter"];
var profanity = profanityFilterObject["profanity"];
var cleanMessage = profanityFilterObject["message_clean"];
}
}
}