Skip to content

Commit

Permalink
feat(moderation): add custom check API (#1411)
Browse files Browse the repository at this point in the history
Co-authored-by: Vishal Narkhede <[email protected]>
  • Loading branch information
varbhat and vishalnarkhede authored Dec 19, 2024
1 parent 745c607 commit ce204d1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
QueryModerationConfigsFilters,
QueryModerationConfigsSort,
Pager,
CustomCheckFlag,
ReviewQueueItem,
} from './types';
import { StreamChat } from './client';
import { normalizeQuerySort } from './utils';
Expand Down Expand Up @@ -255,4 +257,49 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
options,
});
}

/**
*
* @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
* @param {string} entityID string ID of the entity to be checked. This is mainly for tracking purposes
* @param {string} entityCreatorID string ID of the entity creator
* @param {object} moderationPayload object Content to be checked for moderation. E.g., { texts: ['text1', 'text2'], images: ['image1', 'image2']}
* @param {Array} moderationPayload.texts array Array of texts to be checked for moderation
* @param {Array} moderationPayload.images array Array of images to be checked for moderation
* @param {Array} moderationPayload.videos array Array of videos to be checked for moderation
* @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the entity
* @returns
*/
async addCustomFlags(
entityType: string,
entityID: string,
entityCreatorID: string,
moderationPayload: {
images?: string[];
texts?: string[];
videos?: string[];
},
flags: CustomCheckFlag[],
) {
return await this.client.post<{ id: string; item: ReviewQueueItem; status: string } & APIResponse>(
this.client.baseURL + `/api/v2/moderation/custom_check`,
{
entity_type: entityType,
entity_id: entityID,
entity_creator_id: entityCreatorID,
moderation_payload: moderationPayload,
flags,
},
);
}

/**
* Add custom flags to a message
* @param {string} messageID Message ID to be flagged
* @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the message
* @returns
*/
async addCustomMessageFlags(messageID: string, flags: CustomCheckFlag[]) {
return await this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
}
}
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3420,6 +3420,14 @@ export type ReviewQueueItem = {
updated_at: string;
};

export type CustomCheckFlag = {
type: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
custom?: Record<string, any>[];
labels?: string[];
reason?: string;
};

export type SubmitActionOptions = {
ban?: {
channel_ban_only?: boolean;
Expand Down

0 comments on commit ce204d1

Please sign in to comment.