diff --git a/admin/DashboardController.php b/admin/DashboardController.php index 3a3559d..563e34d 100644 --- a/admin/DashboardController.php +++ b/admin/DashboardController.php @@ -3213,14 +3213,11 @@ HTML; foreach ($flowKeysList as $fk) $flowOptsBase .= ''; foreach ([1, 2, 3] as $cat) { - $catCfg = $perTypeConfig[(string)$cat] ?? []; - $m = $catMeta[(string)$cat]; - $greetingVal = array_key_exists('greeting', $catCfg) ? $catCfg['greeting'] : null; - $askFinca = $greetingVal !== null; - $chk = $askFinca ? ' checked' : ''; - $greetFlow = self::h($catCfg['greeting_flow'] ?? ($askFinca ? 'ask_finca' : '')); - $fallback = $catCfg['fallback_flow'] ?? ''; - $selMenu = $catCfg['greeting_menu'] ?? ''; + $catCfg = $perTypeConfig[(string)$cat] ?? []; + $m = $catMeta[(string)$cat]; + $greetFlow = self::h($catCfg['greeting_flow'] ?? ''); + $fallback = $catCfg['fallback_flow'] ?? ''; + $selMenu = $catCfg['greeting_menu'] ?? ''; // greeting_menu selector (insert selected attr) $menuOpts = str_replace( @@ -3235,8 +3232,10 @@ HTML; $flowOptsBase ); - $greetFlowStyle = $askFinca ? '' : 'display:none'; - $greetMenuStyle = $askFinca ? 'display:none' : ''; + // Mostrar greeting_menu solo cuando NO hay greeting_flow (cat 1) + $hasGreetFlow = $greetFlow !== ''; + $greetFlowStyle = ''; + $greetMenuStyle = $hasGreetFlow ? 'display:none' : ''; $label = $m['label']; $icon = $m['icon']; $bg = $m['bg']; $bd = $m['bd']; $clr = $m['clr']; $categoryTabHtml .= <<{$icon} {$label} -
- -
Al activarlo, el bot solicita la finca antes de mostrar el menú principal
-
-
+
-
Flow que se ejecuta en el primer mensaje del usuario
+
+ Flow que se ejecuta al primer mensaje. Si el flow retorna 1 sola opción (finca, empresa, etc.) la selecciona automáticamente sin preguntar. +
-
Menú que se muestra cuando el usuario no tiene contexto activo
+
Menú que se muestra cuando no hay flujo de bienvenida configurado
@@ -3911,33 +3905,17 @@ HTML; const CONFIG = {$botConfigJson}; const ENDPOINTS = {$botEndpointsJson}; -function toggleAskFinca(chk, cat) { - var flowDiv = document.getElementById('cat-greet-flow-' + cat); - var menuDiv = document.getElementById('cat-greet-menu-' + cat); - if (chk.checked) { - if (flowDiv) flowDiv.style.display = ''; - if (menuDiv) menuDiv.style.display = 'none'; - var gf = document.querySelector('[name="per_type_greeting_flow[' + cat + ']"]'); - if (gf && gf.value === '') gf.value = 'ask_finca'; - } else { - if (flowDiv) flowDiv.style.display = 'none'; - if (menuDiv) menuDiv.style.display = ''; - } -} - function savePerType() { const cid = document.querySelector('input[name="company_id"]').value; const fd = new FormData(); fd.set('company_id', cid); [1, 2, 3].forEach(function(cat) { - var chk = document.querySelector('[name="per_type_ask_finca[' + cat + ']"]'); - fd.append('per_type_ask_finca[' + cat + ']', chk && chk.checked ? '1' : '0'); - var gf = document.querySelector('[name="per_type_greeting_flow[' + cat + ']"]'); - if (gf) fd.append('per_type_greeting_flow[' + cat + ']', gf.value); + var gf = document.querySelector('[name="per_type_greeting_flow[' + cat + ']"]'); var sel = document.querySelector('[name="per_type_menu[' + cat + ']"]'); + var fb = document.querySelector('[name="per_type_fallback[' + cat + ']"]'); + if (gf) fd.append('per_type_greeting_flow[' + cat + ']', gf.value); if (sel) fd.append('per_type_menu[' + cat + ']', sel.value); - var fb = document.querySelector('[name="per_type_fallback[' + cat + ']"]'); - if (fb) fd.append('per_type_fallback[' + cat + ']', fb.value); + if (fb) fd.append('per_type_fallback[' + cat + ']', fb.value); }); var btn = document.getElementById('savePerTypeBtn'); if (btn) { btn.textContent = 'Guardando...'; btn.disabled = true; } diff --git a/public/index.php b/public/index.php index a1d630c..a06be03 100644 --- a/public/index.php +++ b/public/index.php @@ -664,24 +664,23 @@ $routes = [ $perType = (is_array($rawPt) && count(array_filter(array_keys($rawPt), 'is_string')) > 0) ? $rawPt : []; - $ptAskFinca = $_POST['per_type_ask_finca'] ?? []; - $ptGreetFlow = $_POST['per_type_greeting_flow'] ?? []; - $ptMenus = $_POST['per_type_menu'] ?? []; - $ptFallback = $_POST['per_type_fallback'] ?? []; + $ptGreetFlow = $_POST['per_type_greeting_flow'] ?? []; + $ptMenus = $_POST['per_type_menu'] ?? []; + $ptFallback = $_POST['per_type_fallback'] ?? []; foreach ([1, 2, 3] as $cat) { $key = (string)$cat; $current = $perType[$key] ?? []; // preserve menus/flows/commands from seed - $askFinca = ($ptAskFinca[$cat] ?? '0') === '1'; - - if ($askFinca) { - $gf = trim($ptGreetFlow[$cat] ?? 'ask_finca'); + $gf = trim($ptGreetFlow[$cat] ?? ''); + if ($gf !== '') { + // Si tiene greeting_flow → greeting='' para que el flow se dispare al primer mensaje $current['greeting'] = ''; - $current['greeting_flow'] = $gf !== '' ? $gf : 'ask_finca'; + $current['greeting_flow'] = $gf; unset($current['greeting_menu']); } else { - $current['greeting'] = null; + // Sin greeting_flow → usa greeting_menu (cat 1) + $current['greeting'] = null; unset($current['greeting_flow']); $mk = trim($ptMenus[$cat] ?? ''); if ($mk !== '') {