Skip to content

Commit 1d8f3bb

Browse files
feat: username moderation endpoint
1 parent 3a7f732 commit 1d8f3bb

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/moderation.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { normalizeQuerySort } from './utils';
2828
export const MODERATION_ENTITY_TYPES = {
2929
user: 'stream:user',
3030
message: 'stream:chat:v1:message',
31+
userprofile: 'stream:v1:user_profile',
3132
};
3233

3334
// Moderation class provides all the endpoints related to moderation v2.
@@ -247,6 +248,7 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
247248
configKey: string,
248249
options?: {
249250
force_sync?: boolean;
251+
test_mode?: boolean;
250252
},
251253
) {
252254
return await this.client.post(this.client.baseURL + `/api/v2/moderation/check`, {
@@ -259,6 +261,52 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
259261
});
260262
}
261263

264+
/**
265+
* Experimental: Check user profile
266+
*
267+
* Warning: This is an experimental feature and the API is subject to change.
268+
*
269+
* This function is used to check a user profile for moderation.
270+
* This will not create any review queue items for the user profile.
271+
* You can just use this to check weather to allow certain user profile to be created or not.
272+
*
273+
* Example:
274+
*
275+
* ```ts
276+
* const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", profileImage: "https://example.com/profile.jpg" });
277+
* if (res.recommended_action === "remove") {
278+
* // Block the user profile from being created
279+
* } else {
280+
* // Allow the user profile to be created
281+
* }
282+
* ```
283+
*
284+
* @param userId
285+
* @param username
286+
* @param profileImage
287+
* @returns
288+
*/
289+
async checkUserProfile(userId: string, profile: { profileImage?: string, username?: string; } = {}) {
290+
if (!profile.username && !profile.profileImage) {
291+
throw new Error('Either username or profileImage must be provided');
292+
}
293+
294+
return await this.check(
295+
MODERATION_ENTITY_TYPES.userprofile,
296+
userId,
297+
userId,
298+
{
299+
texts: [profile.username as string],
300+
images: [profile.profileImage as string],
301+
},
302+
'user_profile:default',
303+
{
304+
force_sync: true,
305+
test_mode: true,
306+
},
307+
);
308+
}
309+
262310
/**
263311
*
264312
* @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string

0 commit comments

Comments
 (0)