bootstrap

package
v0.166.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package bootstrap is the machinery shared by telegram/bot and telegram/user: a telegram.Client with an updates manager and a peer manager, their wiring, startup and lifecycle.

Index

Constants

View Source
const (
	SessionFile = "session.json"
	UpdatesFile = "updates.json"
)

File names in Config.Dir.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Client  telegram.Options
	Dir     string
	Handler telegram.UpdateHandler
	Updates updates.Config
	Peers   peers.Options
	// MaxLoginWait is the maximum total FLOOD_WAIT waited out by
	// RetryFlood. Zero means 5 minutes, negative means do not wait.
	MaxLoginWait time.Duration
	// IsBot is passed to the updates manager.
	IsBot bool
	// OnUpdates is called with every update received by the client before
	// the updates manager gets it (optional), e.g. for updateLoginToken
	// during sign in.
	OnUpdates func(ctx context.Context, u tg.UpdatesClass)
	// Login checks the session and signs in if needed, returning the
	// authorized user.
	Login func(ctx context.Context, r *Runtime) (*tg.User, error)
}

Config of a Runtime.

type Runtime

type Runtime struct {
	Client  *telegram.Client
	API     *tg.Client
	Peers   *peers.Manager
	Updates *updates.Manager
	Sender  *message.Sender
	Clock   clock.Clock
	// contains filtered or unexported fields
}

Runtime is a telegram.Client with an updates manager and a peer manager.

func New

func New(appID int, appHash string, cfg Config) (*Runtime, error)

New creates a Runtime without connecting.

func (*Runtime) Close

func (r *Runtime) Close() error

Close is Shutdown without a deadline.

func (*Runtime) Done

func (r *Runtime) Done() <-chan struct{}

Done returns a channel that is closed when the runtime stops.

func (*Runtime) RetryFlood

func (r *Runtime) RetryFlood(ctx context.Context, f func(ctx context.Context) error) error

RetryFlood calls f, waiting out FLOOD_WAIT errors of it up to the total MaxLoginWait. Other errors are returned at once.

func (*Runtime) RetryFloodIf

func (r *Runtime) RetryFloodIf(ctx context.Context, f func(ctx context.Context) error, retry func() bool) error

RetryFloodIf is RetryFlood that waits out a FLOOD_WAIT only if retry (when set) allows it, e.g. not after a login code was already sent.

func (*Runtime) Self

func (r *Runtime) Self() *tg.User

Self returns the authorized user, nil before Start succeeded.

func (*Runtime) Shutdown

func (r *Runtime) Shutdown(ctx context.Context) error

Shutdown stops and waits until the client and the updates manager are stopped or ctx is done. It returns the error that stopped the runtime before Shutdown was called, nil if Shutdown stopped it or if Start failed, or the wrapped ctx.Err().

func (*Runtime) Start

func (r *Runtime) Start(ctx context.Context, so ...telegram.StartOption) error

Start connects, signs in with Config.Login and starts the updates manager.

func (*Runtime) Stop

func (r *Runtime) Stop()

Stop stops without waiting, see telegram.Client.Stop.

func (*Runtime) Wait

func (r *Runtime) Wait(ctx context.Context) error

Wait blocks until the runtime stops or ctx is done. It returns the error that stopped it, nil if it was stopped by Stop or Close, or the wrapped ctx.Err().

Jump to

Keyboard shortcuts

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