Перейти к навигации

How should I supply Telegram channel usernames, links and message IDs?

Pass a Telegram channel as the plain channel username, such as example, without @ or a link prefix. Identify one message with the channel username plus the integer post_id from the message link: for https://t.me/example/123, channel is example and post_id is 123. fetch_channel_info alone also accepts @durov or a full channel URL.

What belongs in channel?

fetch_channel_info accepts durov, @durov, and https://t.me/durov, normalizing all three inputs. For message lists, message details, comments and search, pass the plain channel username without @, without a URL prefix and without a message path. telegram.web.batch_channel_info takes channels as one comma-separated string of at most 20 usernames, not a JSON array.

What identifies one message?

For https://t.me/example/123, channel is example and post_id is the integer 123. telegram.web.fetch_post_detail and telegram.web.fetch_post_comments both require channel and post_id. A message ID is unique only within one channel, so store and deduplicate messages by channel + post_id; message 123 in one channel and message 123 in another channel are different messages.

For the example link https://t.me/example/123, the message-detail body is shown below. example illustrates the expected request format; replace example with the channel username from your permalink.

{"action":"telegram.web.fetch_post_detail","params":{"channel":"example","post_id":123}}

To read the discussion, keep the same channel and post_id and call the comments action. The comments request is a separate paid call, not an extra field on the detail action:

{"action":"telegram.web.fetch_post_comments","params":{"channel":"example","post_id":123,"limit":20}}

Keep the URL, the channel username and the integer message ID together in each source record. Apply the following identifier rules:

  • A display name is not a username.
  • The visible link of a forwarded message does not prove which channel published the original.
  • A private invite link is not a channel username, and the numbers in an invite link grant no access.
  • Do not add one to a message ID to fill a missing message. For a history task, use the cursors returned by the list action and set a separate request limit.

Does retrieving a message also retrieve the message’s comments?

No. telegram.web.fetch_post_detail does not call the comment action. Comments need a separate telegram.web.fetch_post_comments call, with limit 1–100 (default 50) and no before or after input. Do not pass message-list cursors to the comments action, and do not treat comment records as channel publications.

For example, an events channel forwards a product announcement. First save the forwarding channel and the forwarded message ID. To cite the publisher, open the original message the forward points to, and save the original channel and message ID as a separate record. When both records share the same number, the channel usernames tell the two messages apart.

Pagination · Archive channel messages