feat: auto-select finca cuando la lista tiene un solo ítem
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
060041c855
commit
91dd84cc8d
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user