Basic Concept of Telegram Bot API

Telegram is one of the best chat application in 2019. Its stability, reliability, and server-based chat data makes everything works very seamlessly in everyday use. More interestingly, there is an API to work with Telegram bot, so that we can make a very powerful bot to help us create many beneficial things, like sending report automatically, setting parameters via bot, and sending a broadcast message to users.

In this article, I will tell you the basic concept of telegram bot. Currently, two of the most popular event management tools in telegram bot are Long Polling and Webhook. These two methods are explained in telegram official website, but I will simplify the explanation in the hope of you guys can understand the basic principles better.

1. Long Polling

The concept of polling is very simple: your server continuously checking at a predetermined frequency (e. g : every 2 seconds) to check if there is someone sending a chat to your bot. If the result is empty, then you can simply do nothing. Otherwise, you will get an array of request data, such as chat id, sender id, group id (if chat is sent via group), the raw text sent by user, timestamp, and so on. Afterwards, the data is yours. You can process is and then reply to the chat based on chat id.

Telegram Bot Long Polling Concept

This method is very simple, yet requires continuous checking and creates more delay between request and response of the bot. Moreover, if the internet connection is unstable, your scheduler can pile up and creates a heavy load to the server. Therefore, Telegram BOT api provides second option which is more efficient for servers.

2. Webhook

Unlike long polling, webhook relies on speed and reliability. Using webhook, we don’t need to check every predetermined frequency whether or not there is someone chatting our bot. Instead, we only have to place our code in our hosted network, register the link to Telegram with our bot token code, so that whenever someone chats our bot, Telegram will send it to the webhook link we provided before. This is somehow a passive approach, but more efficient and doesn’t consume a lot of internet bandwidth.

Telegram Bot Webhook Concept

The downside is that we have to provide a hosted site and technically we can not put our code in non hosted local server. But if you really want to use webhook and you don’t have a hosted website, there is a workaround using ngrok. I will make a separate post about this later on.

So that’s it about basic concept of Telegram bot API. For more technical details about how to make a Telegram bot, I will make a post about this in a few days.

582 comments

  1. Payday loans

    A motivating discussion is worth comment. I do think that you ought to write more
    about this topic, it may not be a taboo matter but usually people don’t
    discuss these issues. To the next! Cheers!!

  2. 7Bit Casino

    Appreciating the persistence you put into your blog and in depth information you present.
    It’s awesome to come across a blog every once in a while that isn’t the same old rehashed material.

    Great read! I’ve saved your site and I’m adding your RSS feeds
    to my Google account.

  3. 솔레어카지노

    Heya just wanted to give you a quick heads up and let you know a few of the pictures
    aren’t loading correctly. I’m not sure why but I
    think its a linking issue. I’ve tried it in two different browsers and both show the same outcome.

  4. 빅카지노

    Howdy would you mind stating which blog platform you’re working with?
    I’m going to start my own blog in the near future
    but I’m having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs and I’m looking for
    something unique. P.S My apologies for getting off-topic but I had to ask!

  5. バカラ カジノ

    wonderful issues altogether, you simply received a logo new reader.
    What may you recommend about your publish that you made some days ago?
    Any positive?

  6. バカラ

    For most up-to-date information you have to visit internet and on the
    web I found this web site as a best web page for most up-to-date
    updates.

  7. 우리카지노

    I have read so many articles concerning the blogger lovers however
    this article is truly a nice paragraph, keep it up.

Leave a Reply

Your email address will not be published. Required fields are marked *