This guide will help you set up a local development environment for the TeleBot project, eliminating the need to connect to PostgreSQL and external Redis servers.
In production, TeleBot uses PostgreSQL to store analytics data and Redis for queue management. For local development, we can use:
- No need to install and run a PostgreSQL server
- Self-contained in a single file
- Easy setup and maintenance
- No external dependencies
- Use a local Redis server installation
- Use Redis Cloud free tier
- Configure mock Redis (for advanced users)
Add the following lines to your .env file in the TeleBot/bot/ directory:
export DATABASE_URL=sqlite:///data/database.sqlite
export REDIS_URL=redis://localhost:6379/0
The first line configures SQLAlchemy to use a SQLite database stored in the data directory.
The second line configures the Redis connection for queue management.
Run the setup script to initialize the SQLite database:
cd TeleBot/bot
python setup_sqlite.pyThis script will:
- Create the
datadirectory if it doesn't exist - Initialize the SQLite database with the required tables
- Verify the database connection works properly
You should see output confirming that the database has been initialized successfully. The SQLite database file will be created at TeleBot/bot/data/database.sqlite.
Use the included utility script to view and analyze data in the SQLite database:
# View recent events (default: 20)
python view_sqlite_data.py recent
# View recent events with custom limit
python view_sqlite_data.py recent --limit 50
# View statistics for the past 7 days (default)
python view_sqlite_data.py stats
# View statistics for a custom period
python view_sqlite_data.py stats --days 30-
Install Redis:
- macOS:
brew install redis - Ubuntu:
sudo apt install redis-server - Windows: Use Redis with WSL or download from https://github.com/microsoftarchive/redis/releases
- macOS:
-
Start Redis Server:
- macOS/Linux:
redis-server - Windows: Run the Redis Server executable
- macOS/Linux:
- Sign up for a free Redis Cloud account at https://redis.com/try-free/
- Create a database and get your connection string
- Update your
.envfile with the Redis Cloud URL:export REDIS_URL=redis://username:password@host:port
To switch back to PostgreSQL, update the DATABASE_URL in your .env file:
export DATABASE_URL=postgresql://username:password@localhost:5432/dbname
To switch to a production Redis instance, update the REDIS_URL in your .env file:
export REDIS_URL=redis://username:password@host:port/db
- The SQLite database is intended for local development only
- The database file is excluded from git via
.gitignore - All analytics data is stored locally and won't be synced with production
- SQLite has some limitations compared to PostgreSQL, but they shouldn't impact development
- Redis is required for the bot to function properly (for queue management)
- If you don't have Redis installed, you'll need to install it or use Redis Cloud
If you see an error about the database not being found, run the setup_sqlite.py script again to initialize it.
If you encounter SQLAlchemy errors, ensure you're using a compatible version (2.0 or later).
Ensure the TeleBot/bot/data directory has write permissions for your user.
If you see a Redis connection error:
- Verify that Redis is running:
redis-cli ping(should returnPONG) - Check your Redis URL format:
redis://hostname:port/db - If using Redis Cloud, verify your credentials and network connectivity
- Try a different Redis database number (e.g.,
redis://localhost:6379/1)
- Database file location:
TeleBot/bot/data/database.sqlite - Uses SQLAlchemy ORM with the same models as PostgreSQL
- Schema compatibility is maintained between SQLite and PostgreSQL
- Environment variable configuration remains the same, only the connection URL changes
- Used for queue management and task processing
- Same interface is used for local and production Redis
- The bot uses Redis to manage asynchronous LLM job processing
- No persistent data is stored in Redis (only transient message queues)