Telegram chatbot can receive messages from the telegram server through majorly two ways, namely polling, and web-hook. Each method has its own trade-offs. We shall explore the differences between the two in this short walk up 🚶🏽 hill.
We shall take a quick look at their comparisons. Sarufi provides blueprints that can work either way. It's good to know the differences before sticking to one method so that you get rid of misunderstandings.
To get an idea of what these terminologies mean, I will be using a simple example. Trust me it is really easy to grasp the concept.
Know how polling works
In the first case, Imagine you walk into a restaurant ask for a milkshake. Then a waiter brings you a milkshake. The next day you head to the same restaurant to order a milkshake again, unfortunately it's out of stock.
You leave expecting to come back after a few minutes to check if they already made one. Later you decide to check again whether the milkshake is ready or not, this time you get it available.
Every time you want to know whether your favourite drink is available you will need to head out and ask a waiter.
Here you have to go in and check whether a drink is available or not. This is an example of polling. A bot to check at regular intervals if the telegram server received a new message.
Here a restaurant act as a telegram server while he acts as a bot. So a bot will be checking for messages from the server from time to time.
Know about Web-hook
Here is another case, You walk into a restaurant asking for whatever favorite drink. Luckily by the time, it's available. The next day, you walk in again to take one, unfortunately, the drinks are out of stock.
Then a waiter asks for your home address(contact info). He promises to deliver a drink in person to your doorstep as the drinks get into the restaurant.
Here a restaurant acts as a telegram server and you are a bot. We have an additional member, who is a delivery guy. The guy, in this case, is a web-hook URL.
You just need to tell the telegram server your address(publicly accessed URL) that will be receiving new messages as they hit their server.
Let's make a comparison between the two of them
As our trip is to be short up the hill, let's dive directly into the comparison between them. Let's compare them in terms of:-
In the polling approach, your application periodically sends requests to the Telegram Bot API to retrieve updates. It typically involves making HTTP requests at fixed intervals to check for new messages or events
Contrary to polling, with webhooks, you need to configure a callback URL on your server to receive incoming updates from the Telegram server. Your bot will receive a message whenever there is a new message or event
- Real-time updates
Webhooks offer real-time updates as they send a request to your server immediately when a new message hits your bot. This reduces delays in receiving updates and responding.
With polling, you will have near-real-time updates. However, the frequency of polling determines the delay in receiving updates. This imposes delays in giving responses to users.
- Consumption of resources
Webhooks are generally more resource-friendly compared to polling since the server only sends requests when an update occurs. It reduces unnecessary network traffic and server load. So polling may not be the most efficient approach for high-volume or resource-constrained environments.
A starting point to deploying your chatbot in Telegram is knowing the differences between the two.
Build a bot
Our short journey ends here. Build a bot with sarufi and seamlessly integrate it with Telegram.
Sarufi provides detailed blueprints to deploy your telegram sarufi chatbot using either of the methods above. We have got you covered for whatever method you choose to deploy with. Detailed blueprints are available; sarufi telegram chatbot and sarufi telegram web-hook chatbot.