Files
talia_bot/bot/modules/onboarding.py
google-labs-jules[bot] 0ff8632b6a feat: Complete major refactoring and add initial test suite
This commit addresses a large number of pending tasks from `Tasks.md`, focusing on architectural improvements, documentation consistency, and the introduction of a testing framework.

Key changes include:

- **Button Dispatcher Agent (`[IMP-003]`):** Refactored the button handling logic into a dedicated `ButtonDispatcher` class. This decouples the dispatcher from handlers and improves modularity.
- **Documentation Consistency (`[DOC-001]`):** Updated `AGENTS.md` and `Agent_skills.md` to be consistent with the current codebase, removing outdated information and "Fallo Actual" notes.
- **Code Quality Tools (`[TEST-002]`):** Added `black` to the project for consistent code formatting and applied it to the entire `bot/` directory.
- **Initial Test Coverage (`[TEST-001]`):** Created a `tests/` directory and implemented a comprehensive suite of unit tests for the critical `FlowEngine` module, using Python's `unittest` framework.
- **Task Verification:** Investigated and confirmed that tasks `[ARCH-003]` (Code Duplication), `[PERF-003]` (Flow Engine Memory Usage), and `[PERF-002]` (Voice File Memory Management) were already resolved by previous refactoring.
- **Updated `Tasks.md`:** Updated the status of all addressed tasks to reflect the project's current state.
2025-12-23 01:17:23 +00:00

50 lines
2.1 KiB
Python

# bot/modules/onboarding.py
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
def get_dynamic_menu(user_role, flow_engine):
"""
Creates a dynamic button menu based on the user's role.
It filters the available flows and shows only the ones that:
1. Match the user's role.
2. Contain a 'trigger_button' key, indicating they can be started from a menu.
"""
keyboard = []
# Add role-specific static buttons first, if any.
if user_role == "admin":
keyboard.append([InlineKeyboardButton("👑 Revisar Pendientes", callback_data='view_pending')])
keyboard.append([InlineKeyboardButton("📅 Agenda", callback_data='view_agenda')])
# Dynamically add buttons from flows
if flow_engine:
for flow in flow_engine.flows:
# Check if the flow is for the user's role and has a trigger button
if flow.get("role") == user_role and "trigger_button" in flow and "name" in flow:
button = InlineKeyboardButton(flow["name"], callback_data=flow["trigger_button"])
keyboard.append([button])
# Add secondary menu button for admins
if user_role == "admin":
keyboard.append([InlineKeyboardButton("▶️ Más opciones", callback_data='admin_menu')])
return InlineKeyboardMarkup(keyboard)
def get_admin_secondary_menu():
"""Creates the secondary menu for Administrators."""
text = "Aquí tienes más opciones de administración:"
keyboard = [
[InlineKeyboardButton("📋 Gestionar Tareas (Vikunja)", callback_data='manage_vikunja')],
[InlineKeyboardButton("📊 Estado del sistema", callback_data='view_system_status')],
[InlineKeyboardButton("👥 Gestionar Usuarios", callback_data='manage_users')],
]
reply_markup = InlineKeyboardMarkup(keyboard)
return text, reply_markup
def handle_start(user_role, flow_engine=None):
"""
Decides which message and menu to show based on the user's role.
"""
welcome_message = "Hola, soy Talía. ¿En qué puedo ayudarte hoy?"
menu = get_dynamic_menu(user_role, flow_engine)
return welcome_message, menu