From eeff874305fe697f9727566ab72c80c19f78d054 Mon Sep 17 00:00:00 2001 From: julien Date: Tue, 6 May 2025 12:49:16 +0200 Subject: [PATCH] ddddd --- index.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6e8e59b..0d0f4ae 100644 --- a/index.js +++ b/index.js @@ -124,13 +124,49 @@ app.post('/sendText', async (req, res) => { app.post('/sendButtons', async (req, res) => { const { phone } = req.body; if (!sock || !isConnected) return res.status(400).json({ error: 'Non connecté' }); + try { - await sendInteractive(sock, `${phone}@s.whatsapp.net`, 'https://picsum.photos/200/300'); + const content = { + viewOnceMessage: { + message: { + interactiveMessage: proto.Message.InteractiveMessage.create({ + body: { text: "Choisis une option :" }, + footer: { text: "Réponds via un bouton" }, + nativeFlowMessage: { + buttons: [ + { + name: "quick_reply", + buttonParamsJson: JSON.stringify({ + display_text: "Option A", + id: ".optionA" + }) + }, + { + name: "ctl_url", + buttonParamsJson: JSON.stringify({ + display_text: "Ouvrir mon site", + url: "https://example.com", + merchant_url: "https://example.com" + }) + } + ] + } + }) + } + } + }; + + const msg = generateWAMessageFromContent(`${phone}@s.whatsapp.net`, content, {}); + console.log("📤 Message interactif généré :", JSON.stringify(msg.message, null, 2)); + + await sock.relayMessage(`${phone}@s.whatsapp.net`, msg.message, { messageId: msg.key.id }); + res.json({ success: true }); } catch (e) { - console.error(e); + console.error('❌ Erreur sendButtons:', e); res.status(500).json({ error: e.message }); } }); + app.listen(3001, () => console.log('🚀 Serveur Baileys démarré sur http://localhost:3001'));