Documentation
¶
Overview ¶
Package iambot is the Telegram operator bot: it watches pending access requests through the IAM admin API and lets allowlisted Telegram users approve/deny them (or mint invites) without opening the admin panel.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("iambot: access request not found")
ErrNotFound marks a decision on a request that is gone (already decided by someone else, or deleted).
Functions ¶
This section is empty.
Types ¶
type AccessRequest ¶
AccessRequest is the bot-facing view of a pending request.
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot wires the Telegram bot, the IAM client and the seen-state together.
type Config ¶
type Config struct {
// TelegramToken is the bot token from @BotFather.
TelegramToken string
// BaseURL is the IAM service base URL (e.g. https://iam.example.com).
BaseURL string
// ProjectID scopes every admin call to one project.
ProjectID string
// AdminToken is a project-admin bearer token for the admin API.
AdminToken string
// Environment is the optional X-Environment scope (live/test/…).
Environment string
// AllowedUsers is the allowlist of Telegram user ids the bot talks to.
AllowedUsers []int64
// StatePath is where the seen-request state is persisted.
StatePath string
// PollInterval is how often pending access requests are re-listed.
PollInterval time.Duration
// HealthAddr is the liveness/readiness listener (":8081"); empty disables.
HealthAddr string
// LogFormat is "json" (default) or "text".
LogFormat string
// LogLevel is the xlog level (default "info").
LogLevel string
}
Config is the bot's environment-driven configuration.
type IAM ¶
type IAM struct {
// contains filtered or unexported fields
}
IAM is the thin admin-API surface the bot needs.
func (*IAM) Approve ¶
Approve approves a pending request. IAM mints the email-bound invite and sends the decision email with the magic link as part of the same call.
func (*IAM) CreateInvite ¶
CreateInvite mints an email-bound invitation; the raw token is returned exactly once (and IAM emails it to the invitee as well).
func (*IAM) Deny ¶
Deny denies a pending request with an optional reason (surfaced in the denial email when set).
func (*IAM) ListPending ¶
func (c *IAM) ListPending(ctx context.Context) ([]AccessRequest, error)
ListPending returns every pending access request, following the keyset pagination until the listing is exhausted.
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller watches the pending list and announces requests the state has not seen yet. See State for how "new" is defined (seen-set diff, not time).
func (*Poller) HealthCheck ¶
HealthCheck reports readiness: at least one pass ran, the last pass did not error, and the last success is not older than a few intervals.
type State ¶
type State struct {
// Seen holds the ids of pending requests already pushed to the operators.
// Ids leave the set when they leave the pending list (approved/denied), so
// it stays the size of the current pending backlog.
Seen map[string]struct{} `json:"seen"`
// FirstRunDone marks that the cold-start backlog was silently absorbed.
FirstRunDone bool `json:"first_run_done"`
}
State is the bot's durable memory of which access requests were already announced. The admin list endpoint exposes no created_at and its ordering is id-lexicographic (not temporal), so "new" is defined exactly as "pending id not in the seen set" — immune to clocks, ordering, pagination and restarts.
func LoadState ¶
LoadState reads the state file; a missing file yields a fresh empty state (and firstRunDone=false so the caller can absorb the backlog quietly).