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
- type Config
- type Runtime
- func (r *Runtime) Close() error
- func (r *Runtime) Done() <-chan struct{}
- func (r *Runtime) RetryFlood(ctx context.Context, f func(ctx context.Context) error) error
- func (r *Runtime) RetryFloodIf(ctx context.Context, f func(ctx context.Context) error, retry func() bool) error
- func (r *Runtime) Self() *tg.User
- func (r *Runtime) Shutdown(ctx context.Context) error
- func (r *Runtime) Start(ctx context.Context, so ...telegram.StartOption) error
- func (r *Runtime) Stop()
- func (r *Runtime) Wait(ctx context.Context) error
Constants ¶
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 (*Runtime) Done ¶
func (r *Runtime) Done() <-chan struct{}
Done returns a channel that is closed when the runtime stops.
func (*Runtime) RetryFlood ¶
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) Shutdown ¶
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().