session

package
v0.0.0-...-082db63 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeGramjsSession

func DecodeGramjsSession(hx string) (*session.Data, error)

func DecodePyrogramSession

func DecodePyrogramSession(hx string) (*session.Data, error)

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 AuthKey

type AuthKey struct {
	Value Key
	ID    [8]byte
}

AuthKey is a Key with cached id.

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

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

type Key

type Key [256]byte

func (Key) ID

func (k Key) ID() [8]byte

ID returns auth_key_id.

func (Key) WithID

func (k Key) WithID() AuthKey

WithID creates new AuthKey from Key.

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

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

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

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

Jump to

Keyboard shortcuts

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