Kenny Cason Kenny Cason - 1 year ago 92
Python Question

Responding to new_session_created messages in the API

In my telegram client I go through the seemingly typical process of creating a valid session:

  1. Generate a random session_id

  2. Create an auth key

  3. Call

  4. Switch to the nearest DC, which involves a new random session_id and

  5. Attempt a
    command, which results in another switch to the
    correct DC

At various points in this process I receive
from the server indicating status and
, etc. This is expected and I am now decoding them properly. Some of these messages are of type
and look like this:

{'msg': {u'new_session_created': {u'first_msg_id': 6327252208304908288L, u'unique_id': -4911750325772918873L, u'server_salt': 6799011375684265530L}}, 'seqno': 1, 'msg_id': 6327252210221112321L}

My current server_salt is different than that in this message. Do I need to switch to using the new salt? What about unique_id, is that my new session_id or do I just ignore these messages?

After sorting all this out, what part of the session do I need to save for the next time the client starts up? The session_id, auth_key, auth_key_id?

Answer Source

Save and re-use this new salt you just received for your next requests in this session.

To do a subsequest login all you need is the session_id, recent_salt and the auth_key.

Auth_key_id is computed from the auth_key so you may, or may not choose to store it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download