telegram

package
v0.1.81-dev.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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
	// Edge is the Cloudflare edition: work is triggered by EdgeTick and bounded after-response tasks, not process loops.
	Edge bool
	// AfterResponse keeps short request producers alive until a post-response flush has finished. The runner is bounded by
	// its caller; nil leaves delivery to the VPS background loop.
	AfterResponse func(func())

	// 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 L

type L string

L is a language: en, ru, or zh.

type Service

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

Service is the Telegram module.

func New

func New(cfg Config) (*Service, error)

New builds the module. VPS starts Run; the edge invokes the bounded polling, watcher, and flush methods from EdgeTick.

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 and re-opens quietly.

func (*Service) AwgPrepareFailed

func (s *Service) AwgPrepareFailed(nodeID, code string, at int64)

AwgPrepareFailed announces a failed build of the AmneziaWG kernel module on a node (the same failure is told once).

func (*Service) BackupFailed

func (s *Service) BackupFailed(code string)

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) FlushNow added in v0.1.50

func (s *Service) FlushNow(ctx context.Context)

FlushNow replaces the VPS burst window for bounded edge jobs and request producers.

func (*Service) Handler

func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)

Handler is the admin TelegramService (mounted behind the session like the others).

func (*Service) PlanWaiting

func (s *Service) PlanWaiting(tool, tokenName string)

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) PollPendingLinkCode added in v0.1.50

func (s *Service) PollPendingLinkCode(ctx context.Context) error

PollPendingLinkCode is one edge tick's bounded Telegram poll. It checks D1 before taking the cross-isolate lease, so the edge does not long-poll when there is no link code to hear.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run starts the VPS polling, sending, and watcher loops until ctx ends, then briefly flushes queued messages. No goroutine outlives it; the edge runs bounded methods from EdgeTick instead.

func (*Service) Security

func (s *Service) Security(e auth.Event)

Security is the auth event hook. It is called on its own goroutine and may block.

func (*Service) SetSources

func (s *Service) SetSources(src Sources)

SetSources connects the watcher to the update module (they are built after this one).

func (*Service) WatchTick added in v0.1.50

func (s *Service) WatchTick(ctx context.Context, now time.Time)

WatchTick runs the release and agent watcher every fifth scheduled minute on the edge.

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).

Jump to

Keyboard shortcuts

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