Skip to content

Instantly share code, notes, and snippets.

@xzone911
Forked from painor/README.MD
Created September 10, 2024 16:30
Show Gist options
  • Save xzone911/2aebfa5a996f911ead7b25090acf26e2 to your computer and use it in GitHub Desktop.
Save xzone911/2aebfa5a996f911ead7b25090acf26e2 to your computer and use it in GitHub Desktop.
import GramJS session into Telethon

Import GramJS session into Telethon

Requirements

GramJS version 2.X+

Telethon version 1.X+

This will print out python code that you can use to use the same session in telethon.

It will also print a telethon session string which you can use instead.

import { StringSession } from "telegram/sessions";
(async () => {
const stringSession = new StringSession("your gramjs session here (node only)");
await stringSession.load();
console.log(`
from telethon.sync import TelegramClient
from telethon.crypto import AuthKey
from telethon.sessions import StringSession
my_session = StringSession("")
my_session.set_dc(${stringSession.dcId},"${stringSession.serverAddress}",${stringSession.port})
my_session.auth_key = AuthKey(bytes.fromhex("${stringSession.authKey.getKey().toString("hex")}"))
client = TelegramClient(my_session, 1, "1")
client.start()
print(client.session.save())
print("me is",client.get_me())
`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment