Skip to content

Commit ce204d1

Browse files
feat(moderation): add custom check API (#1411)
Co-authored-by: Vishal Narkhede <vishalnarkhede.iitd@gmail.com>
1 parent 745c607 commit ce204d1

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/moderation.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
QueryModerationConfigsFilters,
1919
QueryModerationConfigsSort,
2020
Pager,
21+
CustomCheckFlag,
22+
ReviewQueueItem,
2123
} from './types';
2224
import { StreamChat } from './client';
2325
import { normalizeQuerySort } from './utils';
@@ -255,4 +257,49 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
255257
options,
256258
});
257259
}
260+
261+
/**
262+
*
263+
* @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
264+
* @param {string} entityID string ID of the entity to be checked. This is mainly for tracking purposes
265+
* @param {string} entityCreatorID string ID of the entity creator
266+
* @param {object} moderationPayload object Content to be checked for moderation. E.g., { texts: ['text1', 'text2'], images: ['image1', 'image2']}
267+
* @param {Array} moderationPayload.texts array Array of texts to be checked for moderation
268+
* @param {Array} moderationPayload.images array Array of images to be checked for moderation
269+
* @param {Array} moderationPayload.videos array Array of videos to be checked for moderation
270+
* @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the entity
271+
* @returns
272+
*/
273+
async addCustomFlags(
274+
entityType: string,
275+
entityID: string,
276+
entityCreatorID: string,
277+
moderationPayload: {
278+
images?: string[];
279+
texts?: string[];
280+
videos?: string[];
281+
},
282+
flags: CustomCheckFlag[],
283+
) {
284+
return await this.client.post<{ id: string; item: ReviewQueueItem; status: string } & APIResponse>(
285+
this.client.baseURL + `/api/v2/moderation/custom_check`,
286+
{
287+
entity_type: entityType,
288+
entity_id: entityID,
289+
entity_creator_id: entityCreatorID,
290+
moderation_payload: moderationPayload,
291+
flags,
292+
},
293+
);
294+
}
295+
296+
/**
297+
* Add custom flags to a message
298+
* @param {string} messageID Message ID to be flagged
299+
* @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the message
300+
* @returns
301+
*/
302+
async addCustomMessageFlags(messageID: string, flags: CustomCheckFlag[]) {
303+
return await this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
304+
}
258305
}

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,6 +3420,14 @@ export type ReviewQueueItem = {
34203420
updated_at: string;
34213421
};
34223422

3423+
export type CustomCheckFlag = {
3424+
type: string;
3425+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3426+
custom?: Record<string, any>[];
3427+
labels?: string[];
3428+
reason?: string;
3429+
};
3430+
34233431
export type SubmitActionOptions = {
34243432
ban?: {
34253433
channel_ban_only?: boolean;

0 commit comments

Comments
 (0)