Skip to content

Commit

Permalink
se corrige la solictud post de multimedia
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKingV committed Jun 14, 2024
1 parent aca55e1 commit 8487d9d
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('dotenv').config()
const { Client, LocalAuth } = require('whatsapp-web.js');
const { Client, LocalAuth, MessageMedia } = require('whatsapp-web.js');
const qrcode = require('qrcode');
const express = require('express');
const bodyParser = require('body-parser');
Expand Down Expand Up @@ -69,24 +69,28 @@ app.post('/send-message', authenticateToken, (req, res) => {
});
});

app.post('/send-media', authenticateToken, (req, res) => {
const { from, text, path } = req.body;
const media = MessageMedia.fromFilePath(path);
app.post('/send-media', authenticateToken, async (req, res) => {
try {
const { from, text, file } = req.body;
const media = await MessageMedia.fromUrl(file);

if(text !== '') {
client.sendMessage(from, media, { caption: text}).then(response => {
res.status(200).send(response);
}).catch(error => {
res.status(500).send(error);
});
}else{
client.sendMessage(from, media).then(response => {
res.status(200).send(response);
}).catch(error => {
res.status(500).send
});
if (text !== '') {
await client.sendMessage(from, media, { caption: text }).then(response => {
res.status(200).send(response);
}).catch(error => {
res.status(500).send(error);
});
} else {
console.log(media);
await client.sendMessage(from, media).then(response => {
res.status(200).send(response);
}).catch(error => {
res.status(500).send(error);
});
}
} catch (error) {
res.status(500).send(error);
}

});

app.listen(port, () => {
Expand Down

0 comments on commit 8487d9d

Please sign in to comment.