Moderation

Update time: 2024/03/14 18:45:33

CommsEase supports three types of content moderation, client-side moderation, GuardEase Moderator and third-party moderation services. You can enable and configure the moderation services based on the requirements of your business to ensure that your application complies with guidelines, terms of service, and legal regulations.

Client-side moderation

introduction

Before sending a message, the client first reviews the content, and decides whether to deliver or replace the message based on the moderation rules.

You can implement client-side moderation for messages in private chats, group chats and chat rooms. For other types of messages such as images, audio and video, use [GuardEase Moderator] (#GuardEase Moderator).

Procedure

Before you begin

  1. Select the application in the Applications section on the homepage of the console. In the left-side navigation pane, click Services->Instant Messaging.

    功能配置.png

  2. Select the Global Features tab at the top to activate Client Moderation.

    客户端反垃圾.png

  3. Read and confirm the settings, and click Confirm.

  4. Click Settings to configure the list of keywords.

    配置词库.png

    Replace/Intercept Rules Description
    Local keywords for interception If the app client detects sensitive words in a text message, the text message will be blocked. The sender will receive warnings or alerts for the highest level of violations, such as politically-sensitive or illegal content in the message.
    Local keywords for replacement The detected text will be replaced by a predefined text and delivered to the server.
    Server-side keywords for interception If the server detects sensitive words in a text message, the message will be blocked. The hit message is only visible to the sender, and the receiver cannot receive the message. In most cases, ad messages are blocked.
  5. After completing the configuration, click Publish to deliver the keywords to the SDK.

Implementation

Step 1: Get the list of keywords

After the initialization is complete, get the keywords by calling the getClientAntispamLexicon method.

Sample code:

JavaScript  // Get the list of keywords
  nim.getClientAntispamLexicon({
    done: function(error, file) {
      console.log(error, file)
    }
  });

The first parameter in the callback function in the example indicates whether there is an error in the method, and the second parameter indicates the keywords object. After the keywords are loaded, it will be automatically stored in memory. You can use it directly.

Step 2: Review content

Determine whether a text message contains inappropriate content by calling the filterClientAntispam method.

Sample code:

javascript/**
 * Call filterClientAntiSpam to check the text message and decide whether to send the message based on the moderation result.
 */
function sendTextAfterAntiSpam(option) {
    // Moderate the message
    const ret = nim.filterClientAntispam({
        content: option.text
    })

    switch (ret.type) {
        case 0:
            // Checked, valid for delivery
            nim.sendText(option)
            break
        case 1:
            // Hit local keywords for replacement Text after replacement: ret.result
            option.text = ret.result
            nim.sendText(option)
            break
        case 2:
            // Hit local keywords for block. The text message is blocked
            showHint('The message was blocked')
            break
        case 3:
            // Hit keywords on the server. It is recommended to send the message and set clientAntiSpam: true. The message will is successfully sent locally, but it will not actually be sent to recipients.
            // Server-side moderation can prevent spamming.
            nim.sendText({
                ...option,
                clientAntiSpam: true
            })
            break
    }
}

Moderator

Introduction

Moderator is a content moderation service provided by CommsEase for a full range of user generated content. If you have enabled and configured the service in the console, messages of the specified types will be moderated before delivery. Moderator can review messages of different types, such as text, images, custom content, profile pictures and information in private chats, group chats, and chat rooms.

For more information about Moderator, see Moderator Overview.

How it works

If you want the CommsEase server to send moderation results to your app server, configure Asynchronous moderation webhook.

Procedure

Before you begin

Go to the CommsEase console to activate [Moderator] (https://doc.yunxin.163.com/messaging/guide/jYxOTcyNzY?platform=server).

Implementation

The following parameters are required to moderate the content of a message using Moderator. If the message body hits the keywords, the result yidunAntiSpamRes will be returned. You must parse the yidunAntiSpamRes in JSON format before use.

  • Parameters for content moderation
Parameter
Required
Type
Description
antiSpamUsingYidun No boolean Whether to use Moderator to check the content of a message. the default value is true
yidunEnable No boolean Whether to moderate the specified content (antiSpamContent) of a custom message. The default value is false
antiSpamContent No String The content in a custom message for moderation. This parameter can only be configured after yidunEnable is enabled, and it is only valid for custom messages. A string in JSON format must be passed, and the length does not exceed 5,000 bytes

The format example: {"type": 1, "data": "custom content"}
Field description:
  • type: 1-text, 2-image, 3-video
  • data: the content can be text content, image URL, and video URL
antiSpamBusinessId No String Custom business ID. If this parameter is specified, the message will be moderated for the custom business. To add a custom business, contact sales for help and go to the CommsEase console to get the bussiness ID.
  • yidunAntiSpamRes
NameTypeDescription
code IntegerStatus code:
  • 200: Moderation result for approved content
  • 404: The result returned is empty. In this case, there is no other field other than code in yidunAntiSpamRes
  • 414: The result returned is too long. In this case, there is no ext field in yidunAntiSpamRes
type StringContent type
  • text: text
  • image: image
version StringAPI version
taskId StringModeration task ID
suggestion Integer Suggested method
  • 0: pass
  • 1: suspected, manual review is recommended
  • 2: fail
status IntegerRequest result
  • 0: success
  • 1: failure
  • < /ul>
ext StringModeration result, corresponding to the result field of GuardEase. For more information, see Moderation result (Note: This link only uses the `result` field for a single synchronous text moderation)

Sample code

javascriptnim.sendText({
  // ... Ignore other fields
  yidunEnable: true,
  antiSpamContent: JSON.stringify({
    "type": 1, //1: text; 2: image; 3: video
    "data": "" //text, image URL, or video URL
  }),
})

API Reference

Moderator guide:

For subsequent extension of Moderator fields for new attributes, pay attention to parsing and compatibility. For more information, see Moderator extension fields.

Third-party moderation service

If your application has access to a third-party moderation service, you can use webhooks to determine whether to deliver the moderated message based on the result.

Was this page helpful?
Yes
No
  • Client-side moderation
  • introduction
  • Procedure
  • Before you begin
  • Implementation
  • Step 1: Get the list of keywords
  • Step 2: Review content
  • Moderator
  • Introduction
  • How it works
  • Procedure
  • Before you begin
  • Implementation
  • API Reference
  • Third-party moderation service