fix: when receiving a file from whatsapp, use the original filename in chatwoot when possible

This commit is contained in:
jaison-x 2023-12-26 01:21:05 -03:00
parent 7430897085
commit 49aa1ea17c

View File

@ -1562,10 +1562,15 @@ export class ChatwootService {
});
let prependFilename: string;
if (body?.message[body?.messageType]?.fileName) {
prependFilename = `${path.parse(body.message[body.messageType].fileName).name}-${Math.floor(
Math.random() * (99 - 10 + 1) + 10,
)}`;
if (
body?.message[body?.messageType]?.fileName ||
body?.message[body?.messageType]?.message?.documentMessage?.fileName
) {
prependFilename = path.parse(
body?.message[body?.messageType]?.fileName ||
body?.message[body?.messageType]?.message?.documentMessage?.fileName,
).name;
prependFilename += `-${Math.floor(Math.random() * (99 - 10 + 1) + 10)}`;
} else {
prependFilename = Math.random().toString(36).substring(7);
}