A comprehensive Python implementation of the SimpleFIN Telegram Bot with FastAPI backend and modern WebApp interface.
- 🤖 Telegram Bot: Full-featured bot with async/await support
- 🌐 FastAPI Backend: High-performance REST API with automatic documentation
- 📱 Modern WebApp: Enhanced HTML5 interface with Telegram theming
- ⚙️ Flexible Configuration: JSON config files + environment variables
- 🔒 Security: Built-in validation and secure database operations
- 📊 Type Safety: Full type hints and Pydantic models
- Python 3.8+
- pip (Python package manager)
cd python/SimpleFinBot
pip install -r requirements.txtcd python/SimpleFinWebApi
pip install -r requirements.txtThe bot will automatically create a config.json file on first run. Edit it with your bot token:
{
"telegram_bot": {
"bot_token": "YOUR_ACTUAL_BOT_TOKEN_HERE",
"webapp_url": "https://your-webapp-domain.com/index.html"
},
"database": {
"connection_string": "Data Source=simplefin_multi_accounts.db"
}
}# Windows PowerShell
$env:TELEGRAM_BOT_TOKEN="your_bot_token_here"
$env:TELEGRAM_WEBAPP_URL="https://your-webapp-domain.com/index.html"
# Linux/macOS
export TELEGRAM_BOT_TOKEN="your_bot_token_here"
export TELEGRAM_WEBAPP_URL="https://your-webapp-domain.com/index.html"cd python/SimpleFinWebApi
python api.pyThe API will be available at http://localhost:8000
- API Documentation:
http://localhost:8000/docs - Health Check:
http://localhost:8000/health
cd python/SimpleFinBot
python bot.py- Start a chat with your Telegram bot
- Use
/addto get SimpleFIN setup instructions - Follow the SimpleFIN bridge link to generate a token
- Send the token to the bot to connect your bank
- Use
/accountsto view your connected accounts - Use
/webto open the WebApp interface
python/
├── SimpleFinBot/ # Telegram Bot
│ ├── bot.py # Main bot application
│ ├── config.py # Configuration management
│ └── requirements.txt # Bot dependencies
├── SimpleFinWebApi/ # FastAPI Backend
│ ├── api.py # Main API application
│ └── requirements.txt # API dependencies
└── SimpleFinWebApp/ # WebApp Frontend
└── index.html # Enhanced web interface
- Async/await support for better performance
- Type hints for better code quality
- Comprehensive error handling
- Structured logging
- Configuration validation
- FastAPI with automatic OpenAPI documentation
- Pydantic models for request/response validation
- CORS middleware for cross-origin requests
- Health check endpoints
- Structured error responses
- Telegram WebApp theming support
- Enhanced UI with loading states
- Error handling and user feedback
- Responsive design
- Version identification
- Environment variable support for sensitive data
- Input validation and sanitization
- Parameterized database queries
- CORS configuration
- Token validation with helpful error messages
When the API is running, visit http://localhost:8000/docs for interactive API documentation powered by FastAPI's automatic OpenAPI generation.
GET /api/accounts?user_id={id}- Get user's bank accountsGET /health- Health checkGET /- API information
# Health check
curl http://localhost:8000/health
# Get accounts (replace USER_ID with actual Telegram user ID)
curl "http://localhost:8000/api/accounts?user_id=USER_ID"- Start the bot
- Send
/startto your bot - Verify all commands work correctly
| Feature | C# Version | Python Version |
|---|---|---|
| Framework | .NET 8 Console App | Python asyncio |
| API | ASP.NET Core | FastAPI |
| Database | SQLite with Microsoft.Data.Sqlite | SQLite with built-in sqlite3 |
| Configuration | appsettings.json + Environment Variables | JSON config + Environment Variables |
| Documentation | XML docs | Type hints + docstrings |
| Performance | High (compiled) | High (async/await) |
| Deployment | Single executable | Python runtime required |
Create a Dockerfile for each component:
# Bot Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "bot.py"]Create service files for automatic startup and monitoring.
This project is a template for SimpleFIN integration with Telegram bots.