diff --git a/index.js b/index.js index eae641d..383546d 100644 --- a/index.js +++ b/index.js @@ -120,44 +120,91 @@ app.post('/sendButtons', async (req, res) => { res.status(500).json({ error: e.message }); } }); - app.post('/sendInteractiveImage', async (req, res) => { const { phone, caption, title, subtitle, footer } = req.body; if (!sock || !isConnected) return res.status(400).json({ error: 'Non connecté' }); try { const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg'); - const resizedBuffer = fs.readFileSync(imagePath); + const imageBuffer = fs.readFileSync(imagePath); - await sock.sendMessage(`${phone}@s.whatsapp.net`, { - image: resizedBuffer, - caption: caption || 'Description par défaut', - title: title || 'Titre par défaut', - subtitle: subtitle || 'Sous-titre', - footer: footer || 'Pied de page', - media: true, - interactiveButtons: [ - { - name: 'cta_url', - buttonParamsJson: JSON.stringify({ - display_text: 'Proposition', - url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf' - }) + // Configuration du message interactif + const message = { + interactive: { + type: 'button', + header: { + type: 'IMAGE', + image: imageBuffer, + title: title || 'Titre par défaut', + subtitle: subtitle || 'Sous-titre', }, - { - name: 'cta_url', - buttonParamsJson: JSON.stringify({ - display_text: 'Spec machine', - url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf' - }) + 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: 'Spec machine', + url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf' + } + ] } - ] - }); + } + }; + + await sock.sendMessage(`${phone}@s.whatsapp.net`, message); res.json({ success: true }); } catch (e) { console.error('❌ Erreur interactive image :', e); res.status(500).json({ error: e.message }); } }); +// app.post('/sendInteractiveImage', async (req, res) => { +// const { phone, caption, title, subtitle, footer } = req.body; +// if (!sock || !isConnected) return res.status(400).json({ error: 'Non connecté' }); + +// try { +// const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg'); +// const resizedBuffer = fs.readFileSync(imagePath); + +// await sock.sendMessage(`${phone}@s.whatsapp.net`, { +// image: resizedBuffer, +// caption: caption || 'Description par défaut', +// title: title || 'Titre par défaut', +// subtitle: subtitle || 'Sous-titre', +// footer: footer || 'Pied de page', +// media: true, +// interactiveButtons: [ +// { +// name: 'cta_url', +// buttonParamsJson: JSON.stringify({ +// display_text: 'Proposition', +// url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf' +// }) +// }, +// { +// name: 'cta_url', +// buttonParamsJson: JSON.stringify({ +// display_text: 'Spec machine', +// url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf' +// }) +// } +// ] +// }); +// res.json({ success: true }); +// } catch (e) { +// console.error('❌ Erreur interactive image :', e); +// res.status(500).json({ error: e.message }); +// } +// }); app.listen(3001, () => console.log('🚀 Serveur Baileys démarré sur http://localhost:3001'));