mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-19 09:53:36 -06:00
Merge pull request #433 from w3nder/develop
Add blockUser functionality
This commit is contained in:
commit
4f206f67c9
@ -539,6 +539,17 @@ export const privacySettingsSchema: JSONSchema7 = {
|
|||||||
required: ['privacySettings'],
|
required: ['privacySettings'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const blockUserSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
number: { type: 'string' },
|
||||||
|
status: { type: 'string', enum: ['block', 'unblock'] },
|
||||||
|
},
|
||||||
|
required: ['number', 'status'],
|
||||||
|
...isNotEmpty('number', 'status'),
|
||||||
|
};
|
||||||
|
|
||||||
export const archiveChatSchema: JSONSchema7 = {
|
export const archiveChatSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import {
|
import {
|
||||||
ArchiveChatDto,
|
ArchiveChatDto,
|
||||||
|
BlockUserDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
getBase64FromMediaMessageDto,
|
getBase64FromMediaMessageDto,
|
||||||
NumberDto,
|
NumberDto,
|
||||||
@ -123,4 +124,9 @@ export class ChatController {
|
|||||||
logger.verbose('requested updateMessage from ' + instanceName + ' instance');
|
logger.verbose('requested updateMessage from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].updateMessage(data);
|
return await this.waMonitor.waInstances[instanceName].updateMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async blockUser({ instanceName }: InstanceDto, data: BlockUserDto) {
|
||||||
|
logger.verbose('requested blockUser from ' + instanceName + ' instance');
|
||||||
|
return await this.waMonitor.waInstances[instanceName].blockUser(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,3 +115,8 @@ export class UpdateMessageDto extends Metadata {
|
|||||||
key: proto.IMessageKey;
|
key: proto.IMessageKey;
|
||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class BlockUserDto {
|
||||||
|
number: string;
|
||||||
|
status: 'block' | 'unblock';
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { RequestHandler, Router } from 'express';
|
|||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import {
|
import {
|
||||||
archiveChatSchema,
|
archiveChatSchema,
|
||||||
|
blockUserSchema,
|
||||||
contactValidateSchema,
|
contactValidateSchema,
|
||||||
deleteMessageSchema,
|
deleteMessageSchema,
|
||||||
messageUpSchema,
|
messageUpSchema,
|
||||||
@ -20,6 +21,7 @@ import {
|
|||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import {
|
import {
|
||||||
ArchiveChatDto,
|
ArchiveChatDto,
|
||||||
|
BlockUserDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
getBase64FromMediaMessageDto,
|
getBase64FromMediaMessageDto,
|
||||||
NumberDto,
|
NumberDto,
|
||||||
@ -384,6 +386,23 @@ export class ChatRouter extends RouterBroker {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
|
})
|
||||||
|
.put(this.routerPath('updateBlockStatus'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateBlockStatus');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
|
const response = await this.dataValidate<BlockUserDto>({
|
||||||
|
request: req,
|
||||||
|
schema: blockUserSchema,
|
||||||
|
ClassRef: BlockUserDto,
|
||||||
|
execute: (instance, data) => chatController.blockUser(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-d
|
|||||||
import { useMultiFileAuthStateRedisDb } from '../../utils/use-multi-file-auth-state-redis-db';
|
import { useMultiFileAuthStateRedisDb } from '../../utils/use-multi-file-auth-state-redis-db';
|
||||||
import {
|
import {
|
||||||
ArchiveChatDto,
|
ArchiveChatDto,
|
||||||
|
BlockUserDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
getBase64FromMediaMessageDto,
|
getBase64FromMediaMessageDto,
|
||||||
LastMessage,
|
LastMessage,
|
||||||
@ -2796,6 +2797,29 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async blockUser(data: BlockUserDto) {
|
||||||
|
this.logger.verbose('Blocking user: ' + data.number);
|
||||||
|
try {
|
||||||
|
const { number } = data;
|
||||||
|
|
||||||
|
this.logger.verbose(`Check if number "${number}" is WhatsApp`);
|
||||||
|
const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift();
|
||||||
|
|
||||||
|
this.logger.verbose(`Exists: "${isWA.exists}" | jid: ${isWA.jid}`);
|
||||||
|
if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) {
|
||||||
|
throw new BadRequestException(isWA);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sender = isWA.jid;
|
||||||
|
|
||||||
|
await this.client.updateBlockStatus(sender, data.status);
|
||||||
|
|
||||||
|
return { block: 'success' };
|
||||||
|
} catch (error) {
|
||||||
|
throw new InternalServerErrorException('Error blocking user', error.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async updateMessage(data: UpdateMessageDto) {
|
public async updateMessage(data: UpdateMessageDto) {
|
||||||
try {
|
try {
|
||||||
const jid = this.createJid(data.number);
|
const jid = this.createJid(data.number);
|
||||||
|
@ -1159,6 +1159,9 @@ export class BusinessStartupService extends WAStartupService {
|
|||||||
public async removeProfilePicture() {
|
public async removeProfilePicture() {
|
||||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
}
|
}
|
||||||
|
public async blockUser() {
|
||||||
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
|
}
|
||||||
public async updateMessage() {
|
public async updateMessage() {
|
||||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user