hlf20010508 / telegram-onedrive

A Telegram Bot to transfer files to OneDrive. No file size limitation. Restricted content supported. Doesn't occupy local space.
MIT License
49 stars 28 forks source link
onedrive telegram-bot telethon

telegram-onedrive

A Telegram Bot to transfer files to OneDrive.

Attention

Account Types

Supported

Not Supported

Not Supported Yet

Introductions

Demos

/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
/autoDelete /autoDelete
/url $file_url /url file_url

Preparation

  1. Open docker-compose.yml and edit the environment configuration.
  2. server_uri is your domain, like https://example.com, or https://127.0.0.1:xxxx if you don't have a web server. Protocol must be "https", not "http".
    • Some web browsers 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, 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. Reflect the port:
    services:
        telegram-onedrive:
          ...
          ports:
            - xxxx:8080
          ...
  4. Optional, if you're using reverse proxy, you need to set reverse_proxy to true. Default to false. Make sure your reverse proxy use ssl, real server protocol is http. For example, in Nginx:

    listen 443 ssl;
    listen [::]:443 ssl;
    
    server_name example.com;
    
    ssl_certificate path/to/public.pem;
    ssl_certificate_key path/to/private.key;
    
    location / {
        proxy_pass http://127.0.0.1:xxxx/;
    }
  5. Create a Telegram bot through BotFather. Record token as tg_bot_token.
  6. Create a Telegram application on my.telegram.org. See details. Record api_id as tg_api_id, api_hash as tg_api_hash.
  7. tg_user_phone is the phone number you just used to login to my.telegram.org. It's in international format, like +xxyyyyyyyyyyy.
  8. Optional, if you have two-step verification enabled, set tg_user_password as your 2FA password.
  9. 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. If you need multiple users, use , to split, like user1,user2. Optional, default to void. If you don't set this parameter, everyone can control your bot.
  10. 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/auth.
      • Explain: The authorization code will be sent through the uri you offer, like https://example.com/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.
  11. remote_root_path is a directory on OneDrive. Like /Videos/from-telegram. Default to /.
  12. delete_flag decides whether bot can auto delete message. Pass true or false. Optional, default to false.
  13. Optional, to keep sessions after recreating docker container, create a volume to store them:
    services:
    telegram-onedrive:
      ...
      volumes:
        - telegram-onedrive-session:/telegram-onedrive/session
      ...
    volumes:
      telegram-onedrive-session:

Usage

Before Start (Important!)

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

Authorization Steps

Start

Bot Command

The bot support files with extension .t2o as scripts. You can use them to automate the bot.

Example

Launch Through Docker

Install docker compose

sudo apt-get install docker-compose-plugin

Launch

sudo docker compose up -d

Build your docker image

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

Links