This commit is contained in:
Lizandro Guarnizo
2026-01-24 01:01:12 -05:00
parent 60e41bfa1a
commit 3d45d54f0c
2 changed files with 16 additions and 5 deletions
+13 -3
View File
@@ -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));
+3 -2
View File
@@ -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;
}