From e94681001d4bf88cf0795ccd12e39b70c215b611 Mon Sep 17 00:00:00 2001 From: julien Date: Tue, 6 May 2025 16:31:16 +0200 Subject: [PATCH] sdsdsddsdsds --- index.js | 79 ++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/index.js b/index.js index 214eb52..26d50fe 100644 --- a/index.js +++ b/index.js @@ -47,6 +47,7 @@ const initBaileys = async () => { }; initBaileys(); +app.use('/static', express.static(path.join(__dirname, 'public'))); app.get('/login', (req, res) => { res.sendFile(path.join(__dirname, 'public', 'login.html')); @@ -127,54 +128,48 @@ app.post('/sendInteractiveImage', async (req, res) => { } try { - // 1) Lire l’image - const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg'); - const imageBuffer = fs.readFileSync(imagePath); + // 2) Construire l'URL publique de l'image + // Remplacez “https://votre-domaine.com” par votre vrai domaine ou IP publique + const imageUrl = `${process.env.BASE_URL || 'https://votre-domaine.com'}/static/logo-merlo-cs-FR.jpg`; - // 2) Préparer le média (upload automatique) - const prepared = await prepareWAMessageMedia( - { image: imageBuffer }, - { upload: sock.waUploadToServer } - ); - - // 3) Construire le message interactif « button » - const interactiveMsg = { - interactive: { - type: 'button', - header: { - type: 'IMAGE', - image: prepared.image // <-- le buffer uploadé - }, - body: { - text: caption || 'Description par défaut' - }, - footer: { - text: footer || 'Pied de page' - }, - action: { - buttons: [ - { - type: 'url', - title: '📄 Proposition', - url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf' - }, - { - type: 'url', - title: '🔧 Spécifications', - url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf' - } - ] + // 3) Envoyer directement le message interactif en référant l'image par URL + await sock.sendMessage( + `${phone}@s.whatsapp.net`, + { + interactive: { + type: 'button', + header: { + type: 'IMAGE', + image: { url: imageUrl } + }, + body: { + text: caption || 'Description par défaut' + }, + footer: { + text: footer || 'Pied de page' + }, + action: { + buttons: [ + { + type: 'url', + title: '📄 Proposition', + url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf' + }, + { + type: 'url', + title: '🔧 Spécifications', + url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf' + } + ] + } } } - }; - - // 4) Envoi - await sock.sendMessage(`${phone}@s.whatsapp.net`, interactiveMsg); - return res.json({ success: true }); + ); + res.json({ success: true }); } catch (e) { console.error('❌ Erreur interactive image :', e); - return res.status(500).json({ error: e.message }); + res.status(500).json({ error: e.message }); } }); // app.post('/sendInteractiveImage', async (req, res) => {