mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-13 13:25:19 +00:00
Merge pull request #42 from marcogll/feat/cleanup-and-refactor-15004564199648452045
refactor: Align codebase configuration with user's .env file
This commit is contained in:
75
.env.example
75
.env.example
@@ -1,18 +1,69 @@
|
||||
# --- TELEGRAM & SECURITY ---
|
||||
# ==================================================
|
||||
# Telegram Configuration
|
||||
# ==================================================
|
||||
# Get your bot token from @BotFather on Telegram.
|
||||
TELEGRAM_BOT_TOKEN=
|
||||
ADMIN_ID=
|
||||
# Your personal Telegram user ID. The bot will send you admin notifications.
|
||||
TELEGRAM_OWNER_CHAT_ID=
|
||||
|
||||
# --- AI CORE ---
|
||||
# ==================================================
|
||||
# Google Services
|
||||
# ==================================================
|
||||
# The path to your Google Cloud service account credentials file.
|
||||
GOOGLE_SERVICE_ACCOUNT_FILE=google_key.json
|
||||
# The ID of the Google Calendar you want the bot to manage.
|
||||
GOOGLE_CALENDAR_ID=
|
||||
|
||||
# ==================================================
|
||||
# Webhooks (n8n)
|
||||
# ==================================================
|
||||
# The URL for your production n8n webhook.
|
||||
N8N_WEBHOOK_URL=
|
||||
# The URL for your test n8n webhook.
|
||||
N8N_WEBHOOK_TEST_URL=
|
||||
|
||||
# ==================================================
|
||||
# AI Core
|
||||
# ==================================================
|
||||
# Your API key from OpenAI.
|
||||
OPENAI_API_KEY=
|
||||
# The specific OpenAI model to use (e.g., gpt-4o-mini, gpt-4-turbo).
|
||||
OPENAI_MODEL=gpt-4o-mini
|
||||
# The time for the AI to send a daily summary (HH:MM format).
|
||||
AI_DAILY_SUMMARY_TIME=08:00
|
||||
# The timezone for scheduling and date/time operations (e.g., America/Mexico_City, America/Bogota).
|
||||
TIMEZONE=America/Monterrey
|
||||
|
||||
# --- INTEGRATIONS ---
|
||||
VIKUNJA_API_URL=https://tuservidor.com/api/v1
|
||||
# ==================================================
|
||||
# Scheduling
|
||||
# ==================================================
|
||||
# Your Calendly link for appointment scheduling.
|
||||
CALENDLY_LINK=
|
||||
|
||||
# ==================================================
|
||||
# Vikunja (Task Management)
|
||||
# ==================================================
|
||||
# The base URL for your Vikunja instance's API.
|
||||
VIKUNJA_BASE_URL=
|
||||
# Your API token for Vikunja.
|
||||
VIKUNJA_TOKEN=
|
||||
GOOGLE_CREDENTIALS_PATH=./data/credentials.json
|
||||
|
||||
# --- PRINT SERVICE ---
|
||||
SMTP_SERVER=smtp.hostinger.com
|
||||
SMTP_PORT=465
|
||||
SMTP_USER=print.service@vanityexperience.mx
|
||||
SMTP_PASS=
|
||||
IMAP_SERVER=imap.hostinger.com
|
||||
# ==================================================
|
||||
# Email Configuration (SMTP / IMAP)
|
||||
# ==================================================
|
||||
# SMTP server for sending emails.
|
||||
SMTP_SERVER=
|
||||
SMTP_PORT=
|
||||
SMTP_USER=
|
||||
SMTP_PASSWORD=
|
||||
|
||||
# IMAP server for reading emails.
|
||||
IMAP_SERVER=
|
||||
IMAP_USER=
|
||||
IMAP_PASSWORD=
|
||||
|
||||
# ==================================================
|
||||
# Printer (Epson Connect)
|
||||
# ==================================================
|
||||
# The dedicated email address for your printer.
|
||||
PRINTER_EMAIL=
|
||||
|
||||
@@ -1,55 +1,51 @@
|
||||
# talia_bot/config.py
|
||||
# Este archivo se encarga de cargar todas las variables de entorno y configuraciones del bot.
|
||||
# Las variables de entorno son valores que se guardan fuera del código por seguridad (como tokens y llaves API).
|
||||
# This file loads all environment variables and bot configurations.
|
||||
# Environment variables are stored securely outside the code (e.g., in a .env file).
|
||||
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from pathlib import Path
|
||||
|
||||
# Cargar variables de entorno desde el archivo .env en la raíz del proyecto
|
||||
# Load environment variables from the .env file in the project root
|
||||
env_path = Path(__file__).parent.parent / '.env'
|
||||
load_dotenv(dotenv_path=env_path)
|
||||
|
||||
# Token del bot de Telegram (obtenido de @BotFather)
|
||||
# --- Telegram Configuration ---
|
||||
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
||||
ADMIN_ID = os.getenv("TELEGRAM_OWNER_CHAT_ID") # Renamed for consistency in the code
|
||||
|
||||
# ID de chat del dueño del bot (para recibir notificaciones importantes)
|
||||
ADMIN_ID = os.getenv("ADMIN_ID")
|
||||
|
||||
# Ruta al archivo de credenciales de la cuenta de servicio de Google
|
||||
# --- Google Services ---
|
||||
GOOGLE_SERVICE_ACCOUNT_FILE = os.getenv("GOOGLE_SERVICE_ACCOUNT_FILE")
|
||||
if GOOGLE_SERVICE_ACCOUNT_FILE and not os.path.isabs(GOOGLE_SERVICE_ACCOUNT_FILE):
|
||||
GOOGLE_SERVICE_ACCOUNT_FILE = str(Path(__file__).parent.parent / GOOGLE_SERVICE_ACCOUNT_FILE)
|
||||
CALENDAR_ID = os.getenv("GOOGLE_CALENDAR_ID")
|
||||
|
||||
# ID del calendario de Google que usará el bot
|
||||
CALENDAR_ID = os.getenv("CALENDAR_ID")
|
||||
|
||||
# URL del webhook de n8n para enviar datos a otros servicios
|
||||
# --- Webhooks (n8n) ---
|
||||
N8N_WEBHOOK_URL = os.getenv("N8N_WEBHOOK_URL")
|
||||
N8N_TEST_WEBHOOK_URL = os.getenv("N8N_TEST_WEBHOOK_URL")
|
||||
N8N_TEST_WEBHOOK_URL = os.getenv("N8N_WEBHOOK_TEST_URL")
|
||||
|
||||
# Configuración de Vikunja
|
||||
VIKUNJA_API_URL = os.getenv("VIKUNJA_API_URL", "https://tasks.soul23.cloud/api/v1")
|
||||
VIKUNJA_API_TOKEN = os.getenv("VIKUNJA_API_TOKEN")
|
||||
|
||||
# Llave de la API de OpenAI para usar modelos de lenguaje (como GPT)
|
||||
# --- AI Core ---
|
||||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
||||
OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-4o-mini")
|
||||
DAILY_SUMMARY_TIME = os.getenv("AI_DAILY_SUMMARY_TIME", "08:00")
|
||||
TIMEZONE = os.getenv("TIMEZONE", "America/Monterrey")
|
||||
|
||||
# Modelo de OpenAI a utilizar (ej. gpt-3.5-turbo, gpt-4)
|
||||
OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-3.5-turbo")
|
||||
# --- Scheduling ---
|
||||
CALENDLY_LINK = os.getenv("CALENDLY_LINK")
|
||||
|
||||
# Hora del resumen diario (formato HH:MM)
|
||||
DAILY_SUMMARY_TIME = os.getenv("DAILY_SUMMARY_TIME", "07:00")
|
||||
# --- Vikunja (Task Management) ---
|
||||
VIKUNJA_API_URL = os.getenv("VIKUNJA_BASE_URL")
|
||||
VIKUNJA_API_TOKEN = os.getenv("VIKUNJA_TOKEN")
|
||||
|
||||
# Enlace de Calendly para agendar citas
|
||||
CALENDLY_LINK = os.getenv("CALENDLY_LINK", "https://calendly.com/user/appointment-link")
|
||||
|
||||
# Zona horaria por defecto para el manejo de fechas y horas
|
||||
TIMEZONE = os.getenv("TIMEZONE", "America/Mexico_City")
|
||||
|
||||
# --- PRINT SERVICE ---
|
||||
# --- Email Configuration (SMTP / IMAP) ---
|
||||
SMTP_SERVER = os.getenv("SMTP_SERVER")
|
||||
SMTP_PORT = os.getenv("SMTP_PORT")
|
||||
SMTP_USER = os.getenv("SMTP_USER")
|
||||
SMTP_PASS = os.getenv("SMTP_PASS")
|
||||
SMTP_PASS = os.getenv("SMTP_PASSWORD")
|
||||
|
||||
IMAP_SERVER = os.getenv("IMAP_SERVER")
|
||||
IMAP_USER = os.getenv("IMAP_USER")
|
||||
IMAP_PASS = os.getenv("IMAP_PASSWORD")
|
||||
|
||||
# --- Printer (Epson Connect) ---
|
||||
PRINTER_EMAIL = os.getenv("PRINTER_EMAIL")
|
||||
|
||||
@@ -16,6 +16,9 @@ from talia_bot.config import (
|
||||
SMTP_USER,
|
||||
SMTP_PASS,
|
||||
IMAP_SERVER,
|
||||
IMAP_USER,
|
||||
IMAP_PASS,
|
||||
PRINTER_EMAIL,
|
||||
)
|
||||
from talia_bot.modules.identity import is_admin
|
||||
|
||||
@@ -28,14 +31,14 @@ async def send_file_to_printer(file_path: str, user_id: int, file_name: str):
|
||||
if not is_admin(user_id):
|
||||
return "No tienes permiso para usar este comando."
|
||||
|
||||
if not all([SMTP_SERVER, SMTP_PORT, SMTP_USER, SMTP_PASS]):
|
||||
logger.error("Faltan una o más variables de entorno SMTP.")
|
||||
if not all([SMTP_SERVER, SMTP_PORT, SMTP_USER, SMTP_PASS, PRINTER_EMAIL]):
|
||||
logger.error("Faltan una o más variables de entorno SMTP o PRINTER_EMAIL.")
|
||||
return "El servicio de impresión no está configurado correctamente."
|
||||
|
||||
try:
|
||||
msg = MIMEMultipart()
|
||||
msg["From"] = SMTP_USER
|
||||
msg["To"] = SMTP_USER # Sending to the printer's email address
|
||||
msg["To"] = PRINTER_EMAIL
|
||||
msg["Subject"] = f"Print Job from {user_id}: {file_name}"
|
||||
|
||||
body = f"Nuevo trabajo de impresión enviado por el usuario {user_id}.\nNombre del archivo: {file_name}"
|
||||
@@ -55,10 +58,10 @@ async def send_file_to_printer(file_path: str, user_id: int, file_name: str):
|
||||
server = smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT)
|
||||
server.login(SMTP_USER, SMTP_PASS)
|
||||
text = msg.as_string()
|
||||
server.sendmail(SMTP_USER, SMTP_USER, text)
|
||||
server.sendmail(SMTP_USER, PRINTER_EMAIL, text)
|
||||
server.quit()
|
||||
|
||||
logger.info(f"Archivo {file_name} enviado a la impresora por el usuario {user_id}.")
|
||||
logger.info(f"Archivo {file_name} enviado a la impresora ({PRINTER_EMAIL}) por el usuario {user_id}.")
|
||||
return f"Tu archivo '{file_name}' ha sido enviado a la impresora. Recibirás una notificación cuando el estado del trabajo cambie."
|
||||
|
||||
except Exception as e:
|
||||
@@ -73,13 +76,13 @@ async def check_print_status(user_id: int):
|
||||
if not is_admin(user_id):
|
||||
return "No tienes permiso para usar este comando."
|
||||
|
||||
if not all([IMAP_SERVER, SMTP_USER, SMTP_PASS]):
|
||||
if not all([IMAP_SERVER, IMAP_USER, IMAP_PASS]):
|
||||
logger.error("Faltan una o más variables de entorno IMAP.")
|
||||
return "El servicio de monitoreo de impresión no está configurado correctamente."
|
||||
|
||||
try:
|
||||
mail = imaplib.IMAP4_SSL(IMAP_SERVER)
|
||||
mail.login(SMTP_USER, SMTP_PASS)
|
||||
mail.login(IMAP_USER, IMAP_PASS)
|
||||
mail.select("inbox")
|
||||
|
||||
status, messages = mail.search(None, "UNSEEN")
|
||||
|
||||
Reference in New Issue
Block a user