Content Moderation sends asynchronous notifications that contain the results of content detection and human review. To use or integrate these results, you must configure callback notifications. This topic describes how to configure callback notifications for the Content Moderation API.
Background information
Content Moderation API callback notifications are categorized as scan result callbacks and review result callbacks.
Scan result callbacks: When Content Moderation completes a detection request, the server sends the detection results to your configured HTTP webhook address in a POST request.
Review result callbacks: When you modify detection results through human review or by calling a feedback API operation, the server sends the review results to your configured HTTP webhook address in a POST request. For more information, see Human review.
Concepts
Before you configure callback notifications, you should understand the concepts described in the following table.
Term | Description |
Webhook address | A webhook address is the server address that you configure in the Content Moderation console. This is usually the public address of your own business server. The webhook address must meet the following requirements:
|
Seed | The Seed value is used to verify that requests sent to your configured HTTP webhook address originate from the Content Moderation server. |
Callback attempts | After your server receives a callback message pushed by Content Moderation, it returns an HTTP status code. A status code of 200 indicates success. Any other status code indicates failure. If the delivery fails, the Content Moderation server retries sending the callback message until it is successfully received. Content Moderation retries up to three times. |
Callback data | Callback data is the content that the Content Moderation server returns to your configured webhook address. For a description of the callback data structure, see Callback notification form data. |
Table 1. Callback notification form data
Name | Type | Description |
checksum | String | The checksum is generated using the SHA256 algorithm on a string concatenated from Note For tamper-proofing, you can generate a string using the same algorithm when you receive the pushed result and verify it against the checksum. |
content | String | A JSON object saved as a string. You must parse and invert it into a JSON object. For the structure of the content after it is parsed into a JSON object, see content description later in this topic. |
Scan result callback notifications
All asynchronous detection API operations of Content Moderation support scan result callbacks, such as asynchronous image scan and asynchronous video scan. When you make an asynchronous invocation, to receive scan results from Content Moderation, you must include the callback (webhook address) and seed (checksum string) parameters in the request.
If you do not use scan result callbacks during an asynchronous invocation, you can retrieve the asynchronous detection results only using periodic polling.
Procedure
Prepare the HTTP webhook address and seed parameter to receive scan results.
When you call an asynchronous Content Moderation API operation, pass the corresponding callback and seed request parameters. For more information, see the parameter descriptions in the API operation documentation.
Human review callback notifications
Human review API operations do not return detection results in real time. Instead, the system uses callbacks to notify the caller.
Machine-assisted human review
If you use the Alibaba Cloud human review service combined with the machine-assisted moderation service, you must configure notifications in the console to receive callbacks from the human review module. Follow these steps:
Log on to the Content Moderation console.
In the navigation pane on the left, choose .
On the Settings page, click the Notification tab, and then click Create New Notification.
In the Create New Notification dialog box, enter a Title and Callback URL. Select an Encryption algorithm, Notification type, and Audit Result. Then, click OK.
After you save the configuration, the system automatically generates a seed. The seed value is used to verify that the requests received by your webhook address are from Alibaba Cloud. You must save the automatically generated seed.
ImportantIf you have already configured a callback notification service for machine-assisted moderation, you can reuse the existing configuration or create a new one as needed.
The system supports callbacks for all review results. You can also choose to receive callbacks for only some review results depending on your business scenario.
For Notification Type, select Manual Review Results by AlibabaCloud.
The following encryption algorithm methods are available:
SHA256: Uses the HMAC-SHA256 encryption algorithm.
SM3: Uses the SM3 encryption algorithm and returns a hexadecimal string of lowercase letters and numbers.
For example, encrypting abc with SM3 returns 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0.
On the Scenario Management tab, find the target business scenario, click Associate Notification in the Actions column, and then associate the Callback Notification Plan that you configured.
content description
After you enable callback notifications, Content Moderation sends callback notifications based on your configuration. The callback notification contains form data in the content field. The following table describes the structure of the content field.
Table 2. Structure of the content field
Name | Type | Required | Description |
scanResult | JSONObject | No | The scan result. The structure varies depending on the detected object, such as an image or a video.
|
auditResult | JSONObject | No | Your human review result. This field is present only when a human review operation occurs. For more information, see auditResult. Note This field is not included if only scan results are pushed. |
humanAuditResult | JSONObject | No | The human review result from Alibaba Cloud. If you purchased Alibaba Cloud's human review service, the review result is included in this field. For more information, see humanAuditResult. |
Table 3. auditResult
Name | Type | Required | Description |
suggestion | String | Yes | The result of the human review. Valid values:
|
labels | JSONArray | No | The labels set during human review. It can contain one or more of the following values:
|
Table 4. humanAuditResult
Name | Type | Required | Description |
suggestion | String | Yes | The result of the Alibaba Cloud human review. Valid values:
|
taskId | String | Yes | The ID of the detection task. You can use the task ID to associate the review result with the corresponding content. |
dataId | String | Yes | The ID of the detected content. |
labels | JSONArray | No | The label results from the human review. There can be multiple values. Note This parameter is not returned by default. Configuring this field incurs extra charges. Contact your business representative for details. |
Example of the content field
{
"scanResult": {
"code": 200,
"msg": "OK",
"taskId": "fdd25f95-4892-4d6b-aca9-7939bc6e9baa-1486198766695",
"url": "http://1.jpg",
"results": [
{
"rate": 100,
"scene": "porn",
"suggestion": "block",
"label": "porn"
}
]
},
"auditResult": {
"suggestion": "block",
"labels": [
"porn",
"ad",
"terrorism"
]
},
"humanAuditResult": {
"suggestion": "pass",
"dataId": "yyyy",
"labels": [
"porn",
"vulgar"
],
"taskId": "xxxxxx"
}
}