mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 20:12:02 -06:00
fix: Update message function to support different message types
The updateMessage function was updated to support different message types such as text, image, and video. A new private function formatUpdateMessage was added to handle the logic of formatting the message based on its type. The function checks the message type and returns the corresponding format for the message. If the message type is not supported, it will return null and throw a BadRequestException. The createJid function is now called in the updateMessage function to get the jid of the recipient. This change improves the flexibility of the updateMessage function and ensures that it can handle different types of messages.
This commit is contained in:
parent
6cb3357f08
commit
b70ab5a4c3
@ -3096,12 +3096,51 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
public async updateMessage(data: UpdateMessageDto) {
|
||||
private async formatUpdateMessage(data: UpdateMessageDto) {
|
||||
try {
|
||||
const jid = this.createJid(data.number);
|
||||
const msg: any = await this.getMessage(data.key, true);
|
||||
|
||||
console.log('msg', msg);
|
||||
if (msg?.messageType === 'conversation' || msg?.messageType === 'extendedTextMessage') {
|
||||
return {
|
||||
text: data.text,
|
||||
};
|
||||
}
|
||||
|
||||
if (msg?.messageType === 'imageMessage') {
|
||||
return {
|
||||
image: msg?.message?.imageMessage,
|
||||
caption: data.text,
|
||||
};
|
||||
}
|
||||
|
||||
if (msg?.messageType === 'videoMessage') {
|
||||
return {
|
||||
video: msg?.message?.videoMessage,
|
||||
caption: data.text,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw new BadRequestException(error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public async updateMessage(data: UpdateMessageDto) {
|
||||
const jid = this.createJid(data.number);
|
||||
|
||||
const options = await this.formatUpdateMessage(data);
|
||||
|
||||
if (!options) {
|
||||
this.logger.error('Message not compatible');
|
||||
throw new BadRequestException('Message not compatible');
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.client.sendMessage(jid, {
|
||||
text: data.text,
|
||||
...(options as any),
|
||||
edit: data.key,
|
||||
});
|
||||
} catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user