Introducing Telegram bots: sending messages and files from the terminal

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.

telegra bots
First you add the @Botfather - an offer you don't...

2. Create Telegram bot

To create your bot, simply send the new user Botfather the messages


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.

telegram bot
Very cool: You create bots in dialogue with @botfather

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

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:


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!

telegra bots
You have to read out the ID of the chat.

4. Send messages and files to Telegram

We also use curl again to send messages:

curl -X  POST '"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 "" -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 "" -F chat_id=-4194264 -F photo="@/home/mirco/rathaus.jpg"
Messaging from the bash - API usage couldn't be much simpler.
Messaging from the bash – API usage couldn't be much simpler.

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 "$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.

Mirco Lang

Freelance journalist, Sauerland exile, (fairly old) skateboarder, graduate computer scientist, retail salesman, open source nerd, Checkmk handbook writer. Ex-Saturn'ler, Ex-Data-Becker'ler, Ex-BSI'ler. First contact with computers: ca. 1982 - a friend's big brother's C64. If you want to read more about open source, Linux and craft stuff and support Tutonaut here: About Coffee sponsorship via Paypal.I'm always happy. In advance: Thank you! Do not miss: and New: Mastodon


  1. 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?

    1. 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.

  2. 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?

    1. 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:

      • Get text from group - as described in part 2
      • Parse/modify retrieved text with sed
      • Write text in group – as described above

      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.

  3. 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

  4. 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 "" -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 "" -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

    1. I tried it briefly with a simplified variant, here the following notation works for the document= part:

       document="@/d/tmp/"$(echo test.png)

      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

      ls $PWD/data/*.jpg

      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.

      1. 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

  5. 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.

    1. 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.

      1. 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?

      2. 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...

    1. 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.


  6. 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?

    1. 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:

      Vorher: '{"force_reply":true}'
      Nachher: '%7B%22force_reply%22%3Atrue%7D'

      The whole part then looks like this:


      A complete link thus:

       curl -X  POST '"test"&reply_markup='%7B%22force_reply%22%3Atrue%7D''

      You can code get it done online.

      1. 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.

      2. 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 ;)


  7. 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?

      1. ...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.

      2. 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?

      3. 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.

    1. 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.

    1. 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.

  8. 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?

    1. 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.

      1. 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?

      2. 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.

    2. Dear Catherine,
      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.

  9. 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

    1. 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:

      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.

  10. 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.

  11. Hallo,
    I'm going with you
    curl -X POST "" -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?

      1. 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?

      2. 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:

        c:\curl\bin\curl -X POST "" -F chat_id=-12345 -F text="%*"
  12. 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,

    1. 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:

      curl -X  POST ''$id1'/sendMessage?chat_id=-111111111&text="texty text"'
      curl -X  POST ''$id2'/sendMessage?chat_id=-111111111&text="texty text"'

      You could then enjoy dozens of chats in a loop if necessary.

  13. 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

  14. 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):
    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

      1. 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 :(

      2. 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...

    1. 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.

      1. 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.

      2. 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 :(

      3. 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

  15. 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…..

    curl -X POST "" -F chat_id=-12345678 -F document="@//Fritz-nas/fritz.nas/Sony-StorageMedia-01/FRITZ /faxbox/25.08.19_14.19_Telefax.080000854334565.pdf"

    1. 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:

      fax=$(ls *.pdf)
      curl -X POST „“ -F chat_id=-12345678 -F document=“@//Fritz-nas/fritz.nas/Sony-StorageMedia-01/FRITZ/faxbox/$fax“
      rm $fax

      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:

      fax=$(find . -maxdepth 1  -printf "%f\n" | egrep '^[[:digit:]]{2}\.[[:digit:]]{2}\.[[:digit:]]{2}_[[:digit:]]{2}\.[[:digit:]]{2}_Telefax.080000854334565.pdf')

      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.

  16. 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…..

    curl -X POST "" -F chat_id=-12345678 -F document="@//Fritz-nas/fritz.nas/Sony-StorageMedia-01/FRITZ /faxbox/25.08.19_14.19_Telefax.08213240.pdf"

  17. 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

    1. 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...

  18. 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?


    1. 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 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.).

      1. Hello Mirco,

        Yes I use that 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!

  19. curl -X POST '"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...

    1. 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:

      curl -X  POST '"texty text"'

      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?

  20. 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?

  21. 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?

    1. 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.

  22. 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.

    1. 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 ...

      1. 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.

  23. 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.

  24. How can I teach Telegram to say good morning and good night at certain times? Optionally with emojis if you like...

  25. 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 "'texty text'"

  26. 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?


  27. Very cool instructions. For me, however, I had to omit the – in front of the Chat_ID for it to work

  28. 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

  29. 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?

  30. 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

  31. 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,

    1. "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.

  32. Hello
    thanks for your info

    but how can I for example

    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?

    1. 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.

  33. 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 " -F chat_id=NUMMER -F document="@/telegram/fdisk3.txt"

    in the command line I only have one at the end

      1. Hello, thanks for the instructions :)
        A question about this, is there a command to clear the content of the chat. (By bot command)

      2. 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

      3. 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 "$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)

  34. 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 = "".$bottoken;

    $update = file_get_contents($website."/getupdates");
    $updatea = json_decode($update, TRUE);

    $text = $updatea["result"][0]["message"]["text"];

    1. 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.

  35. 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 '"texty text"'

    #send photo (not working)
    curl -X POST '" -F chat_id=123456789 -F photo="@home/user/test.jpg"'

    #send document (does not work)
    curl -X POST '" -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

    1. #send message (works)
      curl -X POST '"texty text"'

      after "texty text" there is a comma, but write this with a ' if there are any inconsistencies

    2. 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?

  36. 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)

    not that one:

    on the IP is the synology NAS with apache web server.

    also not like this:""

    The image itself can also be displayed in firefox via http:/

    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?

    1. 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.

  37. 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?

  38. 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 :-)

    1. Sorry, didn't see the comments first. You have to post something there first.
      Incidentally, “/start” is not enough, as written above.

      1. 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

      2. 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

  39. 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?

    1. 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.

      1. 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.

  40. Good description. Thanks.
    Unfortunately I can't get the ID. I always get only one:


    The API is correct, if I change a number, an error is returned immediately.
    Did they change something?
    Best regards,

  41. 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?

    1. 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.

      1. 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!

      1. 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.

  42. Hello
    Found this error, forgot to set -s before -X, but unfortunately I don't get any more requests, everything remains empty

  43. Hello
    I get the error
    curl: (60) SSL certificate problem: self-signed certificate in certificate chain
    More details here:

    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

    1. 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?

  44. 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:

    A parameter is missing or invalid.
    Method: channels.inviteToChannel
    Result: {"_":"rpc_error","error_code":400,"error_message":"USER_BOT"}
    Stack: error
    at u


    Are you aware of this "bug"?

    Thank you!

  45. ... then this applies to me = only under Windows ;)

    Because curl -X POST '"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! :)

      1. 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

      2. For me it was because I already had a sample script running and there were no "unprocessed" updates.

      3. Hi Mirco,

        Thank you for the good guide.

        However, I have a small problem with it.

        I have the following script:


        curl -X POST ""$output"

        The bot should send: Tue Dec 24 12:40:32 UTC 2019

        However, the only thing that matters is: Do

        Merry Christmas


      4. 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:

        a="Hallo Welt"
        [ $a = $a ] && echo "echo wird nie ausgeführt, weil die Aussage unwahr ist ..."
        [ "$a" = "$a" ] && echo "Mit Anführungszeichen ist die Aussage wahr"
        [[ $a = $a ]] && echo "Wahr - aber das ist ein anderes Thema ;)"

        That just by the way. The real insight: It's always the damn quotes to blame :(

  46. Oops - thanks for pointing that out, there was indeed something wrong with the quotation marks. The POST command was of the type:

    POST ' blabla "'

    but should be:

    POST " blabla " 

    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... ;-(

  47. 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

Leave a Comment

Your e-mail address will not be published. Required fields are marked with * marked

This website uses Akismet to reduce spam. Learn more about how your comment data is processed.

Back to Top button


Please deactivate your ad blocker.