Documentation
¶
Index ¶
Constants ¶
const VERSION = "v1.0.0-beta16"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthConversator ¶
type AuthConversator interface {
// AskPhoneNumber is called to ask user for phone number.
// phone number to login should be returned.
AskPhoneNumber() (string, error)
// AskCode is called to ask user for OTP.
// OTP should be returned.
AskCode() (string, error)
// AskPassword is called to ask user for 2FA password.
// 2FA password should be returned.
AskPassword() (string, error)
// RetryPassword is called when the 2FA password is incorrect
// attemptsLeft is the number of attempts left.
// 2FA password should be returned.
RetryPassword(attemptsLeft int) (string, error)
}
AuthConversator is an interface for asking user for auth information.
func BasicConversator ¶
func BasicConversator() AuthConversator
type Client ¶
type Client struct {
// Dispatcher handlers the incoming updates and execute mapped handlers. It is recommended to use dispatcher.MakeDispatcher function for this field.
Dispatcher dispatcher.Dispatcher
// PublicKeys of telegram.
//
// If not provided, embedded public keys will be used.
PublicKeys []telegram.PublicKey
// DC ID to connect.
//
// If not provided, 2 will be used by default.
DC int
// DCList is initial list of addresses to connect.
DCList dcs.List
// Resolver to use.
Resolver dcs.Resolver
// MigrationTimeout configures migration timeout.
MigrationTimeout time.Duration
// AckBatchSize is limit of MTProto ACK buffer size.
AckBatchSize int
// AckInterval is maximum time to buffer MTProto ACK.
AckInterval time.Duration
// RetryInterval is duration between send retries.
RetryInterval time.Duration
// MaxRetries is limit of send retries.
MaxRetries int
// ExchangeTimeout is timeout of every key exchange request.
ExchangeTimeout time.Duration
// DialTimeout is timeout of creating connection.
DialTimeout time.Duration
// CompressThreshold is a threshold in bytes to determine that message
// is large enough to be compressed using GZIP.
// If < 0, compression will be disabled.
// If == 0, default value will be used.
CompressThreshold int
// Whether to show the copyright line in console or no.
DisableCopyright bool
// Logger is instance of zap.Logger. No logs by default.
Logger *zap.Logger
// Self contains details of logged in user in the form of *tg.User.
Self *tg.User
// Code for the language used on the device's OS, ISO 639-1 standard.
SystemLangCode string
// Code for the language used on the client, ISO 639-1 standard.
ClientLangCode string
// PeerStorage is the storage for all the peers.
// It is recommended to use storage.NewPeerStorage function for this field.
PeerStorage *storage.PeerStorage
*telegram.Client
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(appId int, apiHash string, cType ClientType, opts *ClientOpts) (*Client, error)
NewClient creates a new gotgproto client and logs in to telegram.
func (*Client) CreateContext ¶
CreateContext creates a new pseudo updates context. A context retrieved from this method should be reused.
func (*Client) ExportStringSession ¶
ExportStringSession EncodeSessionToString encodes the client session to a string in base64.
Note: You must not share this string with anyone, it contains auth details for your logged in account.
func (*Client) RefreshContext ¶
RefreshContext casts the new context.Context and telegram session to ext.Context (It may be used after doing Stop and Start calls respectively.)
func (*Client) Start ¶
func (c *Client) Start(opts *ClientOpts) error
Start connects the client to telegram servers and logins. It will return error if the client is already running.
type ClientOpts ¶
type ClientOpts struct {
// Logger is instance of zap.Logger. No logs by default.
Logger *zap.Logger
// Whether to store session and peer storage in memory or not
//
// Note: Sessions and Peers won't be persistent if this field is set to true.
InMemory bool
// PublicKeys of telegram.
//
// If not provided, embedded public keys will be used.
PublicKeys []telegram.PublicKey
// DC ID to connect.
//
// If not provided, 2 will be used by default.
DC int
// DCList is initial list of addresses to connect.
DCList dcs.List
// Resolver to use.
Resolver dcs.Resolver
// Whether to show the copyright line in console or no.
DisableCopyright bool
// Session info of the authenticated user, use sessionMaker.NewSession function to fill this field.
Session sessionMaker.SessionConstructor
// Setting this field to true will lead to automatically fetch the reply_to_message for a new message update.
//
// Set to `false` by default.
AutoFetchReply bool
// Setting this field to true will lead to automatically fetch the entire reply_to_message chain for a new message update.
//
// Set to `false` by default.
FetchEntireReplyChain bool
// Code for the language used on the device's OS, ISO 639-1 standard.
SystemLangCode string
// Code for the language used on the client, ISO 639-1 standard.
ClientLangCode string
// Custom client device
Device *telegram.DeviceConfig
// Panic handles all the panics that occur during handler execution.
PanicHandler dispatcher.PanicHandler
// Error handles all the unknown errors which are returned by the handler callback functions.
ErrorHandler dispatcher.ErrorHandler
// Custom Middlewares
Middlewares []telegram.Middleware
// Custom Run() Middleware
// Can be used for floodWaiter package
// https://github.com/celestix/gotgproto/blob/beta/examples/middleware/main.go#L41
RunMiddleware func(
origRun func(ctx context.Context, f func(ctx context.Context) error) (err error),
ctx context.Context,
f func(ctx context.Context) (err error),
) (err error)
// A custom context to use for the client.
// If not provided, context.Background() will be used.
// Note: This context will be used for the entire lifecycle of the client.
Context context.Context
// AuthConversator is the interface for the authenticator.
// gotgproto.BasicConversator is used by default.
AuthConversator AuthConversator
// MigrationTimeout configures migration timeout.
MigrationTimeout time.Duration
// AckBatchSize is limit of MTProto ACK buffer size.
AckBatchSize int
// AckInterval is maximum time to buffer MTProto ACK.
AckInterval time.Duration
// RetryInterval is duration between send retries.
RetryInterval time.Duration
// MaxRetries is limit of send retries.
MaxRetries int
// ExchangeTimeout is timeout of every key exchange request.
ExchangeTimeout time.Duration
// DialTimeout is timeout of creating connection.
DialTimeout time.Duration
// CompressThreshold is a threshold in bytes to determine that message
// is large enough to be compressed using GZIP.
// If < 0, compression will be disabled.
// If == 0, default value will be used.
CompressThreshold int
}
type ClientType ¶
type ClientType struct {
// BotToken is the unique API Token for the bot you're trying to authorize, get it from @BotFather.
BotToken string
// Mobile number of the authenticating user.
Phone string
}
Type of client to login to, can be of 2 types: 1.) Bot (Fill BotToken in this case) 2.) User (Fill Phone in this case)
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
auth-using-api-base
command
|
|
|
echo-bot/memory_session
command
|
|
|
echo-bot/sqlite_session
command
|
|
|
middleware
module
|
|

