<p>Use <ahref="/method/account.initTakeoutSession">account.initTakeoutSession</a> to initialize a takeout session: pass the appropriate flags to enable usage of the corresponding methods, as described below. </p>
<p>When invoking the methods described below, each query must be wrapped using <ahref="/method/invokeWithTakeout">invokeWithTakeout</a>, with the <code>id</code> returned by <ahref="/method/account.initTakeoutSession">account.initTakeoutSession</a>. </p>
<p>After finishing the export, terminate the session using <ahref="/method/account.finishTakeoutSession">account.finishTakeoutSession</a>. </p>
<p>Some method calls require additional pagination using message ranges. </p>
<p>First of all, obtain a list of message ranges by invoking <ahref="/method/messages.getSplitRanges">messages.getSplitRanges</a> (wrapping it in an <ahref="/method/invokeWithTakeout">invokeWithTakeout</a> as usual). </p>
<p>Then, when invoking methods that require message range pagination, wrap the method using <ahref="/method/invokeWithMessagesRange">invokeWithMessagesRange</a>, before also wrapping it in an <ahref="/method/invokeWithTakeout">invokeWithTakeout</a> as usual. </p>
<p>Start by passing the first message range; continue passing the same message range while paginating using the <ahref="/api/offsets">usual <code>offset_*</code>, <code>limit</code>, etc parameters</a>; once there are no more results left, switch to the next message range, re-starting <code>offset_*</code>, <code>limit</code> pagination from the beginning.<br>
Repeat until you've finished all the message ranges that were returned by <ahref="/method/messages.getSplitRanges">messages.getSplitRanges</a>. </p>
<p>Here's an overview of the steps required to export account information. </p>
<p>All requests must be wrapped in an <ahref="/method/invokeWithTakeout">invokeWithTakeout</a> constructors, including <ahref="/method/upload.getFile">upload.getFile</a> calls to save files. </p>
<p>Unless otherwise specified, all requests do <strong>not</strong> require pagination using <ahref="#split-ranges">split ranges</a>. </p>
<ul>
<li>
<p>If the user wants to download messages from chats, groups or channels:</p>
<ul>
<li>
<p>First of all, fetch and save the dialog list using <ahref="#split-ranges">split ranges</a> and <ahref="/method/messages.getDialogs">messages.getDialogs</a>; at the beginning of each split range, make an initial request with all offsets set to <code>0</code> and <code>limit=1</code> to fetch total dialog <code>count</code> to display a proper progress bar. </p>
</li>
<li>
<p><ahref="#left-channels">Request and save info about left channels and supergroups</a> if the user wants to export channel and group messages. </p>
</li>
<li>
<p>For all dialogs, check if they match the dialog types chosen by the user, and if yes download all messages using <ahref="#split-ranges">split ranges</a> and <ahref="/method/messages.getHistory">messages.getHistory</a>; for each split range, make an initial request with all offsets set to <code>0</code> and <code>limit=1</code> to fetch the initial message count to display a proper progress bar.<br>
Use the single message returned by the initial <code>limit=1</code> request to also skip ranges that don't have any messages, because an empty <code>messages</code> vector or a single <ahref="/constructor/messageEmpty">messageEmpty</a> is returned.<br>
If the user also chose to download only messages within a specific date interval, skip ranges whose:</p>
<ul>
<li>Last message (returned by that same initial <code>limit=1</code> call) has a <code>date</code> bigger than the top of the specified date interval.</li>
<li>First message (returned by a new call to <ahref="/method/messages.getHistory">messages.getHistory</a> with <code>limit=1</code>, <code>offset_id=1</code>, <code>add_offset=-1</code>) has a <code>date</code> smaller than the bottom of the specified date interval. </li>
</ul>
<p>For each downloaded and saved message, also download and save all attached media, including <ahref="/api/custom-emoji">custom emojis</a> present in messages and captions, respecting the per-file download filesize limits imposed by the user. </p>
<p>If the user chose to download only their own messages, not messages sent by other users, use <ahref="/method/messages.search">messages.search</a> with <code>peer</code> set to <ahref="/constructor/inputPeerSelf">inputPeerSelf</a> instead of <ahref="/method/messages.getHistory">messages.getHistory</a>. </p>
</li>
</ul>
</li>
<li>
<p>If the user wants to export their <ahref="/api/stories">stories</a>:</p>
<ul>
<li>Use <ahref="/method/stories.getStoriesArchive">stories.getStoriesArchive</a> to fetch, download and store all posted stories, including <ahref="/api/custom-emoji">custom emojis</a> present in captions.</li>
</ul>
</li>
<li>
<p>If the user wants to export personal info:</p>
<ul>
<li>Invoke and store the result of <ahref="/method/users.getFullUser">users.getFullUser</a> with <ahref="/constructor/inputUserSelf">inputUserSelf</a>.</li>
</ul>
</li>
<li>
<p>If the user wants to export their own profile pictures:</p>
<ul>
<li>Invoke <ahref="/method/photos.getUserPhotos">photos.getUserPhotos</a> to fetch the list of and download all profile pictures.</li>
</ul>
</li>
<li>
<p>If the user wants to export their contact list: </p>
<ul>
<li>See <ahref="#contacts">here »</a></li>
</ul>
</li>
<li>
<p>If the user wants to export their sessions: </p>
<ul>
<li>Invoke and store the result of <ahref="/method/account.getAuthorizations">account.getAuthorizations</a> and <ahref="/method/account.getWebAuthorizations">account.getWebAuthorizations</a></li>
</ul>
</li>
<li>
<p>If the user wants to export any other data not mentioned above, like for example personal data related to new Telegram features, that do not have any specific takeout methods in the Takeout API yet.</p>
<ul>
<li>Use <ahref="/method/upload.getFile">upload.getFile</a> with <ahref="/constructor/inputTakeoutFileLocation">inputTakeoutFileLocation</a>; this will download a JSON file that will contain all personal data related to features that do not have a specialized takeout method yet.</li>
<p>This method does <strong>not</strong> require pagination using <ahref="#split-ranges">message ranges</a>. </p>
<p>Use <ahref="/method/contacts.getSaved">contacts.getSaved</a> to export the full contact list, see <ahref="/api/contacts#fetching-the-contact-list">here »</a> for another alternative method that may be used to fetch the full list of all contacts with a Telegram account, without using a takeout session.</p>