21

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'.

asedsami
  • 609
  • 7
  • 26
Samat
  • 511
  • 1
  • 6
  • 15

2 Answers2

14

Here are the steps you have to do in order to get messages from a channel you're not joined:

  1. Resolve the username into ID and access_hash with contacts.resolveUsername
  2. Invoke messages.getHistory to get your desired messages

Here is a short description of messages.getHistory parameters:

peer:        The channel from whom to retrieve the message history
limit:       Number of messages to be retrieved
offset_date: Offset date (messages *previous* to this date will be retrieved)
offset_id:   Offset message ID (only messages *previous* to the given ID will be retrieved)
max_id:      All the messages with a higher (newer) ID or equal to this will be excluded
min_id:      All the messages with a lower (older) ID or equal to this will be excluded
add_offset:  Additional message offset (all of the specified offsets + this offset = older messages)
Mahozad
  • 18,032
  • 13
  • 118
  • 133
Ali Hashemi
  • 3,158
  • 3
  • 34
  • 48
3

It turns out messages.getHistory is just okay, gives you last N messages + total count.

Samat
  • 511
  • 1
  • 6
  • 15