Add Rule
curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/moderation/rules \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--data '
{
"id": "moderation-test",
"name": "Video Moderation",
"enabled": true,
"description": "AI-powered video moderation to detect unsafe content.",
"action": [
"blockMessage"
],
"filters": [
{
"type": "sender",
"entity": "user",
"operator": "equals",
"value": "admin"
}
],
"conditions": [
{
"id": 1,
"entity": "message",
"operand": "image",
"operator": "contains",
"category": "word",
"isKeywordReferencePresent": false,
"isMediaPresent": true,
"value": "violence_greaterThan_30"
}
]
}
'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/moderation/rules"
payload = {
"id": "moderation-test",
"name": "Video Moderation",
"enabled": True,
"description": "AI-powered video moderation to detect unsafe content.",
"action": ["blockMessage"],
"filters": [
{
"type": "sender",
"entity": "user",
"operator": "equals",
"value": "admin"
}
],
"conditions": [
{
"id": 1,
"entity": "message",
"operand": "image",
"operator": "contains",
"category": "word",
"isKeywordReferencePresent": False,
"isMediaPresent": True,
"value": "violence_greaterThan_30"
}
]
}
headers = {
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {apikey: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: 'moderation-test',
name: 'Video Moderation',
enabled: true,
description: 'AI-powered video moderation to detect unsafe content.',
action: ['blockMessage'],
filters: [{type: 'sender', entity: 'user', operator: 'equals', value: 'admin'}],
conditions: [
{
id: 1,
entity: 'message',
operand: 'image',
operator: 'contains',
category: 'word',
isKeywordReferencePresent: false,
isMediaPresent: true,
value: 'violence_greaterThan_30'
}
]
})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/moderation/rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{appId}.api-{region}.cometchat.io/v3/moderation/rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 'moderation-test',
'name' => 'Video Moderation',
'enabled' => true,
'description' => 'AI-powered video moderation to detect unsafe content.',
'action' => [
'blockMessage'
],
'filters' => [
[
'type' => 'sender',
'entity' => 'user',
'operator' => 'equals',
'value' => 'admin'
]
],
'conditions' => [
[
'id' => 1,
'entity' => 'message',
'operand' => 'image',
'operator' => 'contains',
'category' => 'word',
'isKeywordReferencePresent' => false,
'isMediaPresent' => true,
'value' => 'violence_greaterThan_30'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{appId}.api-{region}.cometchat.io/v3/moderation/rules"
payload := strings.NewReader("{\n \"id\": \"moderation-test\",\n \"name\": \"Video Moderation\",\n \"enabled\": true,\n \"description\": \"AI-powered video moderation to detect unsafe content.\",\n \"action\": [\n \"blockMessage\"\n ],\n \"filters\": [\n {\n \"type\": \"sender\",\n \"entity\": \"user\",\n \"operator\": \"equals\",\n \"value\": \"admin\"\n }\n ],\n \"conditions\": [\n {\n \"id\": 1,\n \"entity\": \"message\",\n \"operand\": \"image\",\n \"operator\": \"contains\",\n \"category\": \"word\",\n \"isKeywordReferencePresent\": false,\n \"isMediaPresent\": true,\n \"value\": \"violence_greaterThan_30\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("apikey", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{appId}.api-{region}.cometchat.io/v3/moderation/rules")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"moderation-test\",\n \"name\": \"Video Moderation\",\n \"enabled\": true,\n \"description\": \"AI-powered video moderation to detect unsafe content.\",\n \"action\": [\n \"blockMessage\"\n ],\n \"filters\": [\n {\n \"type\": \"sender\",\n \"entity\": \"user\",\n \"operator\": \"equals\",\n \"value\": \"admin\"\n }\n ],\n \"conditions\": [\n {\n \"id\": 1,\n \"entity\": \"message\",\n \"operand\": \"image\",\n \"operator\": \"contains\",\n \"category\": \"word\",\n \"isKeywordReferencePresent\": false,\n \"isMediaPresent\": true,\n \"value\": \"violence_greaterThan_30\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/moderation/rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"moderation-test\",\n \"name\": \"Video Moderation\",\n \"enabled\": true,\n \"description\": \"AI-powered video moderation to detect unsafe content.\",\n \"action\": [\n \"blockMessage\"\n ],\n \"filters\": [\n {\n \"type\": \"sender\",\n \"entity\": \"user\",\n \"operator\": \"equals\",\n \"value\": \"admin\"\n }\n ],\n \"conditions\": [\n {\n \"id\": 1,\n \"entity\": \"message\",\n \"operand\": \"image\",\n \"operator\": \"contains\",\n \"category\": \"word\",\n \"isKeywordReferencePresent\": false,\n \"isMediaPresent\": true,\n \"value\": \"violence_greaterThan_30\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "moderation-test",
"name": "Video Moderation",
"description": "AI-powered video moderation to detect unsafe content.",
"enabled": true,
"conditions": [
{
"id": 1,
"isKeywordsReferencePresent": false,
"isMediaPresent": true,
"entity": "message",
"operand": "image",
"category": "word",
"operator": "contains",
"value": [
"violence_greaterThan_30"
],
"message": [
"Image contains violence with confidence greater than 30"
]
}
],
"action": [
"blockMessage"
],
"active": true,
"createdAt": 1720003247,
"updatedAt": 1720003247,
"revisionId": "253179cf5f665257_moderation-test_1"
}
}Rules
Add Rule
Create a CometChat moderation rule with REST API to define content checks, actions, and rule conditions.
POST
/
moderation
/
rules
Add Rule
curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/moderation/rules \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--data '
{
"id": "moderation-test",
"name": "Video Moderation",
"enabled": true,
"description": "AI-powered video moderation to detect unsafe content.",
"action": [
"blockMessage"
],
"filters": [
{
"type": "sender",
"entity": "user",
"operator": "equals",
"value": "admin"
}
],
"conditions": [
{
"id": 1,
"entity": "message",
"operand": "image",
"operator": "contains",
"category": "word",
"isKeywordReferencePresent": false,
"isMediaPresent": true,
"value": "violence_greaterThan_30"
}
]
}
'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/moderation/rules"
payload = {
"id": "moderation-test",
"name": "Video Moderation",
"enabled": True,
"description": "AI-powered video moderation to detect unsafe content.",
"action": ["blockMessage"],
"filters": [
{
"type": "sender",
"entity": "user",
"operator": "equals",
"value": "admin"
}
],
"conditions": [
{
"id": 1,
"entity": "message",
"operand": "image",
"operator": "contains",
"category": "word",
"isKeywordReferencePresent": False,
"isMediaPresent": True,
"value": "violence_greaterThan_30"
}
]
}
headers = {
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {apikey: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: 'moderation-test',
name: 'Video Moderation',
enabled: true,
description: 'AI-powered video moderation to detect unsafe content.',
action: ['blockMessage'],
filters: [{type: 'sender', entity: 'user', operator: 'equals', value: 'admin'}],
conditions: [
{
id: 1,
entity: 'message',
operand: 'image',
operator: 'contains',
category: 'word',
isKeywordReferencePresent: false,
isMediaPresent: true,
value: 'violence_greaterThan_30'
}
]
})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/moderation/rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{appId}.api-{region}.cometchat.io/v3/moderation/rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 'moderation-test',
'name' => 'Video Moderation',
'enabled' => true,
'description' => 'AI-powered video moderation to detect unsafe content.',
'action' => [
'blockMessage'
],
'filters' => [
[
'type' => 'sender',
'entity' => 'user',
'operator' => 'equals',
'value' => 'admin'
]
],
'conditions' => [
[
'id' => 1,
'entity' => 'message',
'operand' => 'image',
'operator' => 'contains',
'category' => 'word',
'isKeywordReferencePresent' => false,
'isMediaPresent' => true,
'value' => 'violence_greaterThan_30'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{appId}.api-{region}.cometchat.io/v3/moderation/rules"
payload := strings.NewReader("{\n \"id\": \"moderation-test\",\n \"name\": \"Video Moderation\",\n \"enabled\": true,\n \"description\": \"AI-powered video moderation to detect unsafe content.\",\n \"action\": [\n \"blockMessage\"\n ],\n \"filters\": [\n {\n \"type\": \"sender\",\n \"entity\": \"user\",\n \"operator\": \"equals\",\n \"value\": \"admin\"\n }\n ],\n \"conditions\": [\n {\n \"id\": 1,\n \"entity\": \"message\",\n \"operand\": \"image\",\n \"operator\": \"contains\",\n \"category\": \"word\",\n \"isKeywordReferencePresent\": false,\n \"isMediaPresent\": true,\n \"value\": \"violence_greaterThan_30\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("apikey", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{appId}.api-{region}.cometchat.io/v3/moderation/rules")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"moderation-test\",\n \"name\": \"Video Moderation\",\n \"enabled\": true,\n \"description\": \"AI-powered video moderation to detect unsafe content.\",\n \"action\": [\n \"blockMessage\"\n ],\n \"filters\": [\n {\n \"type\": \"sender\",\n \"entity\": \"user\",\n \"operator\": \"equals\",\n \"value\": \"admin\"\n }\n ],\n \"conditions\": [\n {\n \"id\": 1,\n \"entity\": \"message\",\n \"operand\": \"image\",\n \"operator\": \"contains\",\n \"category\": \"word\",\n \"isKeywordReferencePresent\": false,\n \"isMediaPresent\": true,\n \"value\": \"violence_greaterThan_30\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/moderation/rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"moderation-test\",\n \"name\": \"Video Moderation\",\n \"enabled\": true,\n \"description\": \"AI-powered video moderation to detect unsafe content.\",\n \"action\": [\n \"blockMessage\"\n ],\n \"filters\": [\n {\n \"type\": \"sender\",\n \"entity\": \"user\",\n \"operator\": \"equals\",\n \"value\": \"admin\"\n }\n ],\n \"conditions\": [\n {\n \"id\": 1,\n \"entity\": \"message\",\n \"operand\": \"image\",\n \"operator\": \"contains\",\n \"category\": \"word\",\n \"isKeywordReferencePresent\": false,\n \"isMediaPresent\": true,\n \"value\": \"violence_greaterThan_30\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "moderation-test",
"name": "Video Moderation",
"description": "AI-powered video moderation to detect unsafe content.",
"enabled": true,
"conditions": [
{
"id": 1,
"isKeywordsReferencePresent": false,
"isMediaPresent": true,
"entity": "message",
"operand": "image",
"category": "word",
"operator": "contains",
"value": [
"violence_greaterThan_30"
],
"message": [
"Image contains violence with confidence greater than 30"
]
}
],
"action": [
"blockMessage"
],
"active": true,
"createdAt": 1720003247,
"updatedAt": 1720003247,
"revisionId": "253179cf5f665257_moderation-test_1"
}
}Authorizations
API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).
Body
application/json
Unique identifier for the moderation rule.
Example:
"moderation-test"
Descriptive name for the moderation rule.
Example:
"Video Moderation"
Indicates whether the rule is active.
Example:
true
Detailed explanation of the rule's purpose.
Example:
"AI-powered video moderation to detect unsafe content."
Actions to be taken when a violation is detected.
List of filters to apply
- Option 1
- Option 2
Show child attributes
Show child attributes
List of conditions that must be met for the rule to trigger.
Show child attributes
Show child attributes
Response
200 - application/json
Created Rule
Show child attributes
Show child attributes
Was this page helpful?
⌘I