Search code examples
sessiontelethon

TelegramClient always set default Telethon params in StringSession


When I build the TelegramClient via sqlite3 with giving options

client = TelegramClient(api_hash=api_hash, api_id=api_id, session=session_name, device_model='iPhone 13 Pro Max', system_version='Windows 10', app_version = '3.7.3')

than connect

await session.connect()

send code

client.send_code_request(phone=phone, force_sms=False)

and sign_in

await client.sign_in(phone=phone, code=code)

everything looks fine and in Authorization I have the parameters that I specified.

When I initialize the client via StringSession and same params - client connect with defaults Telethon Authorization params

client = TelegramClient(StringSession(), api_hash=api_hash, api_id=api_id, device_model='iPhone 13 Pro Max', system_version='Windows 10', app_version = '3.7.3')

than connect

await client.connect()

send code

result = await client.send_code_request(phone=phone, force_sms=False)

save session and hash for future use

string = StringSession.save(client.session)
phone_code_hash = result.phone_code_hash

after receiving code - connect and sign_in

client = TelegramClient(StringSession(string), api_id, api_hash)
await client.connect()
await client.sign_in(phone= phone, code=code, phone_code_hash=phone_code_hash)

What am I doing wrong?


Solution

  • StringSession does not pack those unnecessary information. it only has the info needed to authorize successfully..

    system_version and the rest must be passed on each connection in each client instance, it gets overridden with default values once you make a TelegramClient and not pass them, regardless of passing a StringSession.

    so you can't do it through the library, find a different way to pack the info and unpack them with and including the string session.