From a590882063126bb2b3c4d59d79ef172ffdb2d25b Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 23 Jan 2026 23:05:53 -0500 Subject: [PATCH] Update conversations.php --- conversations.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/conversations.php b/conversations.php index 36206ca..8bea055 100644 --- a/conversations.php +++ b/conversations.php @@ -1073,6 +1073,13 @@ return text.substring(0, maxLength) + '...'; } + getConversationPhone(userId) { + const conv = this.conversations.find(c => c.user_id === userId); + if (conv) return conv.phone_number || conv.phone || conv.user_phone || null; + const el = document.getElementById('chat-phone'); + return el ? el.textContent.trim() : null; + } + playNotificationSound() { try { // Small beep using Web Audio API (no external file needed) @@ -1638,7 +1645,13 @@ async sendTemplateQuick(templateName, language) { if (!this.currentUserId) return; const conv = this.conversations.find(c => c.user_id === this.currentUserId); - const phone = conv ? conv.user_phone : document.getElementById('chat-phone').textContent; + const phone = conv ? (conv.phone_number || conv.phone || conv.user_phone) : (document.getElementById('chat-phone') ? document.getElementById('chat-phone').textContent.trim() : null); + + if (!phone) { + alert('No se pudo determinar el número de teléfono del destinatario.'); + console.error('sendTemplateQuick: missing phone for user', this.currentUserId, conv); + return; + } try { const resp = await fetch('api/send_message.php', { @@ -1693,10 +1706,18 @@ alert('Seleccione una plantilla'); return; } + + const recipient = this.getConversationPhone(this.currentUserId); + if (!recipient) { + alert('No se pudo determinar el número de destino para la plantilla'); + console.error('sendMessage(template): missing recipient for user', this.currentUserId); + return; + } + // send template - const resp = await apiCall('send_message.php', { body: { recipient: this.getConversationPhone(this.currentUserId), type: 'template', template_name: template, language: (document.getElementById('templateSelect').selectedOptions[0] ? document.getElementById('templateSelect').selectedOptions[0].dataset.language : 'es') } }); + const resp = await apiCall('send_message.php', { body: { recipient, type: 'template', template_name: template, language: (document.getElementById('templateSelect').selectedOptions[0] ? document.getElementById('templateSelect').selectedOptions[0].dataset.language : 'es') } }); if (resp && resp.success) { - showAlert('Plantilla enviada', 'success'); + showAlert && showAlert('Plantilla enviada', 'success'); await this.loadconversations(this.currentUserId, false); await this.loadConversations(); } else {