A Telegram bot that automatically downloads and sends Instagram reels, posts, videos, and clips when links are shared in your group chats or private messages.
Built with instagrapi - a fast and effective Instagram Private API wrapper.
- π Automatic detection of Instagram links (reels, posts, videos, clips)
- π₯ Downloads and sends videos directly to Telegram
- π Persistent session management with automatic reuse
- π₯ Works in both groups and private chats
- π Fast and reliable using official
instagrapibest practices - πΎ Session persistence across restarts with UUID preservation
- π¦ Support for albums/carousels (downloads first video)
- π¬ Support for Reels clips with proper detection
- Python 3.8 or higher
- A Telegram Bot Token (from @BotFather)
- An Instagram account (create a dedicated account, don't use your personal one!)
git clone <repository-url>
cd instalink-botpip install -r requirements.txtOr if you're using a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtCopy the example environment file:
cp env.example .envEdit .env and fill in your credentials:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
INSTAGRAM_USERNAME=your_instagram_username
INSTAGRAM_PASSWORD=your_instagram_password- Use a dedicated Instagram account for the bot, not your personal account
- Instagram may flag automated access on personal accounts
- Consider creating a new account specifically for this bot
python main.pyOn first run, the bot will:
- Log in to Instagram using your credentials
- Save the session settings (including device UUIDs) to
instagram_session.json - Start listening for Instagram links
On subsequent runs:
- Load existing session from
instagram_session.json - Verify session is still valid
- Auto re-login if session expired (preserving device UUIDs)
- Continue listening for Instagram links
- Add the bot to your group chat or message it directly
- Share an Instagram link (reel, post, or video)
- The bot will automatically download and send the video!
https://www.instagram.com/reel/ABC123/(Reels)https://instagram.com/reels/ABC123/(Reels)https://www.instagram.com/p/ABC123/(Video posts and albums)
/start- Welcome message and bot introduction/help- Show help and usage instructions/status- Check if the bot is logged in to Instagram/login- Force re-login to Instagram (if session expires)
| Variable | Description | Default | Required |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
Your Telegram bot token from BotFather | - | β Yes |
INSTAGRAM_USERNAME |
Instagram account username | - | β Yes |
INSTAGRAM_PASSWORD |
Instagram account password | - | β Yes |
DOWNLOAD_DIR |
Directory for temporary downloads | ./downloads |
β No |
SESSION_FILE |
Path to session file | ./instagram_session.json |
β No |
- Never commit your
.envfile - It contains sensitive credentials - Use a dedicated Instagram account - Don't use your personal account
- Enable 2FA on your bot's Telegram account (optional but recommended)
- Keep your session file secure - It contains your Instagram login session
- Run the bot on a secure server - Use proper firewall and access controls
instalink-bot/
βββ main.py # Main bot application
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (create this!)
βββ env.example # Example environment file
βββ instagram_session.json # Instagram session (auto-generated)
βββ downloads/ # Temporary download directory
βββ README.md # This file
Problem: Login fails with challenge or error
Solutions:
- Check that your Instagram username and password are correct
- Instagram may require verification - check your email/phone
- Try logging in manually to the Instagram account first
- Wait a few minutes and try again (rate limiting)
- Use a fresh Instagram account that hasn't been flagged
- Delete
instagram_session.jsonand try again - Check bot logs for specific error messages
Note: The bot uses instagrapi's recommended login flow with session reuse and UUID preservation.
Problem: Bot keeps asking to login
Solutions:
- Don't use the same Instagram account on multiple devices simultaneously
- Avoid logging into the account manually while the bot is running
- Check if Instagram has sent you a security alert
- Delete
instagram_session.jsonand run/logincommand - The bot preserves device UUIDs across logins to appear more natural to Instagram
Note: Following instagrapi best practices, the bot reuses session settings and device identifiers to minimize re-authentication.
Problem: Bot detects links but can't download videos
Solutions:
- Check
/statusto ensure the bot is logged in - The post might be private (bot can't access private posts)
- The post might be a photo, not a video
- Instagram might be rate limiting - wait a few minutes
- Try
/loginto force a fresh login - For albums/carousels, the bot sends the first video found
- Check bot logs for specific error messages (VideoNotDownload, etc.)
Problem: Instagram rate limiting
Solutions:
- Wait 5-10 minutes before trying again
- Don't spam links - Instagram monitors bot-like behavior
- Consider using Instagram less frequently
- This is Instagram's protection against abuse
- The bot uses
delay_range = [1, 3]seconds between requests to appear more natural
Technical Note: The bot follows instagrapi's recommended practices to minimize rate limiting.
Create a service file /etc/systemd/system/instalink-bot.service:
[Unit]
Description=Instagram Reel Telegram Bot
After=network.target
[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/instalink-bot
Environment="PATH=/path/to/instalink-bot/venv/bin"
ExecStart=/path/to/instalink-bot/venv/bin/python main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl enable instalink-bot
sudo systemctl start instalink-bot
sudo systemctl status instalink-botDocker support is planned for easier deployment.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This bot is for educational purposes. Use responsibly and respect Instagram's Terms of Service. The developers are not responsible for any misuse or violations of Instagram's policies.
Implementation Details: This bot follows the official instagrapi best practices including:
- Session reuse with validation
- Device UUID preservation across logins
- Proper error handling for challenges and rate limits
- Natural request delays
- python-telegram-bot - Telegram Bot API wrapper
- instagrapi by @subzeroid - Instagram Private API wrapper
- python-dotenv - Environment variable management
Special thanks to the instagrapi project for providing excellent documentation and best practices for Instagram API integration.
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Review existing issues on GitHub
- Create a new issue with details about your problem
Made with β€οΈ for the Telegram community