From 16a03b546d0bb5bf365df4425c222c9f8acc303b Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 29 Jun 2026 11:42:56 -0500 Subject: [PATCH] fix: commands clear in-progress state + per_type config rebuilt in DB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two fixes: 1. Any command (menu, salir, etc.) now clears collecting/__foreach/__cap meta before executing, so navigation commands are always a clean reset regardless of what flow the user was in. 2. DB per_type was empty ([]); rebuilt with correct structure: - Type 1: greeting=submenu_subir, menu/inicio/volver → recibir_info - Type 2: greeting=submenu_informes, menu/inicio/volver → descargar_informes - Type 3: greeting=show_main_menu, inherits global commands Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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])) {