A simple and efficient Telegram bot built with Go that downloads YouTube videos. Just send a YouTube link and get the video back!
- Instant Download: Just paste a YouTube link - no commands needed!
- Smart Recognition: Automatically detects YouTube URLs in messages
- 360p Quality: Optimized for quick downloads and Telegram's file size limits
- User-Friendly: Simple interface with helpful messages
- Multiple Modes: Supports both polling and webhook modes
- Clean Architecture: Well-structured Go code following best practices
- Go 1.24+ installed
- yt-dlp installed (
pip install yt-dlporbrew install yt-dlp) - A Telegram Bot Token from @BotFather
- Clone the repository:
git clone https://github.com/yourusername/telegram-yt-bot.git
cd telegram-yt-bot- Install dependencies:
go mod download- Set up environment variables:
Create a
.envfile in the project root:
TELEGRAM_BOT_TOKEN=your_bot_token_here
MODE=polling
# Optional for webhook mode:
# WEBHOOK_URL=https://your-domain.com
# PORT=8080- Run the bot:
go run main.goThe bot supports two modes of operation:
- Simple setup, no external dependencies
- Bot polls Telegram servers for updates
- Perfect for development and small-scale usage
MODE=polling
TELEGRAM_BOT_TOKEN=your_bot_token- More efficient for production
- Requires a public URL (HTTPS)
- Telegram pushes updates to your server
MODE=webhook
TELEGRAM_BOT_TOKEN=your_bot_token
WEBHOOK_URL=https://your-domain.com
PORT=8080- Start a chat with your bot on Telegram
- Send any YouTube URL - the bot will automatically detect it
- Wait for download - the bot will process and send you the video
- Enjoy! Videos are downloaded in 360p for optimal size and speed
https://www.youtube.com/watch?v=VIDEO_IDhttps://youtu.be/VIDEO_IDhttps://m.youtube.com/watch?v=VIDEO_ID
telegram-yt-bot/
├── main.go # Application entry point
├── config/ # Configuration management
│ ├── config.go # Config struct and loader
│ └── config_test.go # Config tests
├── internal/bot/ # Bot implementation
│ ├── client.go # Telegram API client
│ ├── handler.go # Message handling logic
│ ├── server.go # Webhook server
│ └── types.go # Bot type definitions
├── internal/youtube/ # YouTube integration
│ ├── client.go # YouTube downloader client
│ ├── formats.go # Video format handling
│ └── types.go # YouTube type definitions
└── internal/storage/ # Future storage implementation
Run the test suite:
go test ./...Run tests with coverage:
go test -cover ./...docker build -t telegram-yt-bot .
docker run -e TELEGRAM_BOT_TOKEN=your_token telegram-yt-bot- Create a Heroku app
- Set environment variables in Heroku dashboard
- Deploy using Git or GitHub integration
- Copy the binary to your server
- Set up environment variables
- Run as a systemd service for production
- Go 1.24+
- yt-dlp installed locally
- A Telegram bot token for testing
# Clone and setup
git clone <repository>
cd telegram-yt-bot
go mod download
# Create .env file with your test bot token
echo "TELEGRAM_BOT_TOKEN=your_test_token" > .env
echo "MODE=polling" >> .env
# Run in development
go run main.goThe bot uses the Telegram Bot API and yt-dlp for YouTube downloads:
- Telegram Bot API: Official Documentation
- yt-dlp: GitHub Repository
- Fork the repository
- 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 licensed under the MIT License - see the LICENSE file for details.
This bot is for educational purposes. Please respect YouTube's Terms of Service and only download content you have permission to download.
Bot not responding:
- Check your bot token is correct
- Ensure the bot is not already running elsewhere
- Verify network connectivity
Download fails:
- Update yt-dlp:
pip install --upgrade yt-dlp - Check if the YouTube video is available
- Some videos may be geo-restricted
Webhook issues:
- Ensure your webhook URL is accessible via HTTPS
- Check firewall settings
- Verify the webhook endpoint is correct
- Check the Issues page
- Create a new issue with detailed information
- Include logs and error messages when reporting bugs