Skip to content

XylonBots/ImgUploadBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Banner

A powerful Telegram bot that uploads images to multiple hosting services and provides shareable links instantly.

Python Flask MongoDB Vercel Telegram

โœจ Features

  • ๐Ÿ“ค Multiple Image Hosting Services: Upload to ImgBB, FreeImage, or PostImages
  • ๐Ÿ”„ User Preferences: Remember each user's preferred hosting service
  • ๐Ÿ” Force Subscription: Optional channel subscription requirement
  • ๐Ÿ“Š User Tracking: Track served users in MongoDB
  • โšก Serverless Deployment: Deploy on Vercel with zero maintenance
  • ๐ŸŒ Webhook Integration: Real-time Telegram updates via webhook
  • ๐Ÿ’พ Database: MongoDB integration for persistence
  • ๐ŸŽจ Beautiful UI: Inline keyboard buttons for seamless navigation

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have:

  • Telegram Account - For creating a bot
  • Vercel Account - For hosting (free tier available)
  • MongoDB Account - For database (free tier M0 available)

๐Ÿš€ Quick Start

1๏ธโƒฃ Create a Telegram Bot

  1. Open Telegram and search for @BotFather
  2. Send /start and follow the prompts
  3. Send /newbot to create a new bot
  4. Follow the setup wizard and save your:
    • Bot Token (will look like 123456789:ABCdefGHIjklmnoPQRstuvWXYZ)

2๏ธโƒฃ MongoDB Setup

Refer to this video for detailed step by step tutorial: https://youtu.be/SMXbGrKe5gM (Not my video, I just think he explained it well.)

  1. Go to MongoDB Atlas
  2. Create a free account
  3. Create a new cluster (M0 Free tier)
  4. Create a database user with username and strong password
  5. Go to network tab and allow from everywhere
  6. Get your connection string:
    • Click "Connect" โ†’ "Connect your application"
    • Copy the MongoDB URI: mongodb+srv://username:[email protected]/

3๏ธโƒฃ Deploy on Vercel

