ip
This commit is contained in:
@@ -602,7 +602,38 @@ class WhatsAppService
|
||||
$messageData['reaction_emoji'] = $data['reaction']['emoji'] ?? null;
|
||||
}
|
||||
|
||||
$this->db->insert('conversations', $messageData);
|
||||
// Special handling for reactions: update the referenced message instead of creating a separate outgoing message
|
||||
if ($data['type'] === 'reaction' && !empty($messageData['reaction_to_message_id'])) {
|
||||
try {
|
||||
$targetMid = $messageData['reaction_to_message_id'];
|
||||
$update = [
|
||||
'reaction_emoji' => $messageData['reaction_emoji'],
|
||||
'reaction_to_message_id' => $targetMid,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
$this->db->update('conversations', $update, 'message_id = :mid OR id = :mid', ['mid' => $targetMid]);
|
||||
|
||||
// Optionally create a small notification for the operator UI
|
||||
try {
|
||||
$this->db->insert('notifications', [
|
||||
'user_id' => $user['id'],
|
||||
'type' => 'reaction',
|
||||
'message' => 'Reacción: ' . ($messageData['reaction_emoji'] ?? ''),
|
||||
'data' => json_encode(['message_id' => $targetMid, 'emoji' => $messageData['reaction_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());
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Fallback: if update fails, insert as outgoing message
|
||||
error_log('Failed to apply reaction via update, inserting outgoing as fallback: ' . $e->getMessage());
|
||||
$this->db->insert('conversations', $messageData);
|
||||
}
|
||||
} else {
|
||||
$this->db->insert('conversations', $messageData);
|
||||
}
|
||||
|
||||
// Solo limpiar advisor_requested si el mensaje fue enviado por un asesor (operator)
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user