This commit is contained in:
cangui 2025-05-06 21:31:03 +02:00
parent 3d83216978
commit 221d98a541

View File

@ -105,50 +105,61 @@ 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 (!sock || !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`; const jid = `${phone}@s.whatsapp.net`;
try { try {
await sock.sendMessage( const content = {
jid, viewOnceMessage: {
{ message: {
image: { url: imageUrl }, messageContextInfo: {
caption: "Bienvenue sur notre service !", deviceListMetadata: {},
title: "Menu principal", deviceListMetadataVersion: 2
subtitle: "Choisis une action ci-dessous",
footer: "MERLO FRANCE",
media: true,
interactiveButtons: [
{
name: "quick_reply",
buttonParamsJson: JSON.stringify({
display_text: "📩 Contacter support",
id: "support_action"
})
}, },
{ interactiveMessage: proto.Message.InteractiveMessage.create({
name: "cta_url", body: { text: "Bienvenue sur notre service !" },
buttonParamsJson: JSON.stringify({ footer: { text: "Choisis une action ci-dessous" },
display_text: "🌐 Voir notre site", header: {
url: "https://canguidev.fr" hasMediaAttachment: true,
}) imageMessage: { url: imageUrl }
}, },
{ nativeFlowMessage: {
name: "cta_call", buttons: [
buttonParamsJson: JSON.stringify({ {
display_text: "📞 Appeler le support", name: "cta_reply",
id: "+33612345678" buttonParamsJson: JSON.stringify({
}) display_text: "📩 Contacter support",
} id: "support_action"
] })
}, },
{ {
quoted: null // ou un message existant si tu veux répondre à un message name: "cta_url",
buttonParamsJson: JSON.stringify({
display_text: "🌐 Voir notre site",
url: "https://canguidev.fr"
})
},
{
name: "cta_call",
buttonParamsJson: JSON.stringify({
display_text: "📞 Appeler le support",
id: "+33612345678"
})
}
]
}
})
}
} }
); };
const msg = generateWAMessageFromContent(jid, content, {});
await sock.relayMessage(jid, msg.message, { messageId: msg.key.id });
res.json({ success: true }); res.json({ success: true });
} catch (e) { } catch (e) {