Documentation
¶
Overview ¶
Package telegram is a self-contained Telegram Bot API client plus the panel's admin bot: it long-polls for commands (view/add/remove users) and pushes scheduled backups to the linked admin chat. It deliberately depends only on the standard library — the Bot API is plain HTTP+JSON — so the panel keeps its minimal dependency surface.
Index ¶
- func SendBackup(ctx context.Context, client *Client, chats []int64, dataDir string, ...) error
- type CallbackQuery
- type Chat
- type Client
- func (c *Client) AnswerCallback(ctx context.Context, id, text string) error
- func (c *Client) EditMenu(ctx context.Context, chatID, messageID int64, html string, ...) error
- func (c *Client) GetMe(ctx context.Context) (*User, error)
- func (c *Client) GetUpdates(ctx context.Context, offset int64, timeout int) ([]Update, error)
- func (c *Client) SendDocument(ctx context.Context, chatID int64, filename, caption string, r io.Reader) error
- func (c *Client) SendMenu(ctx context.Context, chatID int64, html string, rows [][]InlineButton) error
- func (c *Client) SendMessage(ctx context.Context, chatID int64, html string) error
- func (c *Client) SendPhoto(ctx context.Context, chatID int64, filename, caption string, r io.Reader) error
- type InlineButton
- type Message
- type Panel
- type Service
- type Update
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SendBackup ¶
func SendBackup(ctx context.Context, client *Client, chats []int64, dataDir string, manifest backup.Manifest, checkpoint func() error, caption string) error
SendBackup checkpoints the DB, builds a fresh tar.gz of the data directory, and uploads it to each chat as a document. It's shared by the scheduler and the panel's "send test backup" action. A per-chat send failure doesn't abort the rest; the first error is returned.
Types ¶
type CallbackQuery ¶
type CallbackQuery struct {
ID string `json:"id"`
From *User `json:"from"`
Message *Message `json:"message"`
Data string `json:"data"`
}
CallbackQuery is an inline-button tap (used for the delete confirmation).
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one bot (identified by its token). It's cheap to construct and safe for use from the single bot loop plus the occasional handler-driven send.
func NewClient ¶
NewClient builds a client for the given bot token. The HTTP timeout comfortably exceeds the long-poll window so GetUpdates isn't cut off mid-wait.
func (*Client) AnswerCallback ¶
AnswerCallback acknowledges a button tap so Telegram stops the spinner.
func (*Client) EditMenu ¶
func (c *Client) EditMenu(ctx context.Context, chatID, messageID int64, html string, rows [][]InlineButton) error
EditMenu replaces the text + inline keyboard of an existing message, so the bot's menus navigate in place instead of stacking new messages.
func (*Client) GetMe ¶
GetMe returns the bot's own account (used to show its @username in the panel).
func (*Client) GetUpdates ¶
GetUpdates long-polls for new updates past offset, blocking up to timeout seconds. Only messages and callback queries are requested.
func (*Client) SendDocument ¶
func (c *Client) SendDocument(ctx context.Context, chatID int64, filename, caption string, r io.Reader) error
SendDocument uploads a file to a chat as a document, with an optional caption.
func (*Client) SendMenu ¶
func (c *Client) SendMenu(ctx context.Context, chatID int64, html string, rows [][]InlineButton) error
SendMenu sends an HTML message with an inline keyboard (rows of buttons). Pass a nil/empty rows for a plain message.
func (*Client) SendMessage ¶
SendMessage sends a plain HTML-formatted message (no buttons). HTML parse mode lets the bot bold headers; all dynamic text must be escaped by the caller (esc).
type InlineButton ¶
InlineButton is one inline-keyboard button (label + callback payload).
type Message ¶
type Message struct {
MessageID int64 `json:"message_id"`
From *User `json:"from"`
Chat Chat `json:"chat"`
Text string `json:"text"`
}
Message is the subset of a Telegram message the bot acts on.
type Panel ¶
type Panel interface {
ListUsers() ([]model.User, error)
CreateUser(name string, dataLimit, expireAt int64) (*model.User, error)
DeleteUser(id int64) error
SetUserEnabled(id int64, enabled bool) error
ResetTraffic(id int64) error
BackupManifest() backup.Manifest
Location() *time.Location
}
Panel is the slice of the core Manager the bot drives. Defining it here (rather than importing core) keeps the dependency one-way — core never imports telegram — and makes the bot trivially testable with a fake.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the running bot: it long-polls for updates and pushes scheduled backups. The whole UI is inline buttons — the only text a user ever types is "/start <code>" to link, and (when prompted) a new user's name. It re-reads settings every cycle, so enabling/disabling, rotating the token, or changing the schedule all take effect without a restart.
type Update ¶
type Update struct {
UpdateID int64 `json:"update_id"`
Message *Message `json:"message"`
Callback *CallbackQuery `json:"callback_query"`
}
Update is one polled event: a message or a callback-query (inline button tap).