From 91dd84cc8dfb7fd4cde45a8653a0d57146d83eb7 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 28 Jul 2026 20:12:35 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20auto-select=20finca=20cuando=20la=20lis?= =?UTF-8?q?ta=20tiene=20un=20solo=20=C3=ADtem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si el endpoint de fincas devuelve exactamente 1 opción, el bot la selecciona automáticamente sin mostrar la lista al usuario, y navega directo al menú principal usando los flows del per_type activo. Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/services/NormalBot.php b/services/NormalBot.php index bc1486f..6a7cf7e 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -219,6 +219,29 @@ class NormalBot $labelMap[(string)($item[$labelField] ?? '')] = (string)($item[$valueField] ?? ''); } + // Auto-select cuando hay exactamente 1 opción — no mostrar lista + if (count($items) === 1) { + $item = $items[0]; + $formData = $meta[$group] ?? []; + $formData[$key] = (string)($item[$valueField] ?? ''); + $meta[$group] = $formData; + unset($meta['__nlu_entities']); + ConversationContext::updateMetadata($ctxId, $meta); + if ($nextNode !== null) { + ConversationContext::updateNode($ctxId, $nextNode); + $cfg = self::getConfig($company); + $permType = (string)($company['_permission_type'] ?? 1); + $pt = $cfg['per_type'][$permType] ?? []; + $allFlows = array_merge($cfg['flows'] ?? [], $pt['flows'] ?? []); + $allMenus = array_merge($cfg['menus'] ?? [], $pt['menus'] ?? []); + if (isset($allFlows[$nextNode])) { + return self::handleFlow($allFlows[$nextNode], $context, $company, $ctxId, $allMenus); + } + } + ConversationContext::updateNode($ctxId, null); + return null; + } + // Si el NLU extrajo entities, intentar auto-seleccionar sin mostrar lista $entities = $meta['__nlu_entities'] ?? []; unset($meta['__nlu_entities']);