This Telegram bot template provides a foundation for creating powerful and interactive bots using the aiogram library in Python.
- Clone the repository
$ git clone https://github.com/anekobtw/telegram-bot-template.git
- Go to the project directory
$ cd bot
- Install dependencies.
$ pip install -r requirements.txt
- Create
.env
file. - Customize any configuration settings or add additional functionality according to your requirements.
- Run the bot.
- Using terminal
$ python main.py
- Using docker
docker build --pull --rm -f "bot\Dockerfile" -t telegrambottemplate:latest "bot"
docker compose up --build
- Using terminal
To run this project, you will need to add the following environment variables to your .env
file
TOKEN
- can be obtained from BotFather
└───bot
│ .env
│ main.py
│ requirements.txt
│
├───database
│ Manager.py
│ __init__.py
│
├───handlers
│ common.py
│ uptime.py
│ __init__.py
│
└───keyboards
keyboards.py
__init__.py
As you can see, each folder has an __init__.py
file which is used to make the whole coding process easier. You can learn more from the official documentation: https://docs.python.org/3/tutorial/modules.html.
Don't forget to import everything you need there (classes, functions). For example, if you add a new class to Manager.py in the database folder (such as a custom class), be sure to import it into the __init__.py
file.
Manager.py
class User:
def __init__(self, id: int, name: str, surname: str) -> None:
self.id = id
self.name = name
self.surname = surname
__init__.py
from database.Manager import User
Somewhere in other file
from database import User
user = User(1, 'Wednesday', 'Adams') # creates an instance
- aiogram - A modern and fully asynchronous framework for Telegram Bot API written in Python using asyncio
- dotenv - Reads key-value pairs from a .env file and can set them as environment variables. It helps in developing applications following the 12-factor principles.
If you experience any problem and can't find a solution to it below, feel free to open an issue or DM me in telegram: @anekobtw
Contributions are always welcome! If you have any suggestions, feature requests, or bug reports, please feel free to open an issue on the GitHub repository.
Copyright © 2024 anekobtw.
This project is MIT licensed.