fix: salir button works, cap at 3 buttons, no AI error on unmatched input

- Add 'goodbye' function: resets context + sends farewell with menu hint
- Add safety slice to 3 buttons in buildMenuResponse (WhatsApp hard limit)
- In hybrid mode: when greeting_menu is configured for the user's category,
  use it as fallback instead of escalating to AI — prevents "Lo siento,
  tengo problemas..." from appearing when nothing matches
- Expose buildGreetingMenu() as public for BotRouter access
- DB: fixed submenu_informes and submenu_ciclos from 4→3 buttons,
  added salir flow (goodbye function) and salir/exit commands (company 2)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-28 13:10:08 -05:00
co-authored by Claude Sonnet 4.6
parent 32e2a2a82e
commit b6a85c33f7
2 changed files with 25 additions and 1 deletions
+10 -1
View File
@@ -119,6 +119,10 @@ class NormalBot
ConversationContext::reset($ctxId);
return self::sendText('¿En qué más puedo ayudarte?', $context['from'], $company);
})(),
'goodbye' => (function () use ($ctxId, $context, $company) {
ConversationContext::reset($ctxId);
return self::sendText("Hasta luego 👋\n\nEscribe *menu* cuando quieras volver.", $context['from'], $company);
})(),
'forward_to_ai' => null,
'api_report' => self::executeApiReport($params, $context, $company, $ctxId),
default => null,
@@ -241,6 +245,11 @@ class NormalBot
return self::sendText('✅ Reporte enviado.' . $nav, $context['from'], $company);
}
public static function buildGreetingMenu(array $menu, string $to, array $company): ?array
{
return self::buildMenuResponse($menu, $to, $company);
}
private static function buildMenuResponse(array $menu, string $to, array $company): ?array
{
$menuType = $menu['type'] ?? 'list';
@@ -284,7 +293,7 @@ class NormalBot
if ($menuType === 'button') {
$buttons = [];
foreach ($menu['buttons'] ?? [] as $btn) {
foreach (array_slice($menu['buttons'] ?? [], 0, 3) as $btn) {
$buttons[] = [
'type' => 'reply',
'reply' => [