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.

2 comments

  1. cbd vape oils

    I’m the proprietor of JustCBD label (justcbdstore.com) and am looking to develop my wholesale side of company. It would be great if anybody at targetdomain give me some advice . I thought that the most suitable way to accomplish this would be to connect to vape companies and cbd retailers. I was hoping if anybody could recommend a trusted site where I can buy CBD Shops B2B Mailing List I am presently reviewing creativebeartech.com, theeliquidboutique.co.uk and wowitloveithaveit.com. Not exactly sure which one would be the best choice and would appreciate any support on this. Or would it be much simpler for me to scrape my own leads? Ideas?

  2. Kelvin Matarrita

    Have you ever considered about adding a little bitmore than just your articles? I mean, what you say is valuable and everything.But think about if you added some great photos orvideo clips to give your posts more, “pop”! Your content isexcellent but with pics and video clips, this site could definitely be oneof the greatest in its niche. Great blog!

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *