zeezzezeez

This commit is contained in:
julien 2025-05-06 16:28:31 +02:00
parent 816b57b6fc
commit a27d80d0de

View File

@ -127,39 +127,49 @@ app.post('/sendInteractiveImage', async (req, res) => {
}
try {
// 1) Lire limage en Buffer
// 1) Lire limage
const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg');
const imageBuffer = fs.readFileSync(imagePath);
// 2) Envoyer un message interactif AVEC MEDIA
await sock.sendMessage(
`${phone}@s.whatsapp.net`,
{
// on passe le Buffer directement (pas d'objet url)
image: imageBuffer,
caption: caption || 'Description par défaut',
title: title || 'Titre par défaut',
subtitle: subtitle || 'Sous-titre',
footer: footer || 'Pied de page',
media: true, // active len-tête média
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: '🔧 Spécifications',
url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf'
})
}
]
}
// 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'
}
]
}
}
};
// 4) Envoi
await sock.sendMessage(`${phone}@s.whatsapp.net`, interactiveMsg);
return res.json({ success: true });
} catch (e) {