Short description of what this middleware does.
go get github.com/mtgo-labs/middlewares/YOUR_MIDDLEWARE_NAME- Copy this template to
middlewares/your_middleware_name/ - Replace
YOUR_MIDDLEWARE_NAMEingo.mod,middleware.go,middleware_test.go, andREADME.mdwith your middleware name (lowercase, no hyphens/underscores) - Update
go.modmodule path togithub.com/mtgo-labs/middlewares/your_middleware_name - Implement the middleware logic in the
Middleware()method
import (
tg "github.com/mtgo-labs/mtgo/telegram"
yourmw "github.com/mtgo-labs/middlewares/YOUR_MIDDLEWARE_NAME"
)
func main() {
client, _ := tg.NewClient(apiID, apiHash, &tg.Config{
BotToken: botToken,
})
mw := yourmw.New(yourmw.Config{})
client.UseInvokerMiddleware(mw.Middleware())
// your handlers...
client.Start()
}mtgo has two middleware levels:
| Level | Type | Intercepts | Use case |
|---|---|---|---|
| Invoker | UseInvokerMiddleware |
RPC calls (API calls to Telegram) | Rate limiting, flood wait, logging, metrics |
| Handler | UseMiddleware |
Update dispatch (incoming messages) | Auth, i18n, conversation state |
This template implements an invoker middleware — it wraps outgoing RPC calls. No handler changes are required.
MIT