diff --git a/index.js b/index.js index 7e4f0ae..cfb60ea 100644 --- a/index.js +++ b/index.js @@ -356,44 +356,44 @@ app.post('/sendInteractiveImage', async (req, res) => { } }); -// 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é' }); +app.post('/sendInteractiveImage2', 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); + 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 }); -// } -// }); + 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.post('/sendProductMessage', async (req, res) => { // On vérifie sock et isConnected, pas client if (!sock || !isConnected) {