Skip to content

A Telegram Bot to transfer files to OneDrive. No file size limitation. Restricted content supported. Doesn't occupy local space.

License

Notifications You must be signed in to change notification settings

johnstones214/telegram-onedrive

 
 

Repository files navigation

telegram-onedrive

A Telegram Bot to transfer files to OneDrive.

Attention

Account Types

Supported

  • Persoanl account.
  • All types of business accounts, details.
  • All types of educational accounts if domain administrator exists.

Not Supported

  • All types of educational accounts if domain administrator doesn't exist.

Not Supported Yet

  • Microsoft 365 operated by 21Vianet(世纪互联).

Introductions

  • Based on telethon.
  • Works only in Group.
  • Transfer files you send or forward.
  • Transfer restricted content.
  • Transfer files from url.
  • No file size limitation.
  • Doesn't occupy local space, works entirely on memory through multipart transfer.

Demos

/start /start
/help /help
/auth Telegram /auth Telegram
/auth OneDrive /auth OneDrive
transfer single transfer single
transfer multi transfer multi
link link
/links message_link range /links message_link range
/clear /clear
/clearLogs /clearLogs
/logs /logs
/logs range /logs range
/autoDelete /autoDelete
/url file_url /url file_url

Preparation

  1. Open docker-compose.yml and edit the environment config.
  2. server_uri is your domain. You need to specify a port, like https://example.com:8080, or https://127.0.0.1:8080 if you don't have a web server. Protocol must be "https", not "http".
    • The self-signed ssl keys may be expired, you can remind me for an update.
    • Some web browser may prevent you from visiting this url because of ssl mismatch. Try using Chromium.
    • If you want to specify your own ssl keys, especially if you have your own site, or the self-signed ssl keys have expired, you can import your ssl keys like this:
      services:
      telegram-onedrive:
        ...
        volumes:
          - /path/to/*.crt:/telegram-onedrive/server/ssl/server.crt
          - /path/to/*.key:/telegram-onedrive/server/ssl/server.key
        ...
  3. If you're on Linux, simply use
    services:
        telegram-onedrive:
          ...
          network_mode: host
          ...
    if you're on Windows or macOS, use
    services:
        telegram-onedrive:
          ...
          ports:
            - xxxx:xxxx
          ...
    xxxx is your port in server_uri.
  4. Create a Telegram bot through BotFather. Record token as tg_bot_token.
  5. Create a Telegram application on my.telegram.org. See details. Record api_id as tg_api_id, api_hash as tg_api_hash.
  6. tg_user_phone is the phone number you just used to login to my.telegram.org.
  7. tg_user_name is your telegram user name. Check your profile, find your user name, it should be like @user, then record user as tg_user_name. Optional, default to void. If you don't set this parameter, every one can control your bot.
  8. Create a OneDrive application on portal.azure.com App registrations.
    • Press New registrations.
    • Fill Name.
    • In Supported account types choose Accounts in any organizational directory and personal Microsoft accounts.
    • In Redirect URI, platform select Web, uri domain should be the same with server_uri, route must be /auth, like https://example.com:8080/auth.
      • Explain: The authorization code will be sent through the uri you offer, like https://example.com:8080/auth?code=xxxxxxx. So in this project, it use flask as a server to handle this request.
    • Press Register.
    • In application's Overview, record Application (client) ID as od_client_id.
    • Go to application's Certificates & secrets, press Client secrets, and press New client secret. Then fill Description, and choose an Expires. Finnaly, press Add. Record Value as od_client_secret.
  9. remote_root_path is a directory on OneDrive. Like /Videos/from-telegram. Default to /.
  10. delete_flag decides whether bot can auto delete message. Pass true or false. Optional, default to false.
  11. Optional, to keep sessions after recreating docker container, create a volume to store it in docker-compose.yml:
    services:
    telegram-onedrive:
      ...
      volumes:
        - telegram-onedrive-session:/telegram-onedrive/session
      ...
    volumes:
      telegram-onedrive-session:

Usage

Before Start (Important!)

  • Create a group.
  • In bot's profile, press Add to Group or Channel.
  • Add this bot to your group.
  • Set this bot as Admin, and give it ability to Delete Messages.

If you don't follow these steps, the bot may not works.

Authorization Steps

  • Send /auth.
  • Wait and you'll receive the login code from telegram.
  • Visit the uri the bot sends, and submit the code.
  • After submission, it will send the authorization uri for OneDrive. Visit, login and authorize.
  • If the bot says Onedrive authorization successful!, everything is done.

Start

  • In the group, forward or upload files (or videos, photos, gifs, stickers, voices).
  • If you want to transfer restricted content from a group or channel, right click the content, copy the message link, and send the link.
  • Wait until the transfer completes. You can check status on replied message, tap Status to locate current job.
  • Use /help for more information about other command.

Bot Command

  • /start to start with bot.
  • /auth to authorize telegram and onedrive.
  • /clear to clear all history except status message.
  • /autoDelete to toggle whether bot should auto delete message.
  • /clearLogs to clear logs.
  • /logs to show all logs.
  • /logout to logout OneDrive.
  • /links message_link range to transfer sequential restricted content.
  • /url file_url to upload file through url.
  • /logs range to show the most recent logs for the specified page number.
  • /help for help.

Example:

  • /links https://t.me/c/xxxxxxx/100 2 will transfer https://t.me/c/xxxxxxx/100 and https://t.me/c/xxxxxxx/101.
  • /url https://example.com/file.txt will upload file.txt to Onedrive. It calls Onedrive's API, which means Onedrive's server will visit the url and download the file for you. If the url is invalid to OneDrive, the bot will try using bot's uploader to transfer.
  • /logs 2 will show 2 pages of the most recent logs. Each page contains 50 lines of logs.

Launch Through Docker

# install docker-compose
sudo apt-get install docker-compose
# launch
sudo docker-compose up -d

build your docker image

sudo docker build -t YOUR_HOST_NAME/telegram-onedrive --no-cache .

Links

image

About

A Telegram Bot to transfer files to OneDrive. No file size limitation. Restricted content supported. Doesn't occupy local space.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.2%
  • HTML 2.3%
  • Dockerfile 0.5%