mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
fix: status on send message
This commit is contained in:
parent
1f6473cfd5
commit
0f7c2437bc
@ -1,4 +1,4 @@
|
||||
# 2.1.2 (2024-10-06 09:47)
|
||||
# 2.1.2 (develop)
|
||||
|
||||
### Features
|
||||
|
||||
|
@ -7,6 +7,7 @@ import { ChannelStartupService } from '@api/services/channel.service';
|
||||
import { Events, wa } from '@api/types/wa.types';
|
||||
import { Chatwoot, ConfigService, Openai } from '@config/env.config';
|
||||
import { BadRequestException, InternalServerErrorException } from '@exceptions';
|
||||
import { status } from '@utils/renderStatus';
|
||||
import { isURL } from 'class-validator';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
import mime from 'mime';
|
||||
@ -273,72 +274,59 @@ export class EvolutionStartupService extends ChannelStartupService {
|
||||
|
||||
const messageId = v4();
|
||||
|
||||
let messageRaw: any;
|
||||
let messageRaw: any = {
|
||||
key: { fromMe: true, id: messageId, remoteJid: number },
|
||||
messageTimestamp: Math.round(new Date().getTime() / 1000),
|
||||
webhookUrl,
|
||||
source: 'unknown',
|
||||
instanceId: this.instanceId,
|
||||
status: status[1],
|
||||
};
|
||||
|
||||
if (message?.mediaType === 'image') {
|
||||
messageRaw = {
|
||||
key: { fromMe: true, id: messageId, remoteJid: number },
|
||||
...messageRaw,
|
||||
message: {
|
||||
mediaUrl: message.media,
|
||||
quoted,
|
||||
},
|
||||
messageType: 'imageMessage',
|
||||
messageTimestamp: Math.round(new Date().getTime() / 1000),
|
||||
webhookUrl,
|
||||
source: 'unknown',
|
||||
instanceId: this.instanceId,
|
||||
};
|
||||
} else if (message?.mediaType === 'video') {
|
||||
messageRaw = {
|
||||
key: { fromMe: true, id: messageId, remoteJid: number },
|
||||
...messageRaw,
|
||||
message: {
|
||||
mediaUrl: message.media,
|
||||
quoted,
|
||||
},
|
||||
messageType: 'videoMessage',
|
||||
messageTimestamp: Math.round(new Date().getTime() / 1000),
|
||||
webhookUrl,
|
||||
source: 'unknown',
|
||||
instanceId: this.instanceId,
|
||||
};
|
||||
} else if (message?.mediaType === 'audio') {
|
||||
messageRaw = {
|
||||
key: { fromMe: true, id: messageId, remoteJid: number },
|
||||
...messageRaw,
|
||||
message: {
|
||||
mediaUrl: message.media,
|
||||
quoted,
|
||||
},
|
||||
messageType: 'audioMessage',
|
||||
messageTimestamp: Math.round(new Date().getTime() / 1000),
|
||||
webhookUrl,
|
||||
source: 'unknown',
|
||||
instanceId: this.instanceId,
|
||||
};
|
||||
} else if (message?.mediaType === 'document') {
|
||||
messageRaw = {
|
||||
key: { fromMe: true, id: messageId, remoteJid: number },
|
||||
...messageRaw,
|
||||
message: {
|
||||
mediaUrl: message.media,
|
||||
quoted,
|
||||
},
|
||||
messageType: 'documentMessage',
|
||||
messageTimestamp: Math.round(new Date().getTime() / 1000),
|
||||
webhookUrl,
|
||||
source: 'unknown',
|
||||
instanceId: this.instanceId,
|
||||
};
|
||||
} else {
|
||||
messageRaw = {
|
||||
key: { fromMe: true, id: messageId, remoteJid: number },
|
||||
...messageRaw,
|
||||
message: {
|
||||
...message,
|
||||
quoted,
|
||||
},
|
||||
messageType: 'conversation',
|
||||
messageTimestamp: Math.round(new Date().getTime() / 1000),
|
||||
webhookUrl,
|
||||
source: 'unknown',
|
||||
instanceId: this.instanceId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -484,10 +472,10 @@ export class EvolutionStartupService extends ChannelStartupService {
|
||||
const mediaData: SendAudioDto = { ...data };
|
||||
|
||||
if (file?.buffer) {
|
||||
mediaData.audio = file.buffer.toString('base64');
|
||||
mediaData.audio = file.buffer.toString('base64');
|
||||
} else {
|
||||
console.error("El archivo o buffer no está definido correctamente.");
|
||||
throw new Error("File or buffer is undefined.");
|
||||
console.error('El archivo o buffer no est<73> definido correctamente.');
|
||||
throw new Error('File or buffer is undefined.');
|
||||
}
|
||||
|
||||
const message = await this.processAudio(mediaData.audio, data.number);
|
||||
|
@ -22,6 +22,7 @@ import { ChannelStartupService } from '@api/services/channel.service';
|
||||
import { Events, wa } from '@api/types/wa.types';
|
||||
import { Chatwoot, ConfigService, Database, Openai, S3, WaBusiness } from '@config/env.config';
|
||||
import { BadRequestException, InternalServerErrorException } from '@exceptions';
|
||||
import { status } from '@utils/renderStatus';
|
||||
import axios from 'axios';
|
||||
import { arrayUnique, isURL } from 'class-validator';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
@ -895,12 +896,12 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
|
||||
const messageRaw: any = {
|
||||
key: { fromMe: true, id: messageSent?.messages[0]?.id, remoteJid: this.createJid(number) },
|
||||
//pushName: messageSent.pushName,
|
||||
message: this.convertMessageToRaw(message, content),
|
||||
messageType: this.renderMessageType(content.type),
|
||||
messageTimestamp: (messageSent?.messages[0]?.timestamp as number) || Math.round(new Date().getTime() / 1000),
|
||||
instanceId: this.instanceId,
|
||||
webhookUrl,
|
||||
status: status[1],
|
||||
source: 'unknown',
|
||||
};
|
||||
|
||||
@ -1082,11 +1083,10 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
const mediaData: SendAudioDto = { ...data };
|
||||
|
||||
if (file?.buffer) {
|
||||
// Asegurarse de que file y buffer existen antes de usarlos
|
||||
mediaData.audio = file.buffer.toString('base64');
|
||||
mediaData.audio = file.buffer.toString('base64');
|
||||
} else {
|
||||
console.error('El archivo no tiene buffer o file es undefined');
|
||||
throw new Error('File or buffer is undefined');
|
||||
console.error('El archivo no tiene buffer o file es undefined');
|
||||
throw new Error('File or buffer is undefined');
|
||||
}
|
||||
|
||||
const message = await this.processAudio(mediaData.audio, data.number);
|
||||
|
@ -72,6 +72,7 @@ import { Boom } from '@hapi/boom';
|
||||
import { Instance } from '@prisma/client';
|
||||
import { makeProxyAgent } from '@utils/makeProxyAgent';
|
||||
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
|
||||
import { status } from '@utils/renderStatus';
|
||||
import useMultiFileAuthStatePrisma from '@utils/use-multi-file-auth-state-prisma';
|
||||
import { AuthStateProvider } from '@utils/use-multi-file-auth-state-provider-files';
|
||||
import { useMultiFileAuthStateRedisDb } from '@utils/use-multi-file-auth-state-redis-db';
|
||||
@ -569,7 +570,6 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const isGroupJid = this.localSettings.groupsIgnore && isJidGroup(jid);
|
||||
const isBroadcast = !this.localSettings.readStatus && isJidBroadcast(jid);
|
||||
const isNewsletter = isJidNewsletter(jid);
|
||||
// const isNewsletter = jid && jid.includes('newsletter');
|
||||
|
||||
return isGroupJid || isBroadcast || isNewsletter;
|
||||
},
|
||||
@ -1230,14 +1230,6 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
},
|
||||
|
||||
'messages.update': async (args: WAMessageUpdate[], settings: any) => {
|
||||
const status: Record<number, wa.StatusMessage> = {
|
||||
0: 'ERROR',
|
||||
1: 'PENDING',
|
||||
2: 'SERVER_ACK',
|
||||
3: 'DELIVERY_ACK',
|
||||
4: 'READ',
|
||||
5: 'PLAYED',
|
||||
};
|
||||
for await (const { key, update } of args) {
|
||||
if (settings?.groupsIgnore && key.remoteJid?.includes('@g.us')) {
|
||||
return;
|
||||
@ -2575,46 +2567,46 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const mediaData: SendAudioDto = { ...data };
|
||||
|
||||
if (file?.buffer) {
|
||||
mediaData.audio = file.buffer.toString('base64');
|
||||
mediaData.audio = file.buffer.toString('base64');
|
||||
} else if (!isURL(data.audio) && !isBase64(data.audio)) {
|
||||
console.error('Invalid file or audio source');
|
||||
throw new BadRequestException('File buffer, URL, or base64 audio is required');
|
||||
console.error('Invalid file or audio source');
|
||||
throw new BadRequestException('File buffer, URL, or base64 audio is required');
|
||||
}
|
||||
|
||||
if (!data?.encoding && data?.encoding !== false) {
|
||||
data.encoding = true;
|
||||
data.encoding = true;
|
||||
}
|
||||
|
||||
if (data?.encoding) {
|
||||
const convert = await this.processAudio(mediaData.audio);
|
||||
const convert = await this.processAudio(mediaData.audio);
|
||||
|
||||
if (Buffer.isBuffer(convert)) {
|
||||
const result = this.sendMessageWithTyping<AnyMessageContent>(
|
||||
data.number,
|
||||
{
|
||||
audio: convert,
|
||||
ptt: true,
|
||||
mimetype: 'audio/ogg; codecs=opus',
|
||||
},
|
||||
{ presence: 'recording', delay: data?.delay },
|
||||
isIntegration,
|
||||
);
|
||||
if (Buffer.isBuffer(convert)) {
|
||||
const result = this.sendMessageWithTyping<AnyMessageContent>(
|
||||
data.number,
|
||||
{
|
||||
audio: convert,
|
||||
ptt: true,
|
||||
mimetype: 'audio/ogg; codecs=opus',
|
||||
},
|
||||
{ presence: 'recording', delay: data?.delay },
|
||||
isIntegration,
|
||||
);
|
||||
|
||||
return result;
|
||||
} else {
|
||||
throw new InternalServerErrorException('Failed to convert audio');
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
throw new InternalServerErrorException('Failed to convert audio');
|
||||
}
|
||||
}
|
||||
|
||||
return await this.sendMessageWithTyping<AnyMessageContent>(
|
||||
data.number,
|
||||
{
|
||||
audio: isURL(data.audio) ? { url: data.audio } : Buffer.from(data.audio, 'base64'),
|
||||
ptt: true,
|
||||
mimetype: 'audio/ogg; codecs=opus',
|
||||
},
|
||||
{ presence: 'recording', delay: data?.delay },
|
||||
isIntegration,
|
||||
data.number,
|
||||
{
|
||||
audio: isURL(data.audio) ? { url: data.audio } : Buffer.from(data.audio, 'base64'),
|
||||
ptt: true,
|
||||
mimetype: 'audio/ogg; codecs=opus',
|
||||
},
|
||||
{ presence: 'recording', delay: data?.delay },
|
||||
isIntegration,
|
||||
);
|
||||
}
|
||||
|
||||
@ -3659,7 +3651,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const messageRaw = {
|
||||
key: message.key,
|
||||
pushName: message.pushName,
|
||||
status: message.status,
|
||||
status: status[message.status],
|
||||
message: { ...message.message },
|
||||
contextInfo: contentMsg?.contextInfo,
|
||||
messageType: contentType || 'unknown',
|
||||
|
10
src/utils/renderStatus.ts
Normal file
10
src/utils/renderStatus.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { wa } from '@api/types/wa.types';
|
||||
|
||||
export const status: Record<number, wa.StatusMessage> = {
|
||||
0: 'ERROR',
|
||||
1: 'PENDING',
|
||||
2: 'SERVER_ACK',
|
||||
3: 'DELIVERY_ACK',
|
||||
4: 'READ',
|
||||
5: 'PLAYED',
|
||||
};
|
Loading…
Reference in New Issue
Block a user