Golang Telegram Bot Framework

Inspired by paulsonoflars/gotgbot.
All Telegram types and methods are produced by lumex's own stdlib-only generator (internal/gen) straight from the official Bot API docs into *_gen.go files. Bumping the API version is a single go run ./cmd/gen.
Features
- Auto-generated API — all Telegram types and methods are generated directly from the official bot API docs:
- Guaranteed to match the official documentation
- Easy to update to new API versions
- Self-documenting (reuses existing Telegram docs)
- Type-safe — no
interface{} magic; polymorphic types are sealed interfaces with typed decoders and As<Variant>() accessors
- Dependency-free core — the generated client and runtime use only the standard library (the optional
zerolog log adapter and testify mocks pull their own)
- Concurrent update processing — each update is handled in its own goroutine, keeping the bot responsive
- Automatic panic recovery — panics are caught and logged to prevent unexpected downtime
- FSM support — built-in finite state machine for multi-step flows
- Router with middleware — flexible routing with global and per-route middleware
- Keyboard builders — fluent API for
ReplyKeyboard and InlineKeyboard
- Webhook support — single-bot and multi-bot webhook modes
- Event-driven update handling
Getting Started
Install the library using the standard go get command:
go get github.com/kbgod/lumex/v2
Using with Claude Code
This repo is also a Claude Code plugin that
teaches the assistant how lumex works. Install it into your own bot project:
/plugin marketplace add kbgod/lumex
/plugin install lumex@lumex
It ships five skills: lumex (framework reference —
Context helpers, router filters/middleware/state, keyboard & rich-message
builders, polling/webhook), dialog-flows
(best practices for multi-step conversation flows / wizards),
rich-messages (building, sending and reading
rich messages with the ready-made constructors),
mini-app-auth (verifying Mini App initData
on your backend) and
telegram-widgets (writing HTML widgets and
the bot side behind them).
Examples
Bare API usage
The simplest way to use the library — just call Telegram Bot API methods directly:
package main
import (
"context"
"os"
"github.com/kbgod/lumex/v2"
)
func main() {
bot, err := lumex.NewBot(os.Getenv("BOT_TOKEN"))
if err != nil {
panic(err)
}
message, err := bot.SendMessage(context.Background(), 123, "hello")
}
Production-ready bot (Long Polling + Dispatcher)
A complete example with graceful shutdown, structured logging, error handling, and panic recovery. Uses the recommended Dispatcher:
package main
import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"
"time"
"github.com/kbgod/lumex/v2"
"github.com/kbgod/lumex/v2/dispatcher"
"github.com/kbgod/lumex/v2/router"
)
func main() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
log := slog.New(slog.NewTextHandler(os.Stdout, nil))
bot, err := lumex.NewBot(os.Getenv("BOT_TOKEN"))
if err != nil {
log.Error("failed to create bot", "error", err)
return
}
log.Info("bot authorized successfully", "username", bot.Username)
r := router.New(bot, router.WithErrorHandler(func(ctx *router.Context, err error) {
log.Error("handle update error", "error", err, "update", ctx.Update)
}))
r.OnStart(func(ctx *router.Context) error {
return ctx.ReplyVoid("Hello, World!")
})
r.OnMessage(func(ctx *router.Context) error {
return ctx.ReplyVoid("Undefined command!")
})
d := dispatcher.New(bot, r)