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