diff --git a/index.js b/index.js index e9c2620..9ce90ac 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ const path = require('path'); const fs = require('fs'); const NodeCache = require('node-cache'); const mime = require('mime-types'); +const fetch = require('node-fetch'); // en haut si pas encore ajouté + const { default: makeWASocket, @@ -14,7 +16,20 @@ const { generateWAMessageFromContent, prepareWAMessageMedia } = 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(); app.use(express.json()); app.use(express.static('public')); @@ -31,6 +46,11 @@ async function getMessageFromStore(key) { // À adapter selon ta logique réelle 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 { version } = await fetchLatestBaileysVersion(); @@ -108,7 +128,13 @@ const initBaileys = async () => { } }); }; - +sock.ev.on('messages.update', async (updates) => { + broadcastToClients({ + messageId, + status, + jid + }); +}); initBaileys(); app.use('/static', express.static(path.join(__dirname, 'public'))); diff --git a/package.json b/package.json index 8afd9ad..ba1c54f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,9 @@ "qrcode": "^1.5.1", "sharp": "^0.33.0", "node-cache": "^5.1.2", - "mime-types": "^2.1.35" + "mime-types": "^2.1.35", + "ws": "^8.0.0", + "node-fetch": "^3.3.2" } diff --git a/public/dashboard.html b/public/dashboard.html new file mode 100644 index 0000000..b6ff4e6 --- /dev/null +++ b/public/dashboard.html @@ -0,0 +1,34 @@ + + +
+ +