👥 Configuración por Categoría
-
Define qué menú de bienvenida ve cada categoría de usuario cuando escribe por primera vez o sin contexto activo.
+
Define el comportamiento inicial de cada categoría de usuario: si pide finca, qué menú muestra y qué hacer ante texto no reconocido.
+
@@ -3846,13 +3911,33 @@ 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 sel = document.querySelector('[name="per_type_menu[' + cat + ']"]');
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);
});
var btn = document.getElementById('savePerTypeBtn');
if (btn) { btn.textContent = 'Guardando...'; btn.disabled = true; }
diff --git a/public/index.php b/public/index.php
index eb7de0d..a1d630c 100644
--- a/public/index.php
+++ b/public/index.php
@@ -660,22 +660,48 @@ $routes = [
$config = json_decode($company['config_json'] ?? '{}', true) ?: [];
- $rawPt = $config['per_type'] ?? [];
+ $rawPt = $config['per_type'] ?? [];
$perType = (is_array($rawPt) && count(array_filter(array_keys($rawPt), 'is_string')) > 0)
? $rawPt : [];
- $perTypeMenus = $_POST['per_type_menu'] ?? [];
+ $ptAskFinca = $_POST['per_type_ask_finca'] ?? [];
+ $ptGreetFlow = $_POST['per_type_greeting_flow'] ?? [];
+ $ptMenus = $_POST['per_type_menu'] ?? [];
+ $ptFallback = $_POST['per_type_fallback'] ?? [];
+
foreach ([1, 2, 3] as $cat) {
- $mk = trim($perTypeMenus[$cat] ?? '');
- $key = (string)$cat;
- if ($mk !== '') {
- $perType[$key] = array_merge($perType[$key] ?? [], ['greeting_menu' => $mk]);
+ $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');
+ $current['greeting'] = '';
+ $current['greeting_flow'] = $gf !== '' ? $gf : 'ask_finca';
+ unset($current['greeting_menu']);
} else {
- unset($perType[$key]['greeting_menu']);
- if (empty($perType[$key])) unset($perType[$key]);
+ $current['greeting'] = null;
+ unset($current['greeting_flow']);
+ $mk = trim($ptMenus[$cat] ?? '');
+ if ($mk !== '') {
+ $current['greeting_menu'] = $mk;
+ } else {
+ unset($current['greeting_menu']);
+ }
}
+
+ $fb = trim($ptFallback[$cat] ?? '');
+ if ($fb !== '') {
+ $current['fallback_flow'] = $fb;
+ } else {
+ unset($current['fallback_flow']);
+ }
+
+ $perType[$key] = $current;
}
- $config['per_type'] = empty($perType) ? new stdClass() : $perType;
+
+ $config['per_type'] = $perType;
CompanyRepository::save(['id' => $companyId, 'config_json' => json_encode($config, JSON_UNESCAPED_UNICODE)]);
echo json_encode(['ok' => true]);