dssddsds
This commit is contained in:
parent
91e363ea0d
commit
791967b226
68
index.js
68
index.js
@ -127,50 +127,38 @@ app.post('/sendInteractiveImage', async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1) Charger l'image
|
// 1) Charger l'image en buffer
|
||||||
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 SANS spécifier explicitement le mimetype :
|
// 2) Envoyer directement avec sendMessage
|
||||||
// Baileys détecte automatiquement le format à partir du buffer :contentReference[oaicite:0]{index=0}
|
await sock.sendMessage(
|
||||||
const preparedMedia = await prepareWAMessageMedia(
|
`${phone}@s.whatsapp.net`,
|
||||||
{ image: imageBuffer },
|
{
|
||||||
{ upload: sock.waUploadToServer }
|
image: { url: imageBuffer }, // Buffer pris en charge nativement
|
||||||
);
|
caption: caption || 'Description par défaut',
|
||||||
|
title: title || 'Titre par défaut',
|
||||||
// 3) Construire le message interactif avec en-tête IMAGE
|
subtitle: subtitle || 'Sous-titre',
|
||||||
const message = {
|
footer: footer || 'Pied de page',
|
||||||
interactive: {
|
media: true, // indique un header media
|
||||||
type: 'button',
|
interactiveButtons: [
|
||||||
header: {
|
{
|
||||||
type: 'IMAGE',
|
name: 'cta_url',
|
||||||
image: preparedMedia.image
|
buttonParamsJson: JSON.stringify({
|
||||||
},
|
display_text: '📄 Proposition',
|
||||||
body: {
|
url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf'
|
||||||
text: caption || 'Description par défaut'
|
})
|
||||||
},
|
},
|
||||||
footer: {
|
{
|
||||||
text: footer || 'Pied de page'
|
name: 'cta_url',
|
||||||
},
|
buttonParamsJson: JSON.stringify({
|
||||||
action: {
|
display_text: '🔧 Spec machine',
|
||||||
buttons: [
|
url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf'
|
||||||
{
|
})
|
||||||
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'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
);
|
||||||
|
|
||||||
// 4) Envoi
|
|
||||||
await sock.sendMessage(`${phone}@s.whatsapp.net`, message);
|
|
||||||
return res.json({ success: true });
|
return res.json({ success: true });
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user