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.`); } }