sdsdsddsdsds
This commit is contained in:
parent
a27d80d0de
commit
e94681001d
79
index.js
79
index.js
@ -47,6 +47,7 @@ const initBaileys = async () => {
|
||||
};
|
||||
|
||||
initBaileys();
|
||||
app.use('/static', express.static(path.join(__dirname, 'public')));
|
||||
|
||||
app.get('/login', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'login.html'));
|
||||
@ -127,54 +128,48 @@ app.post('/sendInteractiveImage', async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
// 1) Lire l’image
|
||||
const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg');
|
||||
const imageBuffer = fs.readFileSync(imagePath);
|
||||
// 2) Construire l'URL publique de l'image
|
||||
// Remplacez “https://votre-domaine.com” par votre vrai domaine ou IP publique
|
||||
const imageUrl = `${process.env.BASE_URL || 'https://votre-domaine.com'}/static/logo-merlo-cs-FR.jpg`;
|
||||
|
||||
// 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'
|
||||
}
|
||||
]
|
||||
// 3) Envoyer directement le message interactif en référant l'image par URL
|
||||
await sock.sendMessage(
|
||||
`${phone}@s.whatsapp.net`,
|
||||
{
|
||||
interactive: {
|
||||
type: 'button',
|
||||
header: {
|
||||
type: 'IMAGE',
|
||||
image: { url: imageUrl }
|
||||
},
|
||||
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 });
|
||||
);
|
||||
|
||||
res.json({ success: true });
|
||||
} catch (e) {
|
||||
console.error('❌ Erreur interactive image :', e);
|
||||
return res.status(500).json({ error: e.message });
|
||||
res.status(500).json({ error: e.message });
|
||||
}
|
||||
});
|
||||
// app.post('/sendInteractiveImage', async (req, res) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user