dsdsds
This commit is contained in:
parent
d01955c1f7
commit
a5b6717920
28
index.js
28
index.js
@ -4,6 +4,8 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const NodeCache = require('node-cache');
|
const NodeCache = require('node-cache');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
|
const fetch = require('node-fetch'); // en haut si pas encore ajouté
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
default: makeWASocket,
|
default: makeWASocket,
|
||||||
@ -14,7 +16,20 @@ const {
|
|||||||
generateWAMessageFromContent,
|
generateWAMessageFromContent,
|
||||||
prepareWAMessageMedia
|
prepareWAMessageMedia
|
||||||
} = require('@fizzxydev/baileys-pro');
|
} = require('@fizzxydev/baileys-pro');
|
||||||
|
const http = require('http');
|
||||||
|
const WebSocket = require('ws');
|
||||||
|
|
||||||
|
const server = http.createServer(app);
|
||||||
|
const wss = new WebSocket.Server({ server });
|
||||||
|
|
||||||
|
function broadcastToClients(data) {
|
||||||
|
const message = JSON.stringify(data);
|
||||||
|
wss.clients.forEach(client => {
|
||||||
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
|
client.send(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
@ -31,6 +46,11 @@ async function getMessageFromStore(key) {
|
|||||||
// À adapter selon ta logique réelle
|
// À adapter selon ta logique réelle
|
||||||
return { conversation: "Message temporaire pour retry" };
|
return { conversation: "Message temporaire pour retry" };
|
||||||
}
|
}
|
||||||
|
app.post('/webhook/status', (req, res) => {
|
||||||
|
console.log('📩 Webhook reçu :', req.body);
|
||||||
|
res.sendStatus(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
const initBaileys = async () => {
|
const initBaileys = async () => {
|
||||||
const { version } = await fetchLatestBaileysVersion();
|
const { version } = await fetchLatestBaileysVersion();
|
||||||
@ -108,7 +128,13 @@ const initBaileys = async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
sock.ev.on('messages.update', async (updates) => {
|
||||||
|
broadcastToClients({
|
||||||
|
messageId,
|
||||||
|
status,
|
||||||
|
jid
|
||||||
|
});
|
||||||
|
});
|
||||||
initBaileys();
|
initBaileys();
|
||||||
|
|
||||||
app.use('/static', express.static(path.join(__dirname, 'public')));
|
app.use('/static', express.static(path.join(__dirname, 'public')));
|
||||||
|
|||||||
@ -14,7 +14,9 @@
|
|||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
"sharp": "^0.33.0",
|
"sharp": "^0.33.0",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"mime-types": "^2.1.35"
|
"mime-types": "^2.1.35",
|
||||||
|
"ws": "^8.0.0",
|
||||||
|
"node-fetch": "^3.3.2"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
public/dashboard.html
Normal file
34
public/dashboard.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Status des messages WhatsApp</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: sans-serif; padding: 20px; background: #f5f5f5; }
|
||||||
|
h1 { color: #333; }
|
||||||
|
.message {
|
||||||
|
background: white;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border-left: 4px solid #4CAF50;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>📊 Suivi des messages WhatsApp</h1>
|
||||||
|
<div id="log"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const logContainer = document.getElementById('log');
|
||||||
|
const ws = new WebSocket('ws://' + location.host);
|
||||||
|
|
||||||
|
ws.onmessage = (event) => {
|
||||||
|
const data = JSON.parse(event.data);
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.className = 'message';
|
||||||
|
div.innerHTML = `<strong>${data.status}</strong> pour <code>${data.jid}</code><br>ID: <code>${data.messageId}</code>`;
|
||||||
|
logContainer.prepend(div);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user