Data Masking Filter

Learn how to hide phone numbers, email addresses and other sensitive information in messages.

The Data Masking Extension allows you to hide phone numbers, email address and other sensitive information in messages.
Other sensitive information means that you as a developer, will be able to add regular expressions for matching & masking.


  1. Login to the CometChat Dashboard and select your app.
  2. Go to the Extensions page and add the Data Masking Filter extension.
  3. Go to the Installed tab and open the Settings for this extension.
  4. A few settings that are available for this extension can be broadly categoriezed as follows:
    a. Drop Message: Allows you to set where a message containing sensitive information needs to be dropped or can be allowed to be sent to the intended receiver.
    b. Default Masks: Masks for Emails, SSN and US Phone numbers are already provided. You can enable or disable them as per your requirement.
    c. Custom Masks: You as a developer can add Custom Regular Expressions for blocking any other kind of sensitive information. Refer this guide for more details on Regular Expressions.

How does it work?

Once the Extension is enabled for your App and the Extension Settings are done, the recipients will receive metadata with the masked message. Here is a sample response:

"@injected": {
    "extensions": {
        "data-masking": {
      "data": {
        "sensitive_data": "yes",
                "message_masked": "My number is ***** & my email id is ****"

If the data is missing, it means that the extension has timed out.


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 &&
    ) {
      var dataMaskingFilterObject = extensionsObject["data-masking"]["data"];
      var sensitive_data = dataMaskingFilterObject["sensitive_data"];
      var message_masked = dataMaskingFilterObject["message_masked"];
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("data-masking"))
          JSONObject dataMaskingObject = extensionsObject.getJSONObject("data-masking");
            JSONObject data = dataMaskingObject.getJSONObject("data");
          String sensitive_data = data.getString("sensitive_data");
          String message_masked = data.getString("message_masked");
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("data-masking")) {
     val dataMaskingDetails = extensionsObject.getJSONObject("data")
     val dataMaskingObject = dataMaskingDetails.getJSONObject("data")
     val sensitive_data = dataMaskingObject.getString("sensitive_data")
     val message_masked = dataMaskingObject.getString("message_masked"))
let textMessage = message as? TextMessage
var metadata : [String : Any]? = textMessage.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?["data-masking"] != nil             {                   
        var dataMasking = extensionsObject?["data-masking"] as! [String :  Any]
          var dataMaskingDetails = dataMasking?["data"] as! [String :  Any]
        let sensitive_data = dataMaskingDetails["sensitive_data"] as! String
        let message_masked = dataMaskingDetails["message_masked"] as! String

Did this page help you?