- F0 blindaje: Redis/Celery, pg_hba sin trust LAN, secretos a env 600, backups, webhook auth, jobs muertos - F1 caja: bugs POS, reembolsos al corte, apartados, CFDI, topes de descuento en cotizacion/apartado - F2/F7 IA de catalogo: autocategorizacion, dedup de SKUs con embeddings, OCR de facturas, descripciones, claves SAT, limpieza de fitment - F3 IA en el flujo: vision Yonke, preguntas MeLi, venta cruzada, anomalias, sinonimos, busqueda semantica (rerank/embeddings) - F4/F8 escala y cartera: /metrics+Prometheus+Grafana, pool, score de credito, churn, metricas multi-tenant - Nexus Yonke (M1-M6): modelo de datos 1-de-1, alta por donador, vitrina publica, MeLi usado, consignacion, garantia por dias, reportes, etiquetas - Marketplace B2B entre yonkes (catalogo + pedidos cross-tenant) - Seguridad: auth en /api/admin/* (35 endpoints), alertas por tenant - Migraciones v4.27/v4.28; timers expire-demos y rollup-metrics
231 lines
11 KiB
HTML
231 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<script>/*pos_theme_early*/(function(){var t=localStorage.getItem("pos_theme")||"industrial";document.documentElement.setAttribute("data-theme",t);})()</script>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
|
<meta http-equiv="Pragma" content="no-cache" />
|
|
<meta http-equiv="Expires" content="0" />
|
|
<title>WhatsApp — Nexus Autoparts POS</title>
|
|
<link rel="stylesheet" href="/pos/static/css/chat.css" />
|
|
<link rel="stylesheet" href="/pos/static/css/tokens.css" />
|
|
<link rel="stylesheet" href="/pos/static/css/common.css" />
|
|
<link rel="stylesheet" href="/pos/static/css/pos-ui.css?v=33" />
|
|
<link rel="stylesheet" href="/pos/static/css/sidebar.css" />
|
|
<link rel="stylesheet" href="/pos/static/css/pos-glass.css" />
|
|
<link rel="manifest" href="/pos/static/pwa/manifest.json" />
|
|
<meta name="theme-color" content="#F5A623" />
|
|
<link rel="shortcut icon" type="image/png" href="/pos/static/pwa/icon-192.png" />
|
|
|
|
<link rel="stylesheet" href="/pos/static/css/whatsapp.css"></head>
|
|
<body>
|
|
|
|
<div class="page-shell">
|
|
<!-- Sidebar injected by sidebar.js -->
|
|
<aside class="sidebar"></aside>
|
|
|
|
<div class="main-content pos-main-offset">
|
|
<!-- Top bar -->
|
|
<div class="top-bar">
|
|
<div class="top-bar__title">
|
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/>
|
|
</svg>
|
|
WhatsApp Business
|
|
</div>
|
|
<div class="top-bar__actions">
|
|
<div class="top-bar__status">
|
|
<span class="status-dot" id="statusDot"></span>
|
|
<span id="statusText">Verificando...</span>
|
|
</div>
|
|
<button class="btn btn--sm btn--whatsapp" id="connectBtn" style="display:none">Conectar WhatsApp</button>
|
|
<button class="btn btn--sm" id="disconnectBtn" style="display:none">Desconectar</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Connection / QR section (shown when not connected) -->
|
|
<div class="connect-section" id="connectSection" style="display:none">
|
|
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#25D366" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/>
|
|
</svg>
|
|
<div class="connect-section__title">Conectar WhatsApp</div>
|
|
<div class="connect-section__desc">
|
|
Escanea el codigo QR con tu telefono para vincular WhatsApp.<br>
|
|
Abre WhatsApp > Dispositivos vinculados > Vincular un dispositivo.
|
|
</div>
|
|
<div class="connect-section__qr">
|
|
<img id="qrImg" style="display:none" alt="QR Code" />
|
|
<span class="connect-section__qr-placeholder" id="qrPlaceholder">
|
|
Haz click en "Conectar WhatsApp" para generar el QR
|
|
</span>
|
|
</div>
|
|
<div class="connect-section__actions">
|
|
<button class="btn btn--sm" id="refreshQrBtn" style="display:none">Actualizar QR</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Messenger (shown when connected) -->
|
|
<div class="messenger" id="messengerArea" style="display:none">
|
|
|
|
<!-- Left: Conversation list -->
|
|
<div class="conv-panel">
|
|
<div class="conv-panel__header">
|
|
<span class="conv-panel__title">Conversaciones</span>
|
|
<button class="btn btn--sm btn--whatsapp" id="newChatBtn" title="Nueva conversacion">
|
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>
|
|
</svg>
|
|
Nuevo
|
|
</button>
|
|
</div>
|
|
<div class="conv-panel__list" id="convList">
|
|
<div class="conv-empty">Cargando...</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Right: Chat view (hidden until a conversation is selected) -->
|
|
<div class="empty-state" id="emptyState">
|
|
<svg width="80" height="80" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/>
|
|
</svg>
|
|
<div class="empty-state__text">Selecciona una conversacion<br>o inicia una nueva</div>
|
|
<div class="empty-state__hint">Los mensajes de WhatsApp aparecen aqui en tiempo real</div>
|
|
</div>
|
|
|
|
<div class="wa-chat-panel" id="waChatPanel" style="display:none">
|
|
<div class="wa-chat-panel__header">
|
|
<button class="btn btn--sm" id="backToListBtn" style="display:none;margin-right:8px;">← Volver</button>
|
|
<span class="wa-chat-panel__phone" id="chatHeaderPhone"></span>
|
|
<div class="wa-chat-panel__actions">
|
|
<button class="btn btn--sm" id="sendQuoteBtn" title="Enviar cotizacion por WhatsApp">
|
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/>
|
|
</svg>
|
|
Enviar Cotizacion
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="wa-chat-panel__messages" id="waChatMessages"></div>
|
|
|
|
<div class="chat-input-bar">
|
|
<textarea id="waChatInput" placeholder="Escribe un mensaje..." rows="1"></textarea>
|
|
<button class="btn btn--primary" id="waSendBtn">
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/>
|
|
</svg>
|
|
Enviar
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div style="max-width:720px;margin:16px auto;padding:16px;border:1px solid var(--color-border);border-radius:12px;">
|
|
<h3 style="margin:0 0 4px;">WA CRM — Meta Cloud API (oficial)</h3>
|
|
<p style="margin:0 0 12px;font-size:var(--text-caption);color:var(--color-text-muted);">
|
|
Un número por refaccionaria. Credenciales de Meta Business (phone number ID + token permanente).
|
|
El proveedor Baileys queda como respaldo.</p>
|
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;">
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">Proveedor</label>
|
|
<select id="waProvider" class="form-input">
|
|
<option value="baileys">Baileys (bridge actual)</option>
|
|
<option value="meta">Meta Cloud API (WA CRM)</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">Phone Number ID</label>
|
|
<input id="waPnid" class="form-input" placeholder="ej. 123456789012345" />
|
|
</div>
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">Access Token</label>
|
|
<input id="waToken" type="password" class="form-input" placeholder="(dejar vacío = sin cambio)" />
|
|
</div>
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">App Secret</label>
|
|
<input id="waSecret" type="password" class="form-input" placeholder="(dejar vacío = sin cambio)" />
|
|
</div>
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">Verify Token (webhook)</label>
|
|
<input id="waVerify" class="form-input" />
|
|
</div>
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">WA CRM — API base</label>
|
|
<input id="waApiBase" class="form-input" placeholder="http://192.168.10.91:3010" />
|
|
</div>
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">WA CRM — API key (wacrm_live_…)</label>
|
|
<input id="waApiKey" type="password" class="form-input" placeholder="(dejar vacío = sin cambio)" />
|
|
</div>
|
|
<div>
|
|
<label style="font-size:var(--text-caption);">URL pública del POS (para imágenes)</label>
|
|
<input id="waPublicBase" class="form-input" placeholder="https://<subdominio>.nexusautoparts.com.mx" />
|
|
</div>
|
|
<div style="display:flex;align-items:flex-end;">
|
|
<button class="btn btn--primary" onclick="saveWaMeta()" style="width:100%;">Guardar WA CRM</button>
|
|
</div>
|
|
</div>
|
|
<div id="waMetaStatus" style="margin-top:8px;font-size:var(--text-caption);color:var(--color-text-muted);"></div>
|
|
</div>
|
|
<script>
|
|
(async function loadWaMeta() {
|
|
try {
|
|
const t = localStorage.getItem('pos_token');
|
|
const r = await fetch('/pos/api/config/whatsapp', { headers: { 'Authorization': 'Bearer ' + t } });
|
|
if (!r.ok) return;
|
|
const d = await r.json();
|
|
document.getElementById('waProvider').value = d.provider || 'baileys';
|
|
document.getElementById('waPnid').value = d.phone_number_id || '';
|
|
document.getElementById('waVerify').value = d.verify_token || '';
|
|
document.getElementById('waApiBase').value = d.api_base || '';
|
|
document.getElementById('waPublicBase').value = d.public_base || '';
|
|
document.getElementById('waMetaStatus').textContent =
|
|
(d.has_access_token ? '✓ Token guardado. ' : 'Sin token. ') +
|
|
(d.has_app_secret ? '✓ App secret guardado.' : 'Sin app secret (webhook sin validación HMAC).');
|
|
} catch (e) { /* noop */ }
|
|
})();
|
|
async function saveWaMeta() {
|
|
const t = localStorage.getItem('pos_token');
|
|
const body = {
|
|
provider: document.getElementById('waProvider').value,
|
|
phone_number_id: document.getElementById('waPnid').value.trim(),
|
|
verify_token: document.getElementById('waVerify').value.trim(),
|
|
api_base: document.getElementById('waApiBase').value.trim(),
|
|
api_key: document.getElementById('waApiKey').value.trim(),
|
|
public_base: document.getElementById('waPublicBase').value.trim(),
|
|
access_token: document.getElementById('waToken').value.trim(),
|
|
app_secret: document.getElementById('waSecret').value.trim(),
|
|
};
|
|
const r = await fetch('/pos/api/config/whatsapp', {
|
|
method: 'PUT', headers: { 'Authorization': 'Bearer ' + t, 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
});
|
|
const el = document.getElementById('waMetaStatus');
|
|
if (r.ok) { el.textContent = '✓ Configuración guardada'; el.style.color = 'var(--color-success)'; }
|
|
else { el.textContent = 'Error guardando'; el.style.color = 'var(--color-error)'; }
|
|
}
|
|
</script>
|
|
|
|
<!-- Theme engine -->
|
|
<script>
|
|
function posSetTheme(t){document.documentElement.setAttribute('data-theme',t);localStorage.setItem('pos_theme',t);}
|
|
function posLogout(){localStorage.removeItem('pos_token');window.location.href='/pos/login';}
|
|
</script>
|
|
|
|
<!-- Sidebar -->
|
|
<script src="/pos/static/js/i18n.js?v=39" defer></script>
|
|
<script src="/pos/static/js/app-init.js?v=9" defer></script>
|
|
<script src="/pos/static/js/splash-loader.js?v=33" defer></script>
|
|
<script src="/pos/static/js/whatsapp2.js?v=33" defer></script>
|
|
<script src="/pos/static/js/pos-utils.js?v=33" defer></script>
|
|
<script src="/pos/static/js/sidebar.js?v=46" defer></script>
|
|
|
|
<script src="/pos/static/js/chat.js" defer></script>
|
|
</body>
|
|
</html>
|