mirror of
https://github.com/marcogll/telegram_new_socias.git
synced 2026-01-13 21:25:16 +00:00
124 lines
4.4 KiB
Python
124 lines
4.4 KiB
Python
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,
|
|
InlineKeyboardButton,
|
|
InlineKeyboardMarkup,
|
|
BotCommand,
|
|
)
|
|
from telegram.constants import ParseMode
|
|
from telegram.ext import Application, Defaults, CommandHandler, ContextTypes
|
|
|
|
# --- IMPORTAR HABILIDADES ---
|
|
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"
|
|
"Toca un botón para continuar 👇"
|
|
)
|
|
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
|
|
await application.bot.set_my_commands([
|
|
BotCommand("start", "Mostrar menú principal"),
|
|
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"),
|
|
])
|
|
|
|
def main():
|
|
# Configuración Global
|
|
defaults = Defaults(parse_mode=ParseMode.MARKDOWN)
|
|
app = (
|
|
Application.builder()
|
|
.token(TOKEN)
|
|
.defaults(defaults)
|
|
.post_init(post_init)
|
|
.build()
|
|
)
|
|
|
|
# --- REGISTRO DE HABILIDADES ---
|
|
|
|
# 1. Comando de Ayuda / Menú
|
|
app.add_handler(CommandHandler("start", menu_principal))
|
|
app.add_handler(CommandHandler("help", menu_principal))
|
|
|
|
# 2. Habilidades Complejas (Conversaciones)
|
|
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.")
|
|
app.run_polling()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|