mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-13 21:35:19 +00:00
feat: Add Vikunja task management, refactor Google Calendar integration, and implement N8N webhook fallback.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
# Permite obtener y mostrar las actividades programadas para el día.
|
||||
|
||||
import datetime
|
||||
from calendar import get_events
|
||||
from google_calendar import get_events
|
||||
|
||||
def get_agenda():
|
||||
"""
|
||||
|
||||
@@ -15,8 +15,9 @@ def get_owner_menu():
|
||||
def get_admin_menu():
|
||||
"""Crea el menú de botones para los Administradores."""
|
||||
keyboard = [
|
||||
[InlineKeyboardButton("📊 Ver estado del sistema", callback_data='view_system_status')],
|
||||
[InlineKeyboardButton("👥 Gestionar usuarios", callback_data='manage_users')],
|
||||
[InlineKeyboardButton("📋 Ver Tareas (Vikunja)", callback_data='view_tasks')],
|
||||
[InlineKeyboardButton("🏷️ Crear Tag NFC", callback_data='start_create_tag')],
|
||||
[InlineKeyboardButton("📊 Estado del sistema", callback_data='view_system_status')],
|
||||
]
|
||||
return InlineKeyboardMarkup(keyboard)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
from ..permissions import is_admin
|
||||
from ..config import TIMEZONE, CALENDAR_ID, N8N_WEBHOOK_URL
|
||||
from permissions import is_admin
|
||||
from config import TIMEZONE, CALENDAR_ID, N8N_WEBHOOK_URL
|
||||
|
||||
async def print_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""
|
||||
|
||||
59
app/modules/vikunja.py
Normal file
59
app/modules/vikunja.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# app/modules/vikunja.py
|
||||
# Este módulo maneja la integración con Vikunja para la gestión de tareas.
|
||||
|
||||
import requests
|
||||
import logging
|
||||
from config import VIKUNJA_API_URL, VIKUNJA_API_TOKEN
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_vikunja_headers():
|
||||
"""Devuelve los headers necesarios para la API de Vikunja."""
|
||||
return {
|
||||
"Authorization": f"Bearer {VIKUNJA_API_TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
def get_tasks():
|
||||
"""
|
||||
Obtiene la lista de tareas desde Vikunja.
|
||||
"""
|
||||
if not VIKUNJA_API_TOKEN:
|
||||
return "Error: VIKUNJA_API_TOKEN no configurado."
|
||||
|
||||
try:
|
||||
# Endpoint para obtener todas las tareas (ajustar según necesidad)
|
||||
response = requests.get(f"{VIKUNJA_API_URL}/tasks/all", headers=get_vikunja_headers())
|
||||
response.raise_for_status()
|
||||
tasks = response.json()
|
||||
|
||||
if not tasks:
|
||||
return "No tienes tareas pendientes en Vikunja."
|
||||
|
||||
text = "📋 *Tus Tareas en Vikunja*\n\n"
|
||||
for task in tasks[:10]: # Mostrar las primeras 10
|
||||
status = "✅" if task.get('done') else "⏳"
|
||||
text += f"{status} *{task.get('title')}*\n"
|
||||
|
||||
return text
|
||||
except Exception as e:
|
||||
logger.error(f"Error al obtener tareas de Vikunja: {e}")
|
||||
return f"Error al conectar con Vikunja: {e}"
|
||||
|
||||
def add_task(title):
|
||||
"""
|
||||
Agrega una nueva tarea a Vikunja.
|
||||
"""
|
||||
if not VIKUNJA_API_TOKEN:
|
||||
return "Error: VIKUNJA_API_TOKEN no configurado."
|
||||
|
||||
try:
|
||||
data = {"title": title}
|
||||
# Nota: Vikunja suele requerir un project_id. Aquí usamos uno genérico o el primero disponible.
|
||||
# Por ahora, este es un placeholder para el flujo /vik.
|
||||
response = requests.put(f"{VIKUNJA_API_URL}/tasks", headers=get_vikunja_headers(), json=data)
|
||||
response.raise_for_status()
|
||||
return f"✅ Tarea añadida: *{title}*"
|
||||
except Exception as e:
|
||||
logger.error(f"Error al añadir tarea a Vikunja: {e}")
|
||||
return f"Error al añadir tarea: {e}"
|
||||
Reference in New Issue
Block a user