feat: Implement conversational flow for proposals

- Implements a multi-step conversational flow for team members to propose activities using `ConversationHandler`.
- Enhances the `aprobaciones` module to allow the owner to approve or reject proposals with inline keyboard buttons.
- Integrates the new conversational and approval workflows into the main application in `app/main.py`.
- Updates `tasks.md` to reflect the completion of the `equipo` and `aprobaciones` modules.
This commit is contained in:
google-labs-jules[bot]
2025-12-15 20:41:07 +00:00
parent 82b0e90faa
commit c603f5003e
4 changed files with 148 additions and 41 deletions

View File

@@ -1,15 +1,31 @@
# app/main.py
import logging
from telegram import Update
from telegram.ext import Application, CommandHandler, CallbackQueryHandler, ContextTypes
from telegram.ext import (
Application,
CommandHandler,
CallbackQueryHandler,
ConversationHandler,
MessageHandler,
ContextTypes,
filters,
)
from config import TELEGRAM_BOT_TOKEN
from permissions import get_user_role
from modules.onboarding import handle_start as onboarding_handle_start
from modules.agenda import get_agenda
from modules.citas import request_appointment
from modules.equipo import propose_activity, view_requests_status
from modules.aprobaciones import approve_request, view_pending
from modules.equipo import (
propose_activity_start,
get_description,
get_duration,
cancel_proposal,
view_requests_status,
DESCRIPTION,
DURATION,
)
from modules.aprobaciones import view_pending, handle_approval_action
from modules.servicios import get_service_info
# Enable logging
@@ -25,36 +41,35 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
logger.info(f"User {chat_id} started conversation with role: {user_role}")
# Delegate to the onboarding module
response_text, reply_markup = onboarding_handle_start(user_role)
await update.message.reply_text(response_text, reply_markup=reply_markup)
async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Parses the CallbackQuery and calls the appropriate module."""
"""Parses the CallbackQuery and calls the appropriate module for simple actions."""
query = update.callback_query
await query.answer()
logger.info(f"Received callback query: {query.data}")
logger.info(f"Button handler received callback query: {query.data}")
response_text = "Acción no reconocida."
reply_markup = None
if query.data == 'view_agenda':
response_text = get_agenda()
if query.data.startswith(('approve:', 'reject:')):
response_text = handle_approval_action(query.data)
elif query.data == 'view_pending':
response_text = view_pending()
elif query.data == 'approve_request':
response_text = approve_request()
elif query.data == 'propose_activity':
response_text = propose_activity()
elif query.data == 'view_requests_status':
response_text = view_requests_status()
elif query.data == 'schedule_appointment':
response_text = request_appointment()
elif query.data == 'get_service_info':
response_text = get_service_info()
response_text, reply_markup = view_pending()
else:
simple_callbacks = {
'view_agenda': get_agenda,
'view_requests_status': view_requests_status,
'schedule_appointment': request_appointment,
'get_service_info': get_service_info,
}
handler_func = simple_callbacks.get(query.data)
if handler_func:
response_text = handler_func()
await query.edit_message_text(text=response_text, parse_mode='Markdown')
await query.edit_message_text(text=response_text, reply_markup=reply_markup, parse_mode='Markdown')
def main() -> None:
"""Start the bot."""
@@ -62,14 +77,23 @@ def main() -> None:
logger.error("TELEGRAM_BOT_TOKEN is not set in the environment variables.")
return
# Create the Application and pass it your bot's token.
application = Application.builder().token(TELEGRAM_BOT_TOKEN).build()
# Add command handlers
# Conversation handler for proposing activities
conv_handler = ConversationHandler(
entry_points=[CallbackQueryHandler(propose_activity_start, pattern='^propose_activity$')],
states={
DESCRIPTION: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_description)],
DURATION: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_duration)],
},
fallbacks=[CommandHandler('cancel', cancel_proposal)],
per_message=False
)
application.add_handler(conv_handler)
application.add_handler(CommandHandler("start", start))
application.add_handler(CallbackQueryHandler(button))
# Run the bot until the user presses Ctrl-C
logger.info("Starting Talía Bot...")
application.run_polling()