fix(webhook): skip SSE notification and DB notification for canal=turnero messages

Turnero messages were triggering the SSE event that conversations.php listens to,
causing the contact to flash briefly at the top of the list before disappearing
on the next poll (since get_conversations.php filters them out by canal).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-03 08:43:20 -05:00
co-authored by Claude Sonnet 4.6
parent 3f964b424a
commit 03f02d2788
+4 -3
View File
@@ -395,7 +395,8 @@ class WhatsAppWebhook {
}
}
// Crear notificación para UI (nuevo mensaje entrante)
// Notificaciones y SSE solo para el canal principal (no turnero)
if (!$isTurnero) {
try {
$this->db->insert('notifications', [
'user_id' => $user['id'],
@@ -409,15 +410,15 @@ class WhatsAppWebhook {
error_log('Failed to create notification: ' . $e->getMessage());
}
// Empujar evento SSE en tiempo real
$this->pushSSEEvent('new_message', [
'user_id' => $user['id'],
'phone_number' => $user['phone_number'],
'name' => $user['name'] ?? $from,
'name' => $user['name'] ?? ($phoneNumber ?? ''),
'message' => substr($messageText, 0, 250),
'message_type' => $messageType,
'timestamp' => date('Y-m-d H:i:s')
]);
}
// Procesar con bot solo si el mensaje llegó al número principal
if (!$isTurnero) {