This commit addresses a large number of pending tasks from `Tasks.md`, focusing on architectural improvements, documentation consistency, and the introduction of a testing framework.
Key changes include:
- **Button Dispatcher Agent (`[IMP-003]`):** Refactored the button handling logic into a dedicated `ButtonDispatcher` class. This decouples the dispatcher from handlers and improves modularity.
- **Documentation Consistency (`[DOC-001]`):** Updated `AGENTS.md` and `Agent_skills.md` to be consistent with the current codebase, removing outdated information and "Fallo Actual" notes.
- **Code Quality Tools (`[TEST-002]`):** Added `black` to the project for consistent code formatting and applied it to the entire `bot/` directory.
- **Initial Test Coverage (`[TEST-001]`):** Created a `tests/` directory and implemented a comprehensive suite of unit tests for the critical `FlowEngine` module, using Python's `unittest` framework.
- **Task Verification:** Investigated and confirmed that tasks `[ARCH-003]` (Code Duplication), `[PERF-003]` (Flow Engine Memory Usage), and `[PERF-002]` (Voice File Memory Management) were already resolved by previous refactoring.
- **Updated `Tasks.md`:** Updated the status of all addressed tasks to reflect the project's current state.
- Upgrade Python to 3.11 and update dependencies.
- Refactor main.py to isolate business logic.
- Fix bugs in flow_engine.py and printer.py.
- Improve database connection handling.
- Standardize error handling.
- Verify secret management.
- Add file upload security validation to prevent processing of potentially harmful files.
- Update python-telegram-bot to a pinned version and upgrade other dependencies.
- Implement Whisper transcription agent for voice message processing.
- Restore Google Calendar functionality with provided credentials.
This commit fixes a critical `ImportError` that prevented the bot from starting. The error was caused by the `agenda.py` module attempting to import calendar ID variables that were not being loaded into the application's configuration.
The fix involves:
- Updating `talia_bot/config.py` to correctly load the `WORK_GOOGLE_CALENDAR_ID` and `PERSONAL_GOOGLE_CALENDAR_ID` from the environment.
- Removing the obsolete `CALENDAR_ID` variable from the configuration.
- Updating `talia_bot/modules/calendar.py` to import and use the new, more specific `WORK_GOOGLE_CALENDAR_ID` as its default, ensuring consistency with the rest of the application.
The previous logic for advancing to the next step incorrectly assumed that `step_id`s were always sequential integers (e.g., 0, 1, 2). This caused an immediate failure in any flow that used non-sequential or string-based IDs.
The `handle_response` method in `flow_engine.py` has been refactored to determine the next step by its ordinal position in the flow's `steps` array. This makes the engine robust and compatible with any `step_id` format, ensuring all current and future conversational flows will execute correctly.
This commit addresses critical issues in the Talia Bot system, including fixing missing admin flows, correcting agenda privacy logic, implementing voice message transcription, and enforcing RAG guardrails.
Key changes include:
- Modified the onboarding module to dynamically generate admin menus from available JSON flows, making all admin functions accessible.
- Updated the agenda module to correctly use separate work and personal Google Calendar IDs, ensuring privacy and accurate availability.
- Implemented audio transcription using the OpenAI Whisper API, replacing placeholder logic and enabling multimodal interaction.
- Reworked the sales RAG module to prevent it from generating generic responses when it lacks sufficient context.
Additionally, this commit introduces comprehensive documentation as requested:
- `AGENTS.md`: Defines the roles and responsibilities of each system agent.
- `Agent_skills.md`: Details the technical capabilities and business rules for each agent.
- `plan_de_pruebas.md`: Provides a step-by-step test plan to verify the fixes.
- `reparacion_vs_refactor.md`: Outlines the immediate repairs performed and proposes a strategic, incremental plan for long-term architectural improvements.
The 'get_service_info' button was incorrectly being intercepted by a legacy, hardcoded handler in `main.py`. This prevented the data-driven conversational flow defined in `client_sales_funnel.json` from ever starting.
The fix removes the obsolete handler and its corresponding file (`modules/servicios.py`), ensuring that the button click is now correctly routed to the `FlowEngine` to initiate the proper interactive conversation.
The /start command handler in main.py now explicitly calls flow_engine.end_flow() to clear any existing conversation state for the user.
This ensures that every /start command provides a clean slate, resolving the state management issue and making the bot's interactions predictable and correct.
The Telegram bot was becoming unresponsive due to a conflict between a legacy `ConversationHandler` for the `propose_activity` flow and the main `FlowEngine`. This was likely caused by breaking changes in the `python-telegram-bot` library.
This commit resolves the issue by:
1. Removing the problematic `ConversationHandler` from `main.py` and its related functions from `modules/equipo.py`.
2. Migrating the "propose activity" feature to a data-driven JSON flow (`crew_propose_activity.json`), making it compatible with the existing `FlowEngine`.
3. Pinning the `python-telegram-bot` dependency to `<22` in `requirements.txt` to prevent future breakage from upstream updates.
This change ensures all conversational flows are handled consistently by the `FlowEngine`, restoring bot responsiveness and improving maintainability.
Delete the file `talia_bot/debug.md` which was found to contain a hardcoded Telegram bot token. This is an emergency fix to remove the exposed secret from the current state of the repository.
**Note:** The token is still present in the Git history and must be revoked immediately.
This commit refactors the application's configuration handling to perfectly match the structure and variable names provided by the user in their `.env` file. This resolves multiple critical discrepancies that would have prevented the bot from functioning correctly.
- **Update `config.py`:** The file `talia_bot/config.py` has been completely rewritten to load environment variables using the names specified by the user (e.g., `TELEGRAM_OWNER_CHAT_ID`, `GOOGLE_CALENDAR_ID`, `VIKUNJA_BASE_URL`).
- **Update Printer Logic:** The `talia_bot/modules/printer.py` module has been updated to use the new `PRINTER_EMAIL` variable and the specific IMAP credentials (`IMAP_USER`, `IMAP_PASSWORD`), rather than reusing SMTP credentials.
- **Update `.env.example`:** The `.env.example` template file has been rewritten to serve as an accurate and well-documented guide that matches the user's `.env` structure.
This change ensures that the bot is now fully synchronized with the user's deployment environment, resolving previous inconsistencies and improving the overall robustness of the configuration.
This commit implements the NFC tag creation wizard as a data-driven JSON flow, completing a key item from the roadmap.
- **Refactor to FlowEngine:** The previous implementation, which used a `ConversationHandler`, has been completely replaced. The wizard is now defined in `talia_bot/data/flows/admin_create_nfc_tag.json` and is managed by the central `FlowEngine`.
- **New Module:** The logic for generating the Base64 tag is encapsulated in a new, dedicated module: `talia_bot/modules/nfc_tag.py`.
- **Improved UX:** The "Sucursal" (branch) selection step now uses buttons, as originally specified in the documentation, improving the user experience.
- **Code Cleanup:** The obsolete `talia_bot/modules/create_tag.py` module and its corresponding `ConversationHandler` have been removed from `main.py`, making the codebase more consistent and maintainable.
- **Documentation:** The `README.md` has been updated to mark the feature as complete and to include a description of the new wizard.
Remove outdated files from the root directory to clean up the project.
- Delete `test_calendar_debug.py` and `test_vikunja.py`, which were standalone test scripts from an early development phase.
- Delete `vikunja.md`, an old specification document that has been superseded by the main `README.md`.
This commit completely revamps the README.md to reflect the current state of the project.
- **Update Roadmap:** Mark the Remote Printing and Sales RAG Flow features as complete and reorganize the list for clarity.
- **Rewrite Features Section:** Add detailed descriptions of the new Sales RAG Flow and the Remote Printing Service, explaining how they work.
- **Refine Architecture Description:** Rewrite the "Concepto Central" section to more accurately describe the bot's architecture as an autonomous agent cycle (Reception -> Identification -> Routing -> Execution).
- **Update Role Descriptions:** Adjust the permission descriptions for each user role to match the newly implemented features.
This commit improves the conversational sales flow by:
1. **Updating the Knowledge Base:**
* Replaces the content of `talia_bot/data/services.json` with the new, more detailed list of services provided by the user.
2. **Improving RAG Intelligence:**
* Enhances the `generate_sales_pitch` function in `sales_rag.py` to include `work_examples` in the prompt sent to the LLM. This provides more context and enables the generation of more specific and persuasive sales pitches.
3. **Refining Conversational Tone:**
* Adjusts the text in the `client_sales_funnel.json` flow to be more professional and direct.
* Updates the industry options in the flow to align with the new service categories.