up
This commit is contained in:
+14
-18
@@ -47,26 +47,22 @@ try {
|
||||
error_log('sendReaction failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Registrar la reacción como mensaje saliente en la BD
|
||||
$msgData = [
|
||||
'user_id' => $target['user_id'],
|
||||
'direction' => 'outgoing',
|
||||
'message_type' => 'reaction',
|
||||
'content' => $emoji,
|
||||
'reaction_to_message_id' => $message_id,
|
||||
'reaction_emoji' => $emoji,
|
||||
'status' => ($resp ? 'sent' : 'failed'),
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
// Registrar la reacción en el mensaje objetivo (no crear un nuevo "reaction" como mensaje saliente)
|
||||
try {
|
||||
$update = ['reaction_emoji' => $emoji, 'reaction_to_message_id' => $message_id, 'updated_at' => date('Y-m-d H:i:s')];
|
||||
// If send failed, optionally record a status on target (not mandatory)
|
||||
if (!$resp) $update['reaction_status'] = 'failed';
|
||||
|
||||
// If we got an id from WhatsApp response, save it
|
||||
if (is_array($resp) && isset($resp['conversations'][0]['id'])) {
|
||||
$msgData['message_id'] = $resp['conversations'][0]['id'];
|
||||
$db->update('conversations', $update, 'id = :id', ['id' => $target['id']]);
|
||||
|
||||
// Return updated row for convenience
|
||||
$updated = $db->query('SELECT * FROM conversations WHERE id = ? LIMIT 1', [$target['id']])->fetch();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Reacción aplicada', 'updated' => $updated]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => 'No se pudo guardar la reacción: ' . $e->getMessage()]);
|
||||
}
|
||||
|
||||
$db->insert('conversations', $msgData);
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Reacción enviada', 'saved' => $msgData]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
|
||||
Reference in New Issue
Block a user