Documentation
¶
Overview ¶
Package telegram sends the panel's alerts to the admins who linked a Telegram chat, and serves the admin TelegramService that sets the bot up. One bot (the owner's), long polling only to hear "/start <code>" (the panel sits behind a decoy site and takes no inbound webhook), sendMessage for everything else.
What goes out is decided by the callers (cmd/mistgate wires them): health alert transitions, a new panel release, agents behind a release, a failed backup, an MCP plan waiting for the owner, an AWG kernel build that failed, and sign-in security events. This package owns the how: who receives it by role, never the same open alert twice, bursts coalesced into one message, retries with backoff and Telegram's retry_after, and a clean stop.
Index ¶
- type Config
- type L
- type Service
- func (s *Service) AlertTransition(a store.HealthAlert, resolved bool)
- func (s *Service) AwgPrepareFailed(nodeID, code string, at int64)
- func (s *Service) BackupFailed(code string)
- func (s *Service) BackupOK()
- func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)
- func (s *Service) PlanWaiting(tool, tokenName string)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) Security(e auth.Event)
- func (s *Service) SetSources(src Sources)
- type Sources
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Store *store.Store
Vault *vault.Vault
// StepUp is auth.Service.RequireStepUp: setting the bot and linking a chat ask for it. Required.
StepUp func(context.Context) error
// AdminURL is the public address of the admin ("" = unknown: messages carry no link).
AdminURL string
Log *slog.Logger
// Test seams. The zero value is production.
APIBase string // https://api.telegram.org
HTTPClient *http.Client // default: a client with no timeout of its own (every call has its context's)
Now func() time.Time
Window time.Duration // how long a burst is gathered into one message; default 30 s
PollTimeout int // getUpdates long-poll seconds; default 30
RetryBase time.Duration // first wait after a failed send, doubled each time; default 2 s
RetryMax int // sends tried before a message is dropped; default 6
WatchEvery time.Duration // release / agent check period; default 5 min
WatchFirst time.Duration // first check after Run starts; default 1 min
// Wait replaces the timers in tests: it waits d, or until ctx ends (false) or wake fires (wake is nil where a bot
// change must not cut the wait short).
Wait func(ctx context.Context, d time.Duration, wake <-chan struct{}) bool
}
Config configures Service. Store and Vault are required.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the Telegram module.
func (*Service) AlertTransition ¶
func (s *Service) AlertTransition(a store.HealthAlert, resolved bool)
AlertTransition is health.Config.OnTransition: an alert opened (or re-opened) or ended. An alert already announced as open is not announced again; one that ended because a worse one replaced it, was accepted as normal or lost its node says nothing; one the admin muted ends quietly.
func (*Service) AwgPrepareFailed ¶
AwgPrepareFailed announces a failed build of the AmneziaWG kernel module on a node (the same failure is told once).
func (*Service) BackupFailed ¶
BackupFailed announces a failed backup once; the next one that works resolves it. The scheduler retries with a growing wait, and every retry that fails again would otherwise be a message.
func (*Service) BackupOK ¶
func (s *Service) BackupOK()
BackupOK resolves a failure that was announced.
func (*Service) Handler ¶
Handler is the admin TelegramService (mounted behind the session like the others).
func (*Service) PlanWaiting ¶
PlanWaiting announces an MCP plan that waits for the owner's approval: the owner only, with a link to the screen where the decision is made (never an approval from the chat).
func (*Service) Run ¶
Run polls, sends and watches until ctx ends, then flushes what is queued (briefly) and returns. No goroutine outlives it.
func (*Service) Security ¶
Security is the auth event hook. It is called on its own goroutine and may block.
func (*Service) SetSources ¶
SetSources connects the watcher to the update module (they are built after this one).
type Sources ¶
type Sources struct {
// PanelRelease: the newest signed panel release that is newer than this build, if any.
PanelRelease func() (version string, available bool)
// OutdatedAgents: the version of the release the nodes are compared with and the names of the connected nodes behind it.
OutdatedAgents func(ctx context.Context) (version string, nodes []string)
}
Sources are what the periodic watcher asks other modules (wired after they exist; nil = not watched).