Go API
Package: github.com/mtgo-labs/session-converter
Import as tgconv:
import tgconv "github.com/mtgo-labs/session-converter"Decode
func Decode(str string) (*Session, Format, error)Auto-detects the format and decodes the session string. Returns the parsed Session, the detected Format, and an error.
session, format, err := tgconv.Decode(sessionString)
if err != nil {
log.Fatal(err)
}
fmt.Println("Detected:", format)DecodeFormat
func DecodeFormat(str string, format Format) (*Session, error)Decodes a session string in a known format, skipping auto-detection. Faster than Decode when the source format is already known.
Encode
func Encode(s *Session, format Format) (string, error)Encodes a Session into the specified format.
Convert
func Convert(str string, to Format) (string, error)Decodes (auto-detecting the source format) and re-encodes to the target format in one call.
pyrogramString, err := tgconv.Convert(sessionString, tgconv.FormatPyrogram)ConvertFrom
func ConvertFrom(str string, from, to Format) (*Session, error)Decodes from a known source format and re-encodes. Skips auto-detection.
DetectFormat
func DetectFormat(str string) FormatIdentifies the format without fully decoding. Returns an empty Format if detection fails. See Format Reference — Auto-detection.
ReadSQLite
func ReadSQLite(path string) (*Session, SQLiteFormat, error)Auto-detects whether a SQLite file is a Telethon or Pyrogram session file and extracts the session data. Uses pure-Go SQLite (modernc.org/sqlite), opens read-only, and never modifies the file.
session, sqliteFmt, err := tgconv.ReadSQLite("myaccount.session")
str, _ := tgconv.Encode(session, tgconv.FormatTelethon)Session
type Session struct {
DCID int // data center ID (1-5)
ServerAddress string // IP address or hostname
Port int // server port
AuthKey []byte // 256-byte MTProto authorization key
AppID int32 // API ID from my.telegram.org
TestMode bool // connected to test servers
UserID int64 // authenticated user/bot ID
IsBot bool // whether the account is a bot
}Not every field is populated by every format — the auth key and DC ID are always present. See Field availability.
Format
type Format stringIdentifies a session string encoding format. Constants: FormatTelethon, FormatPyrogram, FormatGramJS, FormatMtcute, FormatMTKruto, FormatGogram, FormatGotgproto.
AllFormats lists every supported format as a slice.
SQLiteFormat
type SQLiteFormat stringConstants: SQLiteTelethon, SQLitePyrogram.
