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']);