Using Vercel Dashboard (Recommended for Beginners)

  1. Fork the Repository

  2. Connect to Vercel

    • Visit vercel.com
    • Sign up or log in with GitHub
    • Click "Add New..." โ†’ "Project"
    • Select your forked repository
    • Click "Import"
  3. Configure Environment Variables

    • In the "Environment Variables" section, add the following:
    Variable Value Example
    MONGO_URI Your MongoDB connection string mongodb+srv://user:[email protected]/
    MONGO_DB_NAME Database name img_uploadbot
    BOT_TOKEN Your bot token from @BotFather 123456789:ABCdefGHIjklmnoPQRst
    WEBHOOK_URL Your Vercel app URL (YOU WILL GET IT AFTER FIRST DEPLOYING THE PROJECT. So leave it empty for now.) https://your-app-name.vercel.app/api/webhook
    ADMIN_IDS Your Telegram user ID (without spaces) 123456789,987654321
    FORCE_SUB Enable force subscription true or false
    FORCE_SUB_CHANNEL Channel username for subscription @YourChannelName

    Note: Get your Telegram user ID by messaging @userinfobot

  4. Deploy

    • Click "Deploy"
    • Wait for the deployment to complete (usually 1-2 minutes)
    • Copy your Vercel deployment URL (e.g., https://your-app-name.vercel.app)
    • Go to settings > Go to Environment Variables > Edit WEBHOOK_URL with https://your-app-name.vercel.app/api/webhook (don't forget to add /api/webhook after your vercel deployment URL) > Click save > (a popup will apear) On that popup click Redeploy

4๏ธโƒฃ Set Webhook

After deployment, set your bot's webhook to receive updates:

Option A: Using Telegram Bot API (Recommended)

Send a GET reques to (just open it in browser):

https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=<VERCEL_DEPLOYMENT_URL>/api/webhook

Replace <YOUR_BOT_TOKEN> with your BOT TOKEN and <VERCEL_DEPLOYMENT_URL> with your DEPLOYMENT URL

Option B: Using Python

import requests

bot_token = "YOUR_BOT_TOKEN"
webhook_url = "https://your-app-name.vercel.app"

response = requests.get(
    f"https://api.telegram.org/bot{bot_token}/setWebhook",
    params={"url": f"{webhook_url}/api/webhook"}
)
print(response.json())

Option C: Using curl

curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=<VERCEL_DEPLOYMENT_URL>/api/webhook"

Replace <YOUR_BOT_TOKEN> with your BOT TOKEN and <VERCEL_DEPLOYMENT_URL> with your DEPLOYMENT URL

โœ… Expected Response:

{
  "ok": true,
  "result": true,
  "description": "Webhook was set"
}

6๏ธโƒฃ Test Your Bot

  1. Open Telegram
  2. Open your bot
  3. Send /start
  4. Try uploading an image
  5. Select your preferred hosting service

๐Ÿ“ Project Structure

ImgUploadBot/
โ”œโ”€โ”€ api/
โ”‚   โ””โ”€โ”€ index.py                 # Main Flask app & webhook handler
โ”œโ”€โ”€ database/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ settings.py              # User settings management
โ”‚   โ””โ”€โ”€ users.py                 # User tracking
โ”œโ”€โ”€ methods/
โ”‚   โ”œโ”€โ”€ inline_keyboard.py       # Keyboard UI components
โ”‚   โ””โ”€โ”€ updates.py               # Telegram Bot API wrapper
โ”œโ”€โ”€ uploaders/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ imgbb.py                 # ImgBB uploader
โ”‚   โ”œโ”€โ”€ freeimage.py             # FreeImage uploader
โ”‚   โ””โ”€โ”€ postimages.py            # PostImages uploader
โ”œโ”€โ”€ config.py                    # Configuration & environment variables
โ”œโ”€โ”€ utils.py                     # Helper functions & messages
โ”œโ”€โ”€ requirements.txt             # Python dependencies
โ”œโ”€โ”€ vercel.json                  # Vercel configuration
โ””โ”€โ”€ example.env                  # Example environment variables

โš™๏ธ Environment Variables Explained

# MongoDB Configuration
MONGO_URI=mongodb+srv://username:[email protected]/
MONGO_DB_NAME=img_uploadbot

# Telegram bot credentials
BOT_TOKEN=1234567890:ABCdefGHIjklmnoPQRstuvWXYZ1234567

# Deployment
WEBHOOK_URL=https://your-app-name.vercel.app/api/webhook

# Admin settings
ADMIN_IDS=123456789,987654321

# Force subscription settings
FORCE_SUB=true
FORCE_SUB_CHANNEL=@YourChannelName

๐ŸŽฎ Bot Commands

Command Description
/start Start the bot and see welcome message
Button: โš™๏ธ Change Hosting Switch between uploading services
Button: ๐Ÿ“ข Join Channel Join the bot's channel
Button: โ†—๏ธ Source Code View the GitHub repository

๐Ÿ”„ How It Works

  1. User sends image โ†’ Bot receives it via Telegram webhook
  2. Download image โ†’ Bot downloads the image to memory
  3. Select uploader โ†’ Uses user's saved preference or ImgBB as default
  4. Upload image โ†’ Image uploaded to selected service
  5. Send link โ†’ Bot sends shareable link back to user
  6. Save preference โ†’ User's choice stored in MongoDB for next time

Dependencies:

  • beautifulsoup4: HTML parsing
  • Flask: Web framework
  • pymongo: MongoDB driver
  • Requests: HTTP library
  • UserAgentReplica: User agent spoofing

๐Ÿ› Troubleshooting

Bot not responding to messages

  • โœ… Check if webhook is correctly set
  • โœ… Verify bot token is correct
  • โœ… Ensure Vercel deployment is active
# Check webhook status
curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getWebhookInfo"

MongoDB connection errors

  • โœ… Verify MONGO_URI format is correct
  • โœ… Check if database user password is URL-encoded
  • โœ… Ensure IP whitelist includes Vercel servers (set to 0.0.0.0/0 if on free tier)

Webhook not received

  • โœ… Make sure Vercel app is deployed and active
  • โœ… Check Vercel logs for errors
  • โœ… Verify webhook URL is publicly accessible

๐Ÿ“Š Features in Detail

๐ŸŽฏ User Preferences System

  • Each user's hosting preference is saved in MongoDB
  • Default uploader is ImgBB if no preference is set
  • Users can change their preference anytime

๐Ÿ” Force Subscription

Enable this feature to require users to join a channel before using the bot. Configure via:

  • FORCE_SUB=true
  • FORCE_SUB_CHANNEL=@YourChannelName

๐Ÿ‘จโ€๐Ÿ’ผ Admin Broadcasting

Admins (configured in ADMIN_IDS) can broadcast messages to all served users. When an admin sends a message, All commands gets pinned for better experience for admin.

๐Ÿ“ˆ Scaling & Performance

  • Serverless: Auto-scales with Vercel
  • Database: MongoDB free tier supports ~500MB storage
  • Requests: Flask handles concurrent requests efficiently
  • Rate Limits: Telegram Bot API has rate limiting (~30 messages/second)

๐Ÿค Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links

๐Ÿ“ž Support

  • โญ Star the repository if you find it helpful
  • ๐Ÿ› Report bugs via GitHub Issues
  • ๐Ÿ’ฌ Discuss improvements in GitHub Discussions
  • ๐Ÿ“ง Contact Hritu maintainers on Telegram

Made with โค๏ธ by XylonBots

About

A feature-rich Telegram bot that allows users to upload images and receive shareable links from multiple hosting services. Built with Python, Flask (webhook), and the Telegram Bot API.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages