antirez/botlib logo

antirez/botlib

Free

C Telegram bot framework

FreeFree tier
Type
Open Source

About antirez/botlib

Botlib is a C framework for writing Telegram bots. It implements a subset of the Telegram bot API, wrapped in an event loop that spawns a new thread for each incoming request, enabling concurrent handling of long-running tasks such as audio transcription or external API calls. The library includes high-level wrappers for Sqlite3 (exported as both a relational database and a key-value store), JSON parsing/generation, and dynamic strings via the SDS library. Written in C for stability, performance in CPU-intensive operations (e.g., Monte Carlo simulations), and minimal dependency churn over long-running bots. Dependencies are limited to libcurl and libsqlite3, making deployment straightforward.

Key Features

Implements a subset of the Telegram bot API with event loop and thread-per-request concurrency
High-level wrappers for Sqlite3 (relational and key-value store), JSON parsing/generation, and dynamic strings (SDS)
Callbacks receive parsed message data and have access to Telegram API functions
Minimal dependencies: only libcurl and libsqlite3
Compiles easily on any system with make
Designed for stability and long-term maintenance without API churn from high-level libraries

Pros & Cons

Pros
  • Lightweight and fast due to C implementation
  • Stable API – no unnecessary changes over time
  • Thread-per-request model simplifies handling of long-running tasks
  • Includes built-in Sqlite3 and JSON support
  • Easy to compile and deploy with few dependencies
  • Well-suited for CPU-intensive bot logic
Cons
  • Limited to Telegram bot API (subset, not full API)
  • Requires C programming knowledge
  • Not suitable for very high-throughput scenarios due to thread-per-request model
  • No built-in support for webhooks (polling only)
  • Documentation is sparse beyond the README example

Best For

Building stable, long-running Telegram bots that require minimal maintenanceWriting CPU-intensive bots (e.g., financial analysis, Monte Carlo simulations) in CCreating bots that handle long-duration requests (e.g., audio transcription, external API calls) via threadingDeveloping lightweight bots that can run on any platform with libcurl and libsqlite3Educational projects to learn C and Telegram bot development

FAQ

What is Botlib?
Botlib is a C framework for writing Telegram bots. It provides an event loop that calls user-defined callbacks in separate threads for each incoming message, along with wrappers for SQLite, JSON, and dynamic strings.
What are the dependencies?
Botlib requires only libcurl and libsqlite3, which are widely available on most systems.
Why is it written in C?
C offers stability, low overhead for CPU-intensive tasks, and avoids API churn common in high-level libraries. The thread-per-request model benefits from C's minimal runtime and shared-state efficiency.
Does it support webhooks?
No, Botlib uses long polling to receive updates from the Telegram API.
Is Botlib production-ready?
The framework is developed by antirez and has been used for actual bots. It is open source under the GPL-3.0 license. Users should evaluate its suitability for their own use cases.