mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-13 21:35:19 +00:00
This commit addresses several pending tasks from Tasks.md and improves the overall quality and security of the codebase. Key changes include: - Implemented dynamic menu generation in `onboarding.py` to create role-based menus from available flows, resolving `[IMP-002]`. - Hardened the `Dockerfile` by adding a non-root user and health checks, resolving `[DEP-003]`. - Fixed a type comparison bug in `identity.py` for the admin ID check, resolving `[BUG-003]`. - Confirmed the fix for the missing `sqlite3` import in `flow_engine.py` and updated `Tasks.md` accordingly, resolving `[BUG-004]`. - Removed unnecessary planning and test files (`plan_de_pruebas.md`, `reparacion_vs_refactor.md`). - Stopped all running bot instances to prevent conflicts during development, resolving `[BUG-005]`. - Updated `Tasks.md` to reflect the completion of all addressed issues.
50 lines
2.1 KiB
Python
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
|