How to programmatically upload files to Telegram?
Since Telegram is an infinite cloud service, I use it as a secondary backup location. I would like to automate this so that I don't have to remember to do it every month (in the last two years I missed about every second monthly backup).
But I can't find a way to automate any Telegram client without click macros (I would like to have it run silently in the background):
./Telegram --helpdoes nothing except opening the program.- I wasn't successful in determining where the
argvvariable goes from the main method, so I don't know if there even are console arguments. - Bots can't access my file system (and that's a good thing).
I can easily automate packing the files I want into 1.5GB archives using 7z, but I have no idea about how to actually send them. Is there a way to do it without click macros?
I'm on Debian 9.5 and using the official Linux client from telegram.org.
linux backup automation upload telegram-messenger
add a comment |
Since Telegram is an infinite cloud service, I use it as a secondary backup location. I would like to automate this so that I don't have to remember to do it every month (in the last two years I missed about every second monthly backup).
But I can't find a way to automate any Telegram client without click macros (I would like to have it run silently in the background):
./Telegram --helpdoes nothing except opening the program.- I wasn't successful in determining where the
argvvariable goes from the main method, so I don't know if there even are console arguments. - Bots can't access my file system (and that's a good thing).
I can easily automate packing the files I want into 1.5GB archives using 7z, but I have no idea about how to actually send them. Is there a way to do it without click macros?
I'm on Debian 9.5 and using the official Linux client from telegram.org.
linux backup automation upload telegram-messenger
Can't you directly use the libmtproto to write a storage backend?
– Martin Ueding
Oct 18 '18 at 12:01
I don't know, since I don't know that program. Also, I would have to know details about how to send packages to the Telegram servers. At some point I just have a custom client. If you know how to make a minimalistic program for that or whatever your idea was, that would be awesome.
– Fabian Röling
Oct 18 '18 at 12:06
I don't know the details, but it seems that TDlib is what you want.
– Martin Ueding
Oct 18 '18 at 12:14
It seems like there is a command line client for Telegram and it can send files, even though it's not in the documentation: github.com/vysheng/tg/issues/458 I'll try that this evening and if it works, write an answer.
– Fabian Röling
Nov 8 '18 at 10:23
add a comment |
Since Telegram is an infinite cloud service, I use it as a secondary backup location. I would like to automate this so that I don't have to remember to do it every month (in the last two years I missed about every second monthly backup).
But I can't find a way to automate any Telegram client without click macros (I would like to have it run silently in the background):
./Telegram --helpdoes nothing except opening the program.- I wasn't successful in determining where the
argvvariable goes from the main method, so I don't know if there even are console arguments. - Bots can't access my file system (and that's a good thing).
I can easily automate packing the files I want into 1.5GB archives using 7z, but I have no idea about how to actually send them. Is there a way to do it without click macros?
I'm on Debian 9.5 and using the official Linux client from telegram.org.
linux backup automation upload telegram-messenger
Since Telegram is an infinite cloud service, I use it as a secondary backup location. I would like to automate this so that I don't have to remember to do it every month (in the last two years I missed about every second monthly backup).
But I can't find a way to automate any Telegram client without click macros (I would like to have it run silently in the background):
./Telegram --helpdoes nothing except opening the program.- I wasn't successful in determining where the
argvvariable goes from the main method, so I don't know if there even are console arguments. - Bots can't access my file system (and that's a good thing).
I can easily automate packing the files I want into 1.5GB archives using 7z, but I have no idea about how to actually send them. Is there a way to do it without click macros?
I'm on Debian 9.5 and using the official Linux client from telegram.org.
linux backup automation upload telegram-messenger
linux backup automation upload telegram-messenger
asked Oct 16 '18 at 21:53
Fabian Röling
2451319
2451319
Can't you directly use the libmtproto to write a storage backend?
– Martin Ueding
Oct 18 '18 at 12:01
I don't know, since I don't know that program. Also, I would have to know details about how to send packages to the Telegram servers. At some point I just have a custom client. If you know how to make a minimalistic program for that or whatever your idea was, that would be awesome.
– Fabian Röling
Oct 18 '18 at 12:06
I don't know the details, but it seems that TDlib is what you want.
– Martin Ueding
Oct 18 '18 at 12:14
It seems like there is a command line client for Telegram and it can send files, even though it's not in the documentation: github.com/vysheng/tg/issues/458 I'll try that this evening and if it works, write an answer.
– Fabian Röling
Nov 8 '18 at 10:23
add a comment |
Can't you directly use the libmtproto to write a storage backend?
– Martin Ueding
Oct 18 '18 at 12:01
I don't know, since I don't know that program. Also, I would have to know details about how to send packages to the Telegram servers. At some point I just have a custom client. If you know how to make a minimalistic program for that or whatever your idea was, that would be awesome.
– Fabian Röling
Oct 18 '18 at 12:06
I don't know the details, but it seems that TDlib is what you want.
– Martin Ueding
Oct 18 '18 at 12:14
It seems like there is a command line client for Telegram and it can send files, even though it's not in the documentation: github.com/vysheng/tg/issues/458 I'll try that this evening and if it works, write an answer.
– Fabian Röling
Nov 8 '18 at 10:23
Can't you directly use the libmtproto to write a storage backend?
– Martin Ueding
Oct 18 '18 at 12:01
Can't you directly use the libmtproto to write a storage backend?
– Martin Ueding
Oct 18 '18 at 12:01
I don't know, since I don't know that program. Also, I would have to know details about how to send packages to the Telegram servers. At some point I just have a custom client. If you know how to make a minimalistic program for that or whatever your idea was, that would be awesome.
– Fabian Röling
Oct 18 '18 at 12:06
I don't know, since I don't know that program. Also, I would have to know details about how to send packages to the Telegram servers. At some point I just have a custom client. If you know how to make a minimalistic program for that or whatever your idea was, that would be awesome.
– Fabian Röling
Oct 18 '18 at 12:06
I don't know the details, but it seems that TDlib is what you want.
– Martin Ueding
Oct 18 '18 at 12:14
I don't know the details, but it seems that TDlib is what you want.
– Martin Ueding
Oct 18 '18 at 12:14
It seems like there is a command line client for Telegram and it can send files, even though it's not in the documentation: github.com/vysheng/tg/issues/458 I'll try that this evening and if it works, write an answer.
– Fabian Röling
Nov 8 '18 at 10:23
It seems like there is a command line client for Telegram and it can send files, even though it's not in the documentation: github.com/vysheng/tg/issues/458 I'll try that this evening and if it works, write an answer.
– Fabian Röling
Nov 8 '18 at 10:23
add a comment |
1 Answer
1
active
oldest
votes
I found a solution! The official client probably doesn't allow it (all known command line arguments are unofficially documented here), but for Linux and Mac (and probably also Linux subsystem on Windows), there is an unofficial command line interface for Telegram called "tg": https://github.com/vysheng/tg
It doesn't mention in its description that it can also send files, but in a Github issue someone wrote that there is the send_file function. In general it's not too well documented, but calling it with --help and entering help inside the program gives a lot of info, the rest can be figured out by fiddling with the parameters and trying different things.
This is the solution I came up with that way:
Preparation
- Install tg like the readme file says. It didn't work rightaway for me on Debian due to a bug, but as said in this bug report comment, installing
libssl1.0-devis a workaround for that bug: Executesudo apt install libssl1.0-devbetween./configureandmake. - Log in with your Telegram account:
bin/telegram-clito start the interactive program, enter phone number, enter login code. I entered my phone number starting with+49and that worked, maybe it's required, I don't know. - Now use another Telegram client to send a message in the target chat (or alternatively receive a message there). That adds the chat's name to the program's internal chat list. If multiple chats with the same name exist, it seems to pick the most recently added one. I have not found a way to message a chat by ID.
That's it for the setup,quitexits the program.
Uploading files programmatically
Now files can be uploaded by giving a send_file command to the program with --execute, which makes it execute that command and then quit automatically:
/path/to/tg/bin/telegram-cli --exec 'send_file <chat> <filename>'
<chat> is the chat's name.<filename> is the path to the file./path/to/tg should be obvious.
Example usage
I'll use something like this to upload a backup of my Google Drive folder to Telegram after I've created it with p7zip:
for filename in ~/drive_backup/drive.zip.*; do ~/tg/bin/telegram-cli --exec 'send_file Backup_chat '"$filename"; done
This uploads all files whose names start with "drive.zip." (.001, .002 etc.) in the folder ~/drive_backup to the Telegram chat "Backup_chat".
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1367443%2fhow-to-programmatically-upload-files-to-telegram%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found a solution! The official client probably doesn't allow it (all known command line arguments are unofficially documented here), but for Linux and Mac (and probably also Linux subsystem on Windows), there is an unofficial command line interface for Telegram called "tg": https://github.com/vysheng/tg
It doesn't mention in its description that it can also send files, but in a Github issue someone wrote that there is the send_file function. In general it's not too well documented, but calling it with --help and entering help inside the program gives a lot of info, the rest can be figured out by fiddling with the parameters and trying different things.
This is the solution I came up with that way:
Preparation
- Install tg like the readme file says. It didn't work rightaway for me on Debian due to a bug, but as said in this bug report comment, installing
libssl1.0-devis a workaround for that bug: Executesudo apt install libssl1.0-devbetween./configureandmake. - Log in with your Telegram account:
bin/telegram-clito start the interactive program, enter phone number, enter login code. I entered my phone number starting with+49and that worked, maybe it's required, I don't know. - Now use another Telegram client to send a message in the target chat (or alternatively receive a message there). That adds the chat's name to the program's internal chat list. If multiple chats with the same name exist, it seems to pick the most recently added one. I have not found a way to message a chat by ID.
That's it for the setup,quitexits the program.
Uploading files programmatically
Now files can be uploaded by giving a send_file command to the program with --execute, which makes it execute that command and then quit automatically:
/path/to/tg/bin/telegram-cli --exec 'send_file <chat> <filename>'
<chat> is the chat's name.<filename> is the path to the file./path/to/tg should be obvious.
Example usage
I'll use something like this to upload a backup of my Google Drive folder to Telegram after I've created it with p7zip:
for filename in ~/drive_backup/drive.zip.*; do ~/tg/bin/telegram-cli --exec 'send_file Backup_chat '"$filename"; done
This uploads all files whose names start with "drive.zip." (.001, .002 etc.) in the folder ~/drive_backup to the Telegram chat "Backup_chat".
add a comment |
I found a solution! The official client probably doesn't allow it (all known command line arguments are unofficially documented here), but for Linux and Mac (and probably also Linux subsystem on Windows), there is an unofficial command line interface for Telegram called "tg": https://github.com/vysheng/tg
It doesn't mention in its description that it can also send files, but in a Github issue someone wrote that there is the send_file function. In general it's not too well documented, but calling it with --help and entering help inside the program gives a lot of info, the rest can be figured out by fiddling with the parameters and trying different things.
This is the solution I came up with that way:
Preparation
- Install tg like the readme file says. It didn't work rightaway for me on Debian due to a bug, but as said in this bug report comment, installing
libssl1.0-devis a workaround for that bug: Executesudo apt install libssl1.0-devbetween./configureandmake. - Log in with your Telegram account:
bin/telegram-clito start the interactive program, enter phone number, enter login code. I entered my phone number starting with+49and that worked, maybe it's required, I don't know. - Now use another Telegram client to send a message in the target chat (or alternatively receive a message there). That adds the chat's name to the program's internal chat list. If multiple chats with the same name exist, it seems to pick the most recently added one. I have not found a way to message a chat by ID.
That's it for the setup,quitexits the program.
Uploading files programmatically
Now files can be uploaded by giving a send_file command to the program with --execute, which makes it execute that command and then quit automatically:
/path/to/tg/bin/telegram-cli --exec 'send_file <chat> <filename>'
<chat> is the chat's name.<filename> is the path to the file./path/to/tg should be obvious.
Example usage
I'll use something like this to upload a backup of my Google Drive folder to Telegram after I've created it with p7zip:
for filename in ~/drive_backup/drive.zip.*; do ~/tg/bin/telegram-cli --exec 'send_file Backup_chat '"$filename"; done
This uploads all files whose names start with "drive.zip." (.001, .002 etc.) in the folder ~/drive_backup to the Telegram chat "Backup_chat".
add a comment |
I found a solution! The official client probably doesn't allow it (all known command line arguments are unofficially documented here), but for Linux and Mac (and probably also Linux subsystem on Windows), there is an unofficial command line interface for Telegram called "tg": https://github.com/vysheng/tg
It doesn't mention in its description that it can also send files, but in a Github issue someone wrote that there is the send_file function. In general it's not too well documented, but calling it with --help and entering help inside the program gives a lot of info, the rest can be figured out by fiddling with the parameters and trying different things.
This is the solution I came up with that way:
Preparation
- Install tg like the readme file says. It didn't work rightaway for me on Debian due to a bug, but as said in this bug report comment, installing
libssl1.0-devis a workaround for that bug: Executesudo apt install libssl1.0-devbetween./configureandmake. - Log in with your Telegram account:
bin/telegram-clito start the interactive program, enter phone number, enter login code. I entered my phone number starting with+49and that worked, maybe it's required, I don't know. - Now use another Telegram client to send a message in the target chat (or alternatively receive a message there). That adds the chat's name to the program's internal chat list. If multiple chats with the same name exist, it seems to pick the most recently added one. I have not found a way to message a chat by ID.
That's it for the setup,quitexits the program.
Uploading files programmatically
Now files can be uploaded by giving a send_file command to the program with --execute, which makes it execute that command and then quit automatically:
/path/to/tg/bin/telegram-cli --exec 'send_file <chat> <filename>'
<chat> is the chat's name.<filename> is the path to the file./path/to/tg should be obvious.
Example usage
I'll use something like this to upload a backup of my Google Drive folder to Telegram after I've created it with p7zip:
for filename in ~/drive_backup/drive.zip.*; do ~/tg/bin/telegram-cli --exec 'send_file Backup_chat '"$filename"; done
This uploads all files whose names start with "drive.zip." (.001, .002 etc.) in the folder ~/drive_backup to the Telegram chat "Backup_chat".
I found a solution! The official client probably doesn't allow it (all known command line arguments are unofficially documented here), but for Linux and Mac (and probably also Linux subsystem on Windows), there is an unofficial command line interface for Telegram called "tg": https://github.com/vysheng/tg
It doesn't mention in its description that it can also send files, but in a Github issue someone wrote that there is the send_file function. In general it's not too well documented, but calling it with --help and entering help inside the program gives a lot of info, the rest can be figured out by fiddling with the parameters and trying different things.
This is the solution I came up with that way:
Preparation
- Install tg like the readme file says. It didn't work rightaway for me on Debian due to a bug, but as said in this bug report comment, installing
libssl1.0-devis a workaround for that bug: Executesudo apt install libssl1.0-devbetween./configureandmake. - Log in with your Telegram account:
bin/telegram-clito start the interactive program, enter phone number, enter login code. I entered my phone number starting with+49and that worked, maybe it's required, I don't know. - Now use another Telegram client to send a message in the target chat (or alternatively receive a message there). That adds the chat's name to the program's internal chat list. If multiple chats with the same name exist, it seems to pick the most recently added one. I have not found a way to message a chat by ID.
That's it for the setup,quitexits the program.
Uploading files programmatically
Now files can be uploaded by giving a send_file command to the program with --execute, which makes it execute that command and then quit automatically:
/path/to/tg/bin/telegram-cli --exec 'send_file <chat> <filename>'
<chat> is the chat's name.<filename> is the path to the file./path/to/tg should be obvious.
Example usage
I'll use something like this to upload a backup of my Google Drive folder to Telegram after I've created it with p7zip:
for filename in ~/drive_backup/drive.zip.*; do ~/tg/bin/telegram-cli --exec 'send_file Backup_chat '"$filename"; done
This uploads all files whose names start with "drive.zip." (.001, .002 etc.) in the folder ~/drive_backup to the Telegram chat "Backup_chat".
edited Dec 21 '18 at 11:50
answered Nov 8 '18 at 22:41
Fabian Röling
2451319
2451319
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1367443%2fhow-to-programmatically-upload-files-to-telegram%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can't you directly use the libmtproto to write a storage backend?
– Martin Ueding
Oct 18 '18 at 12:01
I don't know, since I don't know that program. Also, I would have to know details about how to send packages to the Telegram servers. At some point I just have a custom client. If you know how to make a minimalistic program for that or whatever your idea was, that would be awesome.
– Fabian Röling
Oct 18 '18 at 12:06
I don't know the details, but it seems that TDlib is what you want.
– Martin Ueding
Oct 18 '18 at 12:14
It seems like there is a command line client for Telegram and it can send files, even though it's not in the documentation: github.com/vysheng/tg/issues/458 I'll try that this evening and if it works, write an answer.
– Fabian Röling
Nov 8 '18 at 10:23