This project is a demonstration of a user registration system built with a Telegram bot and a FastAPI backend. It utilizes a PostgreSQL database for data storage and is fully containerized with Docker for straightforward setup and deployment.
- User registration and deregistration via a Telegram bot.
- RESTful API built with FastAPI for user management.
- Asynchronous architecture using
python-telegram-bot
, andSQLAlchemy 2.0
. - Database migrations handled by Alembic.
- Containerized with Docker and Docker Compose for easy development and deployment.
- Backend: FastAPI
- Bot Framework: python-telegram-bot
- Database: PostgreSQL
- ORM: SQLAlchemy 2.0 (async)
- Migrations: Alembic
- Containerization: Docker, Docker Compose
- Dependency Management: Poetry
The project is organized into two main components:
fastapi-application/
: Contains the FastAPI application.api/
: API endpoints (routers).core/
: Core application logic, configuration, and database models.alembic/
: Database migration scripts.
telegram-bot/
: Contains thepython-telegram-bot
application.handlers/
: Bot command and message handlers.keyboards/
: Inline and reply keyboard layouts.states/
: Finite State Machine (FSM) states for conversations.
docker-compose.yml
: Defines the services (API, bot, database) for the application.*.Dockerfile
: Docker build configurations for the API and bot services.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/EZDAMIR/Telegram-Reg-Example.git cd Telegram-Reg-Example
-
Configure Environment Variables: Create a
.env
file in the project root by copying the template.cp fastapi-application/env.template .env
Open the
.env
file and replaceYOUR_TELEGRAM_BOT_TOKEN_HERE
with your actual Telegram Bot Token.TELEGRAM_BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN_HERE FASTAPI__DB__URL=postgresql+asyncpg://user:password@pg:5432/db FASTAPI__DB__ECHO=True
-
Build and Run with Docker Compose: Execute the following command from the project root to build the images and start the containers.
docker-compose up --build
The application stack, including the database, API, and bot, will be started. Database migrations will be applied automatically on startup.
/start
- Displays a welcome message./register
- Initiates the user registration process./unregister
- Removes your data from the system./help
- Shows a help message with available commands.
Once the application is running, the auto-generated API documentation is available at:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc