@@ -21,13 +21,15 @@ import {
2121 CustomCheckFlag ,
2222 ReviewQueueItem ,
2323 QueryConfigsResponse ,
24+ RequireAtLeastOne ,
2425} from './types' ;
2526import { StreamChat } from './client' ;
2627import { normalizeQuerySort } from './utils' ;
2728
2829export const MODERATION_ENTITY_TYPES = {
2930 user : 'stream:user' ,
3031 message : 'stream:chat:v1:message' ,
32+ userprofile : 'stream:v1:user_profile' ,
3133} ;
3234
3335// Moderation class provides all the endpoints related to moderation v2.
@@ -247,6 +249,7 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
247249 configKey : string ,
248250 options ?: {
249251 force_sync ?: boolean ;
252+ test_mode ?: boolean ;
250253 } ,
251254 ) {
252255 return await this . client . post ( this . client . baseURL + `/api/v2/moderation/check` , {
@@ -259,6 +262,57 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
259262 } ) ;
260263 }
261264
265+ /**
266+ * Experimental: Check user profile
267+ *
268+ * Warning: This is an experimental feature and the API is subject to change.
269+ *
270+ * This function is used to check a user profile for moderation.
271+ * This will not create any review queue items for the user profile.
272+ * You can just use this to check whether to allow a certain user profile to be created or not.
273+ *
274+ * Example:
275+ *
276+ * ```ts
277+ * const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", image: "https://example.com/profile.jpg" });
278+ * if (res.recommended_action === "remove") {
279+ * // Block the user profile from being created
280+ * } else {
281+ * // Allow the user profile to be created
282+ * }
283+ * ```
284+ *
285+ * @param userId
286+ * @param profile.username
287+ * @param profile.image
288+ * @returns
289+ */
290+ async checkUserProfile ( userId : string , profile : RequireAtLeastOne < { image ?: string ; username ?: string } > ) {
291+ if ( ! profile . username && ! profile . image ) {
292+ throw new Error ( 'Either username or image must be provided' ) ;
293+ }
294+
295+ const moderationPayload : { images ?: string [ ] ; texts ?: string [ ] } = { } ;
296+ if ( profile . username ) {
297+ moderationPayload . texts = [ profile . username ] ;
298+ }
299+ if ( profile . image ) {
300+ moderationPayload . images = [ profile . image ] ;
301+ }
302+
303+ return await this . check (
304+ MODERATION_ENTITY_TYPES . userprofile ,
305+ userId ,
306+ userId ,
307+ moderationPayload ,
308+ 'user_profile:default' ,
309+ {
310+ force_sync : true ,
311+ test_mode : true ,
312+ } ,
313+ ) ;
314+ }
315+
262316 /**
263317 *
264318 * @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