telegram-crawler/data/web/blogfork.telegram.org/api/paid-media.html
2024-09-23 18:02:35 +00:00

190 lines
19 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html class="">
<head>
<meta charset="utf-8">
<title>Paid media</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="description" content="Content creators can accept Stars by publishing paid photos or videos on their channels. Subscribers will be allowed to view such posts only after paying the author to unlock them.">
<meta property="og:title" content="Paid media">
<meta property="og:image" content="">
<meta property="og:description" content="Content creators can accept Stars by publishing paid photos or videos on their channels. Subscribers will be allowed to view such posts only after paying the author to unlock them.">
<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?241" 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="active"><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="/api" >API</a></li><i class="icon icon-breadcrumb-divider"></i><li><a href="/api/paid-media" >Paid media</a></li></ul></div>
<h1 id="dev_page_title">Paid media</h1>
<div id="dev_page_content"><!-- scroll_nav -->
<p>Content creators can accept <a href="/api/stars">Stars</a> by publishing <strong>paid photos or videos</strong> on their channels. Subscribers will be allowed to view such posts only after paying the author to unlock them. </p>
<p>Creators can then <a href="/api/stars#withdrawing-revenue">withdraw Stars using the Toncoin cryptocurrency »</a>, or use them to <a href="/api/stars#paying-for-ads">advertise their channel</a> and get even more subscribers all of this with next to <strong>0 commission</strong> from Telegram.</p>
<h3><a class="anchor" href="#posting-paid-media" id="posting-paid-media" name="posting-paid-media"><i class="anchor-icon"></i></a>Posting paid media</h3>
<pre><code><a href='/constructor/channelFull'>channelFull</a>#bbab348d flags:<a href='/type/%23'>#</a> can_view_participants:flags.3?<a href='/constructor/true'>true</a> can_set_username:flags.6?<a href='/constructor/true'>true</a> can_set_stickers:flags.7?<a href='/constructor/true'>true</a> hidden_prehistory:flags.10?<a href='/constructor/true'>true</a> can_set_location:flags.16?<a href='/constructor/true'>true</a> has_scheduled:flags.19?<a href='/constructor/true'>true</a> can_view_stats:flags.20?<a href='/constructor/true'>true</a> blocked:flags.22?<a href='/constructor/true'>true</a> flags2:<a href='/type/%23'>#</a> can_delete_channel:flags2.0?<a href='/constructor/true'>true</a> antispam:flags2.1?<a href='/constructor/true'>true</a> participants_hidden:flags2.2?<a href='/constructor/true'>true</a> translations_disabled:flags2.3?<a href='/constructor/true'>true</a> stories_pinned_available:flags2.5?<a href='/constructor/true'>true</a> view_forum_as_messages:flags2.6?<a href='/constructor/true'>true</a> restricted_sponsored:flags2.11?<a href='/constructor/true'>true</a> can_view_revenue:flags2.12?<a href='/constructor/true'>true</a> paid_media_allowed:flags2.14?<a href='/constructor/true'>true</a> can_view_stars_revenue:flags2.15?<a href='/constructor/true'>true</a> id:<a href='/type/long'>long</a> about:<a href='/type/string'>string</a> participants_count:flags.0?<a href='/type/int'>int</a> admins_count:flags.1?<a href='/type/int'>int</a> kicked_count:flags.2?<a href='/type/int'>int</a> banned_count:flags.2?<a href='/type/int'>int</a> online_count:flags.13?<a href='/type/int'>int</a> read_inbox_max_id:<a href='/type/int'>int</a> read_outbox_max_id:<a href='/type/int'>int</a> unread_count:<a href='/type/int'>int</a> chat_photo:<a href='/type/Photo'>Photo</a> notify_settings:<a href='/type/PeerNotifySettings'>PeerNotifySettings</a> exported_invite:flags.23?<a href='/type/ExportedChatInvite'>ExportedChatInvite</a> bot_info:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/BotInfo'>BotInfo</a>&gt; migrated_from_chat_id:flags.4?<a href='/type/long'>long</a> migrated_from_max_id:flags.4?<a href='/type/int'>int</a> pinned_msg_id:flags.5?<a href='/type/int'>int</a> stickerset:flags.8?<a href='/type/StickerSet'>StickerSet</a> available_min_id:flags.9?<a href='/type/int'>int</a> folder_id:flags.11?<a href='/type/int'>int</a> linked_chat_id:flags.14?<a href='/type/long'>long</a> location:flags.15?<a href='/type/ChannelLocation'>ChannelLocation</a> slowmode_seconds:flags.17?<a href='/type/int'>int</a> slowmode_next_send_date:flags.18?<a href='/type/int'>int</a> stats_dc:flags.12?<a href='/type/int'>int</a> pts:<a href='/type/int'>int</a> call:flags.21?<a href='/type/InputGroupCall'>InputGroupCall</a> ttl_period:flags.24?<a href='/type/int'>int</a> pending_suggestions:flags.25?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/string'>string</a>&gt; groupcall_default_join_as:flags.26?<a href='/type/Peer'>Peer</a> theme_emoticon:flags.27?<a href='/type/string'>string</a> requests_pending:flags.28?<a href='/type/int'>int</a> recent_requesters:flags.28?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/long'>long</a>&gt; default_send_as:flags.29?<a href='/type/Peer'>Peer</a> available_reactions:flags.30?<a href='/type/ChatReactions'>ChatReactions</a> reactions_limit:flags2.13?<a href='/type/int'>int</a> stories:flags2.4?<a href='/type/PeerStories'>PeerStories</a> wallpaper:flags2.7?<a href='/type/WallPaper'>WallPaper</a> boosts_applied:flags2.8?<a href='/type/int'>int</a> boosts_unrestrict:flags2.9?<a href='/type/int'>int</a> emojiset:flags2.10?<a href='/type/StickerSet'>StickerSet</a> = <a href='/type/ChatFull'>ChatFull</a>;
<a href='/constructor/inputMediaPaidMedia'>inputMediaPaidMedia</a>#aa661fc3 stars_amount:<a href='/type/long'>long</a> extended_media:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/InputMedia'>InputMedia</a>&gt; = <a href='/type/InputMedia'>InputMedia</a>;
---functions---
<a href='/method/messages.sendMedia'>messages.sendMedia</a>#7852834e flags:<a href='/type/%23'>#</a> silent:flags.5?<a href='/constructor/true'>true</a> background:flags.6?<a href='/constructor/true'>true</a> clear_draft:flags.7?<a href='/constructor/true'>true</a> noforwards:flags.14?<a href='/constructor/true'>true</a> update_stickersets_order:flags.15?<a href='/constructor/true'>true</a> invert_media:flags.16?<a href='/constructor/true'>true</a> peer:<a href='/type/InputPeer'>InputPeer</a> reply_to:flags.0?<a href='/type/InputReplyTo'>InputReplyTo</a> media:<a href='/type/InputMedia'>InputMedia</a> message:<a href='/type/string'>string</a> random_id:<a href='/type/long'>long</a> reply_markup:flags.2?<a href='/type/ReplyMarkup'>ReplyMarkup</a> entities:flags.3?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/MessageEntity'>MessageEntity</a>&gt; schedule_date:flags.10?<a href='/type/int'>int</a> send_as:flags.13?<a href='/type/InputPeer'>InputPeer</a> quick_reply_shortcut:flags.17?<a href='/type/InputQuickReplyShortcut'>InputQuickReplyShortcut</a> effect:flags.18?<a href='/type/long'>long</a> = <a href='/type/Updates'>Updates</a>;</code></pre>
<p><a href="/api/channel">Channel</a> administrators may forward or post paid media if the <a href="/constructor/channelFull">channelFull</a>.<code>paid_media_allowed</code> flag is set. </p>
<p>To post paid media, use <a href="/method/messages.sendMedia">messages.sendMedia</a>, passing an <a href="/constructor/inputMediaPaidMedia">inputMediaPaidMedia</a> constructor, containing:</p>
<ul>
<li>In <code>stars_amount</code>, the amount of <a href="/api/stars">Telegram Stars</a> users must pay to obtain access to the media.<br>
The maximum value that can be passed here is specified in the <a href="/api/config#stars-paid-post-amount-max">stars_paid_post_amount_max client configuration value »</a>.</li>
<li>In <code>extended_media</code>, the actual media files (currently only photos and videos are supported).
To send albums, do <strong>not</strong> use <a href="/method/messages.sendMultiMedia">messages.sendMultiMedia</a>, but rather pass all the medias in the <code>extended_media</code> array. </li>
</ul>
<h3><a class="anchor" href="#viewing-paid-media" id="viewing-paid-media" name="viewing-paid-media"><i class="anchor-icon"></i></a>Viewing paid media</h3>
<pre><code><a href='/constructor/messageExtendedMediaPreview'>messageExtendedMediaPreview</a>#ad628cc8 flags:<a href='/type/%23'>#</a> w:flags.0?<a href='/type/int'>int</a> h:flags.0?<a href='/type/int'>int</a> thumb:flags.1?<a href='/type/PhotoSize'>PhotoSize</a> video_duration:flags.2?<a href='/type/int'>int</a> = <a href='/type/MessageExtendedMedia'>MessageExtendedMedia</a>;
<a href='/constructor/messageExtendedMedia'>messageExtendedMedia</a>#ee479c64 media:<a href='/type/MessageMedia'>MessageMedia</a> = <a href='/type/MessageExtendedMedia'>MessageExtendedMedia</a>;
<a href='/constructor/messageMediaPaidMedia'>messageMediaPaidMedia</a>#a8852491 stars_amount:<a href='/type/long'>long</a> extended_media:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/MessageExtendedMedia'>MessageExtendedMedia</a>&gt; = <a href='/type/MessageMedia'>MessageMedia</a>;
<a href='/constructor/inputInvoiceMessage'>inputInvoiceMessage</a>#c5b56859 peer:<a href='/type/InputPeer'>InputPeer</a> msg_id:<a href='/type/int'>int</a> = <a href='/type/InputInvoice'>InputInvoice</a>;
<a href='/constructor/updateMessageExtendedMedia'>updateMessageExtendedMedia</a>#d5a41724 peer:<a href='/type/Peer'>Peer</a> msg_id:<a href='/type/int'>int</a> extended_media:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/MessageExtendedMedia'>MessageExtendedMedia</a>&gt; = <a href='/type/Update'>Update</a>;
<a href='/constructor/starsTransaction'>starsTransaction</a>#2db5418f flags:<a href='/type/%23'>#</a> refund:flags.3?<a href='/constructor/true'>true</a> pending:flags.4?<a href='/constructor/true'>true</a> failed:flags.6?<a href='/constructor/true'>true</a> gift:flags.10?<a href='/constructor/true'>true</a> id:<a href='/type/string'>string</a> stars:<a href='/type/long'>long</a> date:<a href='/type/int'>int</a> peer:<a href='/type/StarsTransactionPeer'>StarsTransactionPeer</a> title:flags.0?<a href='/type/string'>string</a> description:flags.1?<a href='/type/string'>string</a> photo:flags.2?<a href='/type/WebDocument'>WebDocument</a> transaction_date:flags.5?<a href='/type/int'>int</a> transaction_url:flags.5?<a href='/type/string'>string</a> bot_payload:flags.7?<a href='/type/bytes'>bytes</a> msg_id:flags.8?<a href='/type/int'>int</a> extended_media:flags.9?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/MessageMedia'>MessageMedia</a>&gt; = <a href='/type/StarsTransaction'>StarsTransaction</a>;
---functions---
<a href='/method/messages.getExtendedMedia'>messages.getExtendedMedia</a>#84f80814 peer:<a href='/type/InputPeer'>InputPeer</a> id:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/int'>int</a>&gt; = <a href='/type/Updates'>Updates</a>;</code></pre>
<p>Paid media is represented by a <a href="/constructor/messageMediaPaidMedia">messageMediaPaidMedia</a> constructor, containing:</p>
<ul>
<li>In <code>stars_amount</code>, the price of the media in <a href="/api/stars">Telegram Stars</a></li>
<li>In <code>extended_media</code>, a vector of <a href="/type/MessageExtendedMedia">MessageExtendedMedia</a> constructors, which will <strong>all</strong> be either:<ul>
<li><a href="/constructor/messageExtendedMediaPreview">messageExtendedMediaPreview</a>, for media the current user hasn't bought yet, <strong>optionally</strong> contains basic info about the media (width, height, <a href="/api/files#stripped-thumbnails">extremely low resolution thumbnail</a>, video duration for videos). </li>
<li><a href="/constructor/messageExtendedMedia">messageExtendedMedia</a>, for media the current user has already purchased, containing the actual <a href="/constructor/messageMediaPhoto">messageMediaPhoto</a>/<a href="/constructor/messageMediaDocument">messageMediaDocument</a> (video) that can be downloaded and viewed <a href="/api/files">as usual »</a>. </li>
</ul>
</li>
</ul>
<p>To purchase paid media, follow the <a href="/api/payments#22-getting-invoice-info-about-the-product">usual payment flow »</a>, passing an <a href="/constructor/inputInvoiceMessage">inputInvoiceMessage</a> with the peer and message ID of the paid media. </p>
<p>Once the payment succeds, an <a href="/constructor/updateMessageExtendedMedia">updateMessageExtendedMedia</a> will be emitted, replacing the <a href="/constructor/messageExtendedMediaPreview">messageExtendedMediaPreview</a> constructors associated with the message with <a href="/constructor/messageExtendedMedia">messageExtendedMedia</a> constructors.<br>
No other updates will be emitted (i.e. <strong>no</strong> <a href="/constructor/updateEditChannelMessage">updateEditChannelMessage</a> updates will be emitted for the message containing the paid media, even if re-fetching the same messages through other means like <a href="/method/messages.getHistory">messages.getHistory</a> <em>will</em> return the revealed <a href="/constructor/messageExtendedMedia">messageExtendedMedia</a> constructors).</p>
<p>The associated <a href="/constructor/starsTransaction">starsTransaction</a> that will be generated will be of type <a href="/constructor/starsTransactionPeer">starsTransactionPeer</a> (with <code>peer</code> equal to the channel), <code>msg_id</code> equal to the message ID of the paid media and <code>extended_media</code> set to the revealed paid media. </p>
<p><strong>Note</strong>: the <a href="/constructor/updateMessageExtendedMedia">updateMessageExtendedMedia</a> update does not have a <code>pts</code>/<code>qts</code> field.<br>
This means that this update can only be received passively via the socket (<a href="/api/updates#event-sequences">see here »</a>), and it <strong>cannot</strong> be returned by <a href="/method/updates.getDifference">updates.getDifference</a> or <a href="/method/updates.getChannelDifference">updates.getChannelDifference</a>.<br>
This implies that if a certain client is offline, and another session purchases a paid media, the first client will not receive the revealed <a href="/constructor/messageExtendedMedia">messageExtendedMedia</a> constructors when it reconnects to the server, and it would have no way to know that a cached paid media can be revealed to the user. </p>
<p>To bypass this issue, if:</p>
<ul>
<li>
<p>One or more messages containing not-yet-bought paid media are visible to the user.</p>
</li>
<li>
<p>From the messages selected above, include only messages received <em>before</em> the client last went offline (i.e. exclude paid media messages that were received and cached via updates or getHistory/getMessages/etc N seconds ago, and the client connected to the server M &gt;= N seconds ago).</p>
</li>
<li>
<p>From the messages selected above, include only messages for which <a href="/method/messages.getExtendedMedia">messages.getExtendedMedia</a> was called more than 15 seconds ago. </p>
</li>
<li>
<p>For all messages satisfying the above conditions, make a single query to <a href="/method/messages.getExtendedMedia">messages.getExtendedMedia</a>, aggregating matching message IDs in <code>id</code>.<br>
The method will return an array of <a href="/constructor/updateMessageExtendedMedia">updateMessageExtendedMedia</a> updates, only for passed messages containing <strong>already bought</strong> paid media.<br>
No information will be returned for passed messages containing not yet bought paid media, or not containing paid media. </p>
<p>Repeat the method call every 15 seconds if at least one of the messages satisfying the above conditions is still visible.<br>
Repeat the method call immediately if a new paid message satisfying the above conditions scrolls into view.</p>
</li>
</ul></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="//telegram.org/press">Press</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>