mirror of
https://github.com/MarshalX/telegram-crawler.git
synced 2024-11-25 00:38:33 +01:00
201 lines
31 KiB
HTML
201 lines
31 KiB
HTML
<!DOCTYPE html>
|
|
<html class="">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Getting started with TDLib</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta property="description" content="TDLib is a fully functional Telegram client which takes care of all networking, local storage and data consistency details.…">
|
|
<meta property="og:title" content="Getting started with TDLib">
|
|
<meta property="og:image" content="">
|
|
<meta property="og:description" content="TDLib is a fully functional Telegram client which takes care of all networking, local storage and data consistency details.…">
|
|
<link rel="icon" type="image/svg+xml" href="/img/website_icon.svg?4">
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
|
|
<link rel="alternate icon" href="/img/favicon.ico" type="image/x-icon" />
|
|
<link href="/css/bootstrap.min.css?3" rel="stylesheet">
|
|
|
|
<link href="/css/telegram.css?234" rel="stylesheet" media="screen">
|
|
<style>
|
|
</style>
|
|
</head>
|
|
<body class="preload">
|
|
<div class="dev_page_wrap">
|
|
<div class="dev_page_head navbar navbar-static-top navbar-tg">
|
|
<div class="navbar-inner">
|
|
<div class="container clearfix">
|
|
<ul class="nav navbar-nav navbar-right hidden-xs"><li class="navbar-twitter"><a href="https://twitter.com/telegram" target="_blank" data-track="Follow/Twitter" onclick="trackDlClick(this, event)"><i class="icon icon-twitter"></i><span> Twitter</span></a></li></ul>
|
|
<ul class="nav navbar-nav">
|
|
<li><a href="//telegram.org/">Home</a></li>
|
|
<li class="hidden-xs"><a href="//telegram.org/faq">FAQ</a></li>
|
|
<li class="hidden-xs"><a href="//telegram.org/apps">Apps</a></li>
|
|
<li class=""><a href="/api">API</a></li>
|
|
<li class=""><a href="/mtproto">Protocol</a></li>
|
|
<li class=""><a href="/schema">Schema</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="container clearfix">
|
|
<div class="dev_page">
|
|
<div id="dev_page_content_wrap" class=" ">
|
|
<div class="dev_page_bread_crumbs"><ul class="breadcrumb clearfix"><li><a href="/tdlib" >Telegram Database Library</a></li><i class="icon icon-breadcrumb-divider"></i><li><a href="/tdlib/getting-started" >Getting started</a></li></ul></div>
|
|
<h1 id="dev_page_title">Getting started with TDLib</h1>
|
|
|
|
<div id="dev_page_content"><!-- scroll_nav -->
|
|
|
|
<p><strong>TDLib</strong> is a fully functional Telegram client which takes care of all networking, local storage and data consistency details. In this tutorial we describe the main concepts understanding of which is required for efficient TDLib usage.</p>
|
|
<h3><a class="anchor" name="tdlib-interface" href="#tdlib-interface"><i class="anchor-icon"></i></a>TDLib interface</h3>
|
|
<p>In this text, <em>Client</em> means an interface for interaction with a TDLib instance and <em>Application</em> means the program that uses TDLib to interact with Telegram.</p>
|
|
<p>The main TDLib API is fully-asyncronous. An <em>Application</em> can send a request to TDLib through <code>ClientManager.send</code> method and receive a response asynchronously through the <code>ClientManager.receive</code> method when it becomes available. The exact naming of these methods and the way in which requests are matched with responses is different for different TDLib interfaces, but the concept as a whole remains the same. For example, in <em>TDLib</em> <a href="https://core.telegram.org/tdlib/docs/td__json__client_8h.html"><em>JSON</em></a> interface these methods are called <code>td_send</code> and <code>td_receive</code>, and their <em>@extra</em> field must be used to match requests with the corresponding responses.</p>
|
|
<p>In a high-level interface used by an <em>Application</em> the matching of responses with corresponding requests is often automated and transformed by some wrapper into a call to a continuation, a callback, a Promise or a Future to simplify the handling of responses.</p>
|
|
<p>Aside from responses to requests, an <em>Application</em> receives a lot of important data through incoming <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_update.html"><em>updates</em></a>. <em>Updates</em> are used to pass new data from TDLib to the <em>Application</em> and often control the behavior of the <em>Application</em>, leaving no chance to implement something wrong. The correct handling of <em>updates</em> is crucial for creating an <em>Application</em> that is efficient and works correctly.</p>
|
|
<blockquote>
|
|
<p>You can find a <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html">list of all available TDLib API methods</a> in our web-documentation. You can also find the descriptions of all available TDLib methods and classes in the <a href="https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl">TDLIB API scheme</a>.</p>
|
|
<p>TDLib can be used from any programming language. You can find a lot of examples of TDLib-based frameworks in various programming languages in our <a href="https://github.com/tdlib/td/tree/master/example#readme">examples section</a>.</p>
|
|
</blockquote>
|
|
<h3><a class="anchor" name="tdlib-glossary" href="#tdlib-glossary"><i class="anchor-icon"></i></a>TDLib glossary</h3>
|
|
<p>This section describes the basic notions required for understanding the <em>TDLib API</em>. If you have used the TDLib-based <a href="https://core.telegram.org/bots/api">Telegram Bot API</a> most of them should be already familiar to you.</p>
|
|
<p>Telegram is a messenger, so the main object is a <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1message.html"><em>message</em></a>. Each <em>message</em> belongs to some <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat.html">chat</a> and has a unique identifier within that <em>chat</em>. <em>Messages</em> inside a <em>chat</em> must be sorted by that identifier. Telegram supports many different kinds of <em>messages</em>, so a <em>message</em> can have many different kinds of <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_message_content.html"><em>message content</em></a>. Currently there are more than 45 different kinds of <em>message content</em>, for example <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1message_text.html"><em>messageText</em></a> for text messages, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1message_photo.html"><em>messagePhoto</em></a> for photos, or <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1message_screenshot_taken.html"><em>messageScreenshotTaken</em></a> for notifications about screenshots taken by the other party.</p>
|
|
<p>A Telegram user is called <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1user.html"><em>user</em></a>. Each <em>user</em> has a unique identifier and a <em>first name</em>, and can also have an optional <em>last name</em>, <em>username</em> and <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1profile_photo.html"><em>profile photo</em></a> among other useful fields. <em>Bot</em> is a special <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1user_type_bot.html">type</a> of <em>user</em> which can be controlled through the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
|
|
<p>Each <em>chat</em> has <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_member.html"><em>members</em></a>, i.e. <em>users</em> that immediately receive all <em>messages</em> sent to the <em>chat</em>. Currently there are <strong>6</strong> possible <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_chat_member_status.html">chat member statuses</a> which describe different rights and restrictions a <em>user</em> can have in a <em>chat</em>, ranging from the <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_member_status_creator.html">owner of the chat</a> who has more rights in the <em>chat</em> than any other <em>user</em>, to a <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_member_status_banned.html">user banned in the chat</a> who is <em>banned</em> in the <em>chat</em> and can't return to it by self or even view <em>chat messages</em>, even if the <em>chat</em> is <em>public</em>.</p>
|
|
<p>As noted earlier, each <em>message</em> belongs to a <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat.html">chat</a>. Currently there are <strong>4</strong> different <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_chat_type.html">types</a> of <em>chats</em> on Telegram:</p>
|
|
<ul>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_type_private.html">Private chats</a> are ordinary one-to-one chats with another <em>user</em> (or with oneself in the case of the special “Saved messages” chat).</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_type_basic_group.html">Basic groups</a> are basic groups with 0-200 <em>members</em>. Every <em>basic group</em> <em>member</em> has their own copy of the message history, so new <em>basic group</em> <em>members</em> may not see older <em>messages</em> (unless another user forwards their own copy to them).</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_type_supergroup.html">Supergroups</a> are groups with up to 200000 <em>members</em> who share a common message history, so new <em>supergroup</em> <em>members</em> can see all the previously sent <em>messages</em> (unless this is explicitly forbidden by the <em>chat creator</em>). There are special kinds of <em>supergroups</em>, called <em>broadcast groups</em> and <em>channels</em>, which can have an unlimited number of members and where only the <em>chat creator</em> and some <em>chat administrators</em> can write. All other <em>chat members</em> can only read <em>messages</em> in <em>channel</em> and <em>broadcast group</em> chats.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_type_secret.html">Secret chats</a> are end-to-end encrypted one-to-one <em>chats</em> with another <em>user</em>, available only on the device which was used to initiate and accept the chat.</li>
|
|
</ul>
|
|
<p>Each chat has a unique identifier, a <em>title</em> and an optional <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_photo.html">chat photo</a>. Chats comprise sorted lists shown to the user, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_position.html">position</a> in which is determined, roughly speaking, by the time of latest activity. The correct order of chats in chat lists is maintained by TDLib, so the <em>Application</em> only needs to listen to updates that change the <code>chat.positions</code> field and sort all chats by the pair <code>(position.order, chat.id)</code> in a given <code>position.list</code>.</p>
|
|
<p><em>Messages</em>, <em>chat photos</em> and many other objects can have a <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1file.html"><em>file</em></a> inside of them. Each <em>file</em> has an identifier and may be available <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1local_file.html">locally</a> on a local storage or <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1remote_file.html">remotely</a> on a cloud server. A <em>file</em> can be usually <em>downloaded</em> to the local storage or <em>uploaded</em> to Telegram cloud servers.</p>
|
|
<p><em>Messages</em> with media content like <em>photos</em> or <em>videos</em> can have a short accompanying text called <em>caption</em>. The texts of text messages and media captions can contain fragments, which must be formatted in some unusual way. These fragments are called <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1text_entity.html"><em>text entities</em></a> and the combination of a <em>text</em> and its <em>entities</em> are referred together as a <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1formatted_text.html"><em>formatted text</em></a>.</p>
|
|
<p>TDLib sends a lot of important data to the <em>Application</em> through <em>updates</em>. For example, if there is a user unknown to the <em>Application</em>, or some data about a user has changed, then TDLib immediately sends an <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_user.html"><em>updateUser</em></a> to the <em>Application</em>.</p>
|
|
<blockquote>
|
|
<p>You can find list of all currently available updates <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_update.html">here »</a></p>
|
|
</blockquote>
|
|
<h3><a class="anchor" name="user-authorization" href="#user-authorization"><i class="anchor-icon"></i></a>User authorization</h3>
|
|
<p>Authorization is an example of a behavior, which is controlled by <em>TDLib</em> through <em>updates</em>. Whenever an action is required to proceed with user authorization, the <em>Application</em> receives an <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_authorization_state.html"><em>updateAuthorizationState</em></a> with the description of the current <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_authorization_state.html"><em>AuthorizationState</em></a>. The <em>Application</em> only needs to handle this <em>update</em> appropriately to correctly implement user authorization.</p>
|
|
<p>The first <em>authorization state</em> received by the <em>Application</em> is always of the type <code>authorizationStateWaitTdlibParameters</code>. When it is received, the <em>Application</em> must provide parameters for <em>TDLib</em> initialization by calling the <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1set_tdlib_parameters.html"><em>setTdlibParameters</em></a> method. In this method the <em>Application</em> will need to specify, among other parameters:</p>
|
|
<ul>
|
|
<li>api_id — <em>Application</em> identifier for accessing the Telegram API, which can be obtained at https://my.telegram.org.</li>
|
|
<li>api_hash — Hash of the <em>Application</em> identifier for accessing the Telegram API, which can be obtained at https://my.telegram.org.</li>
|
|
<li>database_directory — The path to the directory on the local disk where the <em>TDLib</em> database is to be stored; must point to a writable directory.</li>
|
|
<li>use_message_database — If set to true, the library will maintain a local cache of <em>chats</em> and <em>messages</em>.</li>
|
|
<li>use_secret_chats — If set to true, support for <em>secret chats</em> will be enabled.</li>
|
|
<li>system_language_code — IETF language tag of the <em>user</em>'s operating system language, like “en-GB”.</li>
|
|
<li>device_model — Model of the device the <em>Application</em> is being run on, like “iPhone Z”.</li>
|
|
</ul>
|
|
<p>After call to <code>setTdlibParameters</code> in case of success <em>Application</em> will receive <code>updateAuthorizationState</code> with new state and just needs to handle that update, nothing should be done explicitly. If <code>setTdlibParameters</code> fails, then authorization state is not changed and the <em>Application</em> must try to handle the current <em>authorization state</em> again.</p>
|
|
<p>If user isn't authorized yet, then some of <code>authorizationStateWaitPhoneNumber</code>, <code>authorizationStateWaitEmailAddress</code>, <code>authorizationStateWaitEmailCode</code>, <code>authorizationStateWaitCode</code>, <code>authorizationStateWaitRegistration</code> and <code>authorizationStateWaitPassword</code> <em>authorization states</em> may be received. After completing these authorization steps, the <em>Application</em> will receive <code>authorizationStateReady</code>, meaning that authorization was successful and ordinary requests can be sent now.</p>
|
|
<blockquote>
|
|
<p>You can find complete examples of <em>user</em> authorization in our <a href="https://github.com/tdlib/td/blob/b3ab664a18f8611f4dfcd3054717504271eeaa7a/example/java/org/drinkless/tdlib/example/Example.java#L97">Java</a> and <a href="https://github.com/tdlib/td/blob/b3ab664a18f8611f4dfcd3054717504271eeaa7a/example/csharp/TdExample.cs#L62">C#</a> examples.</p>
|
|
</blockquote>
|
|
<h3><a class="anchor" name="sending-a-message" href="#sending-a-message"><i class="anchor-icon"></i></a>Sending a message</h3>
|
|
<p>To send any kind of <em>message</em>, the <em>Application</em> needs to call the method <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1send_message.html">sendMessage</a> providing a <code>chat</code> identifier and the <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_input_message_content.html">content of the message to be sent</a>. For example, the <em>Application</em> can send a <em>text message</em> using <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_message_text.html">inputMessageText</a> class as input message content, a <em>photo</em> using <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_message_photo.html">inputMessagePhoto</a>, or a <em>location</em> using <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_message_location.html">inputMessageLocation</a>. The <em>Application</em> can use <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_file_local.html">inputFileLocal</a> as <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_input_file.html">InputFile</a> in these objects to send a local file from the local storage.</p>
|
|
<blockquote>
|
|
<p>You can find examples of sending a <em>text message</em> in our <a href="https://github.com/tdlib/td/blob/b3ab664a18f8611f4dfcd3054717504271eeaa7a/example/java/org/drinkless/tdlib/example/Example.java#L296">Java</a> and <a href="https://github.com/tdlib/td/blob/b3ab664a18f8611f4dfcd3054717504271eeaa7a/example/csharp/TdExample.cs#L207">C#</a> examples.</p>
|
|
</blockquote>
|
|
<h3><a class="anchor" name="handling-updates" href="#handling-updates"><i class="anchor-icon"></i></a>Handling updates</h3>
|
|
<p>All updates and responses to requests must be handled in the order they are received. Here is a list of the most important updates and how they must be handled:</p>
|
|
<ul>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_authorization_state.html">updateAuthorizationState</a> — The handling of this update is essential for correct <a href="#user-authorization">user authorization</a>.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_new_chat.html">updateNewChat</a> — This update is received whenever a new <em>chat</em> is discovered. This update is guaranteed to come before the <em>chat</em> identifier is returned to the <em>Application</em>. So, whenever an <em>Application</em> receives a <code>chat_id</code>, it never needs to use a <code>getChat</code> request to receive the <em>chat</em> object. Instead it must maintain a cache of <em>chats</em> received through this update and take all the necessary data about <em>chats</em> from this cache.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_user.html">updateUser</a> — This update is received whenever a new <em>user</em> has been discovered or some data about a known <em>user</em> has changed. This update is guaranteed to come before the <em>user</em> identifier is returned to the <em>Application</em>. So, whenever an <em>Application</em> receives a <code>user_id</code>, it never needs to use the <code>getUser</code> request to receive the <em>user</em> object. Instead it must maintain a cache of <em>users</em> received through this update and take all the necessary data about <em>users</em> from this cache.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_basic_group.html">updateBasicGroup</a> — This update is received whenever a new <em>basic group</em> has been discovered or some data about a known <em>basic group</em> has changed. This update is guaranteed to come before the <em>basic group</em> identifier is returned to the <em>Application</em>. So, whenever an <em>Application</em> receives a <code>basic_group_id</code>, it never needs to use the <code>getBasicGroup</code> request to receive the <code>basicGroup</code> object. Instead it must maintain a cache of <em>basic groups</em> received through this update and take all the necessary data about <em>basic groups</em> from this cache.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_supergroup.html">updateSupergroup</a> — This update is received whenever a new <em>supergroup</em> has been discovered or some data about a known <em>supergroup</em> has changed. This update is guaranteed to come before the <em>supergroup</em> identifier is returned to the <em>Application</em>. So, whenever an <em>Application</em> receives a <code>supergroup_id</code>, it never needs to use the <code>getSupergroup</code> request to receive the <em>supergroup</em> object. Instead it must maintain a cache of <em>supergroups</em> received through this update and take all the necessary data about <em>supergroups</em> from this cache.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_secret_chat.html">updateSecretChat</a> — This update is received whenever a new <em>secret chat</em> has been discovered or some data about a known <em>secret chat</em> has changed. This update is guaranteed to come before the <em>secret chat</em> identifier is returned to the <em>Application</em>. So, whenever an <em>Application</em> receives a <code>secret_chat_id</code>, it never needs to use the <code>getSecretChat</code> request to receive the <em>secret chat</em> object. Instead it must maintain a cache of <em>secret chats</em> received through this update and take all the necessary data about <em>secret chats</em> from this cache.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_new_message.html">updateNewMessage</a> — This update is received whenever a new <em>message</em> is added to a <em>chat</em>.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_message_send_succeeded.html">updateMessageSendSucceeded</a> — This update is received whenever a <em>message</em> is successfully sent.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_message_content.html">updateMessageContent</a> — This update is received whenever the <em>content</em> of a <em>message</em> changes.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_file.html">updateFile</a> — This update is received whenever information about a file is updated. The handling of this update is essential to follow the progress of files being downloaded or uploaded.</li>
|
|
<li><a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_title.html">updateChatTitle</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_photo.html">updateChatPhoto</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_permissions.html">updateChatPermissions</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_last_message.html">updateChatLastMessage</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_position.html">updateChatPosition</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_read_inbox.html">updateChatReadInbox</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_read_outbox.html">updateChatReadOutbox</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_action_bar.html">updateChatActionBar</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_draft_message.html">updateChatDraftMessage</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_message_sender.html">updateChatMessageSender</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_message_ttl.html">updateChatMessageTtl</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_notification_settings.html">updateChatNotificationSettings</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_pending_join_requests.html">updateChatPendingJoinRequests</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_reply_markup.html">updateChatReplyMarkup</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_theme.html">updateChatTheme</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_unread_mention_count.html">updateChatUnreadMentionCount</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_video_chat.html">updateChatVideoChat</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_default_disable_notification.html">updateChatDefaultDisableNotification</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_has_protected_content.html">updateChatHasProtectedContent</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_has_scheduled_messages.html">updateChatHasScheduledMessages</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_is_blocked.html">updateChatIsBlocked</a>, <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_chat_is_marked_as_unread.html">updateChatIsMarkedAsUnread</a> — These updates are received whenever some information about a <em>chat</em> changes, the <em>chats</em> cache must be updated accordingly</li>
|
|
</ul>
|
|
<blockquote>
|
|
<p>For a full list of currently available <em>updates</em> see the documentation for the <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_update.html">Update</a> class.</p>
|
|
<p>You can find an example of correct handling of some <em>updates</em> in our <a href="https://github.com/tdlib/td/blob/b3ab664a18f8611f4dfcd3054717504271eeaa7a/example/java/org/drinkless/tdlib/example/Example.java#L370">Java</a> example.</p>
|
|
</blockquote>
|
|
<h3><a class="anchor" name="getting-the-lists-of-chats" href="#getting-the-lists-of-chats"><i class="anchor-icon"></i></a>Getting the lists of chats</h3>
|
|
<p>Currently there are <strong>3</strong> different types of <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_chat_list.html">chat lists</a>:<br>- <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_list_main.html">Main chat list</a>.<br>- <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_list_archive.html">Archive chat list</a>.<br>- <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat_list_filter.html">A folder chat list</a>.</p>
|
|
<p>The <a href="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1chat.html#a40cebc843050f52a09e2ef471c9091e1">positions</a> of <em>chats</em> in <em>chat lists</em> are managed by TDLib, so the <em>Application</em> only needs to listen to <em>updates</em> that change the <code>chat.positions</code> field, maintain the list of all <em>chats</em>, sorted by the pair <code>(position.order, chat.id)</code> in descending order, and call <code>loadChats</code> only if more <em>chats</em> are needed. For optimal performance, the number of loaded <em>chats</em> is chosen by TDLib and can be smaller than the specified <em>limit</em>. If the <em>Application</em> needs more <em>chats</em>, it must send another <code>loadChats</code> request.</p>
|
|
<blockquote>
|
|
<p>You can find an example of retrieving the Main <em>chat list</em> in our <a href="https://github.com/tdlib/td/blob/b3ab664a18f8611f4dfcd3054717504271eeaa7a/example/java/org/drinkless/tdlib/example/Example.java#L248">Java</a> example.</p>
|
|
</blockquote>
|
|
<h3><a class="anchor" name="getting-chat-messages" href="#getting-chat-messages"><i class="anchor-icon"></i></a>Getting chat messages</h3>
|
|
<p>The <em>Application</em> can use the method <code>getChatHistory</code> to get <em>messages</em> in a <em>chat</em>. The <em>messages</em> will be returned in the reverse chronological order (i.e., in descending order of <code>message_id</code>). The <em>Application</em> can pass <code>from_message_id == 0</code> to get <em>messages</em> from the last <em>message</em>. To get more <em>messages</em> than can be returned in one response, the <em>Application</em> needs to pass the identifier of the last <em>message</em> it has received as <code>from_message_id</code> to next request. For optimal performance, the number of the returned <em>messages</em> is chosen by TDLib and can be smaller than the specified <em>limit</em>. If the <em>Application</em> needs more <em>messages</em>, it needs to adjust the <code>from_message_id</code> parameter and repeat the request.</p>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="footer_wrap">
|
|
<div class="footer_columns_wrap footer_desktop">
|
|
<div class="footer_column footer_column_telegram">
|
|
<h5>Telegram</h5>
|
|
<div class="footer_telegram_description"></div>
|
|
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.
|
|
</div>
|
|
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/faq">About</a></h5>
|
|
<ul>
|
|
<li><a href="//telegram.org/faq">FAQ</a></li>
|
|
<li><a href="//telegram.org/privacy">Privacy</a></li>
|
|
<li><a href="//telegram.org/press">Press</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/apps#mobile-apps">Mobile Apps</a></h5>
|
|
<ul>
|
|
<li><a href="//telegram.org/dl/ios">iPhone/iPad</a></li>
|
|
<li><a href="//telegram.org/android">Android</a></li>
|
|
<li><a href="//telegram.org/dl/web">Mobile Web</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/apps#desktop-apps">Desktop Apps</a></h5>
|
|
<ul>
|
|
<li><a href="//desktop.telegram.org/">PC/Mac/Linux</a></li>
|
|
<li><a href="//macos.telegram.org/">macOS</a></li>
|
|
<li><a href="//telegram.org/dl/web">Web-browser</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer_column footer_column_platform">
|
|
<h5><a href="/">Platform</a></h5>
|
|
<ul>
|
|
<li><a href="/api">API</a></li>
|
|
<li><a href="//translations.telegram.org/">Translations</a></li>
|
|
<li><a href="//instantview.telegram.org/">Instant View</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="footer_columns_wrap footer_mobile">
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/faq">About</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/blog">Blog</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/apps">Apps</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="/">Platform</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="https://twitter.com/telegram" target="_blank" data-track="Follow/Twitter" onclick="trackDlClick(this, event)">Twitter</a></h5>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="/js/main.js?47"></script>
|
|
<script src="/js/jquery.min.js?1"></script>
|
|
<script src="/js/bootstrap.min.js?1"></script>
|
|
|
|
<script>window.initDevPageNav&&initDevPageNav();
|
|
backToTopInit("Go up");
|
|
removePreloadInit();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|