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

This commit is contained in:
jaison-x 2023-12-25 23:58:07 -03:00
parent dfc8330035
commit 7430897085

View File

@ -1561,8 +1561,15 @@ export class ChatwootService {
},
});
const random = Math.random().toString(36).substring(7);
const nameFile = `${random}.${mimeTypes.extension(downloadBase64.mimetype)}`;
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,
)}`;
} else {
prependFilename = Math.random().toString(36).substring(7);
}
const nameFile = `${prependFilename}.${mimeTypes.extension(downloadBase64.mimetype)}`;
const fileData = Buffer.from(downloadBase64.base64, 'base64');