R
R
rPman2017-10-05 23:08:55
Automation
rPman, 2017-10-05 23:08:55

What tools, applications or libraries can be used to quickly track new messages on public telegram channels?

There is a task, promptly, with minimal delay, to track new messages on the channels in which I am present as a member, i.e. messages are visible to me in the normal desktop client.
The official Bot API allows you to automate and generally work only if you are the creator / owner / administrator of the channel (or a bot that exclusively publishes messages on the channel)
Searched the Internet, most of the recommendations in this area suggest working with a not quite official client, but available on the download pages - telegram.cli was last committed a year and a half ago, there are a bunch of forks that also do not work as expected.
To automate work as a regular user (and not as a channel administrator or a bot), it is possible to output messages in the form of json and connect to the terminal over the network as telnet. It seems that this is actively used for spamming, automatically adding users to groups (when you appear on a channel that you personally did not go to, and there are hundreds more like you among you). The main problem is determining the moment when a message appears on the channel. It is possible to request a list of dialogs (command dialog_list ) and in text mode you will see the number of unread messages on each and get a history of messages for each (command history chat_name_or_id_number_recent).
The client normally works only with personal messages and in some (incomprehensible) situations with groups, but most often, when messages appear on group channels, it does not send any updates to the interface (but the entire screen is crammed with messages about online / offline users who are in contacts, which is sent when the user minimizes or navigates back to their chat window, which happens very often).

It would seem to make a dialog_list request every second, and when new unread messages appear, request them through the history, but unfortunately this does not work. Digging through the source code, I noticed ...
<cry of the soul>
The telegram manager is opensource just for show, it is actually a thin terminal for user actions to closed (with unknown code) servers. Protocols and codes are overcomplicated. The functionality of group chats seems to have been generally added through the left leg_by_shoulder, initially not assuming that they would exist.
</cry from the heart>
... that absolutely all commands are sent to the telegram server, even something as simple as dialog_list, literally! and it is the number of server responses that limits the frequency of requests even less than one per second (ten in ten seconds is already beyond the limit).
Unfortunately, due to the complexity of the protocol, I did not succeed in implementing my own chat from scratch, or rather, it is very difficult. I tried using the library https://github.com/rubenlagus/TelegramApi to write my own chat in java (it was a third-party project), which basically turned out if I close my eyes to the problem of saving authorization (otherwise how to save the sms code and the hash of the initial connection), the client works, but again only for personal messages between users. I did not manage to receive updates from channels (the corresponding callback does not receive the necessary updates, although the same online / offline events and private messages are poured there).
There are also open source applications - a mobile and official desktop client, but I left studying them for last, since ultimately the service should run on a linux server, and preferably without the need to run a GUI.
Please help the community!
ps I tried to use web.telegram.org, if you open it in a browser and inject your javascript code into it, it is possible to track messages from only one current channel, but with a delay of 4-10 seconds, and with a lot of nuances, such as the absence message identifiers, correct timestamp (only time without date, pull date only for old messages, through the appearance of a day separator in the form of a date, etc.). And in general, the esthete programmer in me yells, it’s not necessary to do this.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Shatokhin, 2017-10-06
@rPman

Yes, there is a problem with groups. in the last 2-3 api updates, they changed a lot of things there. Although users only noticed an increase in the maximum number of participants. the original telegram.cli did not have time for these updates. As a result - most of the channels, groups and supergroups (where there are more than 100-200 members) - it does not receive updates.
I can recommend this fork - https://github.com/TehDmitry/tg-cli
Just be careful. There are incorrect links in the assembly instructions.

Z
Zr, 2017-10-06
@Zr

You have written so much, but nothing is clear. This is probably because I do not use this probe. But since you have already assigned tags that have nothing to do with it ([open source], yeah), please write in such a way that it is clear to everyone to whom your question was sent.
Do you need to put a bot on a channel in some proprietary chat server where this is not provided?
But if it is popular and there are "channels", then there must be an adapter for a normal IRC, with which it is easy and pleasant to work with. Google suggests this bundle: Bitlbee [0], built with libpuprle, + telegram-purple [1].
[0] https://www.bitlbee.org
[1] https://github.com/majn/telegram-purple

A
Abror Jakey, 2018-01-17
@ayyjay

A couple of days ago I wrote such a miracle for my needs.
tginfo.tw1.su/v1/?channel=telegram&post=86&format=json
channel -
post channel username - post id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question