Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: moderation endpoints for query and delete config and check api #1387

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion src/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ModerationMuteOptions,
GetUserModerationReportOptions,
SubmitActionOptions,
QueryModerationConfigsFilters,
QueryModerationConfigsSort,
} from './types';
import { StreamChat } from './client';
import { normalizeQuerySort } from './utils';
Expand Down Expand Up @@ -181,6 +183,28 @@
return await this.client.get<GetConfigResponse>(this.client.baseURL + '/api/v2/moderation/config/' + key);
}

async deleteConfig(key: string) {
return await this.client.delete(this.client.baseURL + '/api/v2/moderation/config/' + key);
}

/**
* Query moderation configs
* @param {Object} filterConditions Filter conditions for querying moderation configs
* @param {Object} sort Sort conditions for querying moderation configs
* @param {Object} options Additional options for querying moderation configs
*/
async queryConfigs(
filterConditions: QueryModerationConfigsFilters,
sort: QueryModerationConfigsSort,
options: Record<string, any>,
) {
return await this.client.post(this.client.baseURL + '/api/v2/moderation/configs', {
filter: filterConditions,
sort,
...options,
});
}

async submitAction(actionType: string, itemID: string, options: SubmitActionOptions = {}) {
return await this.client.post<{ item_id: string } & APIResponse>(
this.client.baseURL + '/api/v2/moderation/submit_action',
Expand All @@ -191,4 +215,42 @@
},
);
}
}

/**
*
* @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 configKey
* @param options
* @returns
*/
async check(
entityType: string,
entityID: string,
entityCreatorID: string,
moderationPayload: {
custom?: Record<string, any>;
images?: string[];
texts?: string[];
videos?: string[];
},
configKey: string,
options?: {
force_sync?: boolean;
},
) {
return await this.client.post(this.client.baseURL + `/api/v2/moderation/check`, {
entity_type: entityType,
entity_id: entityID,
entity_creator_id: entityCreatorID,
moderation_payload: moderationPayload,
config_key: configKey,
options,
});
}

12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3321,6 +3321,16 @@ export type GetUserModerationReportResponse<StreamChatGenerics extends Extendabl
user_mutes?: Mute<StreamChatGenerics>[];
};

export type QueryModerationConfigsFilters = QueryFilters<
{
key?: string;
} & {
created_at?: PrimitiveFilter<string>;
} & {
updated_at?: PrimitiveFilter<string>;
}
>;

export type ReviewQueueFilters = QueryFilters<
{
assigned_to?:
Expand Down Expand Up @@ -3377,6 +3387,8 @@ export type ReviewQueueSort =
| Sort<Pick<ReviewQueueItem, 'id' | 'created_at' | 'updated_at'>>
| Array<Sort<Pick<ReviewQueueItem, 'id' | 'created_at' | 'updated_at'>>>;

export type QueryModerationConfigsSort = Array<Sort<'key' | 'created_at' | 'updated_at'>>;

export type ReviewQueuePaginationOptions = Pager;

export type ReviewQueueResponse = {
Expand Down
Loading