fix: unificar modulo de notificação de whatsapp no painel de mensagens
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 1m1s Details

This commit is contained in:
Sidney Gomes 2026-07-24 23:00:50 -03:00
parent f82fe92d70
commit 43643d5930
1 changed files with 6 additions and 22 deletions

View File

@ -2313,30 +2313,14 @@ app.post('/api/admin/reply-message', authenticateToken, requireAdmin, async (req
} }
// 2. Enviar WhatsApp via Evolution API se configurado // 2. Enviar WhatsApp via Evolution API se configurado
const settings = await prisma.systemSettings.findUnique({ where: { id: 'default' } });
const user = await prisma.user.findUnique({ where: { id: userId } }); const user = await prisma.user.findUnique({ where: { id: userId } });
if (settings?.whatsappConnected && settings.evolutionApiUrl && settings.evolutionApiKey && user?.whatsapp) { if (user?.whatsapp) {
try { const waSent = await sendWhatsappNotification(user.whatsapp, message);
const cleanPhone = user.whatsapp.replace(/\D/g, ''); if (waSent) {
if (cleanPhone.length >= 10) { console.log(`WhatsApp reply sent to ${user.whatsapp}`);
const numberId = `${cleanPhone}@s.whatsapp.net`; } else {
const url = `${settings.evolutionApiUrl}/message/sendText/${settings.evolutionInstance}`; console.warn(`Could not send WhatsApp reply to ${user.whatsapp}. Check Evolution API connection.`);
await axios.post(url, {
number: numberId,
text: message,
delay: 1200,
linkPreview: true
}, {
headers: {
'apikey': settings.evolutionApiKey,
'Content-Type': 'application/json'
}
});
console.log(`WhatsApp reply sent to ${cleanPhone}`);
}
} catch (waError: any) {
console.error('Failed to send WhatsApp reply:', waError?.response?.data || waError.message);
} }
} }