Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import {
CustomCheckFlag,
ReviewQueueItem,
QueryConfigsResponse,
RequireAtLeastOne,
} from './types';
import { StreamChat } from './client';
import { normalizeQuerySort } from './utils';

export const MODERATION_ENTITY_TYPES = {
user: 'stream:user',
message: 'stream:chat:v1:message',
userprofile: 'stream:v1:user_profile',
};

// Moderation class provides all the endpoints related to moderation v2.
Expand Down Expand Up @@ -247,6 +249,7 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
configKey: string,
options?: {
force_sync?: boolean;
test_mode?: boolean;
},
) {
return await this.client.post(this.client.baseURL + `/api/v2/moderation/check`, {
Expand All @@ -259,6 +262,57 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
});
}

/**
* Experimental: Check user profile
*
* Warning: This is an experimental feature and the API is subject to change.
*
* This function is used to check a user profile for moderation.
* This will not create any review queue items for the user profile.
* You can just use this to check whether to allow a certain user profile to be created or not.
*
* Example:
*
* ```ts
* const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", image: "https://example.com/profile.jpg" });
* if (res.recommended_action === "remove") {
* // Block the user profile from being created
* } else {
* // Allow the user profile to be created
* }
* ```
*
* @param userId
* @param profile.username
* @param profile.image
* @returns
*/
async checkUserProfile(userId: string, profile: RequireAtLeastOne<{ image?: string; username?: string }>) {
if (!profile.username && !profile.image) {
throw new Error('Either username or image must be provided');
}

const moderationPayload: { images?: string[]; texts?: string[] } = {};
if (profile.username) {
moderationPayload.texts = [profile.username];
}
if (profile.image) {
moderationPayload.images = [profile.image];
}

return await this.check(
MODERATION_ENTITY_TYPES.userprofile,
userId,
userId,
moderationPayload,
'user_profile:default',
{
force_sync: true,
test_mode: true,
},
);
}

/**
*
* @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
Expand Down