Switch from Meta Business Cloud API to Evolution API for WhatsApp integration. Evolution API is self-hosted, free, and connects via WhatsApp Web QR code scan. - Add docker-compose for Evolution API deployment - Rewrite whatsapp_service.py for Evolution API endpoints - Add instance management (create, QR, status, logout) to blueprint - Add QR code scanning UI with connection status indicator - Add duplicate message prevention in webhook handler - Update config.py with EVOLUTION_API_URL/KEY (remove old Meta vars) - Add setup documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
618 lines
19 KiB
HTML
618 lines
19 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es" data-theme="industrial">
|
|
<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" />
|
|
<title>WhatsApp — Nexus Autoparts POS</title>
|
|
<link rel="stylesheet" href="/pos/static/css/tokens.css" />
|
|
<link rel="manifest" href="/pos/static/pwa/manifest.json" />
|
|
<meta name="theme-color" content="#F5A623" />
|
|
|
|
<style>
|
|
/* =========================================================================
|
|
BASE RESET & SHELL
|
|
========================================================================= */
|
|
|
|
*, *::before, *::after {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
html, body {
|
|
height: 100%;
|
|
}
|
|
|
|
body {
|
|
font-family: var(--font-body);
|
|
font-size: var(--text-body-sm);
|
|
color: var(--color-text-primary);
|
|
background-color: var(--color-bg-base);
|
|
transition: background-color var(--duration-normal) var(--ease-in-out),
|
|
color var(--duration-normal) var(--ease-in-out);
|
|
overflow: hidden;
|
|
}
|
|
|
|
[data-theme="modern"] body {
|
|
background-image: radial-gradient(
|
|
circle,
|
|
var(--dot-grid-color) 1px,
|
|
transparent 1px
|
|
);
|
|
background-size: var(--dot-grid-size) var(--dot-grid-size);
|
|
}
|
|
|
|
/* =========================================================================
|
|
LAYOUT: sidebar offset + full-height messenger
|
|
========================================================================= */
|
|
|
|
.page-shell {
|
|
display: flex;
|
|
height: 100vh;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.main-content {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* =========================================================================
|
|
TOP BAR
|
|
========================================================================= */
|
|
|
|
.top-bar {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
height: 48px;
|
|
padding: 0 var(--space-4);
|
|
background: var(--color-bg-elevated);
|
|
border-bottom: 1px solid var(--color-border);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.top-bar__title {
|
|
font-family: var(--font-heading);
|
|
font-size: var(--text-body);
|
|
font-weight: var(--font-weight-bold);
|
|
letter-spacing: var(--tracking-wide);
|
|
text-transform: uppercase;
|
|
color: var(--color-text-primary);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--space-2);
|
|
}
|
|
|
|
.top-bar__title svg {
|
|
color: #25D366;
|
|
}
|
|
|
|
.top-bar__actions {
|
|
display: flex;
|
|
gap: var(--space-2);
|
|
align-items: center;
|
|
}
|
|
|
|
.top-bar__status {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
font-size: var(--text-caption);
|
|
color: var(--color-text-muted);
|
|
}
|
|
|
|
.status-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
background: var(--color-text-muted);
|
|
}
|
|
|
|
.status-dot--ok { background: var(--color-success); }
|
|
.status-dot--warn { background: var(--color-warning); }
|
|
.status-dot--error { background: var(--color-error); }
|
|
|
|
/* =========================================================================
|
|
MESSENGER LAYOUT: conversations list + chat panel
|
|
========================================================================= */
|
|
|
|
.messenger {
|
|
flex: 1;
|
|
display: flex;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* ─── Left panel: conversation list ──────────────────────────────── */
|
|
|
|
.conv-panel {
|
|
width: 320px;
|
|
min-width: 260px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
border-right: 1px solid var(--color-border);
|
|
background: var(--color-bg-elevated);
|
|
}
|
|
|
|
.conv-panel__header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: var(--space-3) var(--space-4);
|
|
border-bottom: 1px solid var(--color-border);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.conv-panel__title {
|
|
font-weight: var(--font-weight-semibold);
|
|
font-size: var(--text-body-sm);
|
|
color: var(--color-text-secondary);
|
|
text-transform: uppercase;
|
|
letter-spacing: var(--tracking-wider);
|
|
}
|
|
|
|
.conv-panel__list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
scrollbar-width: thin;
|
|
scrollbar-color: var(--scrollbar-thumb, #444) var(--scrollbar-track, #222);
|
|
}
|
|
|
|
.conv-item {
|
|
display: flex;
|
|
flex-direction: column;
|
|
padding: var(--space-3) var(--space-4);
|
|
border-bottom: 1px solid var(--color-border);
|
|
cursor: pointer;
|
|
transition: background var(--duration-fast) var(--ease-in-out);
|
|
}
|
|
|
|
.conv-item:hover {
|
|
background: var(--color-surface-2, rgba(255,255,255,0.04));
|
|
}
|
|
|
|
.conv-item.is-active {
|
|
background: var(--color-primary-muted, rgba(245,166,35,0.12));
|
|
border-left: 3px solid var(--color-primary);
|
|
}
|
|
|
|
.conv-item__phone {
|
|
font-weight: var(--font-weight-semibold);
|
|
font-size: var(--text-body-sm);
|
|
color: var(--color-text-primary);
|
|
}
|
|
|
|
.conv-item__preview {
|
|
font-size: var(--text-caption);
|
|
color: var(--color-text-muted);
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
margin-top: 2px;
|
|
}
|
|
|
|
.conv-item__time {
|
|
font-size: 0.6875rem;
|
|
color: var(--color-text-muted);
|
|
margin-top: 2px;
|
|
}
|
|
|
|
.conv-empty {
|
|
padding: var(--space-6);
|
|
text-align: center;
|
|
color: var(--color-text-muted);
|
|
font-size: var(--text-body-sm);
|
|
}
|
|
|
|
/* ─── Right panel: chat view ─────────────────────────────────────── */
|
|
|
|
.chat-panel {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
background: var(--color-bg-base);
|
|
}
|
|
|
|
.chat-panel__header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: var(--space-3) var(--space-4);
|
|
background: var(--color-bg-elevated);
|
|
border-bottom: 1px solid var(--color-border);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.chat-panel__phone {
|
|
font-weight: var(--font-weight-semibold);
|
|
font-size: var(--text-body);
|
|
color: var(--color-text-primary);
|
|
}
|
|
|
|
.chat-panel__actions {
|
|
display: flex;
|
|
gap: var(--space-2);
|
|
}
|
|
|
|
.chat-panel__messages {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: var(--space-4);
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: var(--space-2);
|
|
scrollbar-width: thin;
|
|
scrollbar-color: var(--scrollbar-thumb, #444) var(--scrollbar-track, #222);
|
|
}
|
|
|
|
/* ─── Message bubbles ────────────────────────────────────────────── */
|
|
|
|
.msg-bubble {
|
|
max-width: 70%;
|
|
padding: var(--space-2) var(--space-3);
|
|
border-radius: var(--radius-md, 8px);
|
|
word-wrap: break-word;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.msg-bubble--in {
|
|
align-self: flex-start;
|
|
background: var(--color-surface-2, rgba(255,255,255,0.06));
|
|
color: var(--color-text-primary);
|
|
border-bottom-left-radius: var(--radius-xs, 2px);
|
|
}
|
|
|
|
[data-theme="modern"] .msg-bubble--in {
|
|
background: var(--color-neutral-100);
|
|
}
|
|
|
|
.msg-bubble--out {
|
|
align-self: flex-end;
|
|
background: var(--color-primary-muted, rgba(245,166,35,0.15));
|
|
color: var(--color-text-primary);
|
|
border-bottom-right-radius: var(--radius-xs, 2px);
|
|
}
|
|
|
|
[data-theme="modern"] .msg-bubble--out {
|
|
background: #dcf8c6;
|
|
color: #111;
|
|
}
|
|
|
|
.msg-bubble__text {
|
|
font-size: var(--text-body-sm);
|
|
}
|
|
|
|
.msg-bubble__meta {
|
|
font-size: 0.6875rem;
|
|
color: var(--color-text-muted);
|
|
margin-top: 4px;
|
|
text-align: right;
|
|
}
|
|
|
|
.msg-status {
|
|
display: inline-block;
|
|
font-size: 0.625rem;
|
|
padding: 1px 4px;
|
|
border-radius: var(--radius-xs, 2px);
|
|
background: var(--color-surface-3, rgba(255,255,255,0.04));
|
|
color: var(--color-text-muted);
|
|
margin-left: 4px;
|
|
}
|
|
|
|
.chat-empty {
|
|
text-align: center;
|
|
color: var(--color-text-muted);
|
|
padding: var(--space-8);
|
|
}
|
|
|
|
/* ─── Chat input bar ─────────────────────────────────────────────── */
|
|
|
|
.chat-input-bar {
|
|
display: flex;
|
|
gap: var(--space-2);
|
|
padding: var(--space-3) var(--space-4);
|
|
border-top: 1px solid var(--color-border);
|
|
background: var(--color-bg-elevated);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.chat-input-bar textarea {
|
|
flex: 1;
|
|
resize: none;
|
|
border: 1px solid var(--color-border);
|
|
border-radius: var(--radius-md, 8px);
|
|
background: var(--color-bg-base);
|
|
color: var(--color-text-primary);
|
|
padding: var(--space-2) var(--space-3);
|
|
font-family: var(--font-body);
|
|
font-size: var(--text-body-sm);
|
|
line-height: 1.4;
|
|
min-height: 40px;
|
|
max-height: 100px;
|
|
}
|
|
|
|
.chat-input-bar textarea:focus {
|
|
outline: none;
|
|
border-color: var(--color-primary);
|
|
box-shadow: 0 0 0 2px var(--color-primary-muted, rgba(245,166,35,0.2));
|
|
}
|
|
|
|
.chat-input-bar textarea::placeholder {
|
|
color: var(--color-text-muted);
|
|
}
|
|
|
|
/* ─── Buttons ────────────────────────────────────────────────────── */
|
|
|
|
.btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: var(--space-2) var(--space-3);
|
|
border: 1px solid var(--color-border);
|
|
border-radius: var(--radius-sm, 4px);
|
|
background: var(--color-bg-elevated);
|
|
color: var(--color-text-primary);
|
|
font-family: var(--font-body);
|
|
font-size: var(--text-body-sm);
|
|
font-weight: var(--font-weight-semibold);
|
|
cursor: pointer;
|
|
transition: all var(--duration-fast) var(--ease-in-out);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.btn:hover {
|
|
background: var(--color-surface-2, rgba(255,255,255,0.06));
|
|
}
|
|
|
|
.btn--primary {
|
|
background: var(--color-primary);
|
|
color: var(--color-text-inverse, #fff);
|
|
border-color: var(--color-primary);
|
|
}
|
|
|
|
.btn--primary:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.btn--primary:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.btn--sm {
|
|
padding: 4px 8px;
|
|
font-size: var(--text-caption);
|
|
}
|
|
|
|
.btn--whatsapp {
|
|
background: #25D366;
|
|
color: #fff;
|
|
border-color: #25D366;
|
|
}
|
|
|
|
.btn--whatsapp:hover {
|
|
background: #1da851;
|
|
}
|
|
|
|
/* ─── Empty state (no conversation selected) ─────────────────────── */
|
|
|
|
.empty-state {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: var(--color-text-muted);
|
|
gap: var(--space-4);
|
|
}
|
|
|
|
.empty-state svg {
|
|
opacity: 0.3;
|
|
}
|
|
|
|
.empty-state__text {
|
|
font-size: var(--text-body);
|
|
text-align: center;
|
|
}
|
|
|
|
.empty-state__hint {
|
|
font-size: var(--text-caption);
|
|
color: var(--color-text-muted);
|
|
}
|
|
|
|
/* ─── Connection / QR section ────────────────────────────────────── */
|
|
|
|
.connect-section {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: var(--space-4);
|
|
padding: var(--space-6);
|
|
text-align: center;
|
|
}
|
|
|
|
.connect-section__title {
|
|
font-family: var(--font-heading);
|
|
font-size: var(--text-h3, 1.25rem);
|
|
font-weight: var(--font-weight-bold);
|
|
color: var(--color-text-primary);
|
|
}
|
|
|
|
.connect-section__desc {
|
|
font-size: var(--text-body-sm);
|
|
color: var(--color-text-muted);
|
|
max-width: 400px;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.connect-section__qr {
|
|
border: 2px dashed var(--color-border);
|
|
border-radius: var(--radius-md, 8px);
|
|
padding: var(--space-4);
|
|
background: var(--color-bg-elevated);
|
|
min-width: 280px;
|
|
min-height: 280px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.connect-section__qr img {
|
|
max-width: 256px;
|
|
max-height: 256px;
|
|
border-radius: var(--radius-sm, 4px);
|
|
}
|
|
|
|
.connect-section__qr-placeholder {
|
|
color: var(--color-text-muted);
|
|
font-size: var(--text-body-sm);
|
|
}
|
|
|
|
.connect-section__actions {
|
|
display: flex;
|
|
gap: var(--space-2);
|
|
}
|
|
|
|
/* ─── Industrial theme cuts ──────────────────────────────────────── */
|
|
|
|
[data-theme="industrial"] .btn--primary {
|
|
clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 0 100%);
|
|
}
|
|
|
|
[data-theme="industrial"] .msg-bubble--out {
|
|
clip-path: polygon(0 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%);
|
|
}
|
|
|
|
/* ─── Responsive ─────────────────────────────────────────────────── */
|
|
|
|
@media (max-width: 768px) {
|
|
.conv-panel { width: 100%; min-width: 0; }
|
|
.chat-panel { display: none; }
|
|
.messenger.has-active-chat .conv-panel { display: none; }
|
|
.messenger.has-active-chat .chat-panel { display: flex; }
|
|
}
|
|
</style>
|
|
</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="chat-panel" id="chatPanel" style="display:none">
|
|
<div class="chat-panel__header">
|
|
<span class="chat-panel__phone" id="chatHeaderPhone"></span>
|
|
<div class="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="chat-panel__messages" id="chatMessages"></div>
|
|
|
|
<div class="chat-input-bar">
|
|
<textarea id="chatInput" placeholder="Escribe un mensaje..." rows="1"></textarea>
|
|
<button class="btn btn--primary" id="sendBtn">
|
|
<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>
|
|
|
|
<!-- 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"></script>
|
|
<script src="/pos/static/js/whatsapp.js"></script>
|
|
<script src="/pos/static/js/sidebar.js"></script>
|
|
|
|
</body>
|
|
</html>
|