mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 20:22:54 -06:00
fix: Update message model and enhance media handling in Baileys service
- Changed the type of `message` in `MessageRaw` from `object` to `any` for better flexibility. - Improved media message handling in `BaileysStartupService` to support base64 encoding for various media types, enhancing webhook functionality. - Added logging for media message detection to aid in debugging.
This commit is contained in:
parent
2d9ca15d74
commit
f95727edbf
@ -24,7 +24,7 @@ export class MessageRaw {
|
|||||||
key?: Key;
|
key?: Key;
|
||||||
pushName?: string;
|
pushName?: string;
|
||||||
participant?: string;
|
participant?: string;
|
||||||
message?: object;
|
message?: any;
|
||||||
messageType?: string;
|
messageType?: string;
|
||||||
messageTimestamp?: number | Long;
|
messageTimestamp?: number | Long;
|
||||||
owner: string;
|
owner: string;
|
||||||
|
@ -64,6 +64,7 @@ import {
|
|||||||
Log,
|
Log,
|
||||||
ProviderSession,
|
ProviderSession,
|
||||||
QrCode,
|
QrCode,
|
||||||
|
Websocket,
|
||||||
} from '../../../config/env.config';
|
} from '../../../config/env.config';
|
||||||
import { INSTANCE_DIR } from '../../../config/path.config';
|
import { INSTANCE_DIR } from '../../../config/path.config';
|
||||||
import { BadRequestException, InternalServerErrorException, NotFoundException } from '../../../exceptions';
|
import { BadRequestException, InternalServerErrorException, NotFoundException } from '../../../exceptions';
|
||||||
@ -1115,7 +1116,16 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
const contentMsg = received?.message[getContentType(received.message)] as any;
|
const contentMsg = received?.message[getContentType(received.message)] as any;
|
||||||
|
|
||||||
if (this.localWebhook.webhook_base64 === true && isMedia) {
|
if (
|
||||||
|
(
|
||||||
|
this.localWebhook.webhook_base64 === true ||
|
||||||
|
(
|
||||||
|
this.configService.get<Websocket>('WEBSOCKET').GLOBAL_EVENTS === true &&
|
||||||
|
this.configService.get<Websocket>('WEBSOCKET').ENABLED === true
|
||||||
|
)
|
||||||
|
) &&
|
||||||
|
isMedia
|
||||||
|
) {
|
||||||
const buffer = await downloadMediaMessage(
|
const buffer = await downloadMediaMessage(
|
||||||
{ key: received.key, message: received?.message },
|
{ key: received.key, message: received?.message },
|
||||||
'buffer',
|
'buffer',
|
||||||
@ -1956,6 +1966,36 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
source: getDevice(messageSent.key.id),
|
source: getDevice(messageSent.key.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isMedia =
|
||||||
|
messageRaw.messageType === 'imageMessage' ||
|
||||||
|
messageRaw.messageType === 'videoMessage' ||
|
||||||
|
messageRaw.messageType === 'documentMessage' ||
|
||||||
|
messageRaw.messageType === 'audioMessage';
|
||||||
|
|
||||||
|
console.log('isMedia', isMedia);
|
||||||
|
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
this.localWebhook.webhook_base64 === true ||
|
||||||
|
(
|
||||||
|
this.configService.get<Websocket>('WEBSOCKET').GLOBAL_EVENTS === true &&
|
||||||
|
this.configService.get<Websocket>('WEBSOCKET').ENABLED === true
|
||||||
|
)
|
||||||
|
) &&
|
||||||
|
isMedia
|
||||||
|
) {
|
||||||
|
const buffer = await downloadMediaMessage(
|
||||||
|
{ key: messageRaw.key, message: messageRaw?.message },
|
||||||
|
'buffer',
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
logger: P({ level: 'error' }) as any,
|
||||||
|
reuploadRequest: this.client.updateMediaMessage,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
messageRaw.message.base64 = buffer ? buffer.toString('base64') : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.log(messageRaw);
|
this.logger.log(messageRaw);
|
||||||
|
|
||||||
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
|
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
|
||||||
|
Loading…
Reference in New Issue
Block a user