mirror of
https://github.com/marcogll/telegram_new_socias.git
synced 2026-01-13 13:15:16 +00:00
feat: Implement a new links menu, consolidate the main action keyboard into a ui module, and update employee ID generation logic.
This commit is contained in:
67
main.py
67
main.py
@@ -1,11 +1,17 @@
|
||||
import os
|
||||
import logging
|
||||
from dotenv import load_dotenv
|
||||
from typing import Optional
|
||||
|
||||
# Cargar variables de entorno antes de importar módulos que las usan
|
||||
load_dotenv()
|
||||
|
||||
from telegram import Update, ReplyKeyboardMarkup, BotCommand
|
||||
from telegram import (
|
||||
Update,
|
||||
InlineKeyboardButton,
|
||||
InlineKeyboardMarkup,
|
||||
BotCommand,
|
||||
)
|
||||
from telegram.constants import ParseMode
|
||||
from telegram.ext import Application, Defaults, CommandHandler, ContextTypes
|
||||
|
||||
@@ -13,30 +19,67 @@ from telegram.ext import Application, Defaults, CommandHandler, ContextTypes
|
||||
from modules.onboarding import onboarding_handler
|
||||
from modules.rh_requests import vacaciones_handler, permiso_handler
|
||||
from modules.database import log_request
|
||||
from modules.ui import main_actions_keyboard
|
||||
# from modules.finder import finder_handler (Si lo creas después)
|
||||
|
||||
LINK_CURSOS = "https://cursos.vanityexperience.mx/dashboard-2/"
|
||||
LINK_SITIO = "https://vanityexperience.mx/"
|
||||
LINK_AGENDA_IOS = "https://apps.apple.com/us/app/fresha-for-business/id1455346253"
|
||||
LINK_AGENDA_ANDROID = "https://play.google.com/store/apps/details?id=com.fresha.Business"
|
||||
|
||||
TOKEN = os.getenv("TELEGRAM_TOKEN")
|
||||
|
||||
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
|
||||
|
||||
def _guess_platform(update: Update) -> Optional[str]:
|
||||
"""
|
||||
Telegram no expone el OS del usuario en mensajes regulares.
|
||||
Devolvemos None para mostrar ambos links; si en el futuro llegan datos, se pueden mapear aquí.
|
||||
"""
|
||||
try:
|
||||
_ = update.to_dict() # placeholder por si queremos inspeccionar el payload
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
async def links_menu(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""Muestra accesos rápidos a cursos, sitio y descargas."""
|
||||
user = update.effective_user
|
||||
log_request(user.id, user.username, "links", update.message.text)
|
||||
|
||||
plataforma = _guess_platform(update)
|
||||
descarga_buttons = []
|
||||
if plataforma == "ios":
|
||||
descarga_buttons.append(InlineKeyboardButton("Agenda | iOS", url=LINK_AGENDA_IOS))
|
||||
elif plataforma == "android":
|
||||
descarga_buttons.append(InlineKeyboardButton("Agenda | Android", url=LINK_AGENDA_ANDROID))
|
||||
else:
|
||||
descarga_buttons = [
|
||||
InlineKeyboardButton("Agenda | iOS", url=LINK_AGENDA_IOS),
|
||||
InlineKeyboardButton("Agenda | Android", url=LINK_AGENDA_ANDROID),
|
||||
]
|
||||
|
||||
texto = (
|
||||
"🌐 Links útiles\n"
|
||||
"Claro, aquí tienes enlaces que puedes necesitar durante tu estancia con nosotros:\n"
|
||||
"Toca el que te aplique."
|
||||
)
|
||||
botones = [
|
||||
[InlineKeyboardButton("Cursos Vanity", url=LINK_CURSOS)],
|
||||
[InlineKeyboardButton("Sitio Vanity", url=LINK_SITIO)],
|
||||
descarga_buttons,
|
||||
]
|
||||
await update.message.reply_text(texto, reply_markup=InlineKeyboardMarkup(botones))
|
||||
|
||||
async def menu_principal(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""Muestra el menú de opciones de Vanessa"""
|
||||
user = update.effective_user
|
||||
log_request(user.id, user.username, "start", update.message.text)
|
||||
texto = (
|
||||
"👩💼 **Hola, soy Vanessa. ¿En qué puedo ayudarte hoy?**\n\n"
|
||||
"Comandos rápidos:\n"
|
||||
"/welcome — Registro de nuevas empleadas\n"
|
||||
"/vacaciones — Solicitud de vacaciones\n"
|
||||
"/permiso — Solicitud de permiso por horas\n\n"
|
||||
"También tienes los botones rápidos abajo 👇"
|
||||
"Toca un botón para continuar 👇"
|
||||
)
|
||||
teclado = ReplyKeyboardMarkup(
|
||||
[["/welcome"], ["/vacaciones", "/permiso"]],
|
||||
resize_keyboard=True
|
||||
)
|
||||
await update.message.reply_text(texto, reply_markup=teclado)
|
||||
await update.message.reply_text(texto, reply_markup=main_actions_keyboard())
|
||||
|
||||
async def post_init(application: Application):
|
||||
# Mantén los comandos rápidos disponibles en el menú de Telegram
|
||||
@@ -45,6 +88,7 @@ async def post_init(application: Application):
|
||||
BotCommand("welcome", "Registro de nuevas empleadas"),
|
||||
BotCommand("vacaciones", "Solicitar vacaciones"),
|
||||
BotCommand("permiso", "Solicitar permiso por horas"),
|
||||
BotCommand("links", "Links útiles"),
|
||||
BotCommand("cancelar", "Cancelar flujo actual"),
|
||||
])
|
||||
|
||||
@@ -69,6 +113,7 @@ def main():
|
||||
app.add_handler(onboarding_handler)
|
||||
app.add_handler(vacaciones_handler)
|
||||
app.add_handler(permiso_handler)
|
||||
app.add_handler(CommandHandler("links", links_menu))
|
||||
# app.add_handler(finder_handler)
|
||||
|
||||
print("🧠 Vanessa Bot Brain iniciada y lista para trabajar en todos los módulos.")
|
||||
|
||||
Reference in New Issue
Block a user