Responding to new_session_created messages in the telegram.org API
<p>In my telegram client I go through the seemingly typical process of creating a valid session:</p>

<ol>
<li>Generate a random session_id</li>
<li>Create an auth key</li>
<li>Call <code>initConnection</code> with <code>getNearestDc</code></li>
<li>Switch to the nearest DC, which involves a new random session_id and
auth_key</li>
<li>Attempt a <code>sendCode</code> command, which results in another switch to the
correct DC</li>
</ol>

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

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

<p>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?</p>

<p>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?</p>

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

<p>To do a subsequest login all you need is the <code>session_id</code>, <code>recent_salt</code> and the <code>auth_key</code>.</p>

<p><code>Auth_key_id</code> is computed from the <code>auth_key</code> so you may, or may not choose to store it</p>

python telegram