Minimal skeleton for creating a Telegram bot in Go with full infrastructure for development, testing, and deployment.
- Simple architecture with minimal dependencies
- Support for webhook and long polling modes
- Configuration via environment variables
- Structured logging with zap
- Docker and docker-compose for containerization
- CI/CD with GitHub Actions
- Linting and testing
- Makefile for convenient development
- Health check endpoint
- Graceful shutdown
- Go 1.23+
- Docker and Docker Compose (optional)
- Telegram Bot Token
git clone git@github.com:positron48/tgbot-skeleton.git
cd tgbot-skeleton
make setup- Create a bot via @BotFather
- Get the bot token
- Edit the
.envfile:
# Required settings
TELEGRAM_TOKEN=your_bot_token_here
# Optional settings
TELEGRAM_DEBUG=false
LOG_LEVEL=info
SERVER_ADDRESS=:8080# Install dependencies
make tidy
# Run in development mode
make dev
# Or build and run
make build
make run# Build and run with Docker Compose
make docker-build
make docker-run
# View logs
make docker-logs
# Stop
make docker-stoptgbot-skeleton/
├── cmd/bot/ # Application entry point
├── internal/
│ ├── bot/ # Bot logic
│ ├── config/ # Configuration
│ └── logger/ # Logging
├── .github/workflows/ # GitHub Actions
├── Dockerfile # Docker image
├── docker-compose.yml # Docker Compose
├── Makefile # Development commands
└── README.md # Documentation
make setup # Initial project setup
make build # Build application
make run # Run application
make dev # Run in development mode
make test # Run tests
make lint # Code linting
make clean # Clean build artifactsmake docker-build # Build Docker image
make docker-run # Run with docker-compose
make docker-stop # Stop containers
make docker-logs # View logs
make docker-clean # Clean Docker resources
make deploy # Deploy with Docker| Variable | Description | Default |
|---|---|---|
TELEGRAM_TOKEN |
Telegram bot token | Required |
TELEGRAM_DEBUG |
Debug mode | false |
TELEGRAM_UPDATES_TIMEOUT |
Updates timeout | 30 |
TELEGRAM_WEBHOOK_ENABLE |
Enable webhook | false |
TELEGRAM_WEBHOOK_DOMAIN |
Webhook domain | - |
TELEGRAM_WEBHOOK_PATH |
Webhook path | /webhook |
SERVER_ADDRESS |
Server address | :8080 |
LOG_LEVEL |
Logging level | info |
To use webhook mode:
- Set
TELEGRAM_WEBHOOK_ENABLE=true - Specify
TELEGRAM_WEBHOOK_DOMAIN(e.g.,https://yourdomain.com) - Ensure your server is accessible via HTTPS
- Restart the bot
docker build -t tgbot-skeleton .docker run -d \
--name tgbot-skeleton \
-p 8080:8080 \
-e TELEGRAM_TOKEN=your_token_here \
tgbot-skeleton# Start
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose downThe project uses GitHub Actions for continuous integration and deployment:
- CI: Runs on every push and pull request
- Tests
- Linting with golangci-lint
- Build verification
- Release: Automatic creation of releases with binary files when you push a tag
- Deploy: Automatic deployment to server when you push a tag (requires secrets configuration)
# Deploy from GitHub releases
make deploy
# Update deployed binary
make update
# Check service status
make status
# View service logs
make logs# Build and run with Docker
make docker-deploy# Run all tests
make test
# Run tests with verbose output
make test-verbose
# Check coverage
go test -cover ./...The bot provides a health check endpoint:
curl http://localhost:8080/health- Uses non-root user in Docker
- Security scanning with Gosec in CI
- Configuration validation on startup
- Edit
internal/bot/handler.go - Add a new case to the
handleCommandfunction - Implement the command logic
- Create a middleware function
- Add it to the processing chain in
HandleUpdate
- Fork the project
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is distributed under the most permissive license - the MIT License. This allows maximum freedom for use, modification, and distribution. See the LICENSE file for details.
If you have questions or issues:
- Check Issues
- Create a new Issue with detailed description
- Make sure to provide logs and configuration