In the previous post I read public Telegram channels through the web preview at t.me/s/<channel>. One thing it never shows is comments. A reader asked about exactly that, so here is how to get them, also without an account, api_id or phone number.
Where comments actually live
When a channel turns comments on, Telegram links it to a discussion group. Every post gets a thread in that group, and the "Comments" button under a post opens that thread. The preview page shows channel posts only, so the thread is not there.
With Telethon you would call GetRepliesRequest with an account. But Telegram also ships a comments widget for websites, and the page that widget loads is public:
https://t.me/<channel>/<post_id>?embed=1&discussion=1
Open t.me/cointelegraph/73559?embed=1&discussion=1 and you get the thread as HTML, rendered on the server.
What is on that page
-
The 5 newest comments, each a
div.tgme_widget_messagewith adata-post-idattribute. Author, text and time use the same class names as in the channel preview. A reply carries a.js-reply_toblock whosedata-reply-tois the ID of the comment it answers. -
A comment count in
.js-header: "13 comments". -
Three hidden inputs,
peer,top_msg_idanddiscussion_hash. They identify the thread. -
An
api_urlinside aTWidgetAuth.init({...})script call. It looks likehttps://t.me/api/method?api_hash=....
The widget loads older comments by POSTing those three fields to api_url with method=loadComments and before_id=<comment id>. The answer is JSON with a comments_html chunk, which has the same markup as the page, plus a new data-before cursor if there is more.
The first page holds only 5 comments, but loadComments returns up to 50. So the trick is to throw away the first page and start from before_id = newest_id + 1. That returns the newest 50 in one request, the first five included.
The code
pip install httpx selectolax
import json
import re
import httpx
from selectolax.lexbor import LexborHTMLParser
def parse_comments(html):
"""Comments in a chunk of widget HTML, oldest first, plus the cursor for older ones."""
tree = LexborHTMLParser(html)
comments = []
for node in tree.css("div.tgme_widget_message[data-post-id]"):
author = node.css_first(".tgme_widget_message_bubble > .tgme_widget_message_author .tgme_widget_message_author_name")
text = node.css_first("div.tgme_widget_message_text.js-message_text")
time = node.css_first("a.tgme_widget_message_date time")
reply = node.css_first(".js-reply_to[data-reply-to]")
comments.append({
"id": int(node.attributes["data-post-id"]),
"date": time.attributes.get("datetime") if time else None,
"author": author.text(strip=True) if author else None,
"text": text.text(separator="\n").strip() if text else None,
"reply_to": int(reply.attributes["data-reply-to"]) if reply else None,
})
more = tree.css_first(".js-messages_more[data-before]")
return sorted(comments, key=lambda c: c["id"]), int(more.attributes["data-before"]) if more else None
def post_comments(channel, post_id, limit=200):
"""Newest `limit` comments under a channel post, oldest first. None if the post has no discussion."""
url = f"https://t.me/{channel}/{post_id}"
with httpx.Client(headers={"User-Agent": "Mozilla/5.0"}, timeout=30) as client:
html = client.get(url, params={"embed": 1, "discussion": 1}).text
if 'name="discussion_hash"' not in html:
return None
tree = LexborHTMLParser(html)
form = {n.attributes["name"]: n.attributes["value"] for n in tree.css("input[type=hidden]")
if n.attributes.get("name") in ("peer", "top_msg_id", "discussion_hash")}
api_url = json.loads(re.search(r"TWidgetAuth\.init\((\{.*?\})\)", html).group(1))["api_url"]
comments, _ = parse_comments(html) # the first 5
before = comments[-1]["id"] + 1 if comments else None # restart from the newest, 50 per page
comments = []
while before and len(comments) < limit:
page = client.post(api_url, data={**form, "before_id": before, "method": "loadComments"},
headers={"X-Requested-With": "XMLHttpRequest"}).json()
older, before = parse_comments(page.get("comments_html") or "")
seen = {c["id"] for c in comments}
comments = [c for c in older if c["id"] not in seen] + comments
if not older:
break
return comments[-limit:]
if __name__ == "__main__":
for c in post_comments("cointelegraph", 73559) or []:
print(c["date"], "reply" if c["reply_to"] else " ", (c["text"] or "")[:60].replace("\n", " "))
print(post_comments("durov", 574))
Output when I ran it:
2026-11-27T09:29:39+00:00 Imagine waiting until 2027 for this
2026-11-27T09:29:46+00:00 👏
2026-11-27T09:29:56+00:00 Version histories for white papers - about time.
2026-11-27T09:31:20+00:00 More transparency for crypto, but tighter compliance too. 👀
...
None
The last line is None because Pavel Durov's channel has no discussion group. On a post with 76 comments the function made three requests: the page, then two loadComments calls.
What you run into
"No discussion" and "no comments yet" look alike. A post without a thread shows "Discussion is not available at the moment". A post with an empty thread shows no comments either. The difference is the comment form: the hidden discussion_hash input exists only when there is a thread. Check for that, not for comment elements, or you will skip channels whose newest posts simply have no comments yet.
Old posts can have no thread. Posts published before the channel linked its group, or while comments were off, have no discussion even in a channel that has one now. Do not decide from a single post. I check the two newest and skip the channel only if both have no thread.
Every comment contains three texts. A reply has a quote of the comment it answers, and every comment has a hidden reply template with its own text. Select js-message_text, not tgme_widget_message_text. The quote uses js-message_reply_text, so it does not match.
Do not hardcode api_url. The api_hash in it comes from the page. Read it from each page you load.
Names can disappear. After I had read the same threads over and over while testing, Telegram started returning their comments with empty author names. Text, dates and reply links stayed, other channels were fine at the same time, and the names came back after 15 to 20 minutes. Do not hammer one thread, and keep the concurrency per channel low: three requests at a time works for me.
Comments keep coming. A thread keeps growing after the post goes out. If you capture a post the minute it appears, you get almost nothing. For a monitor, either delay the comment fetch or re-read recent posts for a few days.
Edits and deletions are not tracked. You get the comment as it was when you read it. Comments deleted later stay in your data, and edited ones keep their old text.
A hosted version
I added this to my Apify Actor, Telegram Channel Scraper. Set includeComments: true and each post is followed by its comments as separate records, with author, username, reply links and reactions. Channels without a discussion group are detected and skipped, and keyword search, date filters and the new-posts monitor work as before. It costs $1.50 per 1,000 records, posts and comments alike. I built it and I earn from it.
curl -s -X POST \
"https://api.apify.com/v2/acts/picdev~telegram-channel-scraper-posts-monitor/run-sync-get-dataset-items" \
-H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
-d '{"channels": ["cointelegraph"], "maxPostsPerChannel": 10, "includeComments": true, "maxCommentsPerPost": 100}'
A script that saves comments to CSV is in this repository.
For a handful of posts, the code above is enough.
Top comments (0)