fix: preserve original filename for WhatsApp inbound documents (#12691)

* fix: preserve original filename for WhatsApp inbound documents

* fix: cover WhatsApp document filenames (#12691) (thanks @akramcodez)

* test: streamline inbound media waits (#12691) (thanks @akramcodez)

---------

Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
This commit is contained in:
Sk Akram
2026-02-10 03:26:19 +05:30
committed by GitHub
parent 1074d13e4e
commit 1cee5135e4
5 changed files with 51 additions and 30 deletions

View File

@@ -11,7 +11,7 @@ function unwrapMessage(message: proto.IMessage | undefined): proto.IMessage | un
export async function downloadInboundMedia(
msg: proto.IWebMessageInfo,
sock: Awaited<ReturnType<typeof createWaSocket>>,
): Promise<{ buffer: Buffer; mimetype?: string } | undefined> {
): Promise<{ buffer: Buffer; mimetype?: string; fileName?: string } | undefined> {
const message = unwrapMessage(msg.message as proto.IMessage | undefined);
if (!message) {
return undefined;
@@ -23,6 +23,7 @@ export async function downloadInboundMedia(
message.audioMessage?.mimetype ??
message.stickerMessage?.mimetype ??
undefined;
const fileName = message.documentMessage?.fileName ?? undefined;
if (
!message.imageMessage &&
!message.videoMessage &&
@@ -42,7 +43,7 @@ export async function downloadInboundMedia(
logger: sock.logger,
},
);
return { buffer, mimetype };
return { buffer, mimetype, fileName };
} catch (err) {
logVerbose(`downloadMediaMessage failed: ${String(err)}`);
return undefined;