From 97a48d0fe4d302927103c33f47f3ae7e2fd21317 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 30 Jun 2026 20:07:52 -0500 Subject: [PATCH] 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 --- services/NormalBot.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/NormalBot.php b/services/NormalBot.php index fd0f821..b629e17 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -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');