chore: update CHANGELOG for Baileys v7.0.0-rc.2 and implement message content sanitization in Baileys service
Some checks are pending
Build Docker image / Build and Deploy (push) Waiting to run

This commit is contained in:
Davidson Gomes
2025-09-08 19:53:52 -03:00
parent 8830f476e8
commit 6da79f0313
3 changed files with 33 additions and 5 deletions

View File

@@ -4299,6 +4299,32 @@ export class BaileysStartupService extends ChannelStartupService {
throw new Error('Method not available in the Baileys service');
}
private sanitizeMessageContent(messageContent: any): any {
if (!messageContent) return messageContent;
// Deep clone to avoid modifying original
const sanitized = JSON.parse(JSON.stringify(messageContent, (key, value) => {
// Convert Long objects to numbers
if (Long.isLong(value)) {
return value.toNumber();
}
// Convert Uint8Array to regular arrays or remove them
if (value instanceof Uint8Array) {
return Array.from(value);
}
// Remove functions and other non-serializable objects
if (typeof value === 'function') {
return undefined;
}
return value;
}));
return sanitized;
}
private prepareMessage(message: proto.IWebMessageInfo): any {
const contentType = getContentType(message.message);
const contentMsg = message?.message[contentType] as any;
@@ -4311,10 +4337,12 @@ export class BaileysStartupService extends ChannelStartupService {
? 'Você'
: message?.participant || (message.key?.participant ? message.key.participant.split('@')[0] : null)),
status: status[message.status],
message: { ...message.message },
message: this.sanitizeMessageContent({ ...message.message }),
contextInfo: contentMsg?.contextInfo,
messageType: contentType || 'unknown',
messageTimestamp: message.messageTimestamp as number,
messageTimestamp: Long.isLong(message.messageTimestamp)
? (message.messageTimestamp as Long).toNumber()
: (message.messageTimestamp as number),
instanceId: this.instanceId,
source: getDevice(message.key.id),
};