sddsdsds
This commit is contained in:
parent
fbf251d713
commit
4ffc640513
39
index.js
39
index.js
@ -127,60 +127,57 @@ app.post('/sendInteractiveImage', async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
// Lecture du fichier image
|
||||
const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg');
|
||||
// 1) Charger l'image en buffer
|
||||
const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg');
|
||||
const imageBuffer = fs.readFileSync(imagePath);
|
||||
|
||||
// Préparation du média en spécifiant l'uploader correct
|
||||
const preparedImage = await prepareWAMessageMedia(
|
||||
{ image: imageBuffer },
|
||||
{
|
||||
upload: sock.waUploadToServer,
|
||||
mediaType: 'image',
|
||||
options: { contentType: 'image/jpeg' }
|
||||
}
|
||||
// 2) Préparer le média (Baileys détecte image via la clé `image`)
|
||||
const preparedMedia = await prepareWAMessageMedia(
|
||||
{
|
||||
image: imageBuffer,
|
||||
mimetype: 'image/jpeg' // <-- on précise bien le mimetype ici
|
||||
},
|
||||
{ upload: sock.waUploadToServer }
|
||||
);
|
||||
|
||||
// Construction du message interactif avec boutons URL
|
||||
// 3) Construire le message interactif
|
||||
const message = {
|
||||
interactive: {
|
||||
type: 'button',
|
||||
header: {
|
||||
type: 'IMAGE',
|
||||
image: preparedImage.image,
|
||||
title: title || 'Titre par défaut',
|
||||
subtitle: subtitle || 'Sous-titre'
|
||||
type: 'image', // <-- en minuscules
|
||||
image: preparedMedia.imageMessage // <-- on utilise imageMessage
|
||||
},
|
||||
body: {
|
||||
text: caption || 'Description par défaut'
|
||||
},
|
||||
footer: {
|
||||
text: footer || 'Pied de page'
|
||||
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'
|
||||
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'
|
||||
url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Envoi du message
|
||||
// 4) Envoyer via WhatsApp
|
||||
await sock.sendMessage(`${phone}@s.whatsapp.net`, message);
|
||||
res.json({ success: true });
|
||||
return res.json({ success: true });
|
||||
|
||||
} catch (e) {
|
||||
console.error('❌ Erreur interactive image :', e);
|
||||
res.status(500).json({ error: e.message });
|
||||
return res.status(500).json({ error: e.message });
|
||||
}
|
||||
});
|
||||
// app.post('/sendInteractiveImage', async (req, res) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user