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) => {
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 imageUrl = `${BASE_URL}/static/logo-merlo-cs-FR.jpg`;
const jid = `${phone}@s.whatsapp.net`;
try {
await sock.sendMessage(
jid,
{
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({
display_text: "📩 Contacter support",
id: "support_action"
})
const content = {
viewOnceMessage: {
message: {
messageContextInfo: {
deviceListMetadata: {},
deviceListMetadataVersion: 2
},
{
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"
})
}
]
},
{
quoted: null // ou un message existant si tu veux répondre à un message
interactiveMessage: proto.Message.InteractiveMessage.create({
body: { text: "Bienvenue sur notre service !" },
footer: { text: "Choisis une action ci-dessous" },
header: {
hasMediaAttachment: true,
imageMessage: { url: imageUrl }
},
nativeFlowMessage: {
buttons: [
{
name: "cta_reply",
buttonParamsJson: JSON.stringify({
display_text: "📩 Contacter support",
id: "support_action"
})
},
{
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 });
} catch (e) {