> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickblox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Moderation

> Learn how to moderate messages and users in your app.

<Warning>
  This feature is available for customers on the Enterprise plan only. Take advantage of Enterprise features to unlock new value and opportunities for users. For more information and if you want to request a Demo, please contact us by mail: [enterprise@quickblox.com](mailto:enterprise@quickblox.com.).
</Warning>

## Trust & Safety (TnS)

QuickBlox TnS helps you moderate chat messages in real-time. Whenever a user sends a message to the dialog, the functionality blocks potentially offensive messages from being delivered to the recipient or masks profanity or sensitive information such as social security numbers, addresses, names, and phone numbers, which helps prevent the loss of sensitive data.

<Note>
  TnS settings are not mixed up between multiple apps in one account. You can configure different TnS settings for each app.
</Note>

### Add rule

A **rule** defines moderation criteria based on the words or regexp that should be filtered. To create a moderation rule follow the steps below:

1. Go to the **Dashboard => *YOUR\_APP* => Chat => TnS** section. Click the **Add message rule** button.

<Frame>
  <img src="https://mintcdn.com/quickblox/tw9NMPEfMkW_LAuD/images/d6a7caa-addons-moderation-chat-tns-add_message_rule.png?fit=max&auto=format&n=tw9NMPEfMkW_LAuD&q=85&s=43bb5618dc49526b4a2bb348c3f82ed3" alt="addons-moderation-chat-tns-add_message_rule.png" width="1900" height="900" data-path="images/d6a7caa-addons-moderation-chat-tns-add_message_rule.png" />
</Frame>

1. Enter the name of the rule into the **Name** field.

2. Move to the **Mask** field and enter the symbols to be used instead of the inappropriate word. You can leave it empty if you don't want to use the mask.

