This commit is contained in:
lizandrogd
2026-01-21 11:17:36 -05:00
parent 5727721f02
commit fccaa3b649
6 changed files with 119 additions and 1 deletions
+39
View File
@@ -9,6 +9,10 @@ class SimpleWhatsAppManager {
this.currentTab = 'dashboard';
this.init();
// Webhook polling state
this._lastWebhook = null;
this.setupWebhookPolling();
}
init() {
@@ -161,6 +165,41 @@ class SimpleWhatsAppManager {
}
}
// Polling ligero para detectar nuevos webhooks y refrescar UI rápidamente
setupWebhookPolling() {
// Ejecutar cada 5 segundos
setInterval(async () => {
try {
const res = await fetch(this.apiBaseUrl + 'get_last_webhook_time.php');
if (!res.ok) return;
const data = await res.json();
if (!data || !data.success) return;
const last = data.last_webhook;
if (!last) return;
if (this._lastWebhook && this._lastWebhook === last) return;
// Hubo un nuevo webhook
this._lastWebhook = last;
this.log('Nuevo webhook detectado, refrescando conversaciones', 'info');
// Refrescar lista de conversaciones
await this.loadUsers(); // reload users (optional)
await this.loadconversations(); // reload message-related selects if on send_message
await this.loadConversations();
// Si hay un chat abierto, recargar sus mensajes
if (this.currentTab === 'conversations' && this.currentUserId) {
await this.loadconversations(this.currentUserId, false);
}
} catch (e) {
this.log('Error polling webhook: ' + e.message, 'error');
}
}, 5000);
}
async apiCallReal(endpoint, options = {}) {
const url = `${this.apiBaseUrl}${endpoint}`;