errerer
This commit is contained in:
parent
fa1ad19e55
commit
792b439294
69
index.js
69
index.js
@ -122,61 +122,48 @@ app.post('/sendButtons', async (req, res) => {
|
||||
}
|
||||
});
|
||||
app.post('/sendInteractiveImage', async (req, res) => {
|
||||
const { phone, caption, footer } = req.body;
|
||||
const { phone, caption, title, subtitle, footer } = req.body;
|
||||
if (!sock || !isConnected) {
|
||||
return res.status(400).json({ error: 'Non connecté' });
|
||||
}
|
||||
|
||||
try {
|
||||
// 1) Construisez une URL publique pour votre image statique
|
||||
// Exemple : https://votre-domaine.com/static/logo-merlo-cs-FR.jpg
|
||||
const BASE_URL = process.env.BASE_URL || 'https://wa.canguidev.fr';
|
||||
const imageUrl = `${BASE_URL}/static/logo-merlo-cs-FR.jpg`;
|
||||
// URL publique vers votre image (hébergée dans ./public via express.static)
|
||||
const BASE = process.env.BASE_URL || 'https://wa.canguidev.fr';
|
||||
const imageUrl = `${BASE}/static/logo-merlo-cs-FR.jpg`;
|
||||
|
||||
// 2) Montez le contenu raw du message interactif
|
||||
const interactiveContent = proto.Message.InteractiveMessage.create({
|
||||
header: {
|
||||
type: proto.Message.InteractiveMessage.HeaderType.IMAGE,
|
||||
imageMessage: { url: imageUrl }
|
||||
},
|
||||
body: { text: caption || 'Description par défaut' },
|
||||
footer: { text: footer || 'Pied de page' },
|
||||
action: {
|
||||
buttons: [
|
||||
// Envoi du message “Interactive with media” (image en header + boutons URL)
|
||||
await sock.sendMessage(
|
||||
`${phone}@s.whatsapp.net`,
|
||||
{
|
||||
image: { url: imageUrl }, // header média
|
||||
caption: caption || 'Description par défaut', // texte sous l’image
|
||||
title: title || 'Titre par défaut', // titre au-dessus
|
||||
subtitle: subtitle || 'Sous-titre', // sous-titre
|
||||
footer: footer || 'Pied de page', // pied
|
||||
media: true, // active le header image
|
||||
interactiveButtons: [ // vos boutons URL
|
||||
{
|
||||
// bouton URL “Proposition”
|
||||
urlButton: {
|
||||
displayText: '📄 Proposition',
|
||||
url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf'
|
||||
}
|
||||
name: 'cta_url',
|
||||
buttonParamsJson: JSON.stringify({
|
||||
display_text: '📄 Proposition',
|
||||
url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf'
|
||||
})
|
||||
},
|
||||
{
|
||||
// bouton URL “Spec machine”
|
||||
urlButton: {
|
||||
displayText: '🔧 Spécifications',
|
||||
url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf'
|
||||
}
|
||||
name: 'cta_url',
|
||||
buttonParamsJson: JSON.stringify({
|
||||
display_text: '🔧 Spécifications',
|
||||
url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf'
|
||||
})
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
// 3) Emballez-le pour Baileys
|
||||
const message = {
|
||||
message: {
|
||||
interactiveMessage: interactiveContent
|
||||
}
|
||||
};
|
||||
const jid = `${phone}@s.whatsapp.net`;
|
||||
const msg = generateWAMessageFromContent(jid, message, {});
|
||||
|
||||
// 4) Envoyez-le en relay (pas de prepareWAMessageMedia du tout)
|
||||
await sock.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
||||
|
||||
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