mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 18:38:39 -06:00
feat: new parameters to fetchAllGroups
This commit is contained in:
parent
549ecd8801
commit
ba5539b4e2
@ -6,8 +6,9 @@ import { validate } from 'jsonschema';
|
|||||||
|
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { BadRequestException } from '../../exceptions';
|
import { BadRequestException } from '../../exceptions';
|
||||||
import { GetParticipant, GroupInvite } from '../dto/group.dto';
|
import { FetchAllGroupsDto, GroupInvite } from '../dto/group.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { fetchAllGroupsSchema } from '../../validate/validate.schema';
|
||||||
|
|
||||||
type DataValidate<T> = {
|
type DataValidate<T> = {
|
||||||
request: Request;
|
request: Request;
|
||||||
@ -186,25 +187,25 @@ export abstract class RouterBroker {
|
|||||||
return await execute(instance, ref);
|
return await execute(instance, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getParticipantsValidate<T>(args: DataValidate<T>) {
|
public async fetchAllGroupsValidate<T>(args: DataValidate<T>) {
|
||||||
const { request, ClassRef, schema, execute } = args;
|
const { request, ClassRef, schema, execute } = args;
|
||||||
|
|
||||||
const getParticipants = request.query as unknown as GetParticipant;
|
const fetchAllGroups = request.query as unknown as FetchAllGroupsDto;
|
||||||
|
|
||||||
if (!getParticipants?.getParticipants) {
|
if (!fetchAllGroups?.getParticipants) {
|
||||||
throw new BadRequestException('The getParticipants needs to be informed in the query');
|
throw new BadRequestException('The getParticipants needs to be informed in the query');
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = request.params as unknown as InstanceDto;
|
const instance = request.params as unknown as InstanceDto;
|
||||||
const body = request.body;
|
const body = request.body;
|
||||||
|
|
||||||
const ref = new ClassRef();
|
const ref = new ClassRef();
|
||||||
|
|
||||||
Object.assign(body, getParticipants);
|
Object.assign(body, fetchAllGroups);
|
||||||
Object.assign(ref, body);
|
Object.assign(ref, body);
|
||||||
|
|
||||||
const v = validate(ref, schema);
|
const v = validate(ref, schema || fetchAllGroupsSchema);
|
||||||
|
|
||||||
if (!v.valid) {
|
if (!v.valid) {
|
||||||
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||||
let message: string;
|
let message: string;
|
||||||
@ -221,7 +222,7 @@ export abstract class RouterBroker {
|
|||||||
logger.error([...message]);
|
logger.error([...message]);
|
||||||
throw new BadRequestException(...message);
|
throw new BadRequestException(...message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await execute(instance, ref);
|
return await execute(instance, ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { Logger } from '../../config/logger.config';
|
|||||||
import {
|
import {
|
||||||
AcceptGroupInvite,
|
AcceptGroupInvite,
|
||||||
CreateGroupDto,
|
CreateGroupDto,
|
||||||
GetParticipant,
|
FetchAllGroupsDto,
|
||||||
GroupDescriptionDto,
|
GroupDescriptionDto,
|
||||||
GroupInvite,
|
GroupInvite,
|
||||||
GroupJid,
|
GroupJid,
|
||||||
@ -46,9 +46,9 @@ export class GroupController {
|
|||||||
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
|
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAllGroups(instance: InstanceDto, getPaticipants: GetParticipant) {
|
public async fetchAllGroups(instance: InstanceDto, fetchAllGroupsData: FetchAllGroupsDto) {
|
||||||
logger.verbose('requested fetchAllGroups from ' + instance.instanceName + ' instance');
|
logger.verbose('requested fetchAllGroups from ' + instance.instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].fetchAllGroups(getPaticipants);
|
return await this.waMonitor.waInstances[instance.instanceName].fetchAllGroups(fetchAllGroupsData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async inviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
public async inviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
||||||
|
@ -24,8 +24,10 @@ export class GroupJid {
|
|||||||
groupJid: string;
|
groupJid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetParticipant {
|
export class FetchAllGroupsDto {
|
||||||
getParticipants: string;
|
getParticipants: string;
|
||||||
|
getProfilePicture?: string;
|
||||||
|
delay?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GroupInvite {
|
export class GroupInvite {
|
||||||
|
@ -4,6 +4,7 @@ import { Logger } from '../../config/logger.config';
|
|||||||
import {
|
import {
|
||||||
AcceptGroupInviteSchema,
|
AcceptGroupInviteSchema,
|
||||||
createGroupSchema,
|
createGroupSchema,
|
||||||
|
fetchAllGroupsSchema,
|
||||||
getParticipantsSchema,
|
getParticipantsSchema,
|
||||||
groupInviteSchema,
|
groupInviteSchema,
|
||||||
groupJidSchema,
|
groupJidSchema,
|
||||||
@ -19,7 +20,7 @@ import { RouterBroker } from '../abstract/abstract.router';
|
|||||||
import {
|
import {
|
||||||
AcceptGroupInvite,
|
AcceptGroupInvite,
|
||||||
CreateGroupDto,
|
CreateGroupDto,
|
||||||
GetParticipant,
|
FetchAllGroupsDto,
|
||||||
GroupDescriptionDto,
|
GroupDescriptionDto,
|
||||||
GroupInvite,
|
GroupInvite,
|
||||||
GroupJid,
|
GroupJid,
|
||||||
@ -127,10 +128,10 @@ export class GroupRouter extends RouterBroker {
|
|||||||
|
|
||||||
logger.verbose('request query: ');
|
logger.verbose('request query: ');
|
||||||
logger.verbose(req.query);
|
logger.verbose(req.query);
|
||||||
const response = await this.getParticipantsValidate<GetParticipant>({
|
const response = await this.fetchAllGroupsValidate<FetchAllGroupsDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: getParticipantsSchema,
|
schema: fetchAllGroupsSchema,
|
||||||
ClassRef: GetParticipant,
|
ClassRef: FetchAllGroupsDto,
|
||||||
execute: (instance, data) => groupController.fetchAllGroups(instance, data),
|
execute: (instance, data) => groupController.fetchAllGroups(instance, data),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
AcceptGroupInvite,
|
AcceptGroupInvite,
|
||||||
CreateGroupDto,
|
CreateGroupDto,
|
||||||
GetParticipant,
|
FetchAllGroupsDto,
|
||||||
GroupDescriptionDto,
|
GroupDescriptionDto,
|
||||||
GroupInvite,
|
GroupInvite,
|
||||||
GroupJid,
|
GroupJid,
|
||||||
@ -3293,7 +3293,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAllGroups(getParticipants: GetParticipant) {
|
public async fetchAllGroups(fetchAllGroupsData: FetchAllGroupsDto) {
|
||||||
if (this.localSettings.groups_ignore === true) {
|
if (this.localSettings.groups_ignore === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3303,7 +3303,13 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
const fetch = Object.values(await this.client.groupFetchAllParticipating());
|
const fetch = Object.values(await this.client.groupFetchAllParticipating());
|
||||||
let groups = [];
|
let groups = [];
|
||||||
for (const group of fetch) {
|
for (const group of fetch) {
|
||||||
const picture = await this.profilePicture(group.id);
|
let picture;
|
||||||
|
if (!fetchAllGroupsData.getProfilePicture || fetchAllGroupsData.getProfilePicture != 'false') {
|
||||||
|
picture = await this.profilePicture(group.id);
|
||||||
|
}
|
||||||
|
if (fetchAllGroupsData.delay) {
|
||||||
|
await delay(+fetchAllGroupsData.delay);
|
||||||
|
}
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
id: group.id,
|
id: group.id,
|
||||||
@ -3320,7 +3326,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
announce: group.announce,
|
announce: group.announce,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (getParticipants.getParticipants == 'true') {
|
if (fetchAllGroupsData.getParticipants == 'true') {
|
||||||
result['participants'] = group.participants;
|
result['participants'] = group.participants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1646,6 +1646,19 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: "- required - Indicates whether to retrieve the participants of the group."
|
description: "- required - Indicates whether to retrieve the participants of the group."
|
||||||
|
- name: getProfilePicture
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: boolean
|
||||||
|
required: false
|
||||||
|
description: "Indicates whether to retrieve the profile pictures of the participants."
|
||||||
|
- name: delay
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
pattern: '^\\d+$'
|
||||||
|
required: false
|
||||||
|
description: "Optional delay in milliseconds before the response is sent."
|
||||||
- name: instanceName
|
- name: instanceName
|
||||||
in: path
|
in: path
|
||||||
schema:
|
schema:
|
||||||
|
@ -818,6 +818,18 @@ export const getParticipantsSchema: JSONSchema7 = {
|
|||||||
...isNotEmpty('getParticipants'),
|
...isNotEmpty('getParticipants'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchAllGroupsSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
getParticipants: { type: 'string', enum: ['true', 'false'] },
|
||||||
|
getProfilePicture: { type: 'string', enum: ['true', 'false'] },
|
||||||
|
delay: { type: 'string', pattern: '^\\d+$' },
|
||||||
|
},
|
||||||
|
required: ['getParticipants'],
|
||||||
|
...isNotEmpty('getParticipants'),
|
||||||
|
};
|
||||||
|
|
||||||
export const groupSendInviteSchema: JSONSchema7 = {
|
export const groupSendInviteSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
Loading…
Reference in New Issue
Block a user