mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-13 21:35:19 +00:00
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.
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
# talia_bot/db.py
|
|
# This module will handle the database connection and operations.
|
|
|
|
import sqlite3
|
|
import logging
|
|
|
|
DATABASE_FILE = "talia_bot/data/users.db"
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def get_db_connection():
|
|
"""Creates a connection to the SQLite database."""
|
|
conn = sqlite3.connect(DATABASE_FILE)
|
|
conn.row_factory = sqlite3.Row
|
|
return conn
|
|
|
|
def setup_database():
|
|
"""Sets up the database tables if they don't exist."""
|
|
try:
|
|
conn = get_db_connection()
|
|
cursor = conn.cursor()
|
|
|
|
# Create the users table
|
|
cursor.execute("""
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
telegram_id INTEGER UNIQUE NOT NULL,
|
|
role TEXT NOT NULL CHECK(role IN ('admin', 'crew', 'client')),
|
|
name TEXT,
|
|
employee_id TEXT,
|
|
branch TEXT
|
|
)
|
|
""")
|
|
|
|
conn.commit()
|
|
logger.info("Database setup complete. 'users' table is ready.")
|
|
except sqlite3.Error as e:
|
|
logger.error(f"Database error during setup: {e}")
|
|
finally:
|
|
if conn:
|
|
conn.close()
|
|
|
|
if __name__ == '__main__':
|
|
# This allows us to run the script directly to initialize the database
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger.info("Running database setup manually...")
|
|
setup_database()
|
|
logger.info("Manual setup finished.")
|