sddssddsds

This commit is contained in:
julien 2025-05-06 16:21:18 +02:00
parent 4ffc640513
commit 91e363ea0d

View File

@ -127,26 +127,24 @@ app.post('/sendInteractiveImage', async (req, res) => {
} }
try { try {
// 1) Charger l'image en buffer // 1) Charger l'image
const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg'); const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg');
const imageBuffer = fs.readFileSync(imagePath); const imageBuffer = fs.readFileSync(imagePath);
// 2) Préparer le média (Baileys détecte image via la clé `image`) // 2) Préparer le média SANS spécifier explicitement le mimetype :
// Baileys détecte automatiquement le format à partir du buffer :contentReference[oaicite:0]{index=0}
const preparedMedia = await prepareWAMessageMedia( const preparedMedia = await prepareWAMessageMedia(
{ { image: imageBuffer },
image: imageBuffer,
mimetype: 'image/jpeg' // <-- on précise bien le mimetype ici
},
{ upload: sock.waUploadToServer } { upload: sock.waUploadToServer }
); );
// 3) Construire le message interactif // 3) Construire le message interactif avec en-tête IMAGE
const message = { const message = {
interactive: { interactive: {
type: 'button', type: 'button',
header: { header: {
type: 'image', // <-- en minuscules type: 'IMAGE',
image: preparedMedia.imageMessage // <-- on utilise imageMessage image: preparedMedia.image
}, },
body: { body: {
text: caption || 'Description par défaut' text: caption || 'Description par défaut'
@ -171,7 +169,7 @@ app.post('/sendInteractiveImage', async (req, res) => {
} }
}; };
// 4) Envoyer via WhatsApp // 4) Envoi
await sock.sendMessage(`${phone}@s.whatsapp.net`, message); await sock.sendMessage(`${phone}@s.whatsapp.net`, message);
return res.json({ success: true }); return res.json({ success: true });