This commit is contained in:
julien 2025-05-06 16:10:28 +02:00
parent 4bc2001493
commit d687a2c127

View File

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