Skip to content

Instantly share code, notes, and snippets.

@painor
Last active August 28, 2022 21:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save painor/0eabf0095d18bdc49ec0d2220998a38d to your computer and use it in GitHub Desktop.
Save painor/0eabf0095d18bdc49ec0d2220998a38d 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