Documentation
¶
Index ¶
- Constants
- Variables
- func AsBot(botToken string) clientType
- func AsUser(phoneNumber string) clientType
- func ClientTypeBot(botToken string) clientType
- func ClientTypePhone(phoneNumber string) clientType
- func SendAuthStatus(conversator AuthConversator, event AuthStatusEvent)
- func SendAuthStatusWithRetrials(conversator AuthConversator, event AuthStatusEvent, attemptsLeft int)
- func Simple() clientType
- type AuthConversator
- type AuthStatus
- type AuthStatusEvent
- type Client
- type ClientOpts
- type Flow
- type KeyboardBuilder
- func (k *KeyboardBuilder) Build() tg.ReplyMarkupClass
- func (k *KeyboardBuilder) BuildReply(opts ...ReplyOptions) tg.ReplyMarkupClass
- func (k *KeyboardBuilder) Button(text, data string) *KeyboardBuilder
- func (k *KeyboardBuilder) Copy(text, copyText string) *KeyboardBuilder
- func (k *KeyboardBuilder) Next() *KeyboardBuilder
- func (k *KeyboardBuilder) RequestGeo(text string) *KeyboardBuilder
- func (k *KeyboardBuilder) RequestPhone(text string) *KeyboardBuilder
- func (k *KeyboardBuilder) RequestPoll(text string, quiz bool) *KeyboardBuilder
- func (k *KeyboardBuilder) Switch(text string, samePeer bool, query string) *KeyboardBuilder
- func (k *KeyboardBuilder) Text(text string) *KeyboardBuilder
- func (k *KeyboardBuilder) URL(text, url string) *KeyboardBuilder
- func (k *KeyboardBuilder) WebApp(text, url string) *KeyboardBuilder
- type ReplyOptions
Constants ¶
const VERSION = "v1.0.0-beta23"
Variables ¶
var ( AuthStatusPhoneAsked = AuthStatusEvent("phone number asked") AuthStatusPhoneRetrial = AuthStatusEvent("phone number validation retrial") AuthStatusPhoneFailed = AuthStatusEvent("phone number validation failed") AuthStatusPhoneCodeAsked = AuthStatusEvent("phone otp asked") AuthStatusPhoneCodeVerified = AuthStatusEvent("phone code verified") AuthStatusPhoneCodeRetrial = AuthStatusEvent("phone code verification retrial") AuthStatusPhoneCodeFailed = AuthStatusEvent("phone code verification failed") AuthStatusPasswordAsked = AuthStatusEvent("2fa password asked") AuthStatusPasswordRetrial = AuthStatusEvent("2fa password verification retrial") AuthStatusPasswordFailed = AuthStatusEvent("2fa password verification failed") AuthStatusSuccess = AuthStatusEvent("authentification success") )
Functions ¶
func AsUser ¶
func AsUser(phoneNumber string) clientType
AsUser is a simpler alias for ClientTypePhone
func ClientTypeBot ¶
func ClientTypeBot(botToken string) clientType
func ClientTypePhone ¶
func ClientTypePhone(phoneNumber string) clientType
func SendAuthStatus ¶
func SendAuthStatus(conversator AuthConversator, event AuthStatusEvent)
func SendAuthStatusWithRetrials ¶
func SendAuthStatusWithRetrials(conversator AuthConversator, event AuthStatusEvent, attemptsLeft int)
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)
// SendAuthStatus is called to inform the user about
// the status of the auth process.
// attemptsLeft is the number of attempts left for the user
// to enter the input correctly for the current auth status.
AuthStatus(authStatus AuthStatus)
}
AuthConversator is an interface for asking user for auth information.
func BasicConversator ¶
func BasicConversator() AuthConversator
type AuthStatus ¶
type AuthStatus struct {
Event AuthStatusEvent
AttemptsLeft int
}
type AuthStatusEvent ¶
type AuthStatusEvent string
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
ConversationManager *conversation.Manager
// 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
// NoAutoAuth is a flag to disable automatic authentication
// if the current session is invalid.
NoAutoAuth bool
// NoUpdates is a flag to disable updates.
NoUpdates bool
*telegram.Client
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(apiID int, apiHash string, clientType clientType, opts *ClientOpts) (*Client, error)
NewClient creates a new gotg 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 session.NewSession function to fill this field.
Session session.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
// DispatcherMiddlewares are middleware handlers that run before user-added handlers.
// These are automatically added to groups 0, 1, 2, ... in order.
// Useful for i18n, authentication, logging, etc.
DispatcherMiddlewares []dispatcher.Handler
// Custom Run() Middleware
// Can be used for floodWaiter package
// https://github.com/pageton/gotg/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.
// gotg.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
// NoAutoAuth is a flag to disable automatic authentication
// if the current session is invalid.
NoAutoAuth bool
// NoUpdates is a flag to disable updates.
NoUpdates bool
// SendCodeOptions allows overriding AuthSendCode behavior.
SendCodeOptions *auth.SendCodeOptions
// Only usable by Users not bots
// PeersFromDialogs is a flag to enable adding peers fetched
// from dialogs to memory/database on startup
PeersFromDialogs bool
// WaitOnPeersFromDialogs is a flag to enable waiting on
// PeersFromDialogs to complete during client start
WaitOnPeersFromDialogs bool
}
type KeyboardBuilder ¶
type KeyboardBuilder struct {
// contains filtered or unexported fields
}
KeyboardBuilder is a fluent interface for building Telegram keyboards.
func (*KeyboardBuilder) Build ¶
func (k *KeyboardBuilder) Build() tg.ReplyMarkupClass
Build builds an inline keyboard (for use with inline buttons).
func (*KeyboardBuilder) BuildReply ¶
func (k *KeyboardBuilder) BuildReply(opts ...ReplyOptions) tg.ReplyMarkupClass
BuildReply builds a reply keyboard (for regular buttons).
func (*KeyboardBuilder) Button ¶
func (k *KeyboardBuilder) Button(text, data string) *KeyboardBuilder
Button adds a callback button with data (for inline keyboards).
func (*KeyboardBuilder) Copy ¶
func (k *KeyboardBuilder) Copy(text, copyText string) *KeyboardBuilder
Copy adds a copy button that copies text to clipboard.
func (*KeyboardBuilder) Next ¶
func (k *KeyboardBuilder) Next() *KeyboardBuilder
Next moves to the next row.
func (*KeyboardBuilder) RequestGeo ¶
func (k *KeyboardBuilder) RequestGeo(text string) *KeyboardBuilder
RequestGeo adds a button that requests the user's location.
func (*KeyboardBuilder) RequestPhone ¶
func (k *KeyboardBuilder) RequestPhone(text string) *KeyboardBuilder
RequestPhone adds a button that requests the user's phone number.
func (*KeyboardBuilder) RequestPoll ¶
func (k *KeyboardBuilder) RequestPoll(text string, quiz bool) *KeyboardBuilder
RequestPoll adds a button that creates a poll.
func (*KeyboardBuilder) Switch ¶
func (k *KeyboardBuilder) Switch(text string, samePeer bool, query string) *KeyboardBuilder
Switch adds a switch to inline button. If samePeer is true, the inline query will be sent in the current chat.
func (*KeyboardBuilder) Text ¶
func (k *KeyboardBuilder) Text(text string) *KeyboardBuilder
Text adds a simple text button (for reply keyboards).
func (*KeyboardBuilder) URL ¶
func (k *KeyboardBuilder) URL(text, url string) *KeyboardBuilder
URL adds a URL button.
func (*KeyboardBuilder) WebApp ¶
func (k *KeyboardBuilder) WebApp(text, url string) *KeyboardBuilder
WebApp adds a web app button.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
auth-using-api-base
command
|
|
|
auth-using-tdata
command
|
|
|
conversation-bot
command
|
|
|
conversation-media
command
|
|
|
dispatcher-bot
command
|
|
|
downloader
command
|
|
|
downloader-v2
command
|
|
|
echo-bot/memory_session
command
|
|
|
echo-bot/sqlite_session
command
|
|
|
format-example
command
|
|
|
i18n-bot
command
|
|
|
Package parsemode provides robust parsing for Telegram message formatting.
|
Package parsemode provides robust parsing for Telegram message formatting. |

