rererer
This commit is contained in:
parent
81c1866883
commit
139159b093
39
index.js
39
index.js
@ -269,41 +269,41 @@ app.post('/sendProductMessage', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const jid = `${phone}@s.whatsapp.net`;
|
const jid = `${phone}@s.whatsapp.net`;
|
||||||
|
|
||||||
// Construire le payload "product"
|
// 4.1) Construire le payload "product"
|
||||||
const productPayload = {
|
const productPayload = {
|
||||||
productImage: { url: productImageUrl },
|
productImage: { url: productImageUrl }, // ou buffer si vous préférez
|
||||||
productImageCount,
|
productImageCount,
|
||||||
title: productTitle,
|
title: messageTitle,
|
||||||
description: productDescription,
|
description: productDescription,
|
||||||
priceAmount1000: priceAmount1000 * 1000, // si vous avez déjà *1000, retirez l’opération
|
priceAmount1000: priceAmount1000 * 1000, // attention au facteur 1000
|
||||||
currencyCode,
|
currencyCode,
|
||||||
retailerId,
|
retailerId,
|
||||||
url: productUrl
|
url: productUrl
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transformer vos boutons simples en format Baileys
|
// 4.2) Transformer les boutons
|
||||||
const buttons = interactiveButtons.map(btn => {
|
const buttons = interactiveButtons.map(btn => {
|
||||||
const params = {};
|
const params = {};
|
||||||
if (btn.id) params.id = btn.id;
|
if (btn.id) params.id = btn.id;
|
||||||
if (btn.url) params.url = btn.url;
|
if (btn.url) params.url = btn.url;
|
||||||
if (btn.display_text) params.display_text = btn.display_text;
|
if (btn.display_text) params.display_text = btn.display_text;
|
||||||
return {
|
return {
|
||||||
name: btn.name,
|
name: btn.name,
|
||||||
buttonParamsJson: JSON.stringify(params)
|
buttonParamsJson: JSON.stringify(params)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Envoi du message
|
// 4.3) Envoi du message
|
||||||
await client.sendMessage(
|
await client.sendMessage(
|
||||||
jid,
|
jid,
|
||||||
{
|
{
|
||||||
product: productPayload,
|
product: productPayload,
|
||||||
businessOwnerJid,
|
businessOwnerJid,
|
||||||
caption,
|
caption,
|
||||||
title: messageTitle,
|
title: messageTitle,
|
||||||
footer,
|
footer,
|
||||||
media: true,
|
media: true,
|
||||||
interactiveButtons: buttons
|
interactiveButtons: buttons
|
||||||
},
|
},
|
||||||
quoted ? { quoted } : {}
|
quoted ? { quoted } : {}
|
||||||
);
|
);
|
||||||
@ -314,4 +314,11 @@ app.post('/sendProductMessage', async (req, res) => {
|
|||||||
return res.status(500).json({ error: e.message });
|
return res.status(500).json({ error: e.message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 5) 404 et gestion des erreurs
|
||||||
|
app.use((req, res) => res.status(404).json({ error: 'Ressource introuvable' }));
|
||||||
|
app.use((err, req, res, next) => {
|
||||||
|
console.error('Middleware d’erreur :', err);
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
});
|
||||||
app.listen(3001, () => console.log('🚀 Serveur Baileys démarré sur http://localhost:3001'));
|
app.listen(3001, () => console.log('🚀 Serveur Baileys démarré sur http://localhost:3001'));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user