diff --git a/index.js b/index.js index 0607366..bf7b7f4 100644 --- a/index.js +++ b/index.js @@ -322,6 +322,98 @@ app.post('/sendInteractiveImage', async (req, res) => { return res.status(500).json({ error: e.message }); } }); +app.post('/sendFullInteractive', async (req, res) => { + const { phone } = req.body; + + if (!sock || !isConnected) { + return res.status(400).json({ error: 'Non connecté' }); + } + + const BASE_URL = process.env.BASE_URL || 'https://wa.canguidev.fr'; + const imageUrl = `${BASE_URL}/static/logo-merlo-cs-FR.jpg`; + const jid = `${phone}@s.whatsapp.net`; + + try { + const content = { + viewOnceMessage: { + message: { + messageContextInfo: { + deviceListMetadata: {}, + deviceListMetadataVersion: 2 + }, + interactiveMessage: proto.Message.InteractiveMessage.create({ + header: { + hasMediaAttachment: true, + imageMessage: { url: imageUrl } + }, + body: { text: "Bienvenue chez Merlo France 🇫🇷\nChoisissez une action ci-dessous." }, + footer: { text: "MERLO - Support & Documentation" }, + nativeFlowMessage: { + buttons: [ + { + name: "cta_reply", + buttonParamsJson: JSON.stringify({ + display_text: "📩 Contacter support", + id: "support_action" + }) + }, + { + name: "cta_url", + buttonParamsJson: JSON.stringify({ + display_text: "📄 Voir proposition", + url: "https://merlo-ch.com/uploads/proposition/f_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" + }) + }, + { + name: "single_select", + buttonParamsJson: JSON.stringify({ + title: "📚 Choisir une brochure", + sections: [ + { + title: "Documentation PDF", + highlight_label: "Merlo Docs", + rows: [ + { + id: "brochure_1", + title: "Catalogue Général", + description: "Voir le PDF du catalogue", + header: "Catalogue" + }, + { + id: "brochure_2", + title: "Fiche technique", + description: "Voir le PDF de la fiche technique", + header: "Fiche" + } + ] + } + ] + }) + } + ] + } + }) + } + } + }; + + const msg = generateWAMessageFromContent(jid, content, {}); + await sock.relayMessage(jid, msg.message, { messageId: msg.key.id }); + + res.json({ success: true }); + } catch (e) { + console.error('❌ Erreur sendFullInteractive :', e); + res.status(500).json({ error: e.message }); + } +}); + // app.post('/sendInteractiveImage', async (req, res) => { // const { phone, caption, title, subtitle, footer } = req.body;