telegram

package
v0.31.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: MIT Imports: 16 Imported by: 0

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

View Source
const ChannelType = "telegram"

ChannelType is the registry key for the Telegram adapter.

Variables

This section is empty.

Functions

func EscapeMarkdownV2

func EscapeMarkdownV2(s string) string

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          json.RawMessage `json:"allowed_users,omitempty"`
	AdminUsers            json.RawMessage `json:"admin_users,omitempty"`
	DefaultChatID         json.RawMessage `json:"default_chat_id,omitempty"`
	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.

AllowedUsers / AdminUsers / DefaultChatID are stored as json.RawMessage so that the adapter tolerates both numeric and string-quoted values that users commonly type into the Web UI form (e.g. `"8576996727"` or `"@channel"`). Use the helper methods (DefaultChatIDInt, DefaultChatIDUsername, AdminUsersList, AllowedUsersList) to access typed values.

func (*Config) AdminUsersList added in v0.31.2

func (c *Config) AdminUsersList() []int64

AdminUsersList returns admin_users as []int64. Tolerates both raw integer and string-quoted integers in the JSON array; bad entries are silently skipped to avoid taking down the whole channel for one typo.

func (*Config) AllowedUsersList added in v0.31.2

func (c *Config) AllowedUsersList() []int64

AllowedUsersList returns allowed_users as []int64 with the same tolerance as AdminUsersList.

func (*Config) DefaultChatIDInt added in v0.31.2

func (c *Config) DefaultChatIDInt() (int64, bool)

DefaultChatIDInt returns the integer form of default_chat_id. Accepts both raw JSON integers and string-quoted integers ("123456"). Returns (0, false) when the value is absent or is a non-numeric string (e.g. "@channelusername"), in which case the caller should fall back to DefaultChatIDUsername.

func (*Config) DefaultChatIDUsername added in v0.31.2

func (c *Config) DefaultChatIDUsername() (string, bool)

DefaultChatIDUsername returns the @channelusername form. Only returns a non-empty string when the stored value is a string that does NOT parse as an integer (so DefaultChatIDInt and DefaultChatIDUsername never both return a usable value for the same config).

type TelegramChannel

type TelegramChannel struct {
	// contains filtered or unexported fields
}

TelegramChannel implements notify.Channel for Telegram.

func New

func New() *TelegramChannel

New constructs a fresh TelegramChannel.

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

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 (*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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL