
For Telegram there are so-called Bots – ultimately these are simply user accounts for programs/robots instead of people. These accounts can then be addressed via API/interface and used “normally” in Telegram.
For example, you can integrate surveys for appointments into a Telegram group, cobble together your own clients, send files, photos or text from the command line, display messages as Telegram messages and so on. The nice thing about it: You create the bot very simply via the Telegram standard account Botfather in a dialog. We show you step by step how to create a bot and send texts and files from the command line. Prior knowledge is not required.
[UPDATE] In the second part we show you how you Receive messages in the terminal can.
[UPDATE 2/XNUMX/XNUMX] Since the article is a bit older: As of September 2017, the procedure for Telegram bots still works. If something doesn't work check the quotes!
Of course there are also ready-made Telegram bots for dog pictures and stuff like that, but this is about creating your own bots:
1. Integrate Botfather
First add the "user" @botfather - via the search function or the Link on home page.

2. Create Telegram bot
To create your bot, simply send the new user Botfather the messages
/newbot
and then assigns user and bot names on request - the latter must end with bot. At the end you get the so-called token, a longer character string that uniquely identifies your bot. It is best to copy the token code directly. Optionally, you can also set up an about page, a user picture for the bot, etc. – simply send commands like /setuserpic, /help and so on in the Telegram client. Don't forget: You have to start the bot now and send a first message, otherwise the next step won't work.

