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=
|
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=
|
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=
|
VIKUNJA_TOKEN=
|
||||||
GOOGLE_CREDENTIALS_PATH=./data/credentials.json
|
|
||||||
|
|
||||||
# --- PRINT SERVICE ---
|
# ==================================================
|
||||||
SMTP_SERVER=smtp.hostinger.com
|
# Email Configuration (SMTP / IMAP)
|
||||||
SMTP_PORT=465
|
# ==================================================
|
||||||
SMTP_USER=print.service@vanityexperience.mx
|
# SMTP server for sending emails.
|
||||||
SMTP_PASS=
|
SMTP_SERVER=
|
||||||
IMAP_SERVER=imap.hostinger.com
|
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
|
# talia_bot/config.py
|
||||||
# Este archivo se encarga de cargar todas las variables de entorno y configuraciones del bot.
|
# This file loads all environment variables and bot configurations.
|
||||||
# Las variables de entorno son valores que se guardan fuera del código por seguridad (como tokens y llaves API).
|
# Environment variables are stored securely outside the code (e.g., in a .env file).
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from pathlib import Path
|
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'
|
env_path = Path(__file__).parent.parent / '.env'
|
||||||
load_dotenv(dotenv_path=env_path)
|
load_dotenv(dotenv_path=env_path)
|
||||||
|
|
||||||
# Token del bot de Telegram (obtenido de @BotFather)
|
# --- Telegram Configuration ---
|
||||||
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
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)
|
# --- Google Services ---
|
||||||
ADMIN_ID = os.getenv("ADMIN_ID")
|
|
||||||
|
|
||||||
# Ruta al archivo de credenciales de la cuenta de servicio de Google
|
|
||||||
GOOGLE_SERVICE_ACCOUNT_FILE = os.getenv("GOOGLE_SERVICE_ACCOUNT_FILE")
|
GOOGLE_SERVICE_ACCOUNT_FILE = os.getenv("GOOGLE_SERVICE_ACCOUNT_FILE")
|
||||||
if GOOGLE_SERVICE_ACCOUNT_FILE and not os.path.isabs(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)
|
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
|
# --- Webhooks (n8n) ---
|
||||||
CALENDAR_ID = os.getenv("CALENDAR_ID")
|
|
||||||
|
|
||||||
# URL del webhook de n8n para enviar datos a otros servicios
|
|
||||||
N8N_WEBHOOK_URL = os.getenv("N8N_WEBHOOK_URL")
|
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
|
# --- AI Core ---
|
||||||
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)
|
|
||||||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
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)
|
# --- Scheduling ---
|
||||||
OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-3.5-turbo")
|
CALENDLY_LINK = os.getenv("CALENDLY_LINK")
|
||||||
|
|
||||||
# Hora del resumen diario (formato HH:MM)
|
# --- Vikunja (Task Management) ---
|
||||||
DAILY_SUMMARY_TIME = os.getenv("DAILY_SUMMARY_TIME", "07:00")
|
VIKUNJA_API_URL = os.getenv("VIKUNJA_BASE_URL")
|
||||||
|
VIKUNJA_API_TOKEN = os.getenv("VIKUNJA_TOKEN")
|
||||||
|
|
||||||
# Enlace de Calendly para agendar citas
|
# --- Email Configuration (SMTP / IMAP) ---
|
||||||
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 ---
|
|
||||||
SMTP_SERVER = os.getenv("SMTP_SERVER")
|
SMTP_SERVER = os.getenv("SMTP_SERVER")
|
||||||
SMTP_PORT = os.getenv("SMTP_PORT")
|
SMTP_PORT = os.getenv("SMTP_PORT")
|
||||||
SMTP_USER = os.getenv("SMTP_USER")
|
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_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_USER,
|
||||||
SMTP_PASS,
|
SMTP_PASS,
|
||||||
IMAP_SERVER,
|
IMAP_SERVER,
|
||||||
|
IMAP_USER,
|
||||||
|
IMAP_PASS,
|
||||||
|
PRINTER_EMAIL,
|
||||||
)
|
)
|
||||||
from talia_bot.modules.identity import is_admin
|
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):
|
if not is_admin(user_id):
|
||||||
return "No tienes permiso para usar este comando."
|
return "No tienes permiso para usar este comando."
|
||||||
|
|
||||||
if not all([SMTP_SERVER, SMTP_PORT, SMTP_USER, SMTP_PASS]):
|
if not all([SMTP_SERVER, SMTP_PORT, SMTP_USER, SMTP_PASS, PRINTER_EMAIL]):
|
||||||
logger.error("Faltan una o más variables de entorno SMTP.")
|
logger.error("Faltan una o más variables de entorno SMTP o PRINTER_EMAIL.")
|
||||||
return "El servicio de impresión no está configurado correctamente."
|
return "El servicio de impresión no está configurado correctamente."
|
||||||
|
|
||||||
try:
|
try:
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
msg["From"] = SMTP_USER
|
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}"
|
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}"
|
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 = smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT)
|
||||||
server.login(SMTP_USER, SMTP_PASS)
|
server.login(SMTP_USER, SMTP_PASS)
|
||||||
text = msg.as_string()
|
text = msg.as_string()
|
||||||
server.sendmail(SMTP_USER, SMTP_USER, text)
|
server.sendmail(SMTP_USER, PRINTER_EMAIL, text)
|
||||||
server.quit()
|
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."
|
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:
|
except Exception as e:
|
||||||
@@ -73,13 +76,13 @@ async def check_print_status(user_id: int):
|
|||||||
if not is_admin(user_id):
|
if not is_admin(user_id):
|
||||||
return "No tienes permiso para usar este comando."
|
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.")
|
logger.error("Faltan una o más variables de entorno IMAP.")
|
||||||
return "El servicio de monitoreo de impresión no está configurado correctamente."
|
return "El servicio de monitoreo de impresión no está configurado correctamente."
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mail = imaplib.IMAP4_SSL(IMAP_SERVER)
|
mail = imaplib.IMAP4_SSL(IMAP_SERVER)
|
||||||
mail.login(SMTP_USER, SMTP_PASS)
|
mail.login(IMAP_USER, IMAP_PASS)
|
||||||
mail.select("inbox")
|
mail.select("inbox")
|
||||||
|
|
||||||
status, messages = mail.search(None, "UNSEEN")
|
status, messages = mail.search(None, "UNSEEN")
|
||||||
|
|||||||
Reference in New Issue
Block a user