This project provides a template for initializing a Go bot using telebot, along with a structured directory for FSM, handlers, cache, middlewares, and database connections.
- Structured bot directory with FSM and handlers.
- Integrated with GORM, SQLite, Viper, and more.
- Automated setup with templates.
- Generates
.env
file for bot configuration. - Modular setup for easy extension and maintenance.
- Go 1.23+
-
Clone the repository:
git clone https://github.com/your-repo/go-telebot-init.git cd go-telebot-init
-
Run the
Makefile
to initialize the project:make all
Executes all the necessary steps:
- Set up environment variables.
- Initialize the project structure with templates.
- Install dependencies.
- Clean up template files.
- Initializes a new Git repository for the project.
Generates a .env
file with the following environment variables:
TELEGRAM_TOKEN
: The bot token from Telegram.SUPERUSER_ID
: The chat ID of the bot's superuser.SUPERUSER_FIRSTNAME
: First name of the superuser.SUPERUSER_LASTNAME
: Last name of the superuser.
Creates the necessary project structure, including directories and Go files for bot logic, FSM, handlers, middlewares, cache, database models, and utilities.
Initializes the Go module, installs required Go packages, and tidies up the go.mod
file.
Removes the template files used during project initialization.
Once you run the make all
command, the project will be fully initialized and ready to use. It performs the following actions:
- Sets Up Environment Variables: Creates a
.env
file with your bot's token and superuser details. - Initializes Project Structure: Generates the necessary directories and files for the bot's operation, FSM, handlers, middlewares, and database.
- Installs Dependencies: Automatically installs required Go modules, ensuring your project has all dependencies.
- Cleans Up: Removes template files after copying them into the appropriate directories.
- Git Repository Initialization: Removes any existing Git repository (if present) and initializes a new Git repository, with an initial commit.
After make all
completes, you can start the bot by navigating to the cmd/bot
directory and running:
go run main.go
The bot will be up and running with the initial configuration.
cmd/
└── bot/
└── main.go
config/
└── config.yaml
internal/
└── configs/
└── configs.go
pkg/
├── bot/
│ ├── fsm/
│ ├── handlers/
│ │ ├── admin/
│ │ └── public/
│ └── middlewares/
├── cache/
├── database/
│ ├── dbservice/
│ └── models/
├── helpers/
└── utils/
You'll be prompted to enter the following details:
- Bot Token (from BotFather)
- Superuser Chat ID
- Superuser First and Last Name
These details will be stored in a .env
file automatically.
The following Go libraries are used in this project:
- GORM: For database interactions.
- Viper: For configuration management.
- telebot.v3: For Telegram bot API.
- eqmlog: Custom logging utility.
This project is licensed under the MIT License.