mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:41:23 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -253,6 +253,7 @@ export async function monitorWebInbox(options: {
|
||||
|
||||
let mediaPath: string | undefined;
|
||||
let mediaType: string | undefined;
|
||||
let mediaFileName: string | undefined;
|
||||
try {
|
||||
const inboundMedia = await downloadInboundMedia(msg as proto.IWebMessageInfo, sock);
|
||||
if (inboundMedia) {
|
||||
@@ -266,9 +267,11 @@ export async function monitorWebInbox(options: {
|
||||
inboundMedia.mimetype,
|
||||
"inbound",
|
||||
maxBytes,
|
||||
inboundMedia.fileName,
|
||||
);
|
||||
mediaPath = saved.path;
|
||||
mediaType = inboundMedia.mimetype;
|
||||
mediaFileName = inboundMedia.fileName;
|
||||
}
|
||||
} catch (err) {
|
||||
logVerbose(`Inbound media download failed: ${String(err)}`);
|
||||
@@ -293,7 +296,7 @@ export async function monitorWebInbox(options: {
|
||||
const senderName = msg.pushName ?? undefined;
|
||||
|
||||
inboundLogger.info(
|
||||
{ from, to: selfE164 ?? "me", body, mediaPath, mediaType, timestamp },
|
||||
{ from, to: selfE164 ?? "me", body, mediaPath, mediaType, mediaFileName, timestamp },
|
||||
"inbound message",
|
||||
);
|
||||
const inboundMessage: WebInboundMessage = {
|
||||
@@ -326,6 +329,7 @@ export async function monitorWebInbox(options: {
|
||||
sendMedia,
|
||||
mediaPath,
|
||||
mediaType,
|
||||
mediaFileName,
|
||||
};
|
||||
try {
|
||||
const task = Promise.resolve(debouncer.enqueue(inboundMessage));
|
||||
|
||||
@@ -37,6 +37,7 @@ export type WebInboundMessage = {
|
||||
sendMedia: (payload: AnyMessageContent) => Promise<void>;
|
||||
mediaPath?: string;
|
||||
mediaType?: string;
|
||||
mediaFileName?: string;
|
||||
mediaUrl?: string;
|
||||
wasMentioned?: boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user