<metaproperty="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.">
<metaproperty="og:title"content="Paid media">
<metaproperty="og:image"content="">
<metaproperty="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.">
<p>Content creators can accept <ahref="/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 <ahref="/api/stars#withdrawing-revenue">withdraw Stars using the Toncoin cryptocurrency»</a>, or use them to <ahref="/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>
<p><ahref="/api/channel">Channel</a> administrators may forward or post paid media if the <ahref="/constructor/channelFull">channelFull</a>.<code>paid_media_allowed</code> flag is set. </p>
<p>To post paid media, use <ahref="/method/messages.sendMedia">messages.sendMedia</a>, passing an <ahref="/constructor/inputMediaPaidMedia">inputMediaPaidMedia</a> constructor, containing:</p>
<ul>
<li>In <code>stars_amount</code>, the amount of <ahref="/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 <ahref="/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 <ahref="/method/messages.sendMultiMedia">messages.sendMultiMedia</a>, but rather pass all the medias in the <code>extended_media</code> array. </li>
<p>Paid media is represented by a <ahref="/constructor/messageMediaPaidMedia">messageMediaPaidMedia</a> constructor, containing:</p>
<ul>
<li>In <code>stars_amount</code>, the price of the media in <ahref="/api/stars">Telegram Stars</a></li>
<li>In <code>extended_media</code>, a vector of <ahref="/type/MessageExtendedMedia">MessageExtendedMedia</a> constructors, which will <strong>all</strong> be either:<ul>
<li><ahref="/constructor/messageExtendedMediaPreview">messageExtendedMediaPreview</a>, for media the current user hasn't bought yet, <strong>optionally</strong> contains basic info about the media (width, height, <ahref="/api/files#stripped-thumbnails">extremely low resolution thumbnail</a>, video duration for videos). </li>
<li><ahref="/constructor/messageExtendedMedia">messageExtendedMedia</a>, for media the current user has already purchased, containing the actual <ahref="/constructor/messageMediaPhoto">messageMediaPhoto</a>/<ahref="/constructor/messageMediaDocument">messageMediaDocument</a> (video) that can be downloaded and viewed <ahref="/api/files">as usual»</a>. </li>
</ul>
</li>
</ul>
<p>To purchase paid media, follow the <ahref="/api/payments#22-getting-invoice-info-about-the-product">usual payment flow»</a>, passing an <ahref="/constructor/inputInvoiceMessage">inputInvoiceMessage</a> with the peer and message ID of the paid media. </p>
<p>Once the payment succeds, an <ahref="/constructor/updateMessageExtendedMedia">updateMessageExtendedMedia</a> will be emitted, replacing the <ahref="/constructor/messageExtendedMediaPreview">messageExtendedMediaPreview</a> constructors associated with the message with <ahref="/constructor/messageExtendedMedia">messageExtendedMedia</a> constructors.<br>
No other updates will be emitted (i.e. <strong>no</strong><ahref="/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 <ahref="/method/messages.getHistory">messages.getHistory</a><em>will</em> return the revealed <ahref="/constructor/messageExtendedMedia">messageExtendedMedia</a> constructors).</p>
<p>The associated <ahref="/constructor/starsTransaction">starsTransaction</a> that will be generated will be of type <ahref="/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 <ahref="/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 (<ahref="/api/updates#event-sequences">see here»</a>), and it <strong>cannot</strong> be returned by <ahref="/method/updates.getDifference">updates.getDifference</a> or <ahref="/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 <ahref="/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 >= N seconds ago).</p>
</li>
<li>
<p>From the messages selected above, include only messages for which <ahref="/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 <ahref="/method/messages.getExtendedMedia">messages.getExtendedMedia</a>, aggregating matching message IDs in <code>id</code>.<br>
The method will return an array of <ahref="/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>
<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.