<divclass="dev_page_bread_crumbs"><ulclass="breadcrumb clearfix"><li><ahref="/api">API</a></li><iclass="icon icon-breadcrumb-divider"></i><li><ahref="/api/gifs">Working with GIFs</a></li></ul></div>
<h1id="dev_page_title">Working with GIFs</h1>
<divid="dev_page_content"><!-- scroll_nav -->
<p>Telegram clients support displaying GIFs.</p>
<p>On Telegram, GIFs are actually MPEG4 (h264) videos without sound; if the user tries to upload an actual GIF file, it will be automatically converted to an MPEG4 file by the server. </p>
<p>On Telegram, GIFs are actually MPEG4 videos without sound; if the user tries to upload an actual GIF file, it will be automatically converted to an MPEG4 file by the server. </p>
<p>To upload a GIF, follow the usual <ahref="/api/files#uploading-files">file upload procedure»</a>, specifying the <ahref="/constructor/documentAttributeAnimated">documentAttributeAnimated</a>. </p>
<p>Uploading a GIF will automatically add it to the user's <ahref="#saved-gifs">saved GIFs list»</a>. </p>
<h4><aclass="anchor"href="#uploading-by-hash"id="uploading-by-hash"name="uploading-by-hash"><iclass="anchor-icon"></i></a>Uploading by hash</h4>
<p>For some types of documents like GIFs, <ahref="/method/messages.getDocumentByHash">messages.getDocumentByHash</a> can be used to search for the document on Telegram servers, instead of uploading it from scratch.<br>
See <ahref="/api/files#uploading-by-hash">here»</a> for the full procedure. </p>
<p>GIFs received in a chat may be added to (or removed from) the saved gifs list using <ahref="/method/messages.saveGif">messages.saveGif</a>. </p>
<p>Modifying the saved gifs list with the method indicated above will emit an <ahref="/constructor/updateSavedGifs">updateSavedGifs</a> update to other currently logged in sessions, which should trigger a call to <ahref="/method/messages.getSavedGifs">messages.getSavedGifs</a>, to refresh the locally cached list. </p>
<p><ahref="/method/messages.getSavedGifs">messages.getSavedGifs</a> should also be called when first logging in. </p>
<p><ahref="#uploading-gifs">Uploading»</a> a GIF will automatically add it to the saved gifs list. </p>
<p>The saved GIFs list should be displayed in the <ahref="#searching-gifs">GIF selection UI»</a>. </p>
<p>The maximum number of GIFs that may be added to the saved GIF list is specified by <ahref="/api/config#saved-gifs-limit-default">appConfig.saved_gifs_limit_default</a>/<ahref="/api/config#saved-gifs-limit-premium">appConfig.saved_gifs_limit_premium</a> for non-<ahref="/api/premium">Premium</a>/<ahref="/api/premium">Premium</a> users. </p>
<p>Trying to add one more GIF after the non-Premium limit is reached should open the Premium subscription modal.<br>
If the user adds one more GIF even after the non-Premium/Premium limit is reached, the server will automatically delete the oldest GIF, and the client should display a toast, notifying the user of this deletion. </p>
<p>Clients should implement a GIF selection/search UI that is almost identical to the <ahref="/api/stickers">sticker</a> search UI, featuring a search bar (with a list of <ahref="/api/emoji-categories">emoji categories</a>) followed (initially) by the list of <ahref="#saved-gifs">saved GIFs</a> that may be selected and sent by the user to the current chat. </p>
<p>Entering text in the search bar should replace the saved GIFs list with the results of the GIF search, which must be implemented as an <ahref="/api/bots/inline">inline query»</a> to the bot specified in <ahref="/constructor/config">config</a>.<code>gif_search_username</code>, with <code>peer</code>=<ahref="/constructor/inputPeerEmpty">inputPeerEmpty</a> and <code>query</code> set equal to the input of the user.<br>
Again, the GIF search UI should be almost identical to the <ahref="/api/stickers">sticker</a> search UI: even if inline bot queries are used, the usual inline query UI should <strong>not</strong> be used for the GIF search UI. </p>
<p>As mentioned above, the GIF search bar should also offer a list of categories to quickly filter results by a (list of) emojis, or by some other criteria, see <ahref="/api/emoji-categories">here»</a> for more info. </p>
<p>When an emoji category is selected, the search input bar should be disabled, and a search should be made, passing to <code>query</code> the first emoji of the selected emoji group.</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.