Documentation
¶
Overview ¶
Package telegram implements the notify.Channel adapter for Telegram bots using mymmrac/telego with long-polling. Each NotificationConf gets its own bot instance and goroutine; Init failures are non-fatal so that application boot is never blocked by a misconfigured channel.
Index ¶
- Constants
- func EscapeMarkdownV2(s string) string
- type CallbackActionHandler
- type Config
- type TelegramChannel
- func (c *TelegramChannel) Close(ctx context.Context) error
- func (c *TelegramChannel) Healthy() bool
- func (c *TelegramChannel) Init(ctx context.Context, conf *models.NotificationConf) error
- func (c *TelegramChannel) OnInbound(handler notify.InboundHandler)
- func (c *TelegramChannel) Send(ctx context.Context, n notify.Notification) error
- func (c *TelegramChannel) SetCallbackActionHandler(h CallbackActionHandler)
- func (c *TelegramChannel) SupportsInbound() bool
- func (c *TelegramChannel) Type() string
Constants ¶
const ChannelType = "telegram"
ChannelType is the registry key for the Telegram adapter.
Variables ¶
This section is empty.
Functions ¶
func EscapeMarkdownV2 ¶
EscapeMarkdownV2 escapes Telegram MarkdownV2 reserved characters. Not used by the default Send path on purpose: torrent titles routinely contain `_`, `[`, `]`, `*` etc. and accidental escaping disfigures filenames.
Types ¶
type CallbackActionHandler ¶
type CallbackActionHandler interface {
OnRSSDownload(ctx context.Context, logID uint, userID int64) error
OnRSSIgnore(ctx context.Context, logID uint, userID int64) error
}
CallbackActionHandler dispatches RSS notification button actions parsed from the inline keyboard payload. Set on the channel via SetCallbackActionHandler. If nil, callbacks are acknowledged but no downstream action is taken (stub mode for testing / pre-S5 boots).
type Config ¶
type Config struct {
BotToken string `json:"bot_token"`
AllowedUsers []int64 `json:"allowed_users"`
AdminUsers []int64 `json:"admin_users"`
DefaultChatID int64 `json:"default_chat_id"`
PollingTimeoutSeconds int `json:"polling_timeout_seconds"`
APIServer string `json:"api_server,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
}
Config is the JSON shape stored (encrypted) in NotificationConf.ConfigJSON.
type TelegramChannel ¶
type TelegramChannel struct {
// contains filtered or unexported fields
}
TelegramChannel implements notify.Channel for Telegram.
func (*TelegramChannel) Close ¶
func (c *TelegramChannel) Close(ctx context.Context) error
Close stops the long-poll loop and clears state.
func (*TelegramChannel) Healthy ¶
func (c *TelegramChannel) Healthy() bool
Healthy reports whether Init succeeded and the bot is currently usable.
func (*TelegramChannel) Init ¶
func (c *TelegramChannel) Init(ctx context.Context, conf *models.NotificationConf) error
Init parses the plaintext ConfigJSON (already decrypted by cmd/web.go), builds a per-conf telego bot, and launches the long-poll goroutine.
func (*TelegramChannel) OnInbound ¶
func (c *TelegramChannel) OnInbound(handler notify.InboundHandler)
OnInbound registers the handler invoked once a message passes the permission gate.
func (*TelegramChannel) Send ¶
func (c *TelegramChannel) Send(ctx context.Context, n notify.Notification) error
func (*TelegramChannel) SetCallbackActionHandler ¶
func (c *TelegramChannel) SetCallbackActionHandler(h CallbackActionHandler)
SetCallbackActionHandler installs the dispatcher for RSS notification inline-button actions. Safe to call before or after Init. Pass nil to revert to stub mode.
func (*TelegramChannel) SupportsInbound ¶
func (c *TelegramChannel) SupportsInbound() bool
SupportsInbound reports that Telegram delivers inbound chat messages.
func (*TelegramChannel) Type ¶
func (c *TelegramChannel) Type() string
Type returns the registry key.