let client = FeedsClient(apiKey: apiKey, user: user, token: token)
let moderation = client.moderation
Moderation
Stream Feeds has support for moderation, allowing you to manage user interactions, content moderation, and platform safety. It’s accessible through the client.moderation
property.
Overview
const client = new FeedsClient("<API key>");
client.moderation;
const apiKey = "";
const secret = "";
const client = new StreamClient(apiKey, secret);
client.moderation;
User Moderation
Ban Users
Ban a user from the platform with various options including timeout, shadow bans, and IP bans.
let banRequest = BanRequest(
targetUserId: "user-123",
reason: "Violation of community guidelines",
timeout: 3600, // 1 hour in seconds
shadow: false,
ipBan: false
)
let response = try await client.moderation.ban(banRequest: banRequest)
print("User banned for: \(response.duration)")
await client.moderation.ban({
target_user_id: "user-123",
reason: "Violation of community guidelines",
timeout: 3600, // 1 hour in seconds
shadow: false,
ip_ban: false,
});
await client.moderation.ban({
target_user_id: "user-123",
banned_by_id: "<banned by user id>",
reason: "Violation of community guidelines",
timeout: 3600, // 1 hour in seconds
shadow: false,
ip_ban: false,
});
Parameters:
targetUserId
: The ID of the user to banreason
: Optional reason for the bantimeout
: Optional timeout in seconds (null for permanent ban)shadow
: Whether to perform a shadow ban (user doesn’t know they’re banned)ipBan
: Whether to ban the user’s IP addressbannedBy
: Optional user who performed the bandeleteMessages
: Whether to delete user’s messages
Mute Users
Mute one or more users to prevent them from interacting with your content.
let muteRequest = MuteRequest(
targetIds: ["user-123", "user-456"],
timeout: 86400 // 24 hours in seconds
)
let response = try await client.moderation.mute(muteRequest: muteRequest)
client.moderation.mute({
target_ids: ["user-123", "user-456"],
timeout: 86400, // 24 hours in seconds
});
client.moderation.mute({
target_ids: ["user-123", "user-456"],
user_id: "<moderator id>",
timeout: 86400, // 24 hours in seconds
});
Parameters:
targetIds
: Array of user IDs to mutetimeout
: Optional timeout in seconds (null for permanent mute)
Block Users
Block a user to prevent them from following you or seeing your content.
let blockRequest = BlockUsersRequest(blockedUserId: "user-123")
let response = try await client.moderation.blockUsers(blockUsersRequest: blockRequest)
await client.blockUsers({
blocked_user_id: "user-123",
});
await client.blockUsers({
blocked_user_id: "user-123",
user_id: "<moderator id>",
});
Unblock Users
Unblock a previously blocked user.
let unblockRequest = UnblockUsersRequest(blockedUserId: "user-123")
let response = try await client.moderation.unblockUsers(unblockUsersRequest: unblockRequest)
client.unblockUsers({
blocked_user_id: "user-123",
});
client.unblockUsers({
blocked_user_id: "user-123",
user_id: "<moderator user id>",
});
Get Blocked Users
Retrieve a list of users you have blocked.
let blockedUsers = try await client.moderation.getBlockedUsers()
for user in blockedUsers.users {
print("Blocked user: \(user.id)")
}
client.getBlockedUsers();
client.getBlockedUsers({ user_id: "<moderator user id>" });
Content Moderation
Flag Content
Flag inappropriate content for moderation review.
let flagRequest = FlagRequest(
entityId: "activity-123",
entityType: "activity",
reason: "Inappropriate content",
entityCreatorId: "user-456"
)
let response = try await client.moderation.flag(flagRequest: flagRequest)
await client.moderation.flag({
entity_type: "activity",
entity_id: "activity_123",
reason: "Inappropriate content",
});
await client.moderation.flag({
entity_type: "activity",
entity_id: "activity_123",
reason: "Inappropriate content",
user_id: "<moderator user id>",
});
Parameters:
entityId
: The ID of the content to flagentityType
: The type of content (e.g., “activity”, “comment”)reason
: Optional reason for flaggingentityCreatorId
: Optional ID of the content creatorcustom
: Optional custom data for the flag
Submit Moderation Actions
Submit moderation actions for flagged content.
let actionRequest = SubmitActionRequest(
// Action details for moderation
)
let response = try await client.moderation.submitAction(submitActionRequest: actionRequest)
client.moderation.submitAction({
// Action details for moderation
});
client.moderation.submitAction({
// Action details for moderation
user_id: "<user id>",
});
Review Queue
Query Review Queue
Retrieve items in the moderation review queue.
let queryRequest = QueryReviewQueueRequest(
// Query parameters for filtering and pagination
)
let reviewQueue = try await client.moderation.queryReviewQueue(queryReviewQueueRequest: queryRequest)
client.moderation.queryReviewQueue({
// Query parameters for filtering and pagination
});
client.moderation.queryReviewQueue({
// Query parameters for filtering and pagination
user_id: user.id,
});
Configuration Management
Upsert Moderation Configuration
Create or update moderation configuration settings.
let configRequest = UpsertConfigRequest(
// Configuration details
)
let response = try await client.moderation.upsertConfig(upsertConfigRequest: configRequest)
client.moderation.upsertConfig({
key: 'feeds',
block_list_config: {
enabled: true,
rules: [
// Names of existing block lists
{ name: blocklistName, action: 'remove', team: '' },
{ name: flagBlocklistName, action: 'flag', team: '' },
{ name: shadowBlocklistName, action: 'shadow', team: '' },
{ name: bounceBlocklistName, action: 'bounce', team: '' },
],
},
ai_image_config: {
enabled: true,
rules: [{ label: 'Non-Explicit Nudity', action: 'remove', min_confidence: 0 }],
ocr_rules: [{ label: 'Non-Explicit Nudity', action: 'remove' }],
},
}),
client.moderation.upsertConfig({
key: 'feeds',
block_list_config: {
enabled: true,
rules: [
// Names of existing block lists
{ name: blocklistName, action: 'remove', team: '' },
{ name: flagBlocklistName, action: 'flag', team: '' },
{ name: shadowBlocklistName, action: 'shadow', team: '' },
{ name: bounceBlocklistName, action: 'bounce', team: '' },
],
},
ai_image_config: {
enabled: true,
rules: [{ label: 'Non-Explicit Nudity', action: 'remove', min_confidence: 0 }],
ocr_rules: [{ label: 'Non-Explicit Nudity', action: 'remove' }],
},
}),
Get Moderation Configuration
Retrieve a specific moderation configuration.
let config = try await client.moderation.getConfig(key: "automod_settings", team: "team-123")
client.moderation.getConfig({
key: "feeds",
});
client.moderation.getConfig({
key: "feeds",
});
Parameters:
key
: The configuration key to retrieveteam
: Optional team identifier
Delete Moderation Configuration
Remove a moderation configuration.
let response = try await client.moderation.deleteConfig(key: "automod_settings", team: "team-123")
client.moderation.deleteConfig({
key: "feeds",
});
client.moderation.deleteConfig({
key: "feeds",
});
Query Moderation Configurations
Search and filter moderation configurations.
let queryRequest = QueryModerationConfigsRequest(
// Query parameters for filtering and pagination
)
let configs = try await client.moderation.queryModerationConfigs(queryModerationConfigsRequest: queryRequest)
client.moderation.queryModerationConfigs({
filter: {
// Filter params
},
});
client.moderation.queryModerationConfigs({
filter: {
// Filter params
},
});
Error Handling
All moderation methods can throw errors. Handle them appropriately:
do {
let response = try await client.moderation.ban(banRequest: banRequest)
print("User banned successfully")
} catch {
print("Failed to ban user: \(error)")
}
try {
const response = await client.moderation.ban({
target_user_id: "user-123",
reason: "Violation of community guidelines",
timeout: 3600, // 1 hour in seconds
shadow: false,
ip_ban: false,
});
console.log(`${response.user.id} banned successfully`);
} catch (e) {
console.error(`Failed to ban user, error: ${e}`);
}
try {
const response = await client.moderation.ban({
target_user_id: "user-123",
banned_by_id: "<banned by user id>",
reason: "Violation of community guidelines",
timeout: 3600, // 1 hour in seconds
shadow: false,
ip_ban: false,
});
console.log(`${response.user.id} banned successfully`);
} catch (e) {
console.error(`Failed to ban user, error: ${e}`);
}