-
-
- Modo "Escribiendo..."
-
-
Simula que un humano está tecleando el mensaje. Si lo desactivas, los mensajes llegarán de forma instantánea.
+
+
+
+
+ Estado del Dispositivo
+
+
+
+
+
+
Iniciando instancia...
+
-
-
-
+
+
+
+
+
+
+ Reglas de Envío
+
+
+
+
+
+
+
+
Modo "Escribiendo..."
+
Añade un retraso natural antes de enviar.
+
+
+
+
+
+
+
+
+
+
+
+
Mensaje de Bienvenida
+
Al registrar el servicio en el sistema.
+
+
+
+
+
+
+
+
+
+
+
+
+
Cambio de Cita
+
Cuando se agenda o modifica la fecha de visita.
+
+
+
+
+
+
+
+
+
+
+
+
+
Técnico de Camino
+
Avisa al cliente minutos antes de llegar.
+
+
+
+
+
+
+
+
+
+
+
+
+
Servicio Finalizado
+
Notifica el cierre de la avería.
+
+
+
+
+
+
+
+
+
+
+
+
+
Encuesta de Calidad
+
Se envía automáticamente tras finalizar.
+
+
+
+
+
+
+
+
+
@@ -224,18 +315,55 @@
showTab('templates');
loadTemplates();
- // Cargar preferencia de delay de WhatsApp
- const toggle = document.getElementById('waDelayToggle');
- const savedSetting = localStorage.getItem('wa_delay_enabled');
- // Por defecto activo si no hay ajuste guardado
- toggle.checked = savedSetting === null ? true : savedSetting === 'true';
-
- toggle.addEventListener('change', (e) => {
- localStorage.setItem('wa_delay_enabled', e.target.checked);
- showToast(`Modo "Escribiendo" ${e.target.checked ? 'Activado' : 'Desactivado'}`);
- });
+ // Cargar configuración de eventos de WhatsApp al inicio
+ loadWaSettings();
});
+ function loadWaSettings() {
+ // Lee del LocalStorage.
+ // TODO: En el futuro, cambiar esto por un fetch a la BD (ej. /config/whatsapp)
+ const getCfg = (key, defaultVal) => {
+ const val = localStorage.getItem(key);
+ return val === null ? defaultVal : val === 'true';
+ };
+
+ document.getElementById('cfg_delay').checked = getCfg('wa_delay_enabled', true);
+ document.getElementById('cfg_evt_welcome').checked = getCfg('wa_evt_welcome', true);
+ document.getElementById('cfg_evt_date').checked = getCfg('wa_evt_date', true);
+ document.getElementById('cfg_evt_onway').checked = getCfg('wa_evt_onway', true);
+ document.getElementById('cfg_evt_finished').checked = getCfg('wa_evt_finished', false);
+ document.getElementById('cfg_evt_survey').checked = getCfg('wa_evt_survey', false);
+ }
+
+ async function saveWaSettings() {
+ // Guarda los valores actuales de los switches
+ const settings = {
+ wa_delay_enabled: document.getElementById('cfg_delay').checked,
+ wa_evt_welcome: document.getElementById('cfg_evt_welcome').checked,
+ wa_evt_date: document.getElementById('cfg_evt_date').checked,
+ wa_evt_onway: document.getElementById('cfg_evt_onway').checked,
+ wa_evt_finished: document.getElementById('cfg_evt_finished').checked,
+ wa_evt_survey: document.getElementById('cfg_evt_survey').checked
+ };
+
+ // Guarda en LocalStorage
+ for (const [key, value] of Object.entries(settings)) {
+ localStorage.setItem(key, value);
+ }
+
+ // TODO: Aquí pondrías la llamada al Backend para guardar en PostgreSQL
+ /*
+ await fetch(`${API_URL}/config/whatsapp`, {
+ method: 'POST',
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
+ body: JSON.stringify(settings)
+ });
+ */
+
+ showToast("Ajustes de WhatsApp guardados");
+ }
+
+
function showTab(tabId) {
document.querySelectorAll('.tab-content').forEach(el => el.classList.add('hidden'));
document.getElementById(`view-${tabId}`).classList.remove('hidden');
@@ -298,7 +426,7 @@
async function checkWhatsappStatus() {
const container = document.getElementById('waStatusContainer');
- container.innerHTML = `
Verificando instancia...
`;
+ container.innerHTML = `
`;
lucide.createIcons();
try {
@@ -308,10 +436,10 @@
if (!data.ok) throw new Error(data.error || "Error desconocido");
if (data.state === "open") {
- container.innerHTML = `
Conectado
Instancia: ${data.instanceName}
`;
+ container.innerHTML = `
Conectado
Instancia: ${data.instanceName}
`;
} else if (data.qr) {
- container.innerHTML = `
`;
- if(data.qr.startsWith('data:image')) { document.getElementById('qrcode').innerHTML = `

`; }
+ container.innerHTML = `
`;
+ if(data.qr.startsWith('data:image')) { document.getElementById('qrcode').innerHTML = `

`; }
else { new QRCode(document.getElementById("qrcode"), { text: data.qr, width: 180, height: 180 }); }
} else { container.innerHTML = `
Iniciando... intenta de nuevo en unos segundos.
`; }
} catch(e) {