What is Telebot?
Telebot (gopkg.in/telebot.v4) is a Go framework for the Telegram Bot API. Rather than exposing every raw API method directly, Telebot makes deliberate design choices to keep your bot code readable and maintainable. As the README puts it: instead of making a 1:1 API wrapper, the focus is on the beauty of the API and performance.
The result is a framework where the most common operations — receiving messages, responding to commands, handling callbacks, sending media — collapse into a few expressive lines.
Philosophy
Telebot is built around a few core ideas: Ergonomics over completeness. The API surface is deliberately shaped around what you actually need to do — not around the Telegram Bot API spec. Repetitive boilerplate is eliminated wherever possible. Concurrency by default. Handlers run in goroutines by default, making Telebot suitable for high-load bots without any extra configuration. SetSynchronous: true in Settings if you need sequential processing.
Extensibility without churn. The Poller interface, Sendable interface, Editable interface, and middleware system are all designed so you can extend the framework without touching its internals or breaking backwards compatibility.
Why Telebot?
| Concern | Telebot’s approach |
|---|---|
| Routing | String commands, event constants, and button pointers all work as endpoints in Handle() |
| Middleware | Simple MiddlewareFunc chain — global, group-scoped, or handler-scoped |
| Keyboards | Unified ReplyMarkup builder for both reply and inline keyboards |
| Files | Transparent upload/download; automatic FileID caching on first send |
| Error handling | Configurable OnError callback in Settings; handlers return plain error |
| Testing | Offline: true in Settings skips the getMe API call so bots can be constructed without a network |
Architecture overview
A Telebot bot is composed of five building blocks:Bot
*Bot is the central object. It holds the token, the HTTP client, the update channel, and the handler map. You create one with NewBot:
b.Start() begins consuming updates from the configured Poller and dispatching them to registered handlers.
Context
Context wraps an incoming Update and exposes helpers that work regardless of update type. Instead of branching on whether the update is a message, a callback, or an inline query, you call the same methods:
func(tele.Context) error.
Handlers
Handlers are registered withb.Handle(endpoint, handlerFunc). The endpoint can be:
- A command string like
"/start"or"/help" - A telebot event constant like
tele.OnText,tele.OnPhoto,tele.OnCallback - A pointer to a button (
&btnHelp) for keyboard-driven routing
Middleware
MiddlewareFunc has the type func(HandlerFunc) HandlerFunc. Middleware can be applied at three scopes:
Poller
ThePoller interface decouples update delivery from the rest of the framework:
LongPoller (polling via getUpdates) and Webhook (push via HTTPS). You can implement the interface yourself to receive updates from any source.
Feature highlights
Command routing
Route
/command and /command@botname transparently. Extract payload and space-separated arguments with c.Message().Payload and c.Args().Rich middleware
Chain
MiddlewareFunc handlers globally, per group, or per handler. Ships with Logger, AutoRespond, Whitelist, Blacklist, and IgnoreVia out of the box.Transparent file API
Send files from disk or URL with
tele.FromDisk() / tele.FromURL(). Telebot uploads automatically on first send and caches the Telegram FileID for subsequent sends.Keyboard builders
Build reply and inline keyboards with a unified
ReplyMarkup constructor. Inline buttons double as Handle() endpoints — no manual callback string parsing needed.Inline mode
Handle
tele.OnQuery and respond with typed result objects (PhotoResult, ArticleResult, etc.) through c.Answer().Editable messages
Any struct that implements
MessageSig() (string, int64) can be passed to b.Edit() or b.Delete() — including your own database model structs.Concurrent by default
Handlers run in goroutines. The updates channel capacity (default 100) and
Synchronous mode are both configurable in Settings.Webhook support
Drop in a
Webhook poller for production deployments. Telebot handles TLS, port binding, and update delivery — you only configure the URL.Package import
The module path and import alias used throughout this documentation:gopkg.in/telebot.v4. The tele alias is a convention — you can use any alias you prefer.