Documentation
¶
Overview ¶
Package telegram provides a Telegram bot client for sending notifications and handling commands with built-in chat ID authorization.
It wraps the github.com/go-telegram/bot library and adds:
- Chat ID whitelist middleware for access control
- A simple Notify function for sending messages to a default chat
- Global convenience API via Init/Start/Notify
- Multi-instance support via the Bot struct
Quick Start ¶
Send a one-off notification:
if err := telegram.Init(telegram.Config{
BotToken: "123456:ABC-DEF...",
ChatID: "12345678",
}); err != nil {
log.Fatal(err)
}
if err := telegram.Notify("Hello from Go!"); err != nil {
log.Fatal(err)
}
Start the bot for receiving commands (blocking):
telegram.Start(ctx)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotInitialized = errors.New("telegram: bot not initialized") ErrNoChatID = errors.New("telegram: no default notify chat ID configured") )
Common sentinel errors.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(allowedIds []int64) bot.Middleware
AuthMiddleware creates a middleware that allows only specific chat IDs.
func Init ¶
Init initializes the global bot instance. It is safe to call multiple times; subsequent calls replace the global instance.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot wraps the Telegram bot client with auth and notification support.
func NewBot ¶
NewBot creates a new Bot from the given config. Returns the Bot and any error encountered during creation.
func (*Bot) RegisterHandler ¶
func (b *Bot) RegisterHandler(handlerType bot.HandlerType, pattern string, matchType bot.MatchType, handler bot.HandlerFunc) string
RegisterHandler exposes the underlying client's RegisterHandler method.