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.
Implement the first two items from the product roadmap:
1. **Remote Printing Service:**
* Create a new `printer.py` module to handle sending files via SMTP and checking status via IMAP.
* Add a document handler in `main.py` to allow admin users to send files to the bot for printing.
* Add a `/check_print_status` command for admins to monitor the print job status.
* Add SMTP/IMAP configuration variables to `config.py` and `.env.example`.
2. **Sales RAG Flow:**
* Implement a `sales_rag.py` module to generate personalized sales pitches.
* The sales flow uses a Retrieval-Augmented Generation (RAG) approach, retrieving relevant services from `services.json` to create a detailed prompt for the LLM.
* The existing `flow_engine.py` is modified to trigger the sales pitch generation upon completion of the `client_sales_funnel` flow.
* Update `main.py` to handle the flow engine's responses and send the generated pitch to the user.
* Update `client_sales_funnel.json` to be triggered by a button in the client menu.
Remove empty placeholder modules talia_bot/modules/printer.py and talia_bot/modules/sales_rag.py.
Update import paths across multiple modules to be absolute from the project root (talia_bot), improving consistency.
Corrected import paths for config variables and utility functions. Standardized the use of the ADMIN_ID configuration variable, resolving a discrepancy where OWNER_CHAT_ID was used.
Removed a duplicated docstring in scheduler.py.
This commit provides a comprehensive update to the README.md file.
The previous version was outdated and did not accurately represent the project's structure or architecture after the implementation of the JSON-based flow engine.
Key changes:
- Rewrites the "Arquitectura Técnica" section to be simpler and more accurate.
- Updates the "Estructura del Proyecto" diagram to be a perfect representation of the current file and module structure.
- Corrects the `git clone` URL in the installation instructions.
- Harmonizes file names (e.g., `google_key.json`) across the documentation and configuration to avoid confusion.
- Simplifies and clarifies the setup and execution instructions.
This commit introduces a modular, JSON-driven conversational flow engine.
Key changes:
- Adds `talia_bot/modules/flow_engine.py` to manage loading and processing conversational flows from external files.
- Separates all conversational logic into individual JSON files within `talia_bot/data/flows/`, organized by user role (admin, crew, client).
- Updates `talia_bot/main.py` to use the new flow engine, replacing the previous hardcoded logic with a dynamic dispatcher.
- Corrects the `.gitignore` file to properly track the new JSON flow files while ensuring sensitive credentials like `google_key.json` remain ignored.
- Updates the `README.md` to reflect the new architecture, providing clear documentation for the modular flow system.
This new architecture makes the bot more maintainable and scalable by decoupling the conversation logic from the core application code.
This commit finalizes the implementation of the JSON-driven conversational flow engine.
Key changes:
- Introduces `flow_engine.py` to manage loading and processing conversational flows from external files.
- Adds the complete set of individual JSON files for all admin, crew, and client flows under the `talia_bot/data/flows/` directory.
- Integrates the flow engine into `main.py` to handle user interactions based on the new modular flow definitions.
This resolves the issue where the flow files were missing from the repository, providing a complete and functional implementation.
This commit introduces a new `FlowEngine` to manage conversational flows based on JSON definitions.
Key changes:
- Created `talia_bot/modules/flow_engine.py` to handle the logic of parsing and executing flows.
- Added a `conversations` table to the database to persist user state during flows.
- Created the `talia_bot/data/flows` directory and added a sample `create_project.json` flow.
- Integrated the `FlowEngine` into `main.py` with a `universal_handler` that routes user input to the engine or to legacy handlers.
This commit introduces a new JSON-driven conversational flow engine.
Key changes:
- Added `talia_bot/modules/flow_engine.py` to handle loading and processing of conversational flows from JSON files.
- Created the `talia_bot/data/flows/` directory to store the JSON definitions for each user role's flows (admin, crew, client).
- Integrated the FlowEngine into `main.py` to handle button presses and command triggers.
- Corrected a critical bug in `handle_response` where user input from buttons was not being saved correctly.
- Made role assignment more robust by adding an explicit `role` key to each flow JSON file.
This commit provides a complete and clean implementation of the JSON-driven flow engine to resolve persistent issues with missing files in previous commits.
This commit includes:
- All individual flow definition files in the `talia_bot/data/flows/` directory.
- The `talia_bot/data/services.json` file.
- The `talia_bot/modules/flow_engine.py` module with corrected logic for handling user responses and robust role assignment.
- All other necessary backend modules that were missing after the environment reset.
This comprehensive commit ensures that all required files are present and correctly implemented, providing a stable foundation for the new modular conversational architecture. All code has been reviewed and corrected based on feedback.
The previous commits were missing the newly created data files (`services.json` and the `flows/` directory). This commit adds these untracked files to the branch to make the implementation complete and functional.
This commit refactors the conversational flow architecture by splitting the monolithic `flows.json` file into individual JSON files for each flow, located in the new `talia_bot/data/flows/` directory.
Key changes:
- **Modular Flow Files:** Each conversational flow is now an independent JSON file (e.g., `admin_check_agenda.json`), improving maintainability and making it easier to modify or add new flows.
- **Updated Flow Engine:** The `FlowEngine` in `talia_bot/modules/flow_engine.py` has been updated to dynamically load all `.json` files from the `talia_bot/data/flows/` directory at startup.
- **Removed Monolithic File:** The old `talia_bot/data/flows.json` file has been deleted, completing the transition to the new modular structure.
This change enhances the organization of the project and aligns with the user's request for easier modification of individual flows.
This commit completely refactors the bot's architecture to use a generic, JSON-driven flow engine, replacing the previous hardcoded `ConversationHandler` logic.
Key changes include:
- **New Flow Engine:** Introduces `talia_bot/modules/flow_engine.py` to manage conversational state based on definitions in `talia_bot/data/flows.json`.
- **Centralized Flow Definitions:** All conversational flows for Admin, Crew, and Client roles are now defined in `talia_bot/data/flows.json`.
- **Persistent Conversations:** Adds a `conversations` table to the database (`talia_bot/db.py`) to persist user state, making flows robust across bot restarts.
- **Universal Handler:** Refactors `main.py` to use a `universal_handler` that processes all user input (text, audio, documents, callbacks) and routes it through the flow engine.
- **Asynchronous Refactoring:** Converts key modules (`vikunja.py`, `llm_engine.py`) to be fully asynchronous using `httpx` and `openai` async clients for better performance.
- **Non-Blocking Print Jobs:** Replaces the blocking `asyncio.sleep` in the print confirmation flow with a non-blocking `JobQueue` background task, ensuring the bot remains responsive.
- **New Modules:** Adds `mailer.py`, `imap_listener.py`, and `transcription.py` to support the print and audio transcription flows.
- **Updated Documentation:** The `README.md` and `.env.example` have been comprehensively updated to reflect the new architecture, configuration, and setup instructions.