mejoras
This commit is contained in:
@@ -548,7 +548,7 @@ body {
|
||||
border-left: 4px solid var(--info-color);
|
||||
}
|
||||
|
||||
/* Recent Messages */
|
||||
/* Recent conversations */
|
||||
.recent-message {
|
||||
padding: 10px 15px;
|
||||
border-radius: 8px;
|
||||
|
||||
+36
-36
@@ -52,11 +52,11 @@ class WhatsAppBotManager {
|
||||
|
||||
setupFormListeners() {
|
||||
// Formulario de configuración
|
||||
const settingsForm = document.getElementById('settings-form');
|
||||
if (settingsForm) {
|
||||
settingsForm.addEventListener('submit', (e) => {
|
||||
const system_configForm = document.getElementById('system_config-form');
|
||||
if (system_configForm) {
|
||||
system_configForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
this.saveSettings();
|
||||
this.savesystem_config();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ class WhatsAppBotManager {
|
||||
case 'menus':
|
||||
this.loadMenus();
|
||||
break;
|
||||
case 'messages':
|
||||
case 'conversations':
|
||||
this.loadMessageUsers();
|
||||
break;
|
||||
case 'templates':
|
||||
@@ -158,8 +158,8 @@ class WhatsAppBotManager {
|
||||
case 'autoresponses':
|
||||
this.loadAutoResponses();
|
||||
break;
|
||||
case 'settings':
|
||||
this.loadSettings();
|
||||
case 'system_config':
|
||||
this.loadsystem_config();
|
||||
break;
|
||||
case 'logs':
|
||||
this.loadLogs();
|
||||
@@ -172,12 +172,12 @@ class WhatsAppBotManager {
|
||||
const stats = await this.apiCall('get_stats.php');
|
||||
this.updateStats(stats);
|
||||
|
||||
const recentMessagesResponse = await this.apiCall('get_recent_messages.php');
|
||||
if (recentMessagesResponse && recentMessagesResponse.success && Array.isArray(recentMessagesResponse.data)) {
|
||||
this.updateRecentMessages(recentMessagesResponse.data);
|
||||
} else if (recentMessagesResponse && Array.isArray(recentMessagesResponse)) {
|
||||
const recentconversationsResponse = await this.apiCall('get_recent_conversations.php');
|
||||
if (recentconversationsResponse && recentconversationsResponse.success && Array.isArray(recentconversationsResponse.data)) {
|
||||
this.updateRecentconversations(recentconversationsResponse.data);
|
||||
} else if (recentconversationsResponse && Array.isArray(recentconversationsResponse)) {
|
||||
// Retrocompatibilidad por si la API devuelve directamente el array
|
||||
this.updateRecentMessages(recentMessagesResponse);
|
||||
this.updateRecentconversations(recentconversationsResponse);
|
||||
}
|
||||
|
||||
this.updateChart();
|
||||
@@ -189,20 +189,20 @@ class WhatsAppBotManager {
|
||||
updateStats(stats) {
|
||||
if (stats) {
|
||||
document.getElementById('total-users').textContent = stats.total_users || 0;
|
||||
document.getElementById('messages-today').textContent = stats.messages_today || 0;
|
||||
document.getElementById('conversations-today').textContent = stats.conversations_today || 0;
|
||||
document.getElementById('active-users').textContent = stats.active_users || 0;
|
||||
document.getElementById('total-messages').textContent = stats.total_messages || 0;
|
||||
document.getElementById('total-conversations').textContent = stats.total_conversations || 0;
|
||||
}
|
||||
}
|
||||
|
||||
updateRecentMessages(messages) {
|
||||
const container = document.getElementById('recent-messages');
|
||||
updateRecentconversations(conversations) {
|
||||
const container = document.getElementById('recent-conversations');
|
||||
if (!container) return;
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
if (messages && messages.length > 0) {
|
||||
messages.forEach(message => {
|
||||
if (conversations && conversations.length > 0) {
|
||||
conversations.forEach(message => {
|
||||
const messageElement = this.createRecentMessageElement(message);
|
||||
container.appendChild(messageElement);
|
||||
});
|
||||
@@ -230,9 +230,9 @@ class WhatsAppBotManager {
|
||||
}
|
||||
|
||||
setupCharts() {
|
||||
const ctx = document.getElementById('messagesChart');
|
||||
const ctx = document.getElementById('conversationsChart');
|
||||
if (ctx) {
|
||||
this.charts.messages = new Chart(ctx, {
|
||||
this.charts.conversations = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [],
|
||||
@@ -275,10 +275,10 @@ class WhatsAppBotManager {
|
||||
async updateChart() {
|
||||
try {
|
||||
const chartData = await this.apiCall('get_chart_data.php');
|
||||
if (chartData && this.charts.messages) {
|
||||
this.charts.messages.data.labels = chartData.labels;
|
||||
this.charts.messages.data.datasets[0].data = chartData.data;
|
||||
this.charts.messages.update();
|
||||
if (chartData && this.charts.conversations) {
|
||||
this.charts.conversations.data.labels = chartData.labels;
|
||||
this.charts.conversations.data.datasets[0].data = chartData.data;
|
||||
this.charts.conversations.update();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error updating chart:', error);
|
||||
@@ -725,7 +725,7 @@ class WhatsAppBotManager {
|
||||
}
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
async savesystem_config() {
|
||||
const formData = {
|
||||
whatsapp_token: document.getElementById('whatsapp-token').value,
|
||||
phone_number_id: document.getElementById('phone-number-id').value,
|
||||
@@ -736,7 +736,7 @@ class WhatsAppBotManager {
|
||||
|
||||
try {
|
||||
this.showLoading('Guardando configuración...');
|
||||
const result = await this.apiCall('save_settings.php', 'POST', formData);
|
||||
const result = await this.apiCall('save_system_config.php', 'POST', formData);
|
||||
|
||||
if (result.success) {
|
||||
this.showSuccess('Configuración guardada correctamente');
|
||||
@@ -750,16 +750,16 @@ class WhatsAppBotManager {
|
||||
}
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
async loadsystem_config() {
|
||||
try {
|
||||
const settings = await this.apiCall('get_settings.php');
|
||||
const system_config = await this.apiCall('get_system_config.php');
|
||||
|
||||
if (settings) {
|
||||
document.getElementById('whatsapp-token').value = settings.whatsapp_token || '';
|
||||
document.getElementById('phone-number-id').value = settings.phone_number_id || '';
|
||||
document.getElementById('webhook-token').value = settings.webhook_token || '';
|
||||
document.getElementById('business-name').value = settings.business_name || '';
|
||||
document.getElementById('welcome-message').value = settings.welcome_message || '';
|
||||
if (system_config) {
|
||||
document.getElementById('whatsapp-token').value = system_config.whatsapp_token || '';
|
||||
document.getElementById('phone-number-id').value = system_config.phone_number_id || '';
|
||||
document.getElementById('webhook-token').value = system_config.webhook_token || '';
|
||||
document.getElementById('business-name').value = system_config.business_name || '';
|
||||
document.getElementById('welcome-message').value = system_config.welcome_message || '';
|
||||
}
|
||||
} catch (error) {
|
||||
this.showError('Error cargando configuración: ' + error.message);
|
||||
@@ -1025,7 +1025,7 @@ class WhatsAppBotManager {
|
||||
|
||||
replyToUser(phoneNumber) {
|
||||
document.getElementById('message-recipient').value = phoneNumber;
|
||||
this.showTab('messages');
|
||||
this.showTab('conversations');
|
||||
}
|
||||
|
||||
replyToMessage(messageId, userPhone) {
|
||||
@@ -1049,7 +1049,7 @@ class WhatsAppBotManager {
|
||||
if (data.success) {
|
||||
this.showSuccess('Reacción enviada');
|
||||
// Refrescar mensajes
|
||||
await this.loadMessages(this.currentUserId, false);
|
||||
await this.loadconversations(this.currentUserId, false);
|
||||
} else {
|
||||
this.showError('Error enviando reacción: ' + (data.error || 'desconocido'));
|
||||
}
|
||||
|
||||
+45
-45
@@ -46,11 +46,11 @@ class SimpleWhatsAppManager {
|
||||
|
||||
setupFormListeners() {
|
||||
// Formulario de configuración
|
||||
const settingsForm = document.getElementById('settings-form');
|
||||
if (settingsForm) {
|
||||
settingsForm.addEventListener('submit', (e) => {
|
||||
const system_configForm = document.getElementById('system_config-form');
|
||||
if (system_configForm) {
|
||||
system_configForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
this.saveSettings();
|
||||
this.savesystem_config();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ class SimpleWhatsAppManager {
|
||||
case 'users':
|
||||
this.loadUsers();
|
||||
break;
|
||||
case 'messages':
|
||||
this.loadMessages();
|
||||
case 'conversations':
|
||||
this.loadconversations();
|
||||
break;
|
||||
case 'templates':
|
||||
this.loadTemplates();
|
||||
@@ -123,8 +123,8 @@ class SimpleWhatsAppManager {
|
||||
case 'logs':
|
||||
this.loadLogs();
|
||||
break;
|
||||
case 'settings':
|
||||
this.loadSettings();
|
||||
case 'system_config':
|
||||
this.loadsystem_config();
|
||||
break;
|
||||
default:
|
||||
this.log(`Tab no reconocido: ${tabName}`, 'warning');
|
||||
@@ -200,12 +200,12 @@ class SimpleWhatsAppManager {
|
||||
this.updateStats(stats);
|
||||
|
||||
// Cargar mensajes recientes
|
||||
const recentMessagesResponse = await this.apiCall('get_recent_messages.php');
|
||||
if (recentMessagesResponse && recentMessagesResponse.success && Array.isArray(recentMessagesResponse.data)) {
|
||||
this.updateRecentMessages(recentMessagesResponse.data);
|
||||
} else if (recentMessagesResponse && Array.isArray(recentMessagesResponse)) {
|
||||
const recentconversationsResponse = await this.apiCall('get_recent_conversations.php');
|
||||
if (recentconversationsResponse && recentconversationsResponse.success && Array.isArray(recentconversationsResponse.data)) {
|
||||
this.updateRecentconversations(recentconversationsResponse.data);
|
||||
} else if (recentconversationsResponse && Array.isArray(recentconversationsResponse)) {
|
||||
// Retrocompatibilidad por si la API devuelve directamente el array
|
||||
this.updateRecentMessages(recentMessagesResponse);
|
||||
this.updateRecentconversations(recentconversationsResponse);
|
||||
}
|
||||
|
||||
// Actualizar gráfico si existe
|
||||
@@ -222,9 +222,9 @@ class SimpleWhatsAppManager {
|
||||
if (stats) {
|
||||
const elements = [
|
||||
{ id: 'total-users', value: stats.total_users || 0 },
|
||||
{ id: 'messages-today', value: stats.messages_today || 0 },
|
||||
{ id: 'conversations-today', value: stats.conversations_today || 0 },
|
||||
{ id: 'active-users', value: stats.active_users || 0 },
|
||||
{ id: 'total-messages', value: stats.total_messages || 0 }
|
||||
{ id: 'total-conversations', value: stats.total_conversations || 0 }
|
||||
];
|
||||
|
||||
elements.forEach(item => {
|
||||
@@ -237,8 +237,8 @@ class SimpleWhatsAppManager {
|
||||
}
|
||||
}
|
||||
|
||||
updateRecentMessages(messages) {
|
||||
const container = document.getElementById('recent-messages');
|
||||
updateRecentconversations(conversations) {
|
||||
const container = document.getElementById('recent-conversations');
|
||||
if (!container) {
|
||||
this.log('Contenedor de mensajes recientes no encontrado', 'warning');
|
||||
return;
|
||||
@@ -246,9 +246,9 @@ class SimpleWhatsAppManager {
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
if (messages && messages.length > 0) {
|
||||
this.log(`Mostrando ${messages.length} mensajes recientes`);
|
||||
messages.forEach(message => {
|
||||
if (conversations && conversations.length > 0) {
|
||||
this.log(`Mostrando ${conversations.length} mensajes recientes`);
|
||||
conversations.forEach(message => {
|
||||
const messageElement = this.createRecentMessageElement(message);
|
||||
container.appendChild(messageElement);
|
||||
});
|
||||
@@ -281,17 +281,17 @@ class SimpleWhatsAppManager {
|
||||
}
|
||||
|
||||
async updateChart() {
|
||||
if (!this.charts || !this.charts.messages) {
|
||||
if (!this.charts || !this.charts.conversations) {
|
||||
this.log('Gráfico no inicializado, omitiendo actualización', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const chartData = await this.apiCall('get_chart_data.php');
|
||||
if (chartData && this.charts.messages) {
|
||||
this.charts.messages.data.labels = chartData.labels || [];
|
||||
this.charts.messages.data.datasets[0].data = chartData.data || [];
|
||||
this.charts.messages.update();
|
||||
if (chartData && this.charts.conversations) {
|
||||
this.charts.conversations.data.labels = chartData.labels || [];
|
||||
this.charts.conversations.data.datasets[0].data = chartData.data || [];
|
||||
this.charts.conversations.update();
|
||||
this.log('Gráfico actualizado correctamente');
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -300,7 +300,7 @@ class SimpleWhatsAppManager {
|
||||
}
|
||||
|
||||
setupCharts() {
|
||||
const ctx = document.getElementById('messagesChart');
|
||||
const ctx = document.getElementById('conversationsChart');
|
||||
if (!ctx) {
|
||||
this.log('Canvas de gráfico no encontrado', 'warning');
|
||||
return;
|
||||
@@ -313,7 +313,7 @@ class SimpleWhatsAppManager {
|
||||
|
||||
try {
|
||||
this.charts = this.charts || {};
|
||||
this.charts.messages = new Chart(ctx, {
|
||||
this.charts.conversations = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [],
|
||||
@@ -634,14 +634,14 @@ class SimpleWhatsAppManager {
|
||||
return date.toLocaleDateString();
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
async loadsystem_config() {
|
||||
this.log('Cargando configuraciones');
|
||||
|
||||
try {
|
||||
const response = await this.apiCall('manage_config.php?action=whatsapp');
|
||||
|
||||
if (response && response.success) {
|
||||
this.updateSettingsForm(response.data);
|
||||
this.updatesystem_configForm(response.data);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
@@ -649,7 +649,7 @@ class SimpleWhatsAppManager {
|
||||
}
|
||||
}
|
||||
|
||||
updateSettingsForm(data) {
|
||||
updatesystem_configForm(data) {
|
||||
if (!data) return;
|
||||
|
||||
const fields = [
|
||||
@@ -672,10 +672,10 @@ class SimpleWhatsAppManager {
|
||||
});
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
async savesystem_config() {
|
||||
this.log('Guardando configuraciones');
|
||||
|
||||
const settings = {
|
||||
const system_config = {
|
||||
token: document.getElementById('whatsapp-token').value,
|
||||
phone_number_id: document.getElementById('phone-number-id').value,
|
||||
webhook_verify_token: document.getElementById('webhook-token').value,
|
||||
@@ -687,7 +687,7 @@ class SimpleWhatsAppManager {
|
||||
try {
|
||||
const response = await this.apiCall('manage_config.php?action=save_whatsapp', {
|
||||
method: 'POST',
|
||||
body: { whatsapp: settings }
|
||||
body: { whatsapp: system_config }
|
||||
});
|
||||
|
||||
if (response && response.success) {
|
||||
@@ -741,7 +741,7 @@ class SimpleWhatsAppManager {
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
async loadMessages() {
|
||||
async loadconversations() {
|
||||
this.log('Cargando interfaz de mensajes');
|
||||
|
||||
try {
|
||||
@@ -1606,7 +1606,7 @@ window.openChatWindow = function (userId) {
|
||||
};
|
||||
|
||||
// Función para mostrar modal de chat
|
||||
function showChatModal(user, messages) {
|
||||
function showChatModal(user, conversations) {
|
||||
// Escapar datos del usuario para evitar XSS
|
||||
const userName = escapeHtml(user.name || 'Usuario');
|
||||
const userPhone = escapeHtml(user.phone_number || '');
|
||||
@@ -1623,8 +1623,8 @@ function showChatModal(user, messages) {
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body p-0">
|
||||
<div id="chat-messages" class="chat-container" style="height: 400px; overflow-y: auto; padding: 15px; background-color: #e5ddd5;">
|
||||
${generateChatMessages(messages)}
|
||||
<div id="chat-conversations" class="chat-container" style="height: 400px; overflow-y: auto; padding: 15px; background-color: #e5ddd5;">
|
||||
${generateChatconversations(conversations)}
|
||||
</div>
|
||||
<div class="border-top p-3">
|
||||
<div class="row">
|
||||
@@ -1682,19 +1682,19 @@ function showChatModal(user, messages) {
|
||||
|
||||
// Scroll al final
|
||||
setTimeout(() => {
|
||||
const chatContainer = document.getElementById('chat-messages');
|
||||
const chatContainer = document.getElementById('chat-conversations');
|
||||
chatContainer.scrollTop = chatContainer.scrollHeight;
|
||||
}, 200);
|
||||
}
|
||||
|
||||
// Generar HTML de mensajes del chat
|
||||
function generateChatMessages(messages) {
|
||||
if (!messages || messages.length === 0) {
|
||||
function generateChatconversations(conversations) {
|
||||
if (!conversations || conversations.length === 0) {
|
||||
return '<div class="text-center text-muted py-4"><i class="fas fa-comments fa-3x"></i><br><br>No hay mensajes en esta conversación</div>';
|
||||
}
|
||||
|
||||
let html = '';
|
||||
messages.forEach(msg => {
|
||||
conversations.forEach(msg => {
|
||||
const isOutgoing = msg.direction === 'outgoing';
|
||||
const messageClass = isOutgoing ? 'outgoing' : 'incoming';
|
||||
const alignClass = isOutgoing ? 'justify-content-end' : 'justify-content-start';
|
||||
@@ -1878,8 +1878,8 @@ window.viewConversationDetails = async function (userId) {
|
||||
|
||||
// Obtener estadísticas de la conversación (simuladas por ahora)
|
||||
const stats = {
|
||||
total_messages: Math.floor(Math.random() * 50) + 1,
|
||||
messages_today: Math.floor(Math.random() * 10),
|
||||
total_conversations: Math.floor(Math.random() * 50) + 1,
|
||||
conversations_today: Math.floor(Math.random() * 10),
|
||||
last_activity: user.updated_at || user.created_at,
|
||||
first_contact: user.created_at,
|
||||
status: user.status || 'active'
|
||||
@@ -1948,11 +1948,11 @@ function showConversationDetailsModal(user, stats) {
|
||||
<h6 class="text-muted mb-3"><i class="fas fa-chart-line"></i> Estadísticas de Conversación</h6>
|
||||
<div class="mb-3">
|
||||
<strong>Total de Mensajes:</strong>
|
||||
<span class="badge bg-primary">${stats.total_messages || 0}</span>
|
||||
<span class="badge bg-primary">${stats.total_conversations || 0}</span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong>Mensajes Hoy:</strong>
|
||||
<span class="badge bg-success">${stats.messages_today || 0}</span>
|
||||
<span class="badge bg-success">${stats.conversations_today || 0}</span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong>Última Actividad:</strong><br>
|
||||
|
||||
Reference in New Issue
Block a user