feat(pos): WhatsApp Business API integration — send/receive messages, quotations
Add full WhatsApp Cloud API integration for Nexus POS: - Service layer (whatsapp_service.py): send text, templates, quotations, order confirmations, stock alerts; process incoming webhooks with AI auto-reply - Blueprint (whatsapp_bp.py): public webhook endpoints for Meta verification + incoming messages; authenticated endpoints for send, send-quote, conversations - Conversation UI (whatsapp.html + whatsapp.js): split-panel messenger with conversation list, chat bubbles, send input, quote sending; both themes - Migration v1.4: whatsapp_messages table with phone/direction/status indexes - Config: WHATSAPP_TOKEN, WHATSAPP_PHONE_ID, WHATSAPP_VERIFY_TOKEN env vars - Sidebar: WhatsApp nav item under Gestion with message-bubble icon - Ready for Meta Business credentials (infrastructure complete, no API keys needed) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
538
pos/templates/whatsapp.html
Normal file
538
pos/templates/whatsapp.html
Normal file
@@ -0,0 +1,538 @@
|
||||
<!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);
|
||||
}
|
||||
|
||||
/* ─── 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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Messenger -->
|
||||
<div class="messenger" id="messenger">
|
||||
|
||||
<!-- 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/whatsapp.js"></script>
|
||||
<script src="/pos/static/js/sidebar.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user