I am able to successfully retrieve messages from a channel via channels.getMessages request, once I know their message IDs
. I find channel id by contacts.search, by the way.
At the moment, mesage IDs are consequtive integers, so getting max_id would solve the issue.
I am sure it possible, since official clients do this (view a channel without joining it). I will try to find out how official desktop app does this by reading its sources, but any help will be much appreciated.
I need this because am writing a simple public telegram channel -> rss/web interface.
Please do not confuse Telegram Client API with Telegram Bot API. Bot API allows to receive 'push' messages on new messages, but no 'reading historical logs'.
Public channels have a username. Anyone can find them in Telegram search and join. Private channels are closed societies – you need to be added by the owner or get an invite link to join.
Follow the link to your bot by clicking the link that looks like t.me/{yourBotUsername}. This is where you will receive messages.
In order to send a message to "@Username", you will need them to start your bot, and then store the username with the user_id. Then, you can input the username to find the correct user_id each time you want to send them a message.
Here are the steps you have to do in order to get messages from a channel you're not joined:
contacts.resolveUsername
messages.getHistory
to get your desired messages.Here is a short description on 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With