fix: validacion de url de imagen valida.

This commit is contained in:
2023-01-14 04:52:08 -06:00
parent f5468835bf
commit c4d22e38f6

View File

@@ -50,11 +50,10 @@ router.post('/sendimage/', async (req,res) => {
if (!fs.existsSync('./temp')) {
await fs.mkdirSync('./temp');
}
var path = './temp/' + image.split("/").slice(-1)[0]
if (fs.existsSync(path)){
mediadownloader(image, path, () => {
let media = MessageMedia.fromFilePath(path);
client.sendMessage(`${phone}@c.us`, media, { caption: caption || '' }).then((response) => {
if (response.id.fromMe) {
res.send({ status: 'success', message: `MediaMessage successfully sent to ${phone}` })
@@ -62,6 +61,10 @@ router.post('/sendimage/', async (req,res) => {
}
});
})
} else {
console.log("La imagen no existe o no se pudo descargar.")
res.send({ status:'error', message: 'Invalid URL/Base64 Encoded Media' })
}
} else {
res.send({ status:'error', message: 'Invalid URL/Base64 Encoded Media' })
}