diff --git a/index.js b/index.js index 95346b5..ce2cbfa 100644 --- a/index.js +++ b/index.js @@ -122,53 +122,61 @@ app.post('/sendButtons', async (req, res) => { } }); app.post('/sendInteractiveImage', async (req, res) => { - const { phone, caption, title, subtitle, footer } = req.body; + const { phone, caption, footer } = req.body; if (!sock || !isConnected) { return res.status(400).json({ error: 'Non connecté' }); } try { - // 2) Construire l'URL publique - const imageUrl = `https://wa.canguidev.fr/static/logo-merlo-cs-FR.jpg`; + // 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`; - // 3) Contenu du message interactif - const message = { - 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' + // 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: [ + { + // bouton URL “Proposition” + urlButton: { + displayText: '📄 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' + } + } + ] + } + }); + + // 3) Emballez-le pour Baileys + const message = { + message: { + interactiveMessage: interactiveContent } }; + const jid = `${phone}@s.whatsapp.net`; + const msg = generateWAMessageFromContent(jid, message, {}); - // 4) Envoi - await sock.sendMessage(`${phone}@s.whatsapp.net`, message); - res.json({ success: true }); + // 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 }); } 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) => {