From b288b07ff5c5fe80352887727d9ea77bb1e825ca Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:39:04 -0500 Subject: [PATCH] feat: welcome message, fix per_type save, add missing ciclos flows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Show welcome_msg (button with "Ver menú") for all new sessions before category menu - Fix saveConfig() AJAX to include per_type_menu DOM values so they survive individual saves - Add welcome_menu field to General tab in admin (render + save) - Add 'atras' command alias (→ show_main_menu) - Add ciclos_plagas, ciclos_palm, ciclos_tratamientos flows to DB config - Fix per_type in DB from [] to {} (proper JSON object) Co-Authored-By: Claude Sonnet 4.6 --- admin/DashboardController.php | 22 +++++++++++++++++++++- public/index.php | 2 ++ services/NormalBot.php | 9 ++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/admin/DashboardController.php b/admin/DashboardController.php index 4c4a9d6..b6d86b2 100644 --- a/admin/DashboardController.php +++ b/admin/DashboardController.php @@ -2874,6 +2874,12 @@ HTML; $aiProviderVal = self::h($config['ai_provider'] ?? ''); $approvalWebhookVal = self::h($config['approval_webhook'] ?? ''); $ignoreVal = self::h(implode("\n", $config['ignore_prefixes'] ?? [])); + $welcomeMenuVal = self::h($config['welcome_menu'] ?? ''); + $welcomeMenuOpts = ''; + foreach (array_keys($menus) as $mk) { + $s = ($config['welcome_menu'] ?? '') === $mk ? ' selected' : ''; + $welcomeMenuOpts .= ''; + } $commands = $config['commands'] ?? []; $menus = $config['menus'] ?? []; $flows = $config['flows'] ?? []; @@ -3421,10 +3427,18 @@ HTML;
⚙️ General
+
+ + +
Menú que se muestra a TODOS los usuarios nuevos antes del menú principal
+
-
Primer mensaje que recibe un usuario nuevo
+
Primer mensaje de texto que recibe un usuario nuevo (alternativo al welcome_menu)
@@ -4781,6 +4795,12 @@ function saveConfig() { fd.append('approval_webhook', fullConfig.approval_webhook || ''); fd.append('ignore_prefixes', (fullConfig.ignore_prefixes || []).join('\\n')); + // Per-category menus — read from DOM so they're preserved on every AJAX save + [1, 2, 3].forEach(cat => { + const sel = document.querySelector('select[name="per_type_menu[' + cat + ']"]'); + if (sel) fd.append('per_type_menu[' + cat + ']', sel.value); + }); + fetch('/admin/bot-config/save', { method: 'POST', body: fd diff --git a/public/index.php b/public/index.php index fb84127..dbb0087 100644 --- a/public/index.php +++ b/public/index.php @@ -562,6 +562,8 @@ $routes = [ } $approvalWebhook = trim($_POST['approval_webhook'] ?? ''); if ($approvalWebhook !== '') $config['approval_webhook'] = $approvalWebhook; + $welcomeMenu = trim($_POST['welcome_menu'] ?? ''); + if ($welcomeMenu !== '') $config['welcome_menu'] = $welcomeMenu; CompanyRepository::save(['id' => $companyId, 'config_json' => json_encode($config, JSON_UNESCAPED_UNICODE)]); header('Location: /admin/bot-config?id=' . $companyId . '&msg=saved'); diff --git a/services/NormalBot.php b/services/NormalBot.php index 7dc46fd..9d2ca4c 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -76,7 +76,14 @@ class NormalBot return self::handleFlow($flows[$currentNode], $context, $company, $ctxId, $menus); } - // 4. Per-type greeting menu — only for brand-new sessions (currentNode === null) + // 4. Welcome message — shown once for brand-new sessions before the category menu + $welcomeMenuKey = $config['welcome_menu'] ?? null; + if ($welcomeMenuKey && $currentNode === null && isset($menus[$welcomeMenuKey])) { + ConversationContext::updateNode($ctxId, '__greeted'); + return self::buildMenuResponse($menus[$welcomeMenuKey], $context['from'], $company); + } + + // 4b. Per-type greeting menu — only for brand-new sessions (currentNode === null) $greetingMenuKey = $perType['greeting_menu'] ?? null; if ($greetingMenuKey !== null && $currentNode === null && isset($menus[$greetingMenuKey])) { ConversationContext::updateNode($ctxId, '__greeted'); // sentinel: evita re-envío del menú