Building a minimal Telegram bot in C

In this post I'll show you how to build a minimal Telegram bot using the C language, thanks to json-c and libcurl.

Building a minimal Telegram bot in C

Retrieving Telegram updates

Let’s start with the basics: we need to decide which update method to use between long polling and webhooks. For this project, we’ll go with long polling to avoid the complexities of setting up a domain and SSL certificates.

Long polling is a method for checking updates from Telegram servers. There are two types of polling: short polling and long polling.

  • Short polling involves repeatedly sending requests to Telegram servers to ask if there are any new updates. As you can imagine, this is highly inefficient and puts unnecessary load on both your application and Telegram’s servers.
  • Long polling, on the other hand, is a much smarter approach. Instead of spamming requests, you send a single request and keep the connection open until an update is available. If no updates are received within a specified timeout period (e.g., 30 seconds), the connection closes, and a new request is sent. This ensures that the connection isn’t left open indefinitely while still allowing you to receive updates in near real-time.

This post is a WIP. If you see it, is just because this is a preview. Maybe I should create a new repo for this post?

I'm writing a minimal bot libary, you can find it here.