diff --git a/src/web/inbound/media.ts b/src/web/inbound/media.ts index 9e7d566f4..dda83c3f6 100644 --- a/src/web/inbound/media.ts +++ b/src/web/inbound/media.ts @@ -31,15 +31,30 @@ export async function downloadInboundMedia( return undefined; } try { - const buffer = (await downloadMediaMessage( + // Use stream mode instead of buffer mode to fix audio download issue + // where buffer mode returns empty data for audio messages in Baileys 7.x + const stream = await downloadMediaMessage( msg as WAMessage, - "buffer", + "stream", {}, { reuploadRequest: sock.updateMediaMessage, logger: sock.logger, }, - )) as Buffer; + ); + + const chunks: Buffer[] = []; + for await (const chunk of stream) { + chunks.push(chunk as Buffer); + } + const buffer = Buffer.concat(chunks); + + // Validate buffer is not empty + if (!buffer || buffer.length === 0) { + logVerbose(`downloadMediaMessage returned empty buffer for ${mimetype}`); + return undefined; + } + return { buffer, mimetype }; } catch (err) { logVerbose(`downloadMediaMessage failed: ${String(err)}`);