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()]);
|
||||
|
||||
+37
-3
@@ -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
|
||||
|
||||
+4
-2
@@ -805,10 +805,10 @@
|
||||
<button class="attach-option" data-action="template">Enviar plantilla</button>
|
||||
</div>
|
||||
<div style="display:flex; gap:8px; align-items:center;">
|
||||
<select id="message-type" class="form-select form-select-sm" style="width:auto; margin-right:8px;">
|
||||
<!-- <select id="message-type" class="form-select form-select-sm" style="width:auto; margin-right:8px;">
|
||||
<option value="text">Texto</option>
|
||||
<option value="template">Plantilla</option>
|
||||
</select>
|
||||
</select> -->
|
||||
<div id="templateSelectContainer" style="display:none; margin-right:8px;">
|
||||
<select id="templateSelect" class="form-select form-select-sm">
|
||||
<option value="">Seleccionar plantilla...</option>
|
||||
@@ -2746,6 +2746,8 @@
|
||||
const sendBtn = document.getElementById('send-btn');
|
||||
// ensure send button is enabled
|
||||
if (sendBtn) sendBtn.disabled = false;
|
||||
// Update mic/send visibility (hide mic when a file is selected)
|
||||
if (this._updateSendMicVisibility) this._updateSendMicVisibility();
|
||||
}
|
||||
|
||||
formatFileSize(bytes) {
|
||||
|
||||
Reference in New Issue
Block a user