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:
co-authored by
Claude Sonnet 4.6
parent
3f964b424a
commit
03f02d2788
+23
-22
@@ -395,29 +395,30 @@ class WhatsAppWebhook {
|
||||
}
|
||||
}
|
||||
|
||||
// Crear notificación para UI (nuevo mensaje entrante)
|
||||
try {
|
||||
$this->db->insert('notifications', [
|
||||
'user_id' => $user['id'],
|
||||
'type' => 'incoming_message',
|
||||
'message' => substr($messageText, 0, 250),
|
||||
'data' => json_encode(['message_id' => $messageId]),
|
||||
'is_read' => 0,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
error_log('Failed to create notification: ' . $e->getMessage());
|
||||
}
|
||||
// Notificaciones y SSE solo para el canal principal (no turnero)
|
||||
if (!$isTurnero) {
|
||||
try {
|
||||
$this->db->insert('notifications', [
|
||||
'user_id' => $user['id'],
|
||||
'type' => 'incoming_message',
|
||||
'message' => substr($messageText, 0, 250),
|
||||
'data' => json_encode(['message_id' => $messageId]),
|
||||
'is_read' => 0,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
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,
|
||||
'message' => substr($messageText, 0, 250),
|
||||
'message_type' => $messageType,
|
||||
'timestamp' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$this->pushSSEEvent('new_message', [
|
||||
'user_id' => $user['id'],
|
||||
'phone_number' => $user['phone_number'],
|
||||
'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) {
|
||||
|
||||
Reference in New Issue
Block a user