3. Move to the **Score** field and enter a rule score indicating how bad a word is. Set a value from **0** to **1000** for this field. See how to calculate a message score [here](/docs/chat-moderation#how-message-score-is-calculated).

4. Use either a **RegExp field** or **Find dictionary** to save inappropriate words or expressions.
   * The **RegExp** option allows entering a regular expression, which is a sequence of characters that define a search pattern; used mainly for pattern matching with strings.
   * The **Find dictionary** option allows uploading a file with words that should be filtered. If you want to upload a dictionary file, use the **.txt** file. The cognates order in the dictionary should be from the longest to the shortest. See the screenshot below:
   <Frame>
     <img src="https://mintcdn.com/quickblox/e8BObhqG0WJty0gE/images/61f4d71-tns-dictionary.png?fit=max&auto=format&n=e8BObhqG0WJty0gE&q=85&s=8376b80aab5b0477b5b7d2c230043fcb" alt="tns-dictionary.png" width="2000" height="330" data-path="images/61f4d71-tns-dictionary.png" />
   </Frame>

5. Click the **Save rule** button.

<Frame>
  <img src="https://mintcdn.com/quickblox/4gw4x-2IrfN_sgat/images/14c3425-app-restyle-chat-tns-new-rule.png?fit=max&auto=format&n=4gw4x-2IrfN_sgat&q=85&s=14676781912462a5fdc6c108182022a5" alt="app-restyle-chat-tns-new-rule.png" width="369" height="557" data-path="images/14c3425-app-restyle-chat-tns-new-rule.png" />
</Frame>

<Note>
  The last created rule has the highest priority either it was created with the dictionary or RegExp value.
</Note>

### Add score group

A **score group** defines blocking behavior based on the score provided and works in conjunction with the message score. See how to calculate a message score [here](/docs/chat-moderation#how-message-score-is-calculated). To add a score group, proceed as follows:

1. Go to the **Dashboard => *YOUR\_APP* => Chat => TnS** section. Click the **Add score group** button.

<Frame>
  <img src="https://mintcdn.com/quickblox/e8BObhqG0WJty0gE/images/55ffdeb-addons-moderation-chat-tns-add_score_group.png?fit=max&auto=format&n=e8BObhqG0WJty0gE&q=85&s=07104b73868c0273a292bc0bfa62d307" alt="addons-moderation-chat-tns-add_score_group.png" width="1900" height="900" data-path="images/55ffdeb-addons-moderation-chat-tns-add_score_group.png" />
</Frame>

1. Enter the name of the score group into the **Name** field.
2. Set a score value into the **Score** field. Enter the value from **1** to **100 000** for this field.

<Warning>
  The message is blocked by the TnS system if the message score is **more than** or **equals** the group score.

  If the message score is **less than** the score group, the words or RegExp are masked by the TnS system. This is the case if the mask was set.
</Warning>

1. Click the **Save rule** button.

<Frame>
  <img src="https://mintcdn.com/quickblox/xkS1X1sSZwktmwsY/images/a9ce3af-app-restyle-chat-tns-new-score.png?fit=max&auto=format&n=xkS1X1sSZwktmwsY&q=85&s=44580ad54958433deb08e3bc2069ca84" alt="app-restyle-chat-tns-new-score.png" width="369" height="414" data-path="images/a9ce3af-app-restyle-chat-tns-new-score.png" />
</Frame>

<Warning>
  A **Block** option enables the score group. This means that blocking functionality is up and running. Thus, if a message is blocked, it isn't delivered to the recipient.

  The score group with the lowest score value has the highest priority.
</Warning>

### How message score is calculated

A message score is a score assigned to a message based on the [rule score](/docs/chat-moderation#add-a-rule). If there are several inappropriate words in the message, a total score of all words is calculated.

*Example 1:*

An inappropriate word is repeated 3 times in a single message. According to the message rule, this word is given 2 scores. However, since it is repeated 3 times, the total message score equals 6.

*Example 2:*

There are 2 inappropriate words in a single message. However, these two words come from different rules. One word is assigned 3 scores and another word is assigned 2 scores according to different rules. Thus, the total message score equals 5.

### How it works

Once you've set a message rule and score group, let's check how message blocking/masking functionality works:

1. Send a message with an inappropriate word which score is less than the value set in the score group.
2. Go to the **Chat** tab and click the **view** button in the **History** column for the required dialog. You can see the **Messages History** pop-up showing that the message is masked and is received by the recipient.

<Frame>
  <img src="https://mintcdn.com/quickblox/4gw4x-2IrfN_sgat/images/3a2860f-addons-moderation-chat-tns-history-masked.png?fit=max&auto=format&n=4gw4x-2IrfN_sgat&q=85&s=d243e89a4bd6dfe675225cb5faac2ada" alt="addons-moderation-chat-tns-history-masked.png" width="1900" height="743" data-path="images/3a2860f-addons-moderation-chat-tns-history-masked.png" />
</Frame>

1. Send a message with an inappropriate word which score is more than or equals the value set in the score group.
2. Go to the **Chat** tab and click the **view** in the **History** column for the required dialog. You can see the **Messages History** pop-up showing that the message is displayed with the **blocked\_by=\<array\_of\_rules\_ids>** custom parameter and is not delivered to the recipient.

<Frame>
  <img src="https://mintcdn.com/quickblox/e8BObhqG0WJty0gE/images/4119f6f-addons-moderation-chat-tns-history-blocked.png?fit=max&auto=format&n=e8BObhqG0WJty0gE&q=85&s=43af1515447a019af74ba0c4527b1d82" alt="addons-moderation-chat-tns-history-blocked.png" width="1900" height="640" data-path="images/4119f6f-addons-moderation-chat-tns-history-blocked.png" />
</Frame>

## Ban user

You can ban a user account so the user can no longer connect to the chat. If a banned user tries to connect to chat, the system returns an error saying: “You are banned. Please contact your app customer support.”

1. Go to the **Dashboard => *YOUR\_APP* => Chat => Bans** tab. Click the **Add ban** button.

<Frame>
  <img src="https://mintcdn.com/quickblox/4gw4x-2IrfN_sgat/images/131161b-addons-moderation-chat-bans-list.png?fit=max&auto=format&n=4gw4x-2IrfN_sgat&q=85&s=8bce4a8e706bbf8b199313d2485a38a3" alt="addons-moderation-chat-bans-list.png" width="1900" height="680" data-path="images/131161b-addons-moderation-chat-bans-list.png" />
</Frame>

1. Enter the user ID that is going to be banned into the **QB User ID** field.
2. Enter the ban expiration date into the **Expires** field.
3. Click the **New ban** button.

<Frame>
  <img src="https://mintcdn.com/quickblox/4gw4x-2IrfN_sgat/images/10e633b-addons-moderation-chat-bans-new_ban.png?fit=max&auto=format&n=4gw4x-2IrfN_sgat&q=85&s=f70804b42412cb09d4116a4a2bfaf657" alt="addons-moderation-chat-bans-new_ban.png" width="567" height="378" data-path="images/10e633b-addons-moderation-chat-bans-new_ban.png" />
</Frame>
