From 43643d5930fa750d0923be370b42ab8026d1965c Mon Sep 17 00:00:00 2001 From: Sidney Gomes Date: Fri, 24 Jul 2026 23:00:50 -0300 Subject: [PATCH] =?UTF-8?q?=20fix:=20unificar=20modulo=20de=20notifica?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20whatsapp=20no=20painel=20de=20mensagens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.ts | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/server.ts b/server.ts index 3f5cbd6..ba82b3e 100644 --- a/server.ts +++ b/server.ts @@ -2313,30 +2313,14 @@ app.post('/api/admin/reply-message', authenticateToken, requireAdmin, async (req } // 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 } }); - if (settings?.whatsappConnected && settings.evolutionApiUrl && settings.evolutionApiKey && user?.whatsapp) { - try { - const cleanPhone = user.whatsapp.replace(/\D/g, ''); - if (cleanPhone.length >= 10) { - const numberId = `${cleanPhone}@s.whatsapp.net`; - const url = `${settings.evolutionApiUrl}/message/sendText/${settings.evolutionInstance}`; - 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); + if (user?.whatsapp) { + const waSent = await sendWhatsappNotification(user.whatsapp, message); + if (waSent) { + console.log(`WhatsApp reply sent to ${user.whatsapp}`); + } else { + console.warn(`Could not send WhatsApp reply to ${user.whatsapp}. Check Evolution API connection.`); } }