Skip to content

This is a telegram bot that downloads the publicaly available gdrive files and folder to telegram chat.

License

Notifications You must be signed in to change notification settings

itsmohitnarayan/Telegram-Drive-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Drive Bot

This project is a Telegram bot that allows users to download files from Google Drive by sending a Google Drive folder link. The bot is built using the python-telegram-bot library and the Google Drive API.

Features

  • Start the bot with a /start command.
  • Send a Google Drive folder link to the bot to download files from the folder.
  • The bot will process the link, authenticate with Google Drive, and download the files.
  • Stop the bot with a /stop command.

Prerequisites

  • Python 3.9+
  • A Telegram bot token from BotFather
  • Google Drive API credentials

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/telegram-drive-bot.git
    cd telegram-drive-bot
  2. Create a virtual environment and activate it:

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  3. Install the required packages:

    pip install -r requirements.txt
  4. Create a .env file in the root directory and add your Telegram bot token:

    TELEGRAM_BOT_TOKEN="your-telegram-bot-token"
  5. Set up Google Drive API credentials:

Usage

  1. Run the bot:

    python telegram_drive_bot.py
  2. Start a chat with your bot on Telegram and send the /start command.

  3. Send a Google Drive folder link to the bot. The bot will process the link and download the files from the folder.

  4. Stop the bot with the /stop command.

Code Overview

This is the main script that contains the bot logic.

  • Imports:

    • os: For file operations.
    • dotenv: To load environment variables from the .env file.
    • telegram: For interacting with the Telegram API.
    • telegram.ext: For handling commands and messages.
    • googleapiclient.discovery: For interacting with the Google Drive API.
    • google_auth_oauthlib.flow: For handling OAuth 2.0 authorization.
    • google.auth.transport.requests: For handling HTTP requests.
  • Functions:

  • Main Logic:

    • Loads environment variables from the .env file.
    • Initializes the bot with the Telegram bot token.
    • Adds command handlers for /start and /stop.
    • Adds a message handler for processing Google Drive folder links.
    • Runs the bot using polling.

This file contains environment variables, including the Telegram bot token.

This file contains Google Drive API credentials.

This directory is where downloaded files are stored.

This file stores the Google Drive API token.

License

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

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages