diff --git a/services/NormalBot.php b/services/NormalBot.php index d2cc189..4262911 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -22,6 +22,14 @@ class NormalBot // 1. Commands always win — escape from any state (salir, menu, etc.) foreach ($commands as $keyword => $action) { if ($normalized === self::normalize((string)$keyword)) { + // Clear any in-progress multi-step state so the command is a clean reset + $m = ConversationContext::getMetadata($ctxId); + $dirty = false; + foreach (['collecting', '__foreach', '__cap'] as $stateKey) { + if (isset($m[$stateKey])) { unset($m[$stateKey]); $dirty = true; } + } + if ($dirty) ConversationContext::updateMetadata($ctxId, $m); + ConversationContext::updateNode($ctxId, $action); // Commands that match a flow if (isset($flows[$action])) {