This commit is contained in:
cangui 2025-05-06 21:14:46 +02:00
parent 3b248cc943
commit d2353f9b5b

View File

@ -70,24 +70,28 @@ app.post('/sendText', async (req, res) => {
app.post('/sendButtons', async (req, res) => { app.post('/sendButtons', async (req, res) => {
const { phone } = req.body; const { phone } = req.body;
if (!sock || !isConnected) return res.status(400).json({ error: 'Non connecté' });
if (!client || !isConnected) {
return res.status(400).json({ error: 'Non connecté' });
}
const BASE_URL = process.env.BASE_URL || 'https://wa.canguidev.fr'; const BASE_URL = process.env.BASE_URL || 'https://wa.canguidev.fr';
const imageUrl = `${BASE_URL}/static/logo-merlo-cs-FR.jpg`; const imageUrl = `${BASE_URL}/static/logo-merlo-cs-FR.jpg`;
const jid = `${phone}@s.whatsapp.net`;
try { try {
const content = { await client.sendMessage(
message: { jid,
interactiveMessage: proto.Message.InteractiveMessage.create({
image: { url : imageUrl }, // Can buffer
body: { text: "Bienvenue sur notre service !" },
footer: { text: "Choisis une action ci-dessous" },
header: {
title: "Menu principal",
hasMediaAttachment: false
},
nativeFlowMessage: {
buttons: [
{ {
name: "cta_reply", image: { url: imageUrl },
caption: "Bienvenue sur notre service !",
title: "Menu principal",
subtitle: "Choisis une action ci-dessous",
footer: "MERLO FRANCE",
media: true,
interactiveButtons: [
{
name: "quick_reply",
buttonParamsJson: JSON.stringify({ buttonParamsJson: JSON.stringify({
display_text: "📩 Contacter support", display_text: "📩 Contacter support",
id: "support_action" id: "support_action"
@ -97,8 +101,7 @@ app.post('/sendButtons', async (req, res) => {
name: "cta_url", name: "cta_url",
buttonParamsJson: JSON.stringify({ buttonParamsJson: JSON.stringify({
display_text: "🌐 Voir notre site", display_text: "🌐 Voir notre site",
url: "https://canguidev.fr", url: "https://canguidev.fr"
merchant_url: "https://canguidev.fr"
}) })
}, },
{ {
@ -109,13 +112,11 @@ app.post('/sendButtons', async (req, res) => {
}) })
} }
] ]
},
{
quoted: null // tu peux remplacer `null` par un message existant si besoin
} }
}) );
}
};
const msg = generateWAMessageFromContent(`${phone}@s.whatsapp.net`, content, {});
await sock.relayMessage(`${phone}@s.whatsapp.net`, msg.message, { messageId: msg.key.id });
res.json({ success: true }); res.json({ success: true });
} catch (e) { } catch (e) {
@ -123,6 +124,7 @@ app.post('/sendButtons', async (req, res) => {
res.status(500).json({ error: e.message }); res.status(500).json({ error: e.message });
} }
}); });
// Votre route POST // Votre route POST
app.post('/sendInteractiveImage', async (req, res) => { app.post('/sendInteractiveImage', async (req, res) => {
const { phone, caption, title, subtitle, footer } = req.body; const { phone, caption, title, subtitle, footer } = req.body;