A Telegram Bot to transfer files to OneDrive.
docker-compose.yml
and edit the environment configuration.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".
services:
telegram-onedrive:
...
volumes:
- /path/to/*.crt:/telegram-onedrive/server/ssl/server.crt
- /path/to/*.key:/telegram-onedrive/server/ssl/server.key
...
services:
telegram-onedrive:
...
ports:
- xxxx:8080
...
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/;
}
token
as tg_bot_token
.api_id
as tg_api_id
, api_hash
as tg_api_hash
.tg_user_phone
is the phone number you just used to login to my.telegram.org. It's in international format, like +xxyyyyyyyyyyy
.tg_user_password
as your 2FA password.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.New registrations
.Name
.Supported account types
choose Accounts in any organizational directory and personal Microsoft accounts
.Redirect URI
, platform
select Web
, uri domain should be the same with server_uri
, route must be /auth
, like https://example.com/auth
.
https://example.com/auth?code=xxxxxxx
. So in this project, it use flask as a server to handle this request.Register
.Overview
, record Application (client) ID
as od_client_id
.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
.remote_root_path
is a directory on OneDrive. Like /Videos/from-telegram
. Default to /
.delete_flag
decides whether bot can auto delete message. Pass true
or false
. Optional, default to false
.services:
telegram-onedrive:
...
volumes:
- telegram-onedrive-session:/telegram-onedrive/session
...
volumes:
telegram-onedrive-session:
Add to Group or Channel
.If you don't follow these steps, the bot may not work.
/auth
.Onedrive authorization successful!
, everything is done.Status
to locate current job./help
for more information about other command./start
to start with bot./auth
to authorize telegram and onedrive./clear
to clear history./autoDelete
to toggle whether bot should auto delete message./drive
to list all OneDrive accounts./drive add
to add a OneDrive account./drive $index
to change the OneDrive account./drive logout
to logout current OneDrive account./drive logout $index
to logout specified OneDrive account./links $message_link $range
to transfer sequential restricted content./url $file_url
to upload the file through url./logs
to send log file./logs clear
to clear logs./dir
to show current OneDrive directory./dir $remote_path
to set OneDrive directory./dir temp $remote_path
to set temporary OneDrive directory./dir temp cancel
to restore OneDrive directory to the previous one./dir reset
to reset OneDrive directory to default./help
for help.The bot support files with extension .t2o
as scripts. You can use them to automate the bot.
/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
. The headers of the file response must includes Content-Length
.In a file named example.t2o
, write these lines for example:
[link]
https://t.me/xxxx/100
https://t.me/yyyy/200 2
https://t.me/zzzz/40
[url]
https://example.com/file1.txt
https://example.com/file2.txt
This will transfer https://t.me/xxxx/100
, https://t.me/yyyy/200
, https://t.me/yyyy/201
, https://t.me/zzzz/40
, file1.txt
, file2.txt
.
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 .