const client = new StreamChat("api_key", "api_secret");
await client.moderation.upsertConfig({
key: "chat:messaging",
team: "team-a",
ai_text_config: {
rules: [{ label: "SEXUAL_HARASSMENT", action: "flag" }],
},
ai_image_config: {
rules: [{ label: "Non-Explicit Nudity", action: "flag" }],
},
});
Multitenant Moderation
Many applications with chat functionality serve multiple customers or organizations. For example, platforms like Slack or SaaS applications like InVision need to ensure that messages remain private between different customer organizations. Stream Chat addresses this through multi-tenant mode, which organizes users into separate teams that operate independently. For more details on multitenancy setup, see our Multitenancy documentation.
This guide explains how you can provide moderation experience for your customers (tenants) by using team-level moderation policies. This will allow you to build a multitenant dashboard for your customers to manage their moderation policies and also allow them to review flagged content for their team. Basically we are providing you the APIs that Stream users to build the dashboard for their customers and you can use these APIs to build the dashboard for your customers however you want.
Limitations and Prerequisites
- Multi-tenancy is only supported on chat.
- Team level semantic phrase lists are not supported.
Create Moderation Policy
You can create moderation configs at the team level by setting the team
field in the UpsertConfig
API.
Following moderation configuration will be used for all the messages sent to messaging
channel type within the team team-a
.
Server Side Integration
The server-side integration provides full control over moderation configs and is typically used for:
- Initial setup of team moderation policies
- Bulk updates to moderation rules
- Administrative operations
Client Side Integration
Client side access to API allows you to give control to your customers (tenants) to manage their own moderation policies. This is particularly useful when:
- Building a self-service moderation dashboard
- Allowing teams to customize their moderation settings
- Providing real-time moderation management
const client = new StreamChat("api_key");
await client.connectUser({ id: "user-from-team-a" }, token);
// Get all the moderation configs for the team that the user belongs to
const { configs, next } = await client.moderation.upsertConfig({
key: "chat:messaging",
team: "team-a",
ai_text_config: {
rules: [{ label: "SEXUAL_HARASSMENT", action: "flag" }],
},
ai_image_config: {
rules: [{ label: "Non-Explicit Nudity", action: "flag" }],
},
});
Please check AI Text Supported Harm Categories and AI Image Supported Harm Categories for the list of supported harm categories.
Moderation Policy Scopes
The scope of moderation policies is determined by the combination of the config key and team field. Here’s a detailed breakdown:
Config Key | Team Field | Scope | Use Case |
---|---|---|---|
chat | Applies to all channels across all teams | Global moderation policies | |
chat | team-a | Applies to all channels in team-a | Team-wide policies |
chat:messaging | Applies to messaging channels across all teams | Channel-type specific policies | |
chat:messaging | team-a | Applies to messaging channels in team-a | Team-specific channel type policies |
chat:messaging:<channel_id> | Applies to channel with id channel_id irrespective of team | Channel-specific policies | |
chat:messaging:<channel_id> | team-a | Applies to channel with id channel_id in team-a | Team-specific channel policies |
Query Moderation Policies
You can query moderation configs at the team level to:
- Audit existing moderation policies
- Review team-specific settings
- Monitor policy changes
Using Server side integration
The server-side query provides comprehensive access to all moderation configs:
const client = new StreamChat("api_key", "api_secret");
// Get all the moderation configs for all the teams
const { configs, next } = await client.moderation.queryConfigs({}, [], {
limit: 2,
});
// Get all the moderation configs for the team `team-a`
const { configs, next } = await client.moderation.queryConfigs(
{
team: "team-a",
},
[{ field: "created_at", direction: -1 }],
{ limit: 2 },
);
Using Client side integration
Client-side queries are restricted to the team context of the authenticated user:
const client = new StreamChat("api_key");
await client.connectUser({ id: "little-lake-2" }, token);
// Get all the moderation configs for the team that the user belongs to
const { configs, next } = await client.moderation.queryConfigs({}, [], {
limit: 2,
});
Query Review Queue
The review queue is a crucial component of the moderation system that allows teams to:
- Review flagged content
- Take action on moderated messages
- Track moderation history
- Maintain audit trails
You can query the review queue at the team level to using QueryReviewQueue
API.
Server Side Integration
Server-side access provides complete control over the review queue:
const client = new StreamChat("api_key", "api_secret");
// Get all the review queue for all the teams
const { reviews, next } = await client.moderation.queryReviewQueue({}, [], {
limit: 2,
});
// Get all the review queue for the team `team-a`
const { reviews, next } = await client.moderation.queryReviewQueue(
{ teams: "team-a" },
[{ field: "created_at", direction: -1 }],
{ limit: 2 },
);
// Get all the review queue for the team `team-a` and `team-b`
const { reviews, next } = await client.moderation.queryReviewQueue(
{ teams: { $in: ["team-a", "team-b"] } },
[{ field: "created_at", direction: -1 }],
{ limit: 2 },
);
Client Side Integration
The client-side review queue access enables building custom moderation dashboards:
const client = new StreamChat("api_key");
await client.connectUser({ id: "admin-from-team-a" }, token);
// Get all the review queue for all the teams that the user belongs to.
const { reviews, next } = await client.moderation.queryReviewQueue({}, [], {
limit: 2,
});
// Get all the review queue for the team `team-a`
// This will return all the review queue for the team `team-a`, only if the user belongs to `team-a`
const { reviews, next } = await client.moderation.queryReviewQueue(
{
team: "team-a",
},
[{ field: "created_at", direction: -1 }],
{ limit: 2 },
);
Team level blocklists
Team level blocklists gives your customers the ability to manage blocklists for their team. These blocklists can be used in moderation policies to flag or remove messages that contain specific words or phrases.
CRUD APIs to maintain team level blocklists are accessible on client side integration. This means that you can build a custom moderation dashboard for your teams to maintain the blocklists. Its important to note that team level blocklists can only be created/updated/deleted by team admins and moderators who have the following permissions:
CreateBlockList
UpdateBlockList
ReadBlockLists
DeleteBlockList
Limitations
- Maximum 4 blocklists per team
- Maximum 20,000 blocklists per app (including global blocklists)
- Maximum 200,000 words in total across all blocklists of an app
Create a Team Level Blocklist
You can create a blocklist specific to a team using the following code:
await client.createBlockList({
name: "myblocklist",
team: "team-a",
words: ["bad-word-1", "bad-word-2"],
type: "word",
});
Update a Team Level Blocklist
To update an existing team blocklist:
await client.updateBlockList("myblocklist", {
words: ["test3", "test4"],
team: "team-a",
});
Delete a Team Level Blocklist
To delete a team blocklist:
await client.deleteBlockList("myblocklist", {
team: "team-a",
});
List Blocklists
You can list both global and team-specific blocklists:
// List global blocklists
const globalBlocklists = await client.listBlocklists();
// List team specific blocklists
const teamBlocklists = await client.listBlocklists({ team: "team-a" });
Using Blocklists in Team Level Moderation Configuration
You can use both global and team level blocklists in your team’s moderation configuration:
await client.moderation.upsertConfig({
key: "chat:messaging",
team: "team-a",
blocklist_config: {
rules: [
// team level blocklist
{
name: "my_team_blocklist",
team: "team-a",
action: "remove",
},
// global blocklist
{
name: "my_global_blocklist",
action: "flag",
},
],
},
});
Dashboard Support for Multitenancy Moderation
You can manage team level moderation policies and blocklists from the dashboard as following.
Create Team Level Moderation Policy
You can create a team level moderation policy from the dashboard as following:
- Navigate to “Policies” page in left sidebar
- Click on ”+ Add New” button, which will open a modal to create a new moderation policy
- Select “Chat” as product
- On this modal, you will see an input field to assign a team to the policy
Once you press “Save” button, the policy will be created for the team you selected.
In the policies list, you will see a team column which will show the team to which the policy belongs.
Team Level Blocklists
You can create a team blocklist from the dashboard as following:
- Navigate to “Policies” page in left sidebar
- Select a team policy (or team level moderation configuration) where you want to add the blocklist
- Scroll down to “Blocklists & Regex Filters” section
- Click on ”+ Add New” button, which will open a modal to create a new blocklist
- On this modal, you will see a checkbox to mark this blocklist as team level blocklist
The team blocklists will be shown in the moderation policy as following: