Documentation
¶
Overview ¶
Package telegram provides a tiny, testable wrapper around github.com/go-telegram/bot.
It defines a minimal Bot interface (register handlers, send messages, process single updates, start polling, get ID) so application code depends on an interface and can be unit‑tested with mocks. NewBot returns an adapter that forwards calls to the real *bot.Bot while adapting handler + middleware signatures.
Index ¶
- func Handler(f HandlerFunc) bot.HandlerFunc
- func LogChat(c *models.Chat) slog.Value
- func LogMessage(m *models.Message) slog.Value
- func LogUpdate(u *models.Update) slog.Value
- func LogUser(u *models.User) slog.Value
- func Middlewares(m ...Middleware) []bot.Middleware
- type API
- type Bot
- type HandlerFunc
- type Middleware
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(f HandlerFunc) bot.HandlerFunc
Handler converts a HandlerFunc to a bot.HandlerFunc by injecting the Bot instance.
func LogMessage ¶
LogMessage returns a slog.Value for models.Message for structured logging
func Middlewares ¶
func Middlewares(m ...Middleware) []bot.Middleware
Middlewares converts a slice of Middleware to a slice of bot.Middleware by injecting the Bot instance.
Types ¶
type API ¶
type API interface {
// SendMessage sends a message to a chat and returns the created message.
SendMessage(ctx context.Context, p *bot.SendMessageParams) (*models.Message, error)
}
API defines the subset of the Telegram Bot API methods used in this project.
type Bot ¶
type Bot interface {
API
// ID returns the bot's Telegram ID.
ID() int64
// RegisterHandler registers a new handler with a string pattern.
RegisterHandler(handlerType bot.HandlerType, pattern string, matchType bot.MatchType, f HandlerFunc, m ...Middleware) string
// RegisterHandlerRegexp registers a new handler with a regexp pattern.
RegisterHandlerRegexp(handlerType bot.HandlerType, re *regexp.Regexp, f HandlerFunc, m ...Middleware) string
// RegisterHandlerMatchFunc registers a new handler with a custom match function.
RegisterHandlerMatchFunc(matchFunc bot.MatchFunc, f HandlerFunc, m ...Middleware) string
// UnregisterHandler removes a previously registered handler by its ID.
UnregisterHandler(id string)
// ProcessUpdate passes a single update through the bot’s handler chain.
ProcessUpdate(ctx context.Context, upd *models.Update)
// Start begins receiving updates and dispatching them to handlers.
Start(ctx context.Context)
}
Bot is a minimal abstraction over github.com/go-telegram/bot. It defines the subset of functionality needed in this project and enables replacing the real bot with a mock for convenient testing.
type HandlerFunc ¶
HandlerFunc defines a function to handle a Telegram update.
type Middleware ¶
type Middleware func(next HandlerFunc) HandlerFunc
Middleware defines a function to process middleware.