Telegram API: How to receive messages from a public channel with which I am not a member?

I can successfully receive messages from a channel through the channels.getMessages request as soon as I know their message IDs . By the way, I find the contacts.search channel id.

Currently mesage identifiers are integers, so getting max_id will solve the problem.

I’m sure that this is possible, as official customers do it (watch the channel without joining it). I will try to figure out how the official desktop application does this by reading its sources , but any help would be greatly appreciated.

I need this because I'm writing a simple public telegram channel -> rss / web interface.

Please do not confuse the telegram API with the bot telegram API. The Bot API allows you to receive "push" messages in new messages, but not "reading historical journals."

+5
source share
2 answers

Here are the steps you must follow to receive messages from a channel you are not connected to:

  • Allow username in ID and access_hash using contacts.resolveUsername
  • Call messages.getHistory to get the messages.getHistory you need.

The following is a brief description of the messages.getHistory parameters:

  :param peer: The channel from whom to retrieve the message history :param limit: Number of messages to be retrieved :param offset_date: Offset date (messages *previous* to this date will be retrieved) :param offset_id: Offset message ID (only messages *previous* to the given ID will be retrieved) :param max_id: All the messages with a higher (newer) ID or equal to this will be excluded :param min_id: All the messages with a lower (older) ID or equal to this will be excluded :param add_offset: Additional message offset (all of the specified offsets + this offset = older messages) 
+1
source

It turns out that messages.getHistory is all right, it gives you the last N messages + the total number.

0
source

Source: https://habr.com/ru/post/1271643/


All Articles