I need to convert telegram data to telethon session. How can i do this? I tried to find a solution, spent three days, but I didn't find anything
It's been nearly two years, but there's now a Python library called opentele created to do this.
Assuming you already have Python knowledge, please follow the steps below.
pip install opentele
tdata
folder that is already authorized (have at least one logged-in account).tdata
folder on Windows is located at %appdata%\Telegram Desktop\tdata
. from opentele.td import TDesktop from opentele.tl import TelegramClient from opentele.api import API, UseCurrentSession, CreateNewSession import asyncio
async def main(): # PUT EXAMPLE CODE HERE asyncio.run(main())
tdata
folder into a TDesktop
object: # Load TDesktop client from tdata folder tdataFolder = r"C:\Users\<username>\AppData\Roaming\Telegram Desktop\tdata" tdesk = TDesktop(tdataFolder) # Check if we have loaded any accounts assert tdesk.isLoaded()
There are two ways you can do this, either by using the current session or creating (login to) a new session.
# flag=UseCurrentSession # # Convert TDesktop to Telethon using the current session. client = await tdesk.ToTelethon(session="telethon.session", flag=UseCurrentSession)
# flag=CreateNewSession # # Convert TDesktop to Telethon by creating a new session. # CreateNewSession will use the current session (in tdata folder) to authorize a new session using QR Login. # If 2FA is enabled for this account, you must specify the password via the password argument. # This is of course slower than UseCurrentSession. client = await tdesk.ToTelethon(session="telethon.session", flag=CreateNewSession)
# Connect and print all logged-in sessions of this client.
# Telethon will save the session to telethon.session on creation.
await client.connect()
await client.PrintSessions()
from opentele.td import TDesktop
from opentele.tl import TelegramClient
from opentele.api import API, UseCurrentSession
import asyncio
async def main():
# Load TDesktop client from tdata folder
tdataFolder = r"C:\Users\<username>\AppData\Roaming\Telegram Desktop\tdata"
tdesk = TDesktop(tdataFolder)
# Check if we have loaded any accounts
assert tdesk.isLoaded()
# flag=UseCurrentSession
#
# Convert TDesktop to Telethon using the current session.
client = await tdesk.ToTelethon(session="telethon.session", flag=UseCurrentSession)
# Connect and print all logged-in sessions of this client.
# Telethon will save the session to telethon.session on creation.
await client.connect()
await client.PrintSessions()
asyncio.run(main())
telethon.session
file. telethon.session
with telethon, or use it directly with opentele - which is recommended because you don't need your own API_ID
and API_HASH
, the library by default will use Official Telegram API.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.