From 3d45d54f0c3cb128a54f6eea47320821648c845a Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 24 Jan 2026 01:01:12 -0500 Subject: [PATCH] up --- conversations.php | 16 +++++++++++++--- services/WhatsAppService.php | 5 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/conversations.php b/conversations.php index e7f4b5b..25c1aa8 100644 --- a/conversations.php +++ b/conversations.php @@ -2257,7 +2257,8 @@ // hide reply preview if any this.hideReplyPreview(); if (resp && resp.success) { - this.addMessageToView(`Plantilla: ${templateName}`, 'outgoing'); + const replyToTemplate = document.getElementById('message-input').dataset.replyTo || null; + this.addMessageToView(`Plantilla: ${templateName}`, 'outgoing', { reply_to_message_id: replyToTemplate }); typeof showAlert !== 'undefined' && showAlert('Mensaje de plantilla enviado correctamente', 'success'); await this.loadconversations(this.currentUserId, false); await this.loadConversations(); @@ -2284,7 +2285,7 @@ } // Insertar mensaje saliente en la vista inmediatamente (simular envĂ­o) - addMessageToView(content, type = 'outgoing') { + addMessageToView(content, type = 'outgoing', options = {}) { const msg = { message_id: 'local_' + Date.now(), direction: type === 'outgoing' ? 'outgoing' : 'incoming', @@ -2292,6 +2293,15 @@ created_at: new Date().toISOString(), status: 'sent' }; + // Soportar reply preview inmediato + if (options && options.reply_to_message_id) { + msg.reply_to_message_id = options.reply_to_message_id; + } + // Soportar attachments/meta si es necesario + if (options && options.message_type) { + msg.message_type = options.message_type; + } + this.conversations.push(msg); this.renderconversations(); this.scrollToBottom(); @@ -2417,7 +2427,7 @@ if (result && result.success) { input.value = ''; // Mostrar inmediatamente en la vista - this.addMessageToView(message, 'outgoing'); + this.addMessageToView(message, 'outgoing', { reply_to_message_id: replyTo }); typeof showAlert !== 'undefined' && showAlert('Mensaje enviado correctamente', 'success'); // Recargar mensajes y conversaciones en background this.loadconversations(this.currentUserId, false).catch(e=>console.warn(e)); diff --git a/services/WhatsAppService.php b/services/WhatsAppService.php index 46c50f4..ee5d864 100644 --- a/services/WhatsAppService.php +++ b/services/WhatsAppService.php @@ -551,12 +551,13 @@ class WhatsAppService // Si es reply (context) if (isset($data['context']['message_id'])) { - $messageData['reply_to_message_id'] = is_numeric($data['context']['message_id']) ? intval($data['context']['message_id']) : null; + // WhatsApp message IDs can be alphanumeric (e.g., wamid...), store as string + $messageData['reply_to_message_id'] = trim((string)$data['context']['message_id']) ?: null; } // Si es reaction if ($data['type'] === 'reaction' && isset($data['reaction'])) { - $messageData['reaction_to_message_id'] = is_numeric($data['reaction']['message_id'] ?? null) ? intval($data['reaction']['message_id']) : null; + $messageData['reaction_to_message_id'] = isset($data['reaction']['message_id']) ? trim((string)$data['reaction']['message_id']) : null; $messageData['reaction_emoji'] = $data['reaction']['emoji'] ?? null; }