From 791967b22622bb24c45ab53186b79082e6a8a597 Mon Sep 17 00:00:00 2001 From: julien Date: Tue, 6 May 2025 16:24:21 +0200 Subject: [PATCH] dssddsds --- index.js | 68 +++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/index.js b/index.js index 2b13ff2..d952ed8 100644 --- a/index.js +++ b/index.js @@ -127,50 +127,38 @@ app.post('/sendInteractiveImage', async (req, res) => { } try { - // 1) Charger l'image + // 1) Charger l'image en buffer const imagePath = path.join(__dirname, 'public', 'logo-merlo-cs-FR.jpg'); const imageBuffer = fs.readFileSync(imagePath); - // 2) Préparer le média SANS spécifier explicitement le mimetype : - // Baileys détecte automatiquement le format à partir du buffer :contentReference[oaicite:0]{index=0} - const preparedMedia = await prepareWAMessageMedia( - { image: imageBuffer }, - { upload: sock.waUploadToServer } - ); - - // 3) Construire le message interactif avec en-tête IMAGE - const message = { - interactive: { - type: 'button', - header: { - type: 'IMAGE', - image: preparedMedia.image - }, - 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: 'Spec machine', - url: 'https://merlo-ch.com/uploads/proposition/d_p_250505_0000136_00008_EB00001909.pdf' - } - ] - } + // 2) Envoyer directement avec sendMessage + await sock.sendMessage( + `${phone}@s.whatsapp.net`, + { + image: { url: imageBuffer }, // Buffer pris en charge nativement + caption: caption || 'Description par défaut', + title: title || 'Titre par défaut', + subtitle: subtitle || 'Sous-titre', + footer: footer || 'Pied de page', + media: true, // indique un header media + interactiveButtons: [ + { + name: 'cta_url', + buttonParamsJson: JSON.stringify({ + display_text: '📄 Proposition', + url: 'https://merlo-ch.com/uploads/proposition/f_p_250505_0000136_00008_EB00001909.pdf' + }) + }, + { + name: 'cta_url', + buttonParamsJson: JSON.stringify({ + display_text: '🔧 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 }); } catch (e) {