Real-time transaction processing bot with Google Cloud Vision OCR
A professional Telegram bot for handling deposit and withdrawal transactions with automatic receipt recognition using Google Cloud Vision API. Designed for operations teams requiring real-time notifications and transaction management.
- Telegram Bot Interface - Client and admin interaction via python-telegram-bot
- Receipt OCR - Automatic data extraction using Google Cloud Vision
- Transaction Management - Deposit and withdrawal processing
- Role-based Access - Separate interfaces for clients and administrators
- Status Tracking - Real-time transaction status updates
- Async Processing - Background tasks with Celery
- Extract receipt number, amount, date, payment method
- Automatic image preprocessing for better recognition
- Confidence scoring and validation
- Manual review fallback for failed extractions
- Transaction approval/rejection buttons
- Real-time statistics dashboard
- Transaction history and details
- Bulk operations support
ops-chatbot/
├── main.py # FastAPI REST API
├── telegram_bot.py # Telegram integration
├── tasks.py # Celery tasks
├── config.py # Configuration
├── logging_config.py # Logging configuration
├── requirements.txt # Dependencies
├── docker-compose.yml # Dev environment
├── Dockerfile # Container build
├── .env.example # Environment template
├── .gitignore # Git ignore patterns
├── .dockerignore # Docker ignore patterns
├── alembic.ini # Database migrations config
├── LICENSE # MIT License
├── README.md # This file
├── PREREQUISITES.md # Prerequisites guide
├── google-cloud-setup.md # Google Cloud Vision setup guide
│
├── database/
│ ├── __init__.py # Package initialization
│ ├── models.py # SQLAlchemy models
│ └── migrations/ # Alembic migrations
│ ├── env.py # Alembic environment
│ ├── script.py.mako # Migration template
│ └── versions/ # Migration versions
│
├── services/
│ ├── __init__.py # Package initialization
│ └── ocr_service.py # Google Vision OCR
│
└── scripts/
├── init_db.py # DB initialization
├── check_services.sh # Health check script
├── backup.sh # Backup script
└── deploy.sh # Deployment script
- Python 3.11
- PostgreSQL 15+
- Redis 7+
- Telegram Bot Token (from @BotFather)
- Google Cloud Account with Vision API enabled
- Docker & Docker Compose (for containerized deployment)
- Sentry account (for error tracking)
New to the project? See PREREQUISITES.md for detailed installation instructions for your OS (macOS, Linux, Windows).
Already have prerequisites? Continue with the setup below.
git clone https://github.com/NadiiaBCN/ops-chatbot.git
cd ops-chatbotpython3.11 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install --upgrade pip
pip install -r requirements.txtcp .env.example .env
# Edit .env with your values
nano .envSee PREREQUISITES.md for complete list. Key variables:
| Variable | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN |
YES | Bot token from @BotFather |
TELEGRAM_ADMIN_IDS |
YES | Comma-separated admin user IDs |
GOOGLE_APPLICATION_CREDENTIALS |
YES | Path to Google Cloud JSON key |
GOOGLE_PROJECT_ID |
YES | Google Cloud project ID |
DATABASE_URL |
YES | PostgreSQL connection string |
REDIS_URL |
YES | Redis connection string |
CELERY_BROKER_URL |
YES | Celery broker URL |
CELERY_RESULT_BACKEND |
YES | Celery result backend URL |
Check if PostgreSQL is installed:
psql --versionIf not installed, see PREREQUISITES.md for installation instructions.
Start PostgreSQL service:
macOS:
brew services start postgresql@15Linux:
sudo systemctl start postgresqlCreate database:
# Connect to PostgreSQL
createdb chatbot
# Connect as superuser (without password)
psql -U $(whoami) -d chatbot
# In PostgreSQL console, run:
CREATE USER postgres WITH PASSWORD 'your_secure_password';
CREATE DATABASE chatbot OWNER postgres;
GRANT ALL PRIVILEGES ON DATABASE chatbot TO postgres;
\qUpdate .env file:
DATABASE_URL=postgresql+asyncpg://postgres:your_secure_password@localhost:5432/chatbot# Apply database migrations
alembic upgrade head
# Initialize admin users and seed data
python scripts/init_db.py# Terminal 1: Start Redis
redis-server
# Terminal 2: Start Celery worker
celery -A tasks worker --loglevel=info
# Terminal 3: Start Telegram bot
python telegram_bot.pyTo test the bot as an admin, open Telegram, find your bot, and send the /start command – you should then see the admin interface.
To test the bot as a client, either log in from another Telegram account (recommended) or temporarily change the TELEGRAM_ADMIN_IDS value in the .env file and restart the bot.
Note: Don't forget to restore the real administrator ID after completing the visitor test.
Usage Guide
For Clients
Making a Deposit:
- Send
/depositto the bot - Choose payment method (EUR/USD/CRYPTO)
- Send photo of your receipt
- Wait for confirmation
Checking Status:
- Send
/mystatusto view recent transactions
Canceling Operation:
- Send
/cancelto cancel current operation
For Administrators
Commands:
/admin- Access admin panel/stats- View statistics/transactions- View transactions
# Build and start all services
docker-compose up -d
# Apply database migrations (first time only)
docker-compose exec bot alembic upgrade head
# Initialize admin users (first time only)
docker-compose exec bot python scripts/init_db.py
# View logs
docker-compose logs -f
# Stop services
docker-compose down# Make script executable (first time only)
chmod +x scripts/check_services.sh
# Run inside Docker
docker-compose exec bot bash scripts/check_services.shFor Docker:
# Check Celery worker
docker-compose exec worker celery -A tasks inspect active
# Check database connection
docker-compose exec bot python -c "from database.models import get_database; print('DB OK')"
# Check Google Cloud Vision
docker-compose exec bot python -c "from google.cloud import vision; print('GCV OK')"
# Check Redis
docker-compose exec redis redis-cli pingFor Local:
# Check Celery worker
celery -A tasks inspect active
# Check database connection
python -c "from database.models import get_database; print('DB OK')"
# Check Google Cloud Vision
python -c "from google.cloud import vision; print('GCV OK')"
# Check Redis
redis-cli pingDocker logs:
# View bot logs
docker-compose logs -f bot
# View worker logs
docker-compose logs -f worker
# View all logs
docker-compose logs -f
# View last 100 lines
docker-compose logs --tail=100 botFile logs:
# Telegram bot logs
tail -f logs/telegram_bot.log
# Celery worker logs
tail -f logs/celery.log
# All logs
tail -f logs/*.logAccess Flower dashboard at http://localhost:5555
curl http://localhost:8000/health- Check if bot token is correct
- Check logs:
docker-compose logs botortail -f logs/telegram_bot.log - Restart bot:
docker-compose restart bot
- Verify Google Cloud credentials path
- Check Vision API is enabled
- Test credentials:
docker-compose exec bot python -c "from google.cloud import vision; print('OK')"
- Check PostgreSQL is running:
docker-compose ps postgres - Verify connection string in
.env - Check migrations:
docker-compose exec bot alembic current - Apply migrations:
docker-compose exec bot alembic upgrade head
- Check Redis is running:
docker-compose exec redis redis-cli ping - Verify Celery worker is active:
docker-compose exec worker celery -A tasks inspect active - Check Celery logs:
docker-compose logs worker
- Ensure migrations are applied:
docker-compose exec bot alembic upgrade head - Initialize database:
docker-compose exec bot python scripts/init_db.py - Check database tables:
docker-compose exec postgres psql -U postgres -d chatbot -c "\dt"
- Restart services:
docker-compose restart bot worker
If you see errors like ModuleNotFoundError: No module named 'config' or 'database':
-
Ensure you're in the project root directory:
cd /path/to/ops-chatbot -
Activate virtual environment:
source venv/bin/activate -
Run commands from project root, not from subdirectories
Contributions are welcome! Please follow code style:
- Follow PEP 8
- Add docstrings to all functions
- Write tests for new features
- Update documentation
This project is licensed under the MIT License - see the LICENSE file for details.
