diff --git a/index.js b/index.js index 0b093d2..db10c16 100644 --- a/index.js +++ b/index.js @@ -457,42 +457,26 @@ app.post('/sendProductMessage', async (req, res) => { await sock.sendMessage( jid, { - product: { - productImage: { url: "https://wa.canguidev.fr/static/logo-merlo-cs-FR.jpg"}, - productImageCount: 1, - title: "Title Product", - description: "Description Product", - priceAmount1000: 20000 * 1000, - currencyCode: "IDR", - retailerId: "Retail", - url: "https://example.com", - }, - businessOwnerJid: "33617452235@s.whatsapp.net", - caption: "Description Of Messages", //Additional information - title: "Title Of Messages", - footer: "Footer Messages", - media: true, - interactiveButtons: [ - { - name: "quick_reply", - buttonParamsJson: JSON.stringify({ - display_text: "Display Button", - id: "ID" - }) - }, - { - name: "cta_url", - buttonParamsJson: JSON.stringify({ - display_text: "Display Button", - url: "https://www.example.com" - }) - } - ] + product: { + productImage: { url: productImageUrl }, + productImageCount, + title: productTitle, + description: productDescription, + priceAmount1000, + currencyCode, + retailerId, + url: productUrl, + }, + businessOwnerJid, + caption, + title: messageTitle, + footer, + media: true, + interactiveButtons }, - { - quoted : message - } - ) + quoted ? { quoted } : {} + ); + return res.json({ success: true }); } catch (e) { @@ -602,6 +586,44 @@ app.post('/testHeaderImage', async (req, res) => { } }); +const express = require('express'); +const app = express(); +app.use(express.json()); + +app.post('/sendImageWithBaileysPro', async (req, res) => { + if (!sock || !isConnected) { + return res.status(400).json({ error: 'Non connecté à WhatsApp' }); + } + + const { + phone, // ex: "33612345678" + imageUrl, // ex: "https://example.com/image.jpg" + caption, // ex: "Voici une image !" + quoted // optionnel : message auquel répondre + } = req.body; + + if (!phone || !imageUrl) { + return res.status(400).json({ error: 'Paramètres requis manquants (phone, imageUrl)' }); + } + + const jid = `${phone}@s.whatsapp.net`; + + try { + await sock.sendMessage( + jid, + { + image: { url: imageUrl }, + caption: caption || '', + }, + quoted ? { quoted } : {} + ); + + res.json({ success: true, to: jid }); + } catch (e) { + console.error('❌ Erreur /sendImageWithBaileysPro :', e); + res.status(500).json({ error: e.message }); + } +});