fix: unificar modulo de notificação de whatsapp no painel de mensagens
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 1m1s
Details
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 1m1s
Details
This commit is contained in:
parent
f82fe92d70
commit
43643d5930
28
server.ts
28
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.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue