mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
feat: Added update message endpoint
This commit is contained in:
parent
a446df4620
commit
7373eea842
@ -1,5 +1,9 @@
|
||||
# 1.6.2 (develop)
|
||||
|
||||
### Feature
|
||||
|
||||
* Added update message endpoint
|
||||
|
||||
### Fixed
|
||||
|
||||
* Proxy configuration improvements
|
||||
|
@ -592,6 +592,26 @@ export const profileStatusSchema: JSONSchema7 = {
|
||||
...isNotEmpty('status'),
|
||||
};
|
||||
|
||||
export const updateMessageSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
number: { type: 'string' },
|
||||
text: { type: 'string' },
|
||||
key: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string' },
|
||||
remoteJid: { type: 'string' },
|
||||
fromMe: { type: 'boolean', enum: [true, false] },
|
||||
},
|
||||
required: ['id', 'fromMe', 'remoteJid'],
|
||||
...isNotEmpty('id', 'remoteJid'),
|
||||
},
|
||||
},
|
||||
...isNotEmpty('number', 'text', 'key'),
|
||||
};
|
||||
|
||||
export const profilePictureSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
ProfileStatusDto,
|
||||
ReadMessageDto,
|
||||
SendPresenceDto,
|
||||
UpdateMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
} from '../dto/chat.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
@ -117,4 +118,9 @@ export class ChatController {
|
||||
logger.verbose('requested removeProfilePicture from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].removeProfilePicture();
|
||||
}
|
||||
|
||||
public async updateMessage({ instanceName }: InstanceDto, data: UpdateMessageDto) {
|
||||
logger.verbose('requested updateMessage from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].updateMessage(data);
|
||||
}
|
||||
}
|
||||
|
@ -100,3 +100,9 @@ export class SendPresenceDto extends Metadata {
|
||||
delay: number;
|
||||
};
|
||||
}
|
||||
|
||||
export class UpdateMessageDto extends Metadata {
|
||||
number: string;
|
||||
key: proto.IMessageKey;
|
||||
text: string;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
profileSchema,
|
||||
profileStatusSchema,
|
||||
readMessageSchema,
|
||||
updateMessageSchema,
|
||||
whatsappNumberSchema,
|
||||
} from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
@ -28,6 +29,7 @@ import {
|
||||
ProfileStatusDto,
|
||||
ReadMessageDto,
|
||||
SendPresenceDto,
|
||||
UpdateMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
} from '../dto/chat.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
@ -364,6 +366,23 @@ export class ChatRouter extends RouterBroker {
|
||||
execute: (instance) => chatController.removeProfilePicture(instance),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateMessage'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in updateMessage');
|
||||
logger.verbose('request body: ');
|
||||
logger.verbose(req.body);
|
||||
|
||||
logger.verbose('request query: ');
|
||||
logger.verbose(req.query);
|
||||
|
||||
const response = await this.dataValidate<UpdateMessageDto>({
|
||||
request: req,
|
||||
schema: updateMessageSchema,
|
||||
ClassRef: UpdateMessageDto,
|
||||
execute: (instance, data) => chatController.updateMessage(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
});
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ import {
|
||||
PrivacySettingDto,
|
||||
ReadMessageDto,
|
||||
SendPresenceDto,
|
||||
UpdateMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
} from '../dto/chat.dto';
|
||||
import {
|
||||
@ -3529,6 +3530,21 @@ export class WAStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
public async updateMessage(data: UpdateMessageDto) {
|
||||
try {
|
||||
const jid = this.createJid(data.number);
|
||||
|
||||
this.logger.verbose('Updating message');
|
||||
return await this.client.sendMessage(jid, {
|
||||
text: data.text,
|
||||
edit: data.key,
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw new BadRequestException(error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Group
|
||||
public async createGroup(create: CreateGroupDto) {
|
||||
this.logger.verbose('Creating group: ' + create.subject);
|
||||
|
Loading…
Reference in New Issue
Block a user