telegram

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: MIT Imports: 28 Imported by: 205

Documentation

Index

Constants

View Source
const (
	AddrProduction = "149.154.167.50:443"
	AddrTest       = "149.154.167.40:443"
)

Available MTProto default server addresses.

See https://my.telegram.org/apps.

Variables

View Source
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 Dial

func Dial(ctx context.Context, opt Options) (*Client, error)

Dial initializes Client and creates connection to Telegram, initializing new or loading session from provided storage.

func (*Client) AuthKey

func (c *Client) AuthKey() crypto.AuthKey

func (*Client) AuthStatus

func (c *Client) AuthStatus(ctx context.Context) (*AuthStatus, error)

AuthStatus gets authorization status of client.

func (*Client) Authenticated

func (c *Client) Authenticated() bool

Authenticated returns true of already authenticated.

func (*Client) BotLogin

func (c *Client) BotLogin(ctx context.Context, token string) error

BotLogin performs bot authorization request.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close closes underlying connection and saves session to storage if provided.

func (*Client) InvokeRaw

func (c *Client) InvokeRaw(ctx context.Context, input bin.Encoder, output bin.Decoder) error

InvokeRaw sens input and decodes result into output.

NOTE: Assuming that call contains content message (seqno increment).

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping sends ping request to server and waits until pong is received or context is canceled.

func (*Client) RandInt64

func (c *Client) RandInt64() (int64, error)

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, req *tg.MessagesSendMessageRequest) error

SendMessage sends message to peer.

type Error

type Error struct {
	Code    int
	Message string
}

Error represents RPC error returned to request.

func (Error) Error

func (e Error) Error() string

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)

func (*FileSessionStorage) StoreSession

func (f *FileSessionStorage) StoreSession(_ context.Context, data []byte) error

type Options

type Options struct {

	// AppID is api_id of your application.
	///
	// Can be found on https://my.telegram.org/apps.
	AppID int
	// AppHash is api_hash of your application.
	//
	// Can be found on https://my.telegram.org/apps.
	AppHash string

	// 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 *net.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 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.

type UpdateClient

type UpdateClient interface {
	RandInt64() (int64, error)
	SendMessage(ctx context.Context, m *tg.MessagesSendMessageRequest) error
}

type UpdateHandler

type UpdateHandler func(ctx context.Context, c UpdateClient, u *tg.Updates) error

UpdateHandler will be called on received updates from Telegram.

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.

Jump to

Keyboard shortcuts

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