diff --git a/configuracion.html b/configuracion.html
index 981c1f7..7535eb5 100644
--- a/configuracion.html
+++ b/configuracion.html
@@ -1192,7 +1192,7 @@
}
- // ==========================================
+ // ==========================================
// LÓGICA REGLAS ROBOT HOMESERVE
// ==========================================
function toggleHsConfig(type) {
@@ -1202,10 +1202,8 @@
else body.classList.add('hidden');
}
- // Esta función la llamaremos dentro de loadProviderCredentials() o en el DOMContentLoaded
async function loadRobotConfig() {
try {
- // Aprovechamos la ruta de settings que ya tienes
const res = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const data = await res.json();
const s = data.settings || {};
@@ -1215,7 +1213,7 @@
// Cargar Asignación
if (hsSettings.assign) {
document.getElementById('hs_cfg_assign_enabled').checked = hsSettings.assign.enabled;
- document.getElementById('hs_cfg_assign_status').value = hsSettings.assign.status || "ESPERA";
+ document.getElementById('hs_cfg_assign_status').value = hsSettings.assign.status || "307"; // 307: Espera profesional inicio
document.getElementById('hs_cfg_assign_days').value = hsSettings.assign.days_next ?? 1;
document.getElementById('hs_cfg_assign_inform').checked = hsSettings.assign.check_inform || false;
document.getElementById('hs_cfg_assign_obs').value = hsSettings.assign.obs || "";
@@ -1225,7 +1223,7 @@
// Cargar Cita
if (hsSettings.date) {
document.getElementById('hs_cfg_date_enabled').checked = hsSettings.date.enabled;
- document.getElementById('hs_cfg_date_status').value = hsSettings.date.status || "CITADO";
+ document.getElementById('hs_cfg_date_status').value = hsSettings.date.status || "307"; // 307: Concertado
document.getElementById('hs_cfg_date_days').value = hsSettings.date.days_next ?? 0;
document.getElementById('hs_cfg_date_inform').checked = hsSettings.date.check_inform || false;
document.getElementById('hs_cfg_date_obs').value = hsSettings.date.obs || "";
@@ -1235,7 +1233,7 @@
// Cargar No Localizado
if (hsSettings.notfound) {
document.getElementById('hs_cfg_notfound_enabled').checked = hsSettings.notfound.enabled;
- document.getElementById('hs_cfg_notfound_status').value = hsSettings.notfound.status || "PTE_CLIENTE";
+ document.getElementById('hs_cfg_notfound_status').value = hsSettings.notfound.status || "348"; // 348: Espera cliente
document.getElementById('hs_cfg_notfound_days').value = hsSettings.notfound.days_next ?? 1;
document.getElementById('hs_cfg_notfound_inform').checked = hsSettings.notfound.check_inform || false;
document.getElementById('hs_cfg_notfound_obs').value = hsSettings.notfound.obs || "";
@@ -1244,6 +1242,51 @@
} catch(e) { console.error("Error cargando ajustes del robot", e); }
}
+ async function saveRobotConfig() {
+ const resGet = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
+ const dataGet = await resGet.json();
+ const currentSettings = dataGet.settings || {};
+
+ currentSettings.robot_homeserve = {
+ assign: {
+ enabled: document.getElementById('hs_cfg_assign_enabled').checked,
+ status: document.getElementById('hs_cfg_assign_status').value,
+ days_next: parseInt(document.getElementById('hs_cfg_assign_days').value) || 0,
+ check_inform: document.getElementById('hs_cfg_assign_inform').checked,
+ obs: document.getElementById('hs_cfg_assign_obs').value
+ },
+ date: {
+ enabled: document.getElementById('hs_cfg_date_enabled').checked,
+ status: document.getElementById('hs_cfg_date_status').value,
+ days_next: parseInt(document.getElementById('hs_cfg_date_days').value) || 0,
+ check_inform: document.getElementById('hs_cfg_date_inform').checked,
+ obs: document.getElementById('hs_cfg_date_obs').value
+ },
+ notfound: {
+ enabled: document.getElementById('hs_cfg_notfound_enabled').checked,
+ status: document.getElementById('hs_cfg_notfound_status').value,
+ days_next: parseInt(document.getElementById('hs_cfg_notfound_days').value) || 0,
+ check_inform: document.getElementById('hs_cfg_notfound_inform').checked,
+ obs: document.getElementById('hs_cfg_notfound_obs').value
+ }
+ };
+
+ try {
+ const res = await fetch(`${API_URL}/whatsapp/settings`, {
+ method: 'POST',
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
+ body: JSON.stringify(currentSettings)
+ });
+ if (res.ok) {
+ showToast("✅ Reglas del Robot guardadas");
+ } else {
+ showToast("❌ Error al guardar", true);
+ }
+ } catch(e) {
+ showToast("❌ Error de conexión", true);
+ }
+ }
+
async function saveRobotConfig() {
// Obtenemos todos los settings actuales para no sobreescribir lo de WhatsApp
const resGet = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });