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 });
}
});
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'));