Documentation
¶
Index ¶
- func DecodeGramjsSession(hx string) (*session.Data, error)
- func DecodePyrogramSession(hx string) (*session.Data, error)
- func NewSessionStorage(ctx context.Context, sessionType SessionConstructor, inMemory bool) (*storage.PeerStorage, telegram.SessionStorage, error)
- type AuthKey
- type GramjsSessionConstructor
- type JsonFileSessionConstructor
- type Key
- type PyrogramSessionConstructor
- type SessionConstructor
- type SessionStorage
- type SimpleSessionConstructor
- type SqlSessionConstructor
- type StringSessionConstructor
- type TdataSessionConstructor
- type TelethonSessionConstructor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSessionStorage ¶
func NewSessionStorage(ctx context.Context, sessionType SessionConstructor, inMemory bool) (*storage.PeerStorage, telegram.SessionStorage, error)
NewSessionStorage creates a session storage for Telegram client authentication.
It creates both a PeerStorage (for peer caching) and a SessionStorage (for persisting auth session data like auth keys, DC ID, etc.).
Parameters:
- ctx: Context for session operations
- sessionType: Session type to load (SqlSession, MemorySession, StringSession)
- inMemory: If true, only in-memory storage is used (no database persistence)
Returns:
- PeerStorage: For caching peers (users, chats, channels)
- SessionStorage: For storing Telegram session data
- error: If session loading fails
Example:
// Create session with SQLite database
peerStorage, sessionStorage, err := session.NewSessionStorage(
ctx,
session.SqlSession(sqlite.Open("telegram.db")),
false,
)
// Create in-memory only session
peerStorage, sessionStorage, err := session.NewSessionStorage(
ctx,
session.MemorySession(),
true,
)
Types ¶
type GramjsSessionConstructor ¶
type GramjsSessionConstructor struct {
// contains filtered or unexported fields
}
func GramjsSession ¶
func GramjsSession(value string) *GramjsSessionConstructor
GramjsSession creates a constructor for Gram.js string session format.
Gram.js session strings use a specific hex encoding format.
Parameters:
- value: The Gram.js session string to encode
Returns:
- A constructor that implements SessionConstructor interface
Example:
constructor := session.GramjsSession("v12345...67890abcdef")
func (*GramjsSessionConstructor) Name ¶
func (s *GramjsSessionConstructor) Name(name string) *GramjsSessionConstructor
type JsonFileSessionConstructor ¶
type JsonFileSessionConstructor struct {
// contains filtered or unexported fields
}
func JsonFileSession ¶
func JsonFileSession(filePath string) *JsonFileSessionConstructor
JsonFileSession creates a constructor for JSON file session format.
This allows loading and saving sessions from a local JSON file.
Parameters:
- filePath: Path to the JSON session file
Returns:
- A constructor that implements SessionConstructor interface
Example:
constructor := session.JsonFileSession("/path/to/session.json")
func (*JsonFileSessionConstructor) Name ¶
func (s *JsonFileSessionConstructor) Name(name string) *JsonFileSessionConstructor
type PyrogramSessionConstructor ¶
type PyrogramSessionConstructor struct {
// contains filtered or unexported fields
}
func PyrogramSession ¶
func PyrogramSession(value string) *PyrogramSessionConstructor
PyrogramSession creates a constructor for Pyrogram string session format.
Pyrogram session strings use a specific hex encoding format ( '>BI?256sQ?' prefix followed by encoded session data).
Parameters:
- value: The Pyrogram session string to encode
Returns:
- A constructor that implements SessionConstructor interface
Example:
constructor := session.PyrogramSession("v12345...67890abcdef")
func (*PyrogramSessionConstructor) Name ¶
func (s *PyrogramSessionConstructor) Name(name string) *PyrogramSessionConstructor
type SessionConstructor ¶
type SessionConstructor interface {
// contains filtered or unexported methods
}
type SessionStorage ¶
type SessionStorage struct {
// contains filtered or unexported fields
}
SessionStorage implements SessionStorage for file system as file stored in Path.
func (*SessionStorage) LoadSession ¶
func (f *SessionStorage) LoadSession(_ context.Context) ([]byte, error)
LoadSession loads session from file.
func (*SessionStorage) StoreSession ¶
func (f *SessionStorage) StoreSession(_ context.Context, data []byte) error
StoreSession stores session to sqlite storage.
type SimpleSessionConstructor ¶
type SimpleSessionConstructor int8
func SimpleSession ¶
func SimpleSession() *SimpleSessionConstructor
type SqlSessionConstructor ¶
type SqlSessionConstructor struct {
// contains filtered or unexported fields
}
func SqlSession ¶
func SqlSession(dialector gorm.Dialector) *SqlSessionConstructor
SqlSession creates a constructor for SQLite-based session storage.
This allows loading and saving sessions from a SQLite database file.
Parameters:
- dialector: The GORM dialector for database connection
Returns:
- A constructor that implements SessionConstructor interface
Example:
dialector := sqlite.Open("telegram.db")
constructor := session.SqlSession(dialector)
type StringSessionConstructor ¶
type StringSessionConstructor struct {
// contains filtered or unexported fields
}
func StringSession ¶
func StringSession(value string) *StringSessionConstructor
StringSession creates a constructor for plain string session format.
This allows using simple string-encoded session data without hex encoding.
Parameters:
- value: The session string value
Returns:
- A constructor that implements SessionConstructor interface
Example:
constructor := session.StringSession(sessionString)
func (*StringSessionConstructor) Name ¶
func (s *StringSessionConstructor) Name(name string) *StringSessionConstructor
type TdataSessionConstructor ¶
type TdataSessionConstructor struct {
Account tdesktop.Account
// contains filtered or unexported fields
}
func TdataSession ¶
func TdataSession(account tdesktop.Account) *TdataSessionConstructor
TdataSession creates a constructor for Telegram Desktop session format.
Telegram Desktop session uses a specific binary format for session storage.
Parameters:
- account: The tdesktop.Account containing session data
Returns:
- A constructor that implements SessionConstructor interface
Example:
constructor := session.TdataSession(account)
func (*TdataSessionConstructor) Name ¶
func (s *TdataSessionConstructor) Name(name string) *TdataSessionConstructor
type TelethonSessionConstructor ¶
type TelethonSessionConstructor struct {
// contains filtered or unexported fields
}
func TelethonSession ¶
func TelethonSession(value string) *TelethonSessionConstructor
TelethonSession creates a constructor for Telethon string session format.
Telethon session strings use a specific hex encoding format ( '>BI?256sQ?' prefix followed by encoded session data).
Parameters:
- value: The Telethon session string to encode
Returns:
- A constructor that implements SessionConstructor interface
Example:
constructor := session.TelethonSession("v12345...67890abcdef")
func (*TelethonSessionConstructor) Name ¶
func (s *TelethonSessionConstructor) Name(name string) *TelethonSessionConstructor