Documentation ¶
Overview ¶
Package telegram implements Telegram client.
Index ¶
- Constants
- Variables
- type AuthStatus
- type Client
- func (c *Client) AuthBot(ctx context.Context, token string) error
- func (c *Client) AuthPassword(ctx context.Context, password string) error
- func (c *Client) AuthSendCode(ctx context.Context, phone string, options SendCodeOptions) (codeHash string, err error)
- func (c *Client) AuthSignIn(ctx context.Context, phone, code, codeHash string) error
- func (c *Client) AuthStatus(ctx context.Context) (*AuthStatus, error)
- func (c *Client) Authenticated() bool
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Connect(ctx context.Context) (err error)
- func (c *Client) InvokeRaw(ctx context.Context, input bin.Encoder, output bin.Decoder) error
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) RandInt64() (int64, error)
- func (c *Client) SendMessage(ctx context.Context, req *tg.MessagesSendMessageRequest) error
- type DialFunc
- type Dialer
- type Error
- type FileSessionStorage
- type Options
- type ProtocolErr
- type SendCodeOptions
- type SessionStorage
- type UpdateHandler
Constants ¶
const ( AddrProduction = "149.154.167.50:443" AddrTest = "149.154.167.40:443" )
Available MTProto default server addresses.
Variables ¶
var ErrPasswordAuthNeeded = errors.New("2FA required")
ErrPasswordAuthNeeded means that 2FA auth is required.
var ErrSessionNotFound = errors.New("session storage: not found")
ErrSessionNotFound means that session is not found in storage.
Functions ¶
This section is empty.
Types ¶
type AuthStatus ¶
type AuthStatus struct { // Authorized is true if client is authorized. Authorized bool }
AuthStatus represents authorization status.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a MTProto client to Telegram.
func (*Client) AuthPassword ¶ added in v0.10.0
AuthPassword performs login via secure remote password (aka 2FA).
func (*Client) AuthSendCode ¶ added in v0.10.0
func (c *Client) AuthSendCode(ctx context.Context, phone string, options SendCodeOptions) (codeHash string, err error)
AuthSendCode requests code for provided phone number, returning code hash and error if any.
func (*Client) AuthSignIn ¶ added in v0.10.0
AuthSignIn performs sign in with provided user phone, code and code hash.
If ErrPasswordAuthNeeded is returned, call AuthPassword to provide 2FA password.
func (*Client) AuthStatus ¶
func (c *Client) AuthStatus(ctx context.Context) (*AuthStatus, error)
AuthStatus gets authorization status of client.
func (*Client) Authenticated ¶
Authenticated returns true of already authenticated.
func (*Client) Connect ¶ added in v0.9.0
Connect initializes connection to Telegram server and starts internal read loop.
func (*Client) InvokeRaw ¶
InvokeRaw sens input and decodes result into output.
NOTE: Assuming that call contains content message (seqno increment).
func (*Client) Ping ¶
Ping sends ping request to server and waits until pong is received or context is canceled.
func (*Client) RandInt64 ¶
RandInt64 returns new random int64 from random source.
Useful helper for places in API where random int is required.
func (*Client) SendMessage ¶
SendMessage sends message to peer.
type Dialer ¶ added in v0.9.0
type Dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer dials using a context.
type FileSessionStorage ¶
type FileSessionStorage struct {
Path string
}
FileSessionStorage implements SessionStorage for file system as file stored in Path.
func (*FileSessionStorage) LoadSession ¶
func (f *FileSessionStorage) LoadSession(_ context.Context) ([]byte, error)
LoadSession loads session from file.
func (*FileSessionStorage) StoreSession ¶
func (f *FileSessionStorage) StoreSession(_ context.Context, data []byte) error
StoreSession stores session to file.
type Options ¶
type Options struct { // PublicKeys of telegram. // // If not provided, embedded public keys will be used. PublicKeys []*rsa.PublicKey // Addr to connect. // // If not provided, AddrProduction will be used by default. Addr string // Dialer to use. Default dialer will be used if not provided. Dialer Dialer // Network to use. Defaults to tcp. Network string // Random is random source. Defaults to crypto. Random io.Reader // Logger is instance of zap.Logger. No logs by default. Logger *zap.Logger // SessionStorage will be used to load and save session data. // NB: Very sensitive data, save with care. SessionStorage SessionStorage // UpdateHandler will be called on received update. UpdateHandler UpdateHandler }
Options of Client.
type ProtocolErr ¶
type ProtocolErr struct {
Code int32
}
ProtocolErr represents protocol level error.
func (ProtocolErr) Error ¶
func (p ProtocolErr) Error() string
type SendCodeOptions ¶ added in v0.10.0
type SendCodeOptions struct { // AllowFlashCall allows phone verification via phone calls. AllowFlashCall bool // Pass true if the phone number is used on the current device. // Ignored if AllowFlashCall is not set. CurrentNumber bool // If a token that will be included in eventually sent SMSs is required: // required in newer versions of android, to use the android SMS receiver APIs. AllowAppHash bool }
SendCodeOptions wraps options for user code receive.
type SessionStorage ¶
type SessionStorage interface { LoadSession(ctx context.Context) ([]byte, error) StoreSession(ctx context.Context, data []byte) error }
SessionStorage is secure persistent storage for client session.
NB: Implementation security is important, attacker can use not only for connecting as authenticated user or bot, but even decrypting previous messages in some situations.
Source Files ¶
- auth.go
- auth_bot.go
- auth_user.go
- check_protocol_error.go
- client.go
- close.go
- create_auth_key.go
- decrypt.go
- dialer.go
- doc.go
- encrypt.go
- error.go
- get_state.go
- handle_ack.go
- handle_bad_msg.go
- handle_gzip.go
- handle_result.go
- handle_updates.go
- init_connection.go
- invoke_raw.go
- is_authorized.go
- message_id.go
- new_encrypted_msg.go
- options.go
- ping.go
- rand_int64.go
- read_loop.go
- reconnect.go
- rpc.go
- send_message.go
- seq_no.go
- session_storage.go
- sha.go
- vendored_keys.go
- write.go
Directories ¶
Path | Synopsis |
---|---|
Code generated for package internal by go-bindata DO NOT EDIT.
|
Code generated for package internal by go-bindata DO NOT EDIT. |
tgtest
Package tgtest provides test Telegram server for end-to-end test.
|
Package tgtest provides test Telegram server for end-to-end test. |
Package tgflow implements helpers that reduce boilerplate for telegram client.
|
Package tgflow implements helpers that reduce boilerplate for telegram client. |