feat: Major WhatsApp integration update with Odoo and pause/resume

## Frontend
- Add media display (images, audio, video, docs) in Inbox
- Add pause/resume functionality for WhatsApp accounts
- Fix media URLs to use nginx proxy (relative URLs)

## API Gateway
- Add /accounts/:id/pause and /accounts/:id/resume endpoints
- Fix media URL handling for browser access

## WhatsApp Core
- Add pauseSession() - disconnect without logout
- Add resumeSession() - reconnect using saved credentials
- Add media download and storage for incoming messages
- Serve media files via /media/ static route

## Odoo Module (odoo_whatsapp_hub)
- Add Chat Hub interface with DOLLARS theme (dark, 3-column layout)
- Add WhatsApp/DRRR theme switcher for chat view
- Add "ABRIR CHAT" button in conversation form
- Add send_message_from_chat() method
- Add security/ir.model.access.csv
- Fix CSS scoping to avoid breaking Odoo UI
- Update webhook to handle message events properly

## Documentation
- Add docs/CONTEXTO_DESARROLLO.md with complete project context

## Infrastructure
- Add whatsapp_media Docker volume
- Configure nginx proxy for /media/ route
- Update .gitignore to track src/sessions/ source files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude AI
2026-01-30 20:48:56 +00:00
parent 1040debe2e
commit 5dd3499097
33 changed files with 3636 additions and 138 deletions

220
qr-realtime.html Normal file
View File

@@ -0,0 +1,220 @@
<!DOCTYPE html>
<html>
<head>
<title>WhatsApp QR - Tiempo Real</title>
<script src="https://cdn.socket.io/4.7.2/socket.io.min.js"></script>
<style>
body {
font-family: Arial;
text-align: center;
padding: 20px;
background: linear-gradient(135deg, #075e54 0%, #128c7e 100%);
color: white;
min-height: 100vh;
margin: 0;
}
.container { max-width: 500px; margin: 0 auto; }
h1 { margin-bottom: 10px; }
#qr-container {
background: white;
padding: 20px;
border-radius: 15px;
margin: 20px 0;
min-height: 300px;
display: flex;
align-items: center;
justify-content: center;
}
#qr-container img { max-width: 100%; border-radius: 10px; }
#status {
padding: 15px;
border-radius: 10px;
margin: 10px 0;
font-size: 18px;
font-weight: bold;
}
.connecting { background: #f39c12; }
.connected { background: #27ae60; }
.disconnected { background: #e74c3c; }
.waiting { background: #3498db; }
button {
padding: 15px 40px;
font-size: 18px;
cursor: pointer;
border: none;
border-radius: 10px;
background: #25D366;
color: white;
margin: 10px;
}
button:hover { background: #128C7E; }
.instructions {
background: rgba(255,255,255,0.1);
padding: 15px;
border-radius: 10px;
margin-top: 20px;
text-align: left;
}
.instructions ol { margin: 10px 0; padding-left: 20px; }
</style>
</head>
<body>
<div class="container">
<h1>📱 Vincular WhatsApp</h1>
<p>Servidor: 192.168.10.221</p>
<div id="status" class="waiting">Esperando conexión...</div>
<div id="qr-container">
<p style="color: #666;">Click "Iniciar" para generar el código QR</p>
</div>
<button onclick="startSession()">🚀 Iniciar Sesión</button>
<button onclick="checkStatus()" style="background: #3498db;">🔄 Verificar Estado</button>
<div class="instructions">
<strong>Instrucciones:</strong>
<ol>
<li>Click en "Iniciar Sesión"</li>
<li>Espera a que aparezca el código QR</li>
<li>Abre WhatsApp en tu teléfono</li>
<li>Ve a Configuración → Dispositivos vinculados</li>
<li>Escanea el código QR</li>
</ol>
</div>
<div id="phone-info" style="margin-top: 20px;"></div>
</div>
<script>
const API = 'http://192.168.10.221:3001';
const SESSION_ID = 'whatsapp_' + Date.now();
let socket = null;
function updateStatus(status, className) {
const el = document.getElementById('status');
el.textContent = status;
el.className = className;
}
function showQR(qrDataUrl) {
document.getElementById('qr-container').innerHTML =
'<img src="' + qrDataUrl + '" alt="QR Code">';
updateStatus('📸 Escanea el código QR con WhatsApp', 'connecting');
}
function connectSocket() {
socket = io(API, { path: '/ws' });
socket.on('connect', () => {
console.log('Socket conectado');
socket.emit('subscribe', SESSION_ID);
});
socket.on('qr', (event) => {
console.log('QR recibido:', event);
if (event.accountId === SESSION_ID && event.data.qrCode) {
showQR(event.data.qrCode);
}
});
socket.on('connected', (event) => {
console.log('WhatsApp conectado:', event);
if (event.accountId === SESSION_ID) {
document.getElementById('qr-container').innerHTML =
'<div style="color: #27ae60; font-size: 48px;">✅</div>' +
'<h2 style="color: #333;">¡Conectado!</h2>';
updateStatus('✅ WhatsApp conectado exitosamente', 'connected');
document.getElementById('phone-info').innerHTML =
'<p>Teléfono: <strong>' + (event.data.phoneNumber || 'N/A') + '</strong></p>';
}
});
socket.on('disconnected', (event) => {
console.log('Desconectado:', event);
if (event.accountId === SESSION_ID) {
updateStatus('❌ Desconectado: ' + (event.data.reason || ''), 'disconnected');
}
});
}
async function startSession() {
updateStatus('🔄 Creando sesión...', 'connecting');
document.getElementById('qr-container').innerHTML =
'<p style="color: #666;">Generando código QR...</p>';
// Conectar socket primero
if (!socket || !socket.connected) {
connectSocket();
}
try {
const res = await fetch(API + '/api/sessions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
accountId: SESSION_ID,
name: 'WhatsApp ' + new Date().toLocaleTimeString()
})
});
const data = await res.json();
console.log('Sesión creada:', data);
updateStatus('⏳ Esperando código QR...', 'waiting');
// Verificar estado cada 2 segundos
let attempts = 0;
const checkInterval = setInterval(async () => {
attempts++;
try {
const statusRes = await fetch(API + '/api/sessions/' + SESSION_ID);
const statusData = await statusRes.json();
console.log('Estado:', statusData);
if (statusData.qrCode) {
showQR(statusData.qrCode);
} else if (statusData.status === 'connected') {
clearInterval(checkInterval);
document.getElementById('qr-container').innerHTML =
'<div style="color: #27ae60; font-size: 48px;">✅</div>' +
'<h2 style="color: #333;">¡Conectado!</h2>';
updateStatus('✅ WhatsApp conectado', 'connected');
}
if (attempts > 30) { // 60 segundos
clearInterval(checkInterval);
updateStatus('⏱️ Tiempo agotado. Intenta de nuevo.', 'disconnected');
}
} catch (e) {
console.error('Error verificando:', e);
}
}, 2000);
} catch (e) {
console.error('Error:', e);
updateStatus('❌ Error: ' + e.message, 'disconnected');
}
}
async function checkStatus() {
try {
const res = await fetch(API + '/api/sessions');
const sessions = await res.json();
console.log('Sesiones:', sessions);
let info = 'Sesiones activas: ' + sessions.length;
sessions.forEach(s => {
info += '\\n- ' + s.name + ': ' + s.status;
if (s.phoneNumber) info += ' (' + s.phoneNumber + ')';
});
alert(info);
} catch (e) {
alert('Error: ' + e.message);
}
}
// Auto-conectar socket al cargar
connectSocket();
</script>
</body>
</html>