<p><ahref="/api/channel">Groups</a> can be associated to a <ahref="/api/channel">channel</a> as a <ahref="https://telegram.org/blog/privacy-discussions-web-bots">discussion group</a>, to allow users to discuss about posts. </p>
<p>A discussion group can be associated to a channel using <ahref="/method/channels.setDiscussionGroup">channels.setDiscussionGroup</a>.<br>
The discussion group can be accessed in the client by clicking on the discuss button of the channel, or by accessing the <ahref="/api/threads">comment section</a> of a specific post; the discussion group ID is also present in the <code>linked_chat_id</code> field of the <ahref="/constructor/channelFull">channelFull</a> constructor. </p>
<p>All messages sent to the channel will also be forwarded to the linked group (with sender peer <code>from_id</code> equal to the peer of the linked channel); those messages will also be automatically <ahref="/api/pin">pinned</a> in the group. </p>
<p>The comment section of a channel post is simply the <ahref="/api/threads">message thread</a> of the automatically forwarded channel message in the linked discussion supergroup.<br>
Thus, the comment section of a particular post can be disabled by removing the autoforwarded channel post message from the discussion group. </p>
<p>A <ahref="/constructor/messageReplies">messageReplies</a> constructor will be attached the channel post in the original channel, containing information about the comment section, specifically:</p>
<ul>
<li><code>replies.channel_id</code> will contain the ID of the linked discussion supergroup</li>
<li><code>replies.recent_repliers</code> will contain information about the last few comment posters for a specific thread, to show a small list of commenter profile pictures in client previews.</li>
<li><code>replies.replies</code> will contains the total number of replies in the comment section.</li>
<li><code>replies.max_id</code><em>may</em> contain the ID of the latest message in the comment section, if any.</li>
<li><code>replies.replies_pts</code><em>may</em> contain the PTS of the autoforwarded channel message that started the comment section.</li>
</ul>
<p>The same <ahref="/constructor/messageReplies">messageReplies</a> constructor with the usual flags for a <ahref="/api/threads">thread</a> (i.e. without <code>channel_id</code>, <code>recent_replies</code>) will also be present in the message automatically forwarded to the discussion group, as for all group messages that start a <ahref="/api/threads">thread</a>. </p>
<p>Use <ahref="/method/messages.getDiscussionMessage">messages.getDiscussionMessage</a> to obtain the initial messages of the <ahref="/api/threads">message thread</a> of the autoforwaded channel message in the linked discussion supergroup. </p>
<p>The messages are returned in a reverse chronological order (i.e., in order of decreasing message ID); thus the last message returned by the method will be the autoforwarded channel message that started the comment section. </p>
<p>Since a user can comment in channel posts without joining the actual <ahref="/api/discussion">discussion supergroup</a>, there must be a way for them to receive notifications about replies in comment sections.<br>
For this reason, a special <code>@replies</code> username is provided.
Its ID for main and testing endpoints can be seen in the <ahref="https://github.com/tdlib/td/blob/34cf869c02583c23b023f725dca30cd18efc82a3/td/telegram/ContactsManager.cpp#L4418">tdlib sources</a>. </p>
<p>When someone replies to one of our messages in the comment section of a channel post, and the user is not subscribed to the discussion group, the client will receive two updates:</p>
<ul>
<li>An <ahref="/constructor/updateNewChannelMessage">updateNewChannelMessage</a> from the discussion group itself, structured just like any other update coming from a subscribed group, with:<ul>
<li><code>id</code> set to the ID of the reply</li>
<li><code>from_id</code> set to the peer that replied to us</li>
<li><code>peer_id</code> set to the peer of the <ahref="/api/discussion">discussion group</a></li>
<li><code>reply_to.reply_to_msg_id</code> set to the ID of our message</li>
<li><code>reply_to.reply_to_top_id</code> set to the <ahref="/api/threads">thread ID</a>. </li>
<li><code>id</code> set to the common ID sequence for users</li>
<li><code>from_id</code> set to the peer of <code>@replies</code></li>
<li><code>peer_id</code> set to our own peer</li>
<li><code>fwd_from.saved_from_msg_id</code> set to the ID of the reply</li>
<li><code>fwd_from.from_id</code> set to the peer that replied to us</li>
<li><code>reply_to.reply_to_peer_id</code> set to the peer of the <ahref="/api/discussion">discussion group</a></li>
<li><code>reply_to.reply_to_msg_id</code> set to the ID of our message</li>
<li><code>reply_to.reply_to_top_id</code> set to the <ahref="/api/threads">thread ID</a></li>
</ul>
</li>
</ul>
<p>Clients should display messages coming from <code>@replies</code> as a read-only supergroup, with each reply displayed as a separate message from the author of the reply, with a "View in chat" button like for channel comments. </p>
<p><ahref="/method/contacts.blockFromReplies">contacts.blockFromReplies</a> may be used to stop getting notifications about thread replies from a certain user in <code>@replies</code>.</p>
<h3><aclass="anchor"href="#linking-a-discussion-group"id="linking-a-discussion-group"name="linking-a-discussion-group"><iclass="anchor-icon"></i></a>Linking a discussion group</h3>
<p>To obtain a list of admined supergroups that a channel admin can possibly associate to a channel, use <ahref="/method/channels.getGroupsForDiscussion">channels.getGroupsForDiscussion</a>.<br>
Returned <ahref="/api/channel#basic-groups">basic group chats</a> must be first <ahref="/api/channel#migration">upgraded to supergroups</a> before they can be set as a discussion group.<br>
Before linking a supergroup to a channel, access to the supergroup's old messages must also be enabled using <ahref="/method/channels.togglePreHistoryHidden">channels.togglePreHistoryHidden</a>. </p>
<p>To set a returned supergroup as a discussion group use <ahref="/method/channels.setDiscussionGroup">channels.setDiscussionGroup</a>.</p>
<h3><aclass="anchor"href="#requiring-users-to-join-the-group"id="requiring-users-to-join-the-group"name="requiring-users-to-join-the-group"><iclass="anchor-icon"></i></a>Requiring users to join the group</h3>
<p>Admins may use <ahref="/method/channels.toggleJoinToSend">channels.toggleJoinToSend</a> to force users to join a discussion group before commenting.<br>
The <ahref="/constructor/channel"><code>channel.join_to_send</code></a> flag will be set accordingly, and all attempts by non-members to send a message to the group will return a <code>CHAT_GUEST_SEND_FORBIDDEN</code> RPC error.</p></div>