sdsdsddsdsds
This commit is contained in:
parent
a27d80d0de
commit
e94681001d
79
index.js
79
index.js
@ -47,6 +47,7 @@ const initBaileys = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
initBaileys();
|
initBaileys();
|
||||||
|
app.use('/static', express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
app.get('/login', (req, res) => {
|
app.get('/login', (req, res) => {
|
||||||
res.sendFile(path.join(__dirname, 'public', 'login.html'));
|
res.sendFile(path.join(__dirname, 'public', 'login.html'));
|
||||||
@ -127,54 +128,48 @@ app.post('/sendInteractiveImage', async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1) Lire l’image
|
// 2) Construire l'URL publique de l'image
|
||||||
const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg');
|
// Remplacez “https://votre-domaine.com” par votre vrai domaine ou IP publique
|
||||||
const imageBuffer = fs.readFileSync(imagePath);
|
const imageUrl = `${process.env.BASE_URL || 'https://votre-domaine.com'}/static/logo-merlo-cs-FR.jpg`;
|
||||||
|
|
||||||
// 2) Préparer le média (upload automatique)
|
// 3) Envoyer directement le message interactif en référant l'image par URL
|
||||||
const prepared = await prepareWAMessageMedia(
|
await sock.sendMessage(
|
||||||
{ image: imageBuffer },
|
`${phone}@s.whatsapp.net`,
|
||||||
{ upload: sock.waUploadToServer }
|
{
|
||||||
);
|
interactive: {
|
||||||
|
type: 'button',
|
||||||
// 3) Construire le message interactif « button »
|
header: {
|
||||||
const interactiveMsg = {
|
type: 'IMAGE',
|
||||||
interactive: {
|
image: { url: imageUrl }
|
||||||
type: 'button',
|
},
|
||||||
header: {
|
body: {
|
||||||
type: 'IMAGE',
|
text: caption || 'Description par défaut'
|
||||||
image: prepared.image // <-- le buffer uploadé
|
},
|
||||||
},
|
footer: {
|
||||||
body: {
|
text: footer || 'Pied de page'
|
||||||
text: caption || 'Description par défaut'
|
},
|
||||||
},
|
action: {
|
||||||
footer: {
|
buttons: [
|
||||||
text: footer || 'Pied de page'
|
{
|
||||||
},
|
type: 'url',
|
||||||
action: {
|
title: '📄 Proposition',
|
||||||
buttons: [
|
url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf'
|
||||||
{
|
},
|
||||||
type: 'url',
|
{
|
||||||
title: '📄 Proposition',
|
type: 'url',
|
||||||
url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf'
|
title: '🔧 Spécifications',
|
||||||
},
|
url: 'https://merlo-ch.com/uploads/proposition/d_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) {
|
} catch (e) {
|
||||||
console.error('❌ Erreur interactive image :', 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) => {
|
// app.post('/sendInteractiveImage', async (req, res) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user