Skip to content

Commit bfb64e1

Browse files
vishalnarkhedesanthoshvai
authored andcommitted
feat: user profile check endpoint (#1503)
- [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required). - [ ] Code changes are tested - Added a new endpoint for moderation `checkUserProfile` - Have added clear warning in description that this is subject to introducing breaking changes. - Backend PR: GetStream/chat#8424 --------- Co-authored-by: Santhosh Vaiyapuri <[email protected]>
1 parent 58d9e7b commit bfb64e1

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/moderation.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import {
2121
CustomCheckFlag,
2222
ReviewQueueItem,
2323
QueryConfigsResponse,
24+
RequireAtLeastOne,
2425
} from './types';
2526
import { StreamChat } from './client';
2627
import { normalizeQuerySort } from './utils';
2728

2829
export 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

Comments
 (0)