This commit is contained in:
Lizandro Guarnizo
2026-01-24 01:17:22 -05:00
parent d0232c9c21
commit ac6d04c31d
3 changed files with 55 additions and 23 deletions
+37 -3
View File
@@ -247,9 +247,43 @@ class WhatsAppWebhook {
$saveData['reply_to_message_id'] = $message['context']['id'];
}
// Añadir campos extra (si se detectaron)
if (isset($extraFields) && is_array($extraFields)) {
$saveData = array_merge($saveData, $extraFields);
// Special handling for reaction messages: apply reaction to referenced message instead of creating separate record
if (isset($extraFields) && is_array($extraFields) && isset($messageType) && $messageType === 'reaction' && !empty($reactionTo)) {
try {
// Try to update the referenced message (by message_id or id)
$updated = $this->db->update(
'conversations',
['reaction_emoji' => $emoji, 'reaction_to_message_id' => $reactionTo, 'updated_at' => date('Y-m-d H:i:s')],
'message_id = :mid OR id = :mid',
['mid' => $reactionTo]
);
// Optionally create a small notification about the reaction
try {
$this->db->insert('notifications', [
'user_id' => $user['id'],
'type' => 'reaction',
'message' => "Reacción recibida: {$emoji}",
'data' => json_encode(['message_id' => $reactionTo, 'emoji' => $emoji]),
'is_read' => 0,
'created_at' => date('Y-m-d H:i:s')
]);
} catch (Exception $ne) {
error_log('Failed to create reaction notification: ' . $ne->getMessage());
}
// We handled the reaction by updating the target message - skip creating a separate reaction record
continue;
} catch (Exception $e) {
// If update failed, fallback to saving the reaction as a message
error_log('Failed to apply reaction update: ' . $e->getMessage());
$saveData = array_merge($saveData, $extraFields);
}
} else {
// Añadir campos extra (si se detectaron)
if (isset($extraFields) && is_array($extraFields)) {
$saveData = array_merge($saveData, $extraFields);
}
}
// Filtrar campos según columnas existentes para evitar errores en esquemas antiguos