-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
events.NewMessage event is not triggered for certain channels #4345
Comments
This comment was marked as duplicate.
This comment was marked as duplicate.
Please react with the thumbs-up emoji instead of posting "me too" comments. |
Update: |
Telegram doesn't always send all updates to the client. Some channels can only be updated after manually calling for updates. You can try restarting your app, creating a new session, changing the IP or the account itself. |
Same problem for me, and it's not the library. Same problem with Pyrogram |
I noticed the same ,,, few months back i was runing multiple clients via mobile IP , and received 100% all updates ,,, few months later , after a pause , i started a single client over VPN , and not all updates where being registered . |
Some people have reported that some channels must be polled manually to receive updates as of recently. Telethon does not have any built-in way to do this yet (but of course can be done via raw API; I just haven't checked so I don't know exactly how). I don't know if this will ever be "fixed" to work automatically, because if the need for manual polling is true, Telethon would have no way to know what it needs to poll manually. |
Since when did you start noticing this issue? |
Actually, in my case, even the read of the message from the Telegram app does not trigger it. Is it only a problem of mine? |
In my case the whole app just blackouts for randomly 1-2 minutes and then it receives the new messages updates properly. I have 10 channels subscribed and for 2 minutes app did not receive any update from any channels between 9:27-9:29 AM and 10:02-10:04 AM. Afterward, for the rest of the day, all updates were received properly. So as suggested here NewMessage event is not reliable and we should poll those channels manually. I will try that and let you know how it goes. |
I've encountered a peculiar situation with a message delivery order, and I'd like to explain it in hopes of shedding light on the issue.
In my case, the following occurred:
To better understand and debug this issue, I have the following questions:
Checking the behavior of other packages written in other languages can also help us to confirm where the issue is from and why. |
Out-of-order messages shouldn't occur because the library checks that the incoming Telethon/telethon/_updates/messagebox.py Line 561 in 4767368
Make sure the message isn't being deleted and getting resent. I have observed official clients displaying messages that had been deleted multiple times, and not too long ago. If you really think Telethon is processing updates out of order, I either need someone with that problem to debug it themselves, or a way in which I can reliably reproduce it myself. Although I've already spent a significant amount of time going over the update handling code myself, so I doubt I would uncover anything. As far as I know https://core.telegram.org/api/updates doesn't say anything Telethon isn't doing already (at the time of writing). As for missing messages, or the library fetching them after a while. Yes, there is a default timeout after which the library will attempt to fetch updates: Telethon/telethon/_updates/messagebox.py Line 46 in 4767368
This is in line with Telegram's documentation above:
|
Dear @Lonami, I'm sure that I received message (C) before (B) but I'm not sure if it was deleted and sent again or not. If it was deleted, I expected to receive that exact same message again after a while, right? but as you know, sometimes messages do not get delayed, they simply get ignored and never get transmitted. Even after opening that channel on my phone, message (B) was not received "twice", just only once and I also didn't receive message (C) again (meaning that message (C) was not deleted and got resent). As far as I consider these messy updates complicated and not quite trackable, I cannot really guarantee that this unordered updates issue is valid but It was my observation that I decided to share with you because my whole project is now unusable after a few months of not being on the server. It's not working and I'm very concerned. :) P.S.: If you haven't any channel suffering from this updating issue (not the ordering one), I know one that I can send only privately to you. |
I do not have interest in submitting bug reports to Telegram. You can certainly message me privately (or include the channel in a GitHub comment between Perhaps trying this out would be a good excuse to make sure update handling works correctly in the (not ready for use) v2 version. |
Has anyone found a solution to this problem? |
Is there any workaround yet? |
Hi There, There is no solution to make the update function work the way we want. I also tried another library but no luck. It is already established its an issue with Telegram API and not with libraries. Here is the workaround that might help your case. (It requires heavy usage of Asyncio) Run a task every 30 sec (or less) to pull the messages from Telegram using iter_messages. Use offset_id instead of offset_date to fetch messages. The function should effectively use the message ID to track the current state of every channel you listen to. Few important points
This works for me like a charm - not even a single message missed in the last 30 days for almost 5 clients running on one server. Not sure if this is the right solution but at least for my use case it's working. Hope this helps. Thanks |
I noticed this issue over 6 months ago. If Telegram hasn't fixed anything until now I don't see them fixing it at all. As already mentioned, if the App is open NewMessage works correctly. |
for me this problem only happens on channels and only on those with a lot of subscribers. everything else works normally this channel with over 100,000 subscribers is working https://t.me/apostasepalpites |
I wonder if anybody has done reading the source code of official Android/iOS telegram app and find out what (hack) they use for new message event instead? It seems that the official mobile app didn't suffer from this problem at all |
Actually, with official clients exactly the same problem, some channels are updated only when you open them. |
Oh yeah, totally missed that. I opened my Telegram when watching them. Now, what do they use instead? Manual fetch? |
I assume this is done for resource optimization purposes. Some channels get real time updates, some only manually. Official clients also listen for updates just like telethon, but it's not as important for the user to get necessarily all the updates from 500+ channels. Further, when the channel is opened, the updates will be pulled up. |
Hello! Is there any way to fetch updates for client manually from my script? |
Hi, @Lonami! Can you help with my previous message please? |
|
Plz update Traceback (most recent call last): |
Thanks, I tried this solution and it works now: |
Code that causes the issue
Expected behavior
When a new message is sent in a channel passed to
chats
, theevents.NewMessage
should be triggered.Actual behavior
When a new message is sent, the
events.NewMessage
is not being triggered for certain channels.I have tested to create a channel in an account A and monitor it in account B (where telethon is running) and the
events.NewMessage
was triggered instantly. However, for certain public channels that I do not own, the event is not being triggered.Tested on a newly created channel with 2 subscribers and it worked.
Tested on a public channel with 500K subscribers and it did not work.
Traceback
No crashes are happening.
Telethon version
1.34.0
Python version
3.10.12
Operating system (including distribution name and version)
Ubuntu 22.04.4 LTS
Other details
No response
Checklist
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.The text was updated successfully, but these errors were encountered: