Update conversations.php

This commit is contained in:
Lizandro Guarnizo
2026-01-23 23:05:53 -05:00
parent f8e3ae73c1
commit a590882063
+24 -3
View File
@@ -1073,6 +1073,13 @@
return text.substring(0, maxLength) + '...'; 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() { playNotificationSound() {
try { try {
// Small beep using Web Audio API (no external file needed) // Small beep using Web Audio API (no external file needed)
@@ -1638,7 +1645,13 @@
async sendTemplateQuick(templateName, language) { async sendTemplateQuick(templateName, language) {
if (!this.currentUserId) return; if (!this.currentUserId) return;
const conv = this.conversations.find(c => c.user_id === this.currentUserId); 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 { try {
const resp = await fetch('api/send_message.php', { const resp = await fetch('api/send_message.php', {
@@ -1693,10 +1706,18 @@
alert('Seleccione una plantilla'); alert('Seleccione una plantilla');
return; 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 // 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) { if (resp && resp.success) {
showAlert('Plantilla enviada', 'success'); showAlert && showAlert('Plantilla enviada', 'success');
await this.loadconversations(this.currentUserId, false); await this.loadconversations(this.currentUserId, false);
await this.loadConversations(); await this.loadConversations();
} else { } else {