A simple template for creating a telegram bot on webhooks using the aiogram and fastapi
- Clone project
git clone https://github.com/BushlanovDev/aiogram-fastapi-bot-template.git
- Create a virtual venv
python -m venv venv
andsource venv/bin/activate
- Install dependencies
pip install -r requirements.txt
- Copy config template
cp .env.example .env
Edit the .env file
APP__DEBUG
true
or false
, development mode
APP__PORT
Port of application for fastapi (8080
)
APP__URL
The base domain of the application (https://example.com
)
APP__WEBHOOK_PATH
The route to which hooks from telegram will come (/webhook/tg
)
APP__DEFAULT_LANGUAGE
Default response language if the user's language is not received in the hook (en
)
TG_BOT__TOKEN
Telegram bot secret token
For local launch you will most likely need the application ngrok or similar. APP__URL
needs to
be copied from ngrok window to config.
Run bot python main.py
or docker compose up -d
Folder | Description |
---|---|
callbacks | Callback data |
configs | Configuration files |
handlers | Handlers, commands, callbacks |
i18n | Localization |
keyboards | Keyboards reply, inline |
middlewares | Middlewares for localization, throttling |
services | Custom libraries |
states | State objects |