diff --git a/conversations.php b/conversations.php index ddd1f69..36206ca 100644 --- a/conversations.php +++ b/conversations.php @@ -553,7 +553,7 @@
-
Usuario +
Usuario
+1234567890 @@ -1099,7 +1099,8 @@ document.getElementById('chat-area').style.display = 'flex'; // Actualizar header - document.getElementById('chat-name').textContent = userName; + const nameEl = document.getElementById('chat-name-text') || document.getElementById('chat-name'); + nameEl.textContent = userName; document.getElementById('chat-phone').textContent = phoneNumber; document.getElementById('chat-avatar').textContent = this.getInitials(userName); @@ -1658,6 +1659,14 @@ } } + async sendQuickReply(text) { + if (!text) return; + const input = document.getElementById('message-input'); + if (!input) return; + input.value = text; + await this.sendMessage(); + } + scrollToBottom() { const container = document.getElementById('chat-conversations'); container.scrollTop = container.scrollHeight; @@ -1732,31 +1741,12 @@ } } - async loadQuickReplies() { - try { - const resp = await fetch('api/get_templates.php?approved_only=1&limit=10'); - const json = await resp.json(); - const container = document.getElementById('quick-replies'); - if (!container) return; - container.innerHTML = ''; - if (json && json.success && Array.isArray(json.data)) { - const templates = json.data.slice(0,5); - templates.forEach(t => { - const text = (t.body_text || t.name || t.template_name || '').replace(/\n/g,' '); - const btn = document.createElement('button'); - btn.className = 'btn btn-sm btn-outline-secondary'; - btn.dataset.qr = text; - btn.textContent = text.length > 30 ? text.substring(0,30) + '...' : text; - container.appendChild(btn); - }); - } - } catch (err) { - console.error('loadQuickReplies error', err); - } - } + // loadQuickReplies is implemented earlier (combined autoresponses & templates) + // kept here as a no-op to avoid accidentally overriding the real implementation. async promptEditUser() { - const currentName = document.getElementById('chat-name').textContent || ''; + const nameEl = document.getElementById('chat-name-text') || document.getElementById('chat-name'); + const currentName = nameEl ? nameEl.textContent.trim() : ''; const newName = prompt('Nombre del usuario:', currentName); if (!newName) return; @@ -1768,15 +1758,15 @@ }); const json = await resp.json(); if (json && json.success) { - document.getElementById('chat-name').textContent = newName; - this.showSuccess('Usuario actualizado'); + if (nameEl) nameEl.textContent = newName; + this.showSuccess && this.showSuccess('Usuario actualizado'); this.loadConversations(); } else { - this.showError('No se pudo actualizar usuario'); + this.showError && this.showError('No se pudo actualizar usuario'); } } catch (err) { console.error(err); - this.showError('Error actualizando usuario'); + this.showError && this.showError('Error actualizando usuario'); } }