client, err := getstream.NewClient("key", "secret")
if err != nil {
// Handle error
}
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
User Moderation
Ban Users
Ban a user from the platform with various options including timeout, shadow bans, and IP bans.
request := &getstream.BanRequest{
TargetUserID: "user123",
Reason: getstream.PtrTo("spam"),
Timeout: getstream.PtrTo(60), // 60 minutes
BannedByID: getstream.PtrTo("moderator456"),
}
_, err := client.Moderation().Ban(context.Background(), request)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
To reverse a ban, see Unban User in the Moderation docs. The user object returned by queryUsers only exposes the ban state (banned, ban_expires) — it does not include banned_by or the ban reason. To retrieve that metadata, use Query Banned Users.
Mute Users
Mute is not supported in Feeds. Muting a user does not hide their activities from feed reads.
To hide another user's activities in Feeds, use Block Users instead.
Block Users
Block a user. Blocking is bidirectional:
- Neither user sees the other's activities in feeds
- Neither can follow the other
This replaces the v2 discard_actors option. Instead of sending blocked user IDs on every feed read, call blockUsers once — Stream filters those activities automatically.
response, err := client.BlockUsers(ctx, &getstream.BlockUsersRequest{
BlockedUserID: "user-123",
UserID: getstream.PtrTo("user-456"),
})Unblock Users
Unblock a previously blocked user.
response, err := client.UnblockUsers(ctx, &getstream.UnblockUsersRequest{
BlockedUserID: "user-123",
UserID: getstream.PtrTo("user-456"),
})Get Blocked Users
Retrieve a list of users you have blocked.
response, err := client.GetBlockedUsers(ctx, &getstream.GetBlockedUsersRequest{
UserID: getstream.PtrTo("user-456"),
})Content Moderation
Flag Content
Flag inappropriate content for moderation review.
request := &getstream.FlagRequest{
EntityType: "stream:feeds:v3:activity",
EntityID: "activity123",
EntityCreatorID: getstream.PtrTo("user456"),
Reason: getstream.PtrTo("harassment"),
UserID: getstream.PtrTo("reporter789"),
}
_, err := client.Moderation().Flag(context.Background(), request)Parameters:
entityId: The ID of the content to flagentityType: The type of content (e.g., "stream:feeds:v3:activity", "stream:feeds:v3: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.
request := &getstream.SubmitActionRequest{
ItemID: "review_item_123",
ActionType: "mark_reviewed",
UserID: getstream.PtrTo("moderator456"),
}
_, err := client.Moderation().SubmitAction(context.Background(), request)Review Queue
Query Review Queue
Retrieve items in the moderation review queue.
request := &getstream.QueryReviewQueueRequest{
Filter: map[string]any{
"status": "pending",
},
Limit: getstream.PtrTo(25),
}
_, err := client.Moderation().QueryReviewQueue(context.Background(), request)Configuration Management
Upsert Moderation Configuration
Create or update moderation configuration settings.
request := &getstream.UpsertConfigRequest{
Key: "chat:messaging:general",
AutomodToxicityConfig: &getstream.AutomodToxicityConfig{
Enabled: getstream.PtrTo(true),
Rules: []getstream.AutomodRule{
{
Label: "toxic",
Threshold: 0.8,
Action: "remove",
},
},
},
}
_, err := client.Moderation().UpsertConfig(context.Background(), request)Get Moderation Configuration
Retrieve a specific moderation configuration.
request := &getstream.GetConfigRequest{
Team: getstream.PtrTo(""),
}
_, err := client.Moderation().GetConfig(context.Background(), "feeds", request)Parameters:
key: The configuration key to retrieveteam: Optional team identifier
Delete Moderation Configuration
Remove a moderation configuration.
request := &getstream.DeleteConfigRequest{
}
_, err := client.Moderation().DeleteConfig(context.Background(), "feeds", request)Query Moderation Configurations
Search and filter moderation configurations.
request := &getstream.QueryModerationConfigsRequest{
Filter: map[string]any{
"key": map[string]any{
"$in": []string{"feeds", "automod"},
},
},
Limit: getstream.PtrTo(10),
}
_, err := client.Moderation().QueryModerationConfigs(context.Background(), request)Moderation Config Queryable Built-In Fields
| name | type | description | supported operations | example |
|---|---|---|---|---|
key | string or list of strings | The configuration key identifier | $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $autocomplete | { key: { $autocomplete: 'spam' } } |
team | string or list of strings | The team identifier for multi-tenant applications | $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists | { team: { $eq: 'team_123' } } |
created_at | string, must be formatted as an RFC3339 timestamp | The time the configuration was created | $eq, $gt, $gte, $lt, $lte | { created_at: { $gte: '2023-12-04T09:30:20.45Z' } } |
updated_at | string, must be formatted as an RFC3339 timestamp | The time the configuration was last updated | $eq, $gt, $gte, $lt, $lte | { updated_at: { $gte: '2023-12-04T09:30:20.45Z' } } |
Error Handling
All moderation methods can throw errors. Error handling documents the exception classes and their fields for each backend SDK, and API error codes explains what the codes mean. Handle them appropriately:
request := &getstream.BanRequest{
TargetUserID: "user123",
Reason: getstream.PtrTo("spam"),
Timeout: getstream.PtrTo(60),
BannedByID: getstream.PtrTo("moderator456"),
}
_, err := client.Moderation().Ban(context.Background(), request)
if err != nil {
// Handle error
log.Printf("Failed to ban user: %v", err)
}