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.

var metadata : [String : Any]? = message.metaData
if metadata != nil {

    var injectedObject : [String : Any]? = (metadata?["@injected"] as? [String : Any])!
            
    if injectedObject != nil && (injectedObject!["extensions"] != nil){

      var extensionsObject : [String : Any]? = injectedObject?["extensions"] as? [String : Any]

      if extensionsObject != nil && extensionsObject?["profanity-filter"] != nil 			 {
                    
        var profanityFilterObject = extensionsObject?["profanity-filter"] as! [String :  Any]

        let profanity = profanityFilterObject["profanity"] as! String
        let cleanMessage = profanityFilterObject["language_translated"] as! String
      }
   }
}

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.