Validate dynamic_list input and fix cosecha button IDs

- dynamic_list now stores valid IDs in collecting state; rejects
  free-text input that doesn't match a list option
- Fixed submenu_ciclo_cosecha button IDs to match real flow names
  (ciclo_cosecha_dia / ciclo_cosecha_historico)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-30 20:07:52 -05:00
co-authored by Claude Sonnet 4.6
parent 0ce766a9eb
commit 97a48d0fe4
+13 -3
View File
@@ -136,6 +136,14 @@ class NormalBot
$group = $col['meta_group'] ?? '';
$key = $col['meta_key'] ?? '';
$nextNode = $col['next_node'] ?? null;
$validIds = $col['__valid_ids'] ?? null;
if ($validIds !== null && !in_array(trim($input), $validIds, true)) {
return self::sendText(
'⚠️ Por favor selecciona una opción válida de la lista.',
$context['from'], $company
);
}
$formData = $meta[$group] ?? [];
$formData[$key] = trim($input);
@@ -182,10 +190,12 @@ class NormalBot
);
}
$valueField = $flow['value_field'] ?? 'id';
$meta['collecting'] = [
'meta_group' => $flow['meta_group'] ?? '',
'meta_key' => $flow['meta_key'] ?? '',
'next_node' => $flow['next_node'] ?? null,
'meta_group' => $flow['meta_group'] ?? '',
'meta_key' => $flow['meta_key'] ?? '',
'next_node' => $flow['next_node'] ?? null,
'__valid_ids' => array_column($items, $valueField),
];
ConversationContext::updateMetadata($ctxId, $meta);
ConversationContext::updateNode($ctxId, 'collecting');