3. Find out ID of chat
In order to send a message to a Telegram chat or a Telegram group, you need the corresponding chat ID, which you can get with the following command:
curl -X POST https://api.telegram.org/bot123456:abcde1234ABCDE/getUpdates
First of all: You must of course replace 123456:abcde1234ABCDE with your token code – but the preceding “bot” must remain. The Linux standard tool curl is only used to send an HTTP request to Telegram. On Windows you have to first curl for Windows to install. By the way: cURL stands for "see url", but it doesn't matter. The result of this query is something like this:
{"ok":true,"result":[{"update_id":638422092,
"message":{"message_id":9,"from":{"id":268963852,"first_name":"Gizlog"},"chat":{"id":268963852,"first_name":"Gizlog"},"date":1437389925,"text":"c"}},{"update_id":638422093,
The ID of the chat is important here, in this example 268963852. Note: Of course you can add your new bot to a group like any other account - then the ID of the group chat that you can use will also appear in the above result to post to the group. If no chats appear: Post a message in the desired chat - of course there are no updates without messages!

4. Send messages and files to Telegram
We also use curl again to send messages:
curl -X POST 'https://api.telegram.org/bot123456:abcde1234ABCDE/sendMessage?chat_id=-4194264&text="texty text"'
You see, it's again the same construct as above but with the method/command "sendMessage" appended to it, separated by ?, first the chat id and then separated with & the text to send. And the message "texty text" ends up in your Telegram account, sent by "user" TutoBot in our example. Sending files and photos is then self-explanatory:
curl -X POST "https://api.telegram.org/bot123456:abcde1234ABCDE/sendDocument" -F chat_id=-419426123 -F document="@/home/mirco/misto.txt"
The method is now called sendDocument - however, the HTTP request must be sent in the format "multipart/form-data", which is why the chat ID and document path are appended separately to the curl command via F parameters. In this example the file misto.txt will be sent to our Tutonaut own group chat (the dash belongs to the group chat id!). Remember the @ in front of the document path. The photo command is completely analogous:
curl -X POST "https://api.telegram.org/bot123456:abcde1234ABCDE/sendPhoto" -F chat_id=-4194264 -F photo="@/home/mirco/rathaus.jpg"

Use Telegram bots productively
So far it's all just a gimmick - what's next? On the one hand, you could of course also address Telegram via programming languages and knit entire program logic around it. But there is still a lot that can be done on the command line: Instead of a fixed text, you can of course also use a variable, for example “$text” instead of “texty text” – and this variable could be easily assigned via script or user requests. A super simple example would be a mini-script like:
echo "Gib die Nachricht ein:" &&
read text &&
curl -X POST "https://api.telegram.org/bot123456:abcde1234ABCDE/sendMessage?chat_id=-4194264&text=$text"
If you save it as an alias or script and then call it up, "Enter the message" is first output, then you just enter the message and the entered text is sent to Telegram via return. So far just as an introduction.
If something is unclear, just ask, there are no such thing as “stupid” questions anyway. And what do you do with bots? Or would you like to do it? What do you think of it anyway?
By the way, we now have quite a number of telegram articles, about to send one CLI client.
Since the update to Bot API Version 6.7 from April 21.04.23, 8.0.1, my curl call no longer works under Windows. Changing to the latest curl version 7_XNUMX didn't help either. For me it breaks off with the TLS handshake ("Recv failure: Connection was reset"). Does anyone have an idea what to do there?
Unfortunately I can't contribute anything concrete, but maybe point in a direction. First of all: Just tested, my old curl call in the terminal still works. And since the release notes don't say anything in that direction either, it should at least not be due to the new API version.
Unless the settings for proxies, firewalls and the like have been changed, I would first try a system update and restart - everything that has to do with verification can fail due to all sorts of little things. A test on another system, for example a virtual Linux, could confirm this.
Otherwise you have no choice but to go with all Information to look for help, for example on Stackoverflow. The abbreviated error message with a TLS hint is not enough.
Hello :)
Very good article and nicely explained. I am new to the field and have a question. Is it possible to have a telegram group chat read out and have certain texts from it automatically changed, for example if it is always the same line of text and then have it forwarded to another group chat. Everything automated, so to speak?
That's definitely possible. On the one hand, you could do that with Python or another programming language – if you know one. And if it's supposed to be a real app, it should be, especially since it should somehow run online.
On the other hand, this could also be done via the terminal – that should suffice for smaller purposes. The article above tells you how to send the text. The second part shows how to read text. In this respect, only the part in the middle is missing - and texts can be processed wonderfully on the command line with sed. So workflow would be:
This is certainly not the most elegant solution, but tends to be easier than just learning a real programming language. sed may not appeal to everyone right away ;) The sed syntax is basically quite simple, but you have to deal with regular expressions in order to be able to automatically detect and change the searched patterns in the text. If regex don't tell you anything: Here we have an introduction, and a little more about sed here (search pattern over several lines) or directly in the terminal:
The effort for the whole project should be quite manageable - plus the regex learning! If you then, no idea, maybe want to automatically convert hymns of praise to FC Köln to BVB and post them in another chat ... - that would work.
Hello
how do i have to design the url so that it sends me the messages without notification
it has to work somehow with disable_notification.
Thanks in advance
Hello ,
IOS, wants to confirm my number, unfortunately I can't find an option to share my number in Messenger
Hello Mirco,
I try to send the last (newest) photo from the camera folder (/var/lib/hkcam/data) via Telegram with the following command:
curl -X POST "https://api.telegram.org/bot123456:abcde1234ABCDE/sendDocument" -F chat_id=-4194264 -F document="@$(ls -rt1 /var/lib/hkcam/data | tail -1 )”
Unfortunately I keep getting the following error message:
curl: (26) couldn't open file "902511643.jpg"
The following command works, so it's not the file:
curl -X POST "https://api.telegram.org/bot123456:abcde1234ABCDE/sendDocument" -F chat_id=-4194264 -F document="@/var/lib/hkcam/data/902511643.jpg"
Does the command need to be adjusted, or do you know of a workaround?
Thanks and regards, Mathias
I tried it briefly with a simplified variant, here the following notation works for the document= part:
Means: Your ls command only outputs the file name, but not all of it Path! You can enter the path (here /d/tmp/) manually or try with
The $PWD gives you the complete path. You have to test how exactly this suits you best. You could also use the find command or whatever.
Hallo,
I would like certain information from my website to be automatically forwarded to my respective employees on telegram, how can I do that. I have already successfully created a bot. LG
Hello, can you also use a bot to read a telegram channel and automatically mirror it on a blog, for example?
I run a Telegram channel where I share travel reports and photos. But I would like to make it accessible to non-Telegram users on my website!
Website is based on WordPress in the current version.
How to read it out in the terminal is in the second part of the article. Then you would have the content locally and from there you can get it played back in WordPress, for example via its CLI client. But that is certainly associated with some fiddling.
That reminds me, I once wrote an article about it with IFTTT works - it's been a while but might be worth a try. (Although the free version of IFTTT is quite limited now.)
I didn't find any other solutions spontaneously, and the many WordPress plugins don't seem to help either.
Hello Mirco
Do you know how to create a bot that automatically copies the file from a channel and posts it in a new channel?
I have 2 channels with a friend, my buddy posts something in his channel and we want a bot that copies directly from the buddy channel and automatically posts in my channel. Would something like that be possible?
There is the method forward message, it should be possible to do that - something like this: First retrieve messages (including IDs) via getUpdates, then forward them via forwardMessage, specifying the ID. How exactly, I don't know right now.
Alternatively, it would of course be “manual” using a script: messages as in Part 2 pick up described, files as with Stackoverflow Download as described and send as described above - packed in an endless loop. If you always have a NAS or other computer connected to the network or a real server, of course... But that would only make sense if you didn't want the whole message to be forwarded, but only certain files, for example. Or multiple files as an archive. Or files are to be converted into another format beforehand. Or or or...
Alternatively, there are also ready-to-use forwarding bots that do this - but of course third parties can then read along! And since there is usually no manufacturer there, I'll refrain from links ;) It should also tend to work with IFTTT; I have the variant Telegram message to WordPress previously described. Of course, IFTTT can also read along, but that is at least an established provider. Cons: The messages must contain a trigger word and "/ifttt", which probably makes it a bit impractical...
hello at
curl -X POST https://api.telegram.org/bot123456:abcde1234ABCDE/getUpdates
comes out with me the following.
{"ok":true,"result":[]}
No idea what my mistake is or what to do, doing this for the first time.
Hope someone can help me, thanks.
Hi Rico,
I'm also a total newbie and had the same problem. I then wrote hello again in the chat and called up the page again with the desired result.
Hope that helps you.
Lg
Hello Mirco,
thank you very much for your tutorial.
So far everything works.
Unfortunately, what I can't do is to give the sendMessage method something in reply_markup.
For example a force reply. Unfortunately, I can't seem to get the forcereply type to be specified correctly.
curl -d text='TEST' -d chat_id=XXXX -d forcereply(force_reply=true)
If I just send curl -d text='TEST' -d chat_id=XXXX it works.
If I then add the -d forcereply(force_reply=true), I only get the message in Telegram, without the reply function.
Do you or someone else have an idea how to correctly implement the forcereply type?
Okay, I had to search a bit - the API use via a simple command line is somehow not well documented, probably hardly anyone uses it ;) What you are still missing is the "reply_markup" part, in which "force_reply" can be used , i.e. in the sense of:
However, the force_reply part URI encoded Werden:
The whole part then looks like this:
A complete link thus:
You can code get it done online.
Hello Marco,
You weren't the first one I asked, but the only one who could answer my question correctly.
Thank you and RESPECT for that!
I briefly had problems with the ' in your answer. But if I just leave them out, it actually works.
Also your link for coding is helpful.
May I ask you for your/a source for your help?
I would be happy if I could possibly look around for further information worth knowing.
Regards
Christian
Hi Christian,
Nice, that it works! And yes, quotation marks are almost always an option for errors, which unfortunately sometimes vary from shell to shell (I use bash from Git for Windows instead of cmd on Windows).
What finally brought me to the answer was the simple hint in a stackoverflow question: You need to encode the markup text too. It's about Google Apps Script, but it could be derived accordingly for shell script/HTTP. In general, you can find much more information about such things if you work with JavaScript, Python or any other scripting/programming language.
In general, Stackoverflow is by far the best site for such questions, there is hardly a developer who could still work without the site ;)
greeting,
Mirco
Hello dear Mirko,
Thank you for your help here on this page. I have a problem with the captcha in the greeting. Like many other groups on telegram, mine should also have a confirmation text where you click a button and confirm that you are a human and not a bot or robot. Something doesn't work there. The @GroupHelpBot actually let me fine-tune everything. If I have defined a welcome text elsewhere, can it be that it overlays or displaces the captcha text?
Unfortunately, I am so spontaneously stumped, I have never dealt with the Group Help Bot before. I'll catch up on the days and report back if anything comes up.
...okay, or not, after a little research. the bot saves pretty much everything of data that he can get his hands on - up to 20 years after the deletion of a Telegram account. Where? As? No info. There is almost no information about the manufacturer (Bruno Andreuccetti), no imprint and above all absolutely nothing about the software behind it. And I don't like doing something like that as the admin of a group.
To put it bluntly: the operator of the bot can read all the messages, link them to user IDs, email accounts from payment transactions, biographies and so on - across the affected group! Personally, I can think of a lot of very dishonest possible uses very quickly. Well, Telegram itself can of course do that too, but Telegram as a service provider is something other than an add-on by an individual about whom next to nothing is known.
Question: I have a group, but I have no idea about bots. About the help (hilfe-bot) I got information and at some point the offer to write to one of the guys privately. I did then too. He helped me a lot, created and programmed bots and then left the group again.
Now I would like to change something in the captcha (language and time). But I can't reach him anymore, or he doesn't answer.
Hence my question: Does he have access to the bot from outside if he is no longer in the group? Can I access the bot's settings if I haven't programmed it myself?
In an emergency, I delete all bots and then I have to see how I can arrange it so that I can get a bot back in there. Is it difficult for a layman to set up a bot without a clue?
Yes, of course these are still completely unresolved aspects. Difficult to make the right decision. But right now I'm very reliant on this bot in my group as it keeps the many Asian trolls at bay.
In the meantime everything works. Maybe you just had to wait a while for the commands to catch on in the Telegram network. / reload also helps sometimes.
How can I set a bot clone so that it cannot be used by other members of our group for other groups?
Are you the admin of said group? If so, you can call up an extensive configuration menu with /Settings, in which you can set, for example, that no group participant is allowed to call bot commands. With that you are already secured.
Hallo,
I have several telegram groups. Some of these are already provided with bots (I love people who have created and set them up) - some of us now have new groups - so far without bots - in which we have various problems and would therefore set up bots. So I think it's about time to familiarize myself with the topic of bots. You could also use the bots in the other groups (e.g. Alexis, Rose, etc.) for the new groups?
I'm already over 50 - but still capable of learning - and I don't always want to take up other people's time to provide me with bots for the next groups.
My problem is - I don't want to create new bots, just use - install - and adjust the existing ones. Eg that nobody can add users with arabic characters in their name, greeting new members with a reaction they have to do etc.
Have now googled longer - but I only find instructions for creating new bots - but not for configuring already created bots. Can someone give me a link or help me?
Bots can be added to groups just like users, so just "New User" and then find and add the bot. Bots that are not yet in the contacts can also be found in the normal way using the search function and then started in a direct dialogue - as a rule, the corresponding information also appears when a bot account is selected.
The configuration of your own bots usually runs via the BotFather, where a "/mybots" for example shows your own bots. Or the bot can be configured in a direct dialog - a / shows the options.
Thanks for the answer. Adding is not the problem. So far I am already in the matter. And then you have to give him admin rights – right?
I would simply use the same bot for the new groups as in my existing ones - which a nice person installed and configured for me. Because they just work. But I don't quite trust the configuration yet. Above all, I think it's totally stupid - that everyone in this group can then see what I'm doing - and if necessary can laugh their heads off. Isn't there a way to set this in the background - and only then let loose on the group?
Am I correct – I add the bot to the group, give it admin rights – and then see what I can configure and how?
Have you tried the @GroupHelpBot? Once you have found it using the search function within Telegram, you can start and configure it. A separate chat window opens, only for these configurations. There it will automatically find the groups in which you are an admin. You then need to add them as a group member and make them an admin as well. Then you can steer via a very clear interface, in which things are also explained (!). It's not always "what you see is what you get", but by trying you can make progress.
Dear Catherine,
@GroupHelpBot
you can set it so that neither "Chinese" nor "Cyrillic" or "Arabic" font users can enter (can be set separately). See my more detailed answer on this below/above here.
Hi Mirco!
There's a lot going on in our group and we just wanted to see which user invited the most people, who's the most active, etc.
Now I wanted to ask if you can do that somehow with the bot.
I'm fairly new to Telegram and appreciate any help!!
Best regards Dominic
Sorry, overlooked ... if still relevant:
I'm not sure, but the API seems - after a quick look! – not to provide such information directly. You would probably have to program a little more for that. In any case, the possibilities of bots are well documented in the API overview:
https://core.telegram.org/bots/api
However, such administrative tasks shouldn't be untypical, so I would first see if there isn't already something ready-made for it somewhere. I couldn't name any off the top of my head, though.
Hello, I'm trying to familiarize myself with the topic of bots.
I created a bot in Botfather and can now use it to put likes or comments under my posts. That doesn't work in my group.
So if the bot works but not in the group, I would (without further info) tap on Permissions - the privacy setting of the bot has to be implemented if it should be able to see messages in groups. Take a look at the first step of the second part of the article:
https://www.tutonaut.de/anleitung-einfuehrung-telegram-bots-2-nachrichten-terminal/
Hallo,
I'm going with you
curl -X POST "https://api.telegram.org/bot12345:abcdefgh/sendMessage" -F chat_id=-1234567 -F text="%1 %2 %3 %4 %5 %6 %7"
write a sentence in a Telegram chat. Goes so far. But if the sentence contains umlauts, it doesn't work and I get the error message: string must be encoded in utf-8
How can I implement this?
You can easily specify umlauts in URL encodings - here is one Listing.
Here is an example for hello:
Many thanks for your response. This will work for sure. But I use placeholders as text. The sentence comes from another program. Everything should run automatically. Is there a better placeholder than the "%1" I'm using? Or do I have to take a detour via a text file and translate it into utf-8?
I'm afraid so. There are probably other options with curl, but apparently not in interaction with the link building of Telegram - my attempts have failed in any case. Maybe this StackOverflow entry will give you an idea:
https://stackoverflow.com/questions/12489530/how-do-i-post-form-data-with-utf-8-encoding-by-using-curl
Thank you for your effort, I thought it was just a small setting that was wrong.
I have now found a solution. Add @chcp 65001 to the beginning of the batch and use the latest version of curl. Windows 10 also comes with Curl. But this version is too old. Also specify the path to the new Curl.exe so that the Win10 version is not used. Example:
Thanks for resolving!
Hi,
Does anyone know if you can also create polls with the Telegram Bot via VBA? If so what would the https command line look like?
Currently I only have a VBA to send texts, files and photos.
With kind regards,
Chris
Hi Mirco,
is it possible to add or connect multiple chat IDs?
LG Justin
In a single curl request this will not work. To post to multiple chats, I'd just replace the id from the curl request with a variable, off the top of my head:
You could then enjoy dozens of chats in a loop if necessary.
Moooop, now I've replaced the bot's ID... But of course it's the same with the chat_id string.
Thank you very much for the help... unfortunately the above only works with Linux.
I figured it out after a lot of tinkering and with help.
Nevertheless many thanks
Hey,
Thank you for your guidance. Unfortunately I can't get any further because I just can't get the ChatID.
My bot is several years old and I use it regularly. Still, I get this (also mentioned several times above by others):
{"ok":true,"result":[]}
in response with curl...
I then created a new bot with the same result. In addition to "/start", I also simply wrote "teeeest" etc in the chat with the bot. Unfortunately without success.
Do you have another tip for me? Is the method no longer possible to find out the ID? (Once you have the ID, it could be that it continues to work).
Thanks in advance
Max
hi max
go under https://web.telegram.org sign up… go to this chat and then look in the address bar…
Looks like this then..
https://web.telegram.org/#/im?p=(××××××××) the one in the brackets is the ID
Greetings Daniel
Yep, that's another round easier ;)
Hey,
Thank you for the fast answer.
Unfortunately, I only see "@BOTNAME" or "@CHATNAME" and no ID...
so in the chat with botfather there is "@botfather" in my test channel "@testkanal".
Only when Telgram reports that someone has logged on to the network (I - just in the browser) is there an ID... All other chats and channels are only named by name :(
Since I have the same problem as Max M, namely not finding out the chat ID, I tried your tip. Unfortunately without success.
In my browser, the chat ID is not displayed in the address bar, but that of the bot :(
Does anyone have another idea? Bkn despairing...
This is probably due to the privacy settings: deactivate in the botfather via /setprivacy or try sending a message in the chat that begins with /, for example /foobar. The bot can read messages with / despite the privacy option being set. In both cases, don't forget to first send a message, then use curl to send getUpdates - otherwise the update will of course remain empty.
Hey,
thank you too for the quick reply.
Unfortunately that was unsuccessful. Both bots were actually set to "enable" at /setprivacy. Unfortunately, disabling didn't do anything.
I queried both bots and the second one got the message that two bot instances are running (after a few seconds, but then the "empty" response again).
I have sent a lot of /1234abc messages with my old bot since it was created.
EDIT: While I was writing this, I kept trying and suddenly it worked. It seems like something takes a few memorial minutes to respond. Also, it seems important to create a channel and invite the bot to it? Unfortunately I have to work now and can't test any further. But this is what happened now:
BOTalt is in a public channel (created by me) with me. I wrote a message there via the WEBapi. If I now query the BOTneu via CURL, I get IDs displayed for the messages in the channel with the old bot... So it's kind of strange... I query the new bot and get the messages in the channel with the old bot displayed? When I get home from work I try the other way around and then try again after deleting the bot again.
So I'm home now and tested it.
It just doesn't work with my existing bot. I did everything the same as with the new bot and I just can't get an ID... very strange. I guess I have to maintain two bots :(
So to correct myself.
If I enter the CURL command with the new bot's token, I get the ID of the OLD bot and the chat ID of the channel the OLD bot is in.
It doesn't work the other way around. But I don't care, because I've now deleted the NEW bot and can now send messages to the old bot and the channel with the old bot via the CURL....sendMessage command including token of the OLD bot. It's all a bit weird, but it works
Thanks for the update - and yes, the main thing is that it works, may it stay that way ;)
Hello
following question
I receive faxes regularly... but always with the date and time. Of course that changes...
Here I have to specify the exact file name. Is there a possibility that he always sends digits despite other?
It is best to delete it in the folder after sending it to Telegram…..
(EXAMPLE)
curl -X POST "https://api.telegram.org/botxxxxxx:xxxxxxx/sendDocument" -F chat_id=-12345678 -F document="@//Fritz-nas/fritz.nas/Sony-StorageMedia-01/FRITZ /faxbox/25.08.19_14.19_Telefax.080000854334565.pdf"
It depends a little on what exactly you're doing and what's in the folder. Assuming there is only this one PDF file in the folder that is to be sent and then deleted, then this would be a possible workflow:
So you specify a variable instead of the file name. Exactly how you get the correct filename into the variable depends on the circumstances. Of course, an “ls *.pdf” only works if there is only one PDF in the folder. Otherwise you would have to work with regular expressions, i.e. (quite complex) descriptions of the file name:
The regex after egrep matches if the line begins with two digits (^), followed by a period (.), then two digits again, a period, two digits, an underscore, two digits, a period, two digits, an underscore and then Fax.080000854334565.pdf.
To test you can go to regex101 playing around.
so somehow it doesn't work... hiiiillllffffeeee
but yes there is only one pdf in the folder
Hello
following question
I receive faxes regularly... but always with the date and time. Of course that changes...
Here I have to specify the exact file name. Is there a possibility that he always sends digits despite other?
It is best to delete it in the folder after sending it to Telegram…..
(EXAMPLE)
curl -X POST "https://api.telegram.org/botxxxxxx:xxxxxxx/sendDocument" -F chat_id=-12345678 -F document="@//Fritz-nas/fritz.nas/Sony-StorageMedia-01/FRITZ /faxbox/25.08.19_14.19_Telefax.08213240.pdf"
Hello, I run a chat on our club homepage. I let Telegrambot send me a message when someone entered the chat. I would now also like to get the message that the chat user is also logging out!
I'm not a php or html expert and I've read everything from the internet together, but I haven't found anything for the logout.
Can you help me?
Thanks Christopher
I have to pass, it's more a question of the chat used.
Basically, I see two possibilities: either in the chat software, logging in and out is simply provided with an additional (PHP) command, i.e. a URL is called up that is quite similar to the terminal variant described in the article. Maybe helps here a post on Stack Overflow further. Or if that doesn't work: handicrafts/scripting. Here, too, it depends on the chat software, but you could probably somehow read out the registered users, save them in a temporary “database” (array, text file, real database), query them every five minutes, for example, and send messages via Telegram in the event of changes .
But as I said, the manufacturer of the chat software can probably help more. I know that this is not always an option, but the simplest option would probably be to move the chat from the website to a telegram group ;) Well, then all members would have to go along with it...
Can I send you the code once?
Clear: machinist@tutonaut.de
It's worth a try, but I'm not a big programmer either, more of an occasional hobby scripter ;)
Hello, thank you for your tips, I'll keep trying.
Greetings Christopher
Hallo,
I am using a Telegram bot with ioBroker. I wrote a script that sends me the status of my smart home devices via Telegram. So far everything works, but after every message I get a second one. The content of the message is: "Test message".
Why am I being sent this message and how do I get rid of it?
Greetings,
Philip
I have to guess a little... The message shouldn't have come from Telegram, at least I've never heard it before and I don't know where it should have come from either. Do you maybe use the ioBroker telegram adapter from https://github.com/iobroker-community-adapters/ioBroker.telegram? If so: Exactly “Test message” appears in the example calls – I would assume that you slipped an example somewhere when you set it up. The only alternative that comes to mind spontaneously would be that some smart home device sends this message - but it doesn't seem particularly plausible to me.
As I said, I have to guess a little, for everything else there are too many unknowns for me (scripts, devices used, etc.).
Hello Mirco,
Yes I use that https://github.com/iobroker-community-adapters/ioBroker.telegram Adapter.
Already deleted it and installed it again. The message will continue to be sent.
I've already looked in all objects relating to the telegram adapter and also those from text2command. Can't find anything that could cause this though.
Have now created a simple JavaScript, and execute this.
sendTo("telegram", "send", {
text: 'Hello world!'
});
Still the second message that shows me Test message.
No idea.
Thanks for your answer!
Greetings,
Philip
curl -X POST 'https://api.telegram.org/bot123456:abcde1234ABCDE/sendMessage?chat_id=-4194264&text="texty text"'
[...]
And the message "texty text" ends up in your Telegram account, sent by "user" TutoBot in our example.
Unfortunately this is not the case, only an error message appears (not found). That's it. I love tutorials that assume everything will work, and if it doesn't, then it won't...
That's how it is with instructions, you can't map every eventuality in them... If you have a little more information than the incomplete error message, we'll definitely jump you to the works page. For example, if you mean "command not found", the program curl could simply be missing.
I just tested the command again - it still works. In your quoted string, the whole http string is in commas, although single quotation marks are needed, like this:
Without the quotation marks, the terminal would interpret everything after the & as a new command and output a "command not found" for the non-command "text". Does that help?
For dummies:
When is this online? Does the PC have to be on for this? Do you have to rent a server? Or does it run permanently via Telegram's server?
Am I wrong, or is there really nowhere that can be used for this? If I understand correctly, I can send texts, but I don't see who I can send them to. Is there perhaps an explanation somewhere that one can understand if one does not know beforehand?
Who you are writing to is under step 2 – to the found out chat ID. The chat ID represents one of the contacts/chats. Unfortunately, this is not possible using the names of the contacts.
Hallo,
is it possible to invite or add someone to a group with a bot?
gruß
Mario
Hello!
Great contribution!
Is there a way to make video calls?
I want the bot to call me on demand and send me a live stream of my 3D printer.
Thanks! And: Very nice question, you don't hear it every day ;)
I don't think so, the bot API doesn't seem to give anything for initiating calls, you would probably have to program correctly via the Telegram API, a video call-only client or something. I'm not sure about that though.
I'm more into crude detours.
So from the gut: You could definitely set a Telegram (web) client so that it only ever shows the latest message. And since such a live webcam stream is just a series of images, you can split it up into individual images and send 25 of them per second to Telegram; or however many the technology would make possible in the first place. It might be easier to make a script a X-second-long video on demand and then send it by telegram - if it's just a matter of short checks. Either way, it's scripting handiwork.
Personally, I would probably shy away from the effort and just use the web interface of a webcam ...
The bot API could give something after all: When sending videos, there is an option "supports_streaming" - maybe that's a possibility. If the camera is streaming to a video file - who knows, maybe that file could be sent and even more likely it would come out as a stream... I'd start there anyway.
Great cookbook.
Thank you Thomas
Thank you for this great description! My son wanted to use this service to monitor his HomeMatic, but couldn't find anything to send to groups. With this guide it worked for me right away.
How can I teach Telegram to say good morning and good night at certain times? Optionally with emojis if you like...
Spontaneously: Create a command as described here, put it in a script and let cron run it at the desired times. Of course, a Linux computer somewhere has to be running all day for this. An Android smartphone is also enough Linux computer for this: Described here from step 6.
Hey
how do I get it done so that the bot can only send a word but also a sentence?
Thanks for the guide
the first hurdle to recognize the ChatID (first start the chat) could possibly be presented even more simply
and using curl on windows was tricky too
Swapping inverted commas wasn't enough for me, the minus - he didn't accept the chat ID either.
In case anyone else stumbles upon it :)
curl -X POST "https://api.telegram.org/botBOTID/sendMessage?chat_id=CHAT-ID&text='texty text'"
First of all thanks for the good tutorial it helped me a lot.
Now I have a question, after a certain number of updates only the same messages are displayed, how do I get the latest news?
VG
Sven
Have a look in the second part of the article. The solution should be behind step 4 – keywords are “offset” and “tail”.
Very cool instructions. For me, however, I had to omit the – in front of the Chat_ID for it to work
Hello
I use several surveillance cameras with gprs function, where I get the pictures by mail, but that's very confusing.
I would like to send these pictures directly to Telegram, possibly also directly to a group, are there already instructions.
thank you in advance
Greetings Michael
Hello I want a URL that sends me the file Test.mp3 when I open the URL (I don't have curl installed)
if i get this url
... text=$text
When I open Firefox, a message with "text" is sent to me. I haven't managed to get the MP3 sent to me yet.
Can someone help me there?
Evening together, can someone explain to me whether there is also a group-based solution? So far only found opportunities for the named channel. Whether the bot is there or not is not important to me.
Kind regards, have a nice evening
Tobi
A question about the groups - I would like to automatically evaluate responses to the bot via script ... but this currently only works for me if I write to the bot directly - if I write to the group, he doesn't notice anything. (It also says "no access to messages" in the group settings for the bot) - is that a general restriction or am I doing something wrong?
Thank you,
Philip
"No access to messages" is the default privacy setting, you can also allow bots to access messages. Just run /setprivacy in the BotFather and then set the privacy setting to Disabled.
Hello
thanks for your info
but how can I for example
hostname
hostname –ip address
df -T /
send this information in a telegram?
Do I have to write this information into a file
then read out the file with cat and send?
Ah - you came up with the solution yourself ;) Then the answer from just now was probably superfluous.
Instead of using a text file, this could certainly also be controlled using variables, but basically it fits as you wrote: The text must be transferred directly to Telegram. Sending a file and reading it out on the client side, so to speak, doesn't really sound feasible from the gut.
Hello
I have a problem with sending a text file under Debian (in the telegram directory, the file and is readable
hostname > fdisk3.txt
fdisk -l >> fdisk3.txt
curl -X POST "https://api.telegram.org/botNUMMER -F chat_id=NUMMER -F document="@/telegram/fdisk3.txt"
in the command line I only have one at the end
>
Try it
curl -X POST "https://api.telegram.org/botNUMMER" -F chat_id=NUMBER -F document="@/telegram/fdisk3.txt"
You are missing a quotation mark after "botNUMMER".
Hello, thanks for the instructions :)
A question about this, is there a command to clear the content of the chat. (By bot command)
There are commands for deleting, you can find them here in the bot API documentation:
https://core.telegram.org/bots/api
Just search for "delete". However, I cannot tell you off the cuff how exactly this is built into concrete commands.
that sends me a txt file but not the content of the txt file ;-)
That's the way it's meant to be ;) If you want to send the content of a text file, just use the normal send text command. Instead of fixed text, you set a variable there, to which you in turn assign the text beforehand
Please, please a small pattern for dummies
The principle with the variable corresponds to the last chapter "Using Telegram bots productively", except that the variable is not read in here but is assigned manually beforehand. For example, sending the content of the MyFile.txt file:
a=$(cat MyFile.txt)
curl -X POST "https://api.telegram.org/botBlaBlaBlaBlaBla/sendMessage?chat_id=-123456789&text=$a"'
Instead of writing the text to be sent directly after the equals sign, the variable simply goes there. How you assign the variable beforehand is up to you. For example, instead of cat, you could have any commands “written directly into the variable”, such as:
a=$(ls ./MyDirectory)
a=$(curl https://www.tutonaut.de)
a=$(MyScript.sh)
hello,
#
can someone help me ?
have a telegram bot .
After this script I see the first post on my PHP webpage
that's what the [0] stands for
but would like to display all posts!
How do I do that?
$bottoken = "kjbkjebflknefofofokrogjorjgpr";
$website = "https://api.telegram.org/bot".$bottoken;
$update = file_get_contents($website."/getupdates");
$updatea = json_decode($update, TRUE);
$text = $updatea["result"][0]["message"]["text"];
print_r($text);
I can't tell you exactly, but maybe the offset parameter will help you - there's a little more on that in the second bot article:
https://www.tutonaut.de/anleitung-einfuehrung-telegram-bots-2-nachrichten-terminal/
As far as I can see you use arrays in php and to read them you need a loop that runs until there are no more records left.
I hope to get you a little closer to your goal of having helped.
Hello Mirco
I have now been able to send me a text according to your instructions, but a document or a photo will not work either as a URL input in Firefox or as a terminal input (text works both)
#send message (works)
curl -X POST 'https://api.telegram.org/bot123456:abcde1234ABCDE/sendMessage?chat_id=123456789&text="texty text"'
#send photo (not working)
curl -X POST 'https://api.telegram.org/bot123456:abcde1234ABCDE/sendPhoto" -F chat_id=123456789 -F photo="@home/user/test.jpg"'
#send document (does not work)
curl -X POST 'https://api.telegram.org/bot123456:abcde1234ABCDE/sendDocument" -F chat_id=123456789 -F document="@/home/user/test.jpg"'
Have now played through some variants with the quotation marks or spaces, etc
Can you please help me here, because it should actually be possible.
At least I think so
The error can only be found in the line, right?
greetings Stefan
#send message (works)
curl -X POST 'https://api.telegram.org/bot123456:abcde1234ABCDE/sendMessage?chat_id=123456789&text="texty text"'
after "texty text" there is a comma, but write this with a ' if there are any inconsistencies
So in your examples, the quotation marks don't fit: A single one before https and a double one after sendDocument. If you change the first one, it should work. At least then the syntax would be correct. If the file path, ID and token are correct, it should work.
If not, what error message did you get?
Hi Mirco,
I found an interesting application of your article, but I am stuck at one point.
The bot pushes images that I address from the internet, but no local images from the NAS or my PC.
The application would be to enter the command later in the command line of the Axis CCTV camera.
In Step 1, this will first create a snapshoot and upload it to a synology NAS via FTP.
In Step 2, the telegram command should be given and the image should be sent to the iPhone.
The trigger of the camera is motion detection.
Result: Image on the Iphone & Watch when there is movement at the front door.
I try to test under Win10, input in Firefox address bar.
that works: (ID's changed)
https://api.telegram.org/bot12345678:AAabababababababZw/sendPhoto?chat_id=141414141&photo=https://www.rattengift.com/wp-content/uploads/2011/04/ratten-paar.jpg
not that one:
https://api.telegram.org/bot12345678:AAabababababababZw/sendPhoto?chat_id=141414141&photo=http:/192.168.1.44/image.jpg
on the IP is the synology NAS with apache web server.
also not like this:
https://api.telegram.org/bot12345678:AAabababababababZw/sendPhoto?chat_id=141414141&photo="http://192.168.1.44/image.jpg"
The image itself can also be displayed in firefox via http:/192.168.1.44/image.jpg.
Am I addressing wrong?
Error 400 "Bad Request: wrong file identifier/HTTP URL specified"
I'm not looking.. it can't be that difficult...
Do you have an idea for me?
I've never played around with online files, but I got a gut feeling: You pass the local address 192.1268.1.44 to the Telegram server - and it probably doesn't know what to do with your local address. Actually strange, because a normal file path also works, but spontaneously I can't think of anything better.
If you use a DDNS, try the address.
Hey...I've done everything as described in the instructions...I don't have an id, but I can't send any messages to the bot via message.sendmessage (I don't know if I wrote the right thing)...why is that?
Hello, can you tell me how to add a button to a bot?
So say that you don't have to enter /1 as a command, for example, but you have a button for it.
That would be cool :-)
Unfortunately I can only refer to the API because I haven't done anything with buttons yet. Anyway, this falls under Inline Keyboard: https://core.telegram.org/bots/api#inlinekeyboardmarkup
The result for me is:
{"ok":true,"result":[]}
So no ChatID
Sorry, didn't see the comments first. You have to post something there first.
Incidentally, “/start” is not enough, as written above.
Hallo,
I have the same problem. I set up my bot and I can also trigger FHEM action etc.
But now I need the ChatID for Tasker.
Someone an idea?
I created another bot as a test (of course made /start and wrote texts several times) and I only get that
{"ok":true,"result":[]}
I tried too. The same result with the new bot. getMe works, getUpdates always only {"ok":true,"result":[]}.
My search elsewhere on the web didn't turn up anything either. A tip would be nice! Thanks
Nobody has an idea?
Thanks for your great guide. I use the bot for ioBroker and home automation. That means I can chat with my house and, for example, turn on the light remotely or receive status reports. That works fine. In order to work with IFTTT now, I have to send commands via the URL, since there is currently no Telegram instance for IFTTT. I followed your instructions to get the chat ID, but I always get: {"ok":false,"error_code":404,"description":"Not Found"} as a result.
On the Mac terminal I use the following input:
sudo curl -X POST
If the bot is called R2D2 and his username is Peter, then do I enter R2D2, Peter@R2D2 or R2D2_bot? I've gone through all the variants and I certainly haven't made a mistake with the token. What else can I do?
The bot name does not have to be in the URL, only the token that the botfather issued, so that something like this comes out: .../botTOKEN/getUpdates. "bot" does not stand for the bot name here, it should actually be the three letters bot. If that helps, let me know and I'll add a note to the text.
That helped. At least something ;-)
However, I always get {"ok":true,"result":[]} as a response. The group is active, I sent and received messages from the bot. Only the getMe parameter returns the chat ID of the bot. The getUpdates parameter always returns the empty result.
Good description. Thanks.
Unfortunately I can't get the ID. I always get only one:
{"ok":true,"result":[]}
The API is correct, if I change a number, an error is returned immediately.
Did they change something?
Best regards,
Gal
Of course I wrote to the bot beforehand...
Did you start the bot in the Telegram client? If the bot only exists but is not running, your message will appear.
I have the following "problem" and I'm not quite sure whether I can or should solve it with Telegram bots or whether there are easier/better methods:
several people are automatically alerted by e-mail from a server and everyone then has to decide whether to go to the scene or not. So far there is no way of informing the other alarmed people whether you are coming and how long the journey will take. So it can happen that we are overstaffed or - even worse - there are not enough people, because everyone thinks the other will drive anyway. I would like to change that with a feedback option for all those who have been alarmed.
People use a wide variety of end devices, operating systems and e-mail programs.
Does it make sense to solve this with such a Telegram bot? Any opinions/suggestions on this?
Mmmhhh, right off the bat it sounds like it would help to send Telegram messages to instead of or in addition to emails. This could simply be sent to a group in which everyone is included - everyone could then easily give feedback. It would take a little more effort to solve this with a bot, which could do something like this: a message goes to the individual users and they answer with a yes/no button and maybe a selection for the time, around 15/30/ 45/60 minutes.
In general, I'd say Telegram would be a good solution for this since, unlike Mail, it's synchronous communication - and "deployment" now sounds more urgent. The question is how the previous mail is sent. Variant 1: If someone does this manually, they can also send a telegram message to the group - there is then zero technical effort. Variant 2: If the e-mail is sent automatically, for example by an information system, and the Telegram message is then simply to be sent out as well, this would have to be solved somehow with a script - the technical effort depends on the e-mail dispatch system, on the Telegram side it would be roughly what is in this article. Variant 3: If the whole thing is to happen comfortably via bot, a little logic has to be created for it - that shouldn't be too difficult, but you would need a person who has basic knowledge of scripting/programming and the time to get used to it.
Alternatively, you can also take a look to see if there are any quick and dirty options. For example, there is the @PollBot, which creates polls including answer options via button and evaluations. You can reach the bot via Telegram's search function - perhaps it could be misused.
If 'deployment' isn't time-sensitive here, and I would have to assume it is for e-mail, I'd be surprised if a piece of software couldn't be found somewhere; for example as an add-on for a content management system. Keywords that could be expedient here: club administration, control system, conference management, real-time appointment management (bot-based Doodle would be perfect ;) ) or maybe something from the field of fire brigades, there there also seems to be open source control system solutions admit …
It's all a bit like brainstorming now, but maybe there's a suitable approach here.
Thank you for the quick reply.
The example of the fire brigade goes in that direction, but we are part of the rescue service. We are alerted fully automatically by the control center, but primarily via the beeper (i.e. radio) and only additionally via e-mail and SMS. The beeper is only a radio receiver and cannot send anything back. It is well known that this is not optimal, but there is currently no accepted solution.
Until then, we want to have at least one quick & dirty solution here on site, which will only be used as additional information - we will certainly not rely on it 100%.
We cannot change anything in the control center system and certainly cannot persuade the IT people to do so either; everything we do is not official anyway and is therefore a gray area. Variants 1 + 2 are therefore not applicable.
Brainstorming was right. I just wasn't sure if I understood the bot system correctly.
So I'll keep looking and won't report back if needed.
Many thanks for the effort and the answer!
Thanks! :)
Hallo,
With:
curl -X POST
I don't get a chat ID but:
{"ok":true,"result":[]}
Greeting
result[] remains empty if the bot has not previously taken any action. So just write to the bot. The botfather gives you a link for this when creating the bot. Then run getUpdates again and it should work.
Can I also send pictures or videos?
Yes, as explained in step 4: there is the photo option for images and the document option for documents – whereby “document” can also be a video here.
Hello
Found this error, forgot to set -s before -X, but unfortunately I don't get any more requests, everything remains empty
Hello
I get the error
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the –cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or –insecure) option.
What am I doing wrong
mfg farmer
Somewhere on the way from you to the server you addressed is an invalid SSL certificate - I can't say exactly where and why. As suggested, you could use the "-k" switch, which also allows SSL connections without a certificate check. In case of doubt, transport encryption via SSL could be vulnerable/insecure. If it's about testing and/or no vital data is telegramed, that's not so tragic.
As for the problem itself: Are you perhaps radioing out of a more complex network? Is there someone configuring SSL themselves? (If so: THEY must know.) Or has the problem perhaps already been resolved?
I have a comment on this one ;)
→ »Note: Of course you can add your new bot to a group like any other account«
Because when I try to add my bot (via the web client) to a channel of mine (in which only I am a member, since it is only intended for myself), the following error message appears:
===
Error
A parameter is missing or invalid.
Method: channels.inviteToChannel
Result: {"_":"rpc_error","error_code":400,"error_message":"USER_BOT"}
Stack: error
at u https://web.telegram.org)
...
Are you aware of this "bug"?
Thank you!
webashtl
No, unfortunately I have to pass; I've only invited bots to standard groups so far, never had any problems.
... then this applies to me = only under Windows ;)
Because curl -X POST 'https://api.telegram.org/bot123456:abcde1234ABCDE/sendMessage?chat_id=-4194264&text="texty text"' I could NOT run. Only after I "flipped" the quotes...
But a completely different question: could such a bot also be used to read the messages from a channel that only I “fill” myself, so to speak, only use for my own purposes?
THANK YOU & good night soon! :)
Note on the answer:
"yes", the type of 'single' and 'double' quotes is important - that's why I had to find this solution first: https://stackoverflow.com/a/24232441
I've just tested the variant under step 4 and the last version again - it works here.
Hallo,
With:
curl -X POST
I don't get a chat ID but:
{"ok":true,"result":[]}
Greeting
Even if you probably don't need it anymore. For those after us :D
You also have to write a message to your bot first. The default "/start" is enough
For me it was because I already had a sample script running and there were no "unprocessed" updates.
Hi Mirco,
Thank you for the good guide.
However, I have a small problem with it.
I have the following script:
output=$(date)
curl -X POST "https://api.telegram.org/bot123456:abcde1234ABCDE/sendMessage?chat_id=-4194264&text="$output"
The bot should send: Tue Dec 24 12:40:32 UTC 2019
However, the only thing that matters is: Do
Merry Christmas
Malta
Merry Christmas!
The quotes in front of $output have to be removed, then it should work. You tend not to get the "Do" directly after the command above, but only a ">" in the terminal, which must be confirmed with Enter - because you are waiting for a closing quotation mark. A Tue, or here a "Mi," arises because the first space in the variable is evaluated as the end of the variable value.
This is also the case with bash conditions, for example:
That just by the way. The real insight: It's always the damn quotes to blame :(
Oops - thanks for pointing that out, there was indeed something wrong with the quotation marks. The POST command was of the type:
but should be:
so only normal quotation marks around the address. Changed it, should work now.
I had copied that out of my alias, which is why there was a "'" at the end - and then at some point I probably made it worse. If something doesn't work in the terminal, it's almost always these old quotation marks... ;-(
Hallo,
nice introduction. However, your command will not work with the variable. As a result, I only get "$text".
Is there anything else that needs to be changed?
Greetings Andreas