<p>Telegram allows importing messages and media from foreign chat apps.</p>
<blockquote>
<p>Note: This article is intended for MTProto API developers. If you're looking for a way to move history from other chat apps into Telegram, check out the related <ahref="https://telegram.org/blog/move-history">Telegram blog post</a>.</p>
</blockquote>
<h3><aclass="anchor"href="#1-validate-the-chat-export-file"id="1-validate-the-chat-export-file"name="1-validate-the-chat-export-file"><iclass="anchor-icon"></i></a>1. Validate the chat export file</h3>
<p>The import process begins by calling <ahref="/method/messages.checkHistoryImport">messages.checkHistoryImport</a>, passing to <code>import_head</code> up to 100 lines of the chat export file, starting from the beginning of the file.</p>
<p>The returned constructor contains information about the exported chat, including its title or type.
If the <code>pm</code> flag is set, the chat export file was generated from a private chat.
If the <code>group</code> flag is set, the chat export file was generated from a group chat.
If neither the <code>pm</code> or <code>group</code> flags are set, the specified chat export was generated from a chat of unknown type.</p>
<h3><aclass="anchor"href="#2-choosing-a-destination-telegram-chat"id="2-choosing-a-destination-telegram-chat"name="2-choosing-a-destination-telegram-chat"><iclass="anchor-icon"></i></a>2. Choosing a destination Telegram chat</h3>
<p>Using <ahref="/method/messages.checkHistoryImportPeer">messages.checkHistoryImportPeer</a>, check whether chat history exported from another chat app can be imported into a specific Telegram <code>peer</code>, chosen by the user.<br>
Typically, history imports are allowed for private chats with a mutual contact or <ahref="/api/channel">supergroups</a> with <ahref="/api/rights"><code>change_info</code> administrator rights »</a>.</p>
<p>If the check succeeds, and no RPC errors are returned, a <ahref="/type/messages.CheckedHistoryImportPeer">messages.CheckedHistoryImportPeer</a> constructor will be returned, with a confirmation text to be shown to the user in a confirmation prompt.<br>
Upon final user confirmation, <ahref="#3-initialize-the-import">the import process is initialized</a>. </p>
<h3><aclass="anchor"href="#3-initialize-the-import"id="3-initialize-the-import"name="3-initialize-the-import"><iclass="anchor-icon"></i></a>3. Initialize the import</h3>
<p>Use <ahref="/method/messages.initHistoryImport">messages.initHistoryImport</a> to initialize the import process, passing the following parameters: </p>
<ul>
<li><code>peer</code> - The Telegram chat where the history should be imported.</li>
<li><code>file</code> - The chat export file.</li>
<li><code>media_count</code> - The number of media files associated with the export, to be uploaded in <ahref="#4-uploading-media">the next step</a>. </li>
<p>Use <ahref="/method/messages.uploadImportedMedia">messages.uploadImportedMedia</a> to upload media files eventually associated with the chat export.<br>
<code>import_id</code> is the <code>id</code> contained in the <ahref="/constructor/messages.historyImport">messages.historyImport</a> constructor, returned by <ahref="/method/messages.initHistoryImport">messages.initHistoryImport</a><ahref="#3-initialize-the-import">in the previous step</a>. </p>
<h3><aclass="anchor"href="#5-finalize-the-import"id="5-finalize-the-import"name="5-finalize-the-import"><iclass="anchor-icon"></i></a>5. Finalize the import</h3>
<p>Finally, invoke <ahref="/method/messages.startHistoryImport">messages.startHistoryImport</a> to complete the <ahref="/api/import">history import process</a>, importing all messages into the chat.<br>
As usual, <code>import_id</code> is the <code>id</code> contained in the <ahref="/constructor/messages.historyImport">messages.historyImport</a> constructor, returned by <ahref="/method/messages.initHistoryImport">messages.initHistoryImport</a>. </p>
<p>Imported messages will show in the chat history as <ahref="/constructor/message">messages</a> containing a <code>fwd_from</code><ahref="/constructor/messageFwdHeader">messageFwdHeader</a> constructor with the <code>imported</code> flag, and should be appropriately marked in the UI as messages imported from a foreign chat app.</p></div>
</div>
</div>
</div>
<divclass="footer_wrap">
<divclass="footer_columns_wrap footer_desktop">
<divclass="footer_column footer_column_telegram">
<h5>Telegram</h5>
<divclass="footer_telegram_description"></div>
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.