wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
956 stars 156 forks source link

Is it possible to reduce delay receiving channel messages/updates? #275

Closed NMishchenko closed 1 month ago

NMishchenko commented 1 month ago

Hi.

I'm using UpdateManager to receive updates: Manager = Client.WithUpdateManager(Client_OnUpdate);

My application needs to react to new channel messages as fast as possible, but UpdateNewChannelMessage can be received even 10 minutes after they were posted. I saw InactivityThreshold property inside UpdateManager, so I changed it to 1 minute: Manager.InactivityThreshold = TimeSpan.FromMinutes(1) and now it receives updates guaranteed every minute. I'm afraid that if I change that property to 1 second, the account with a bot can be banned.

I also noticed that updates from my test channel with 2 subscribers are received immediately without any delay every time, so this problem occurs only with big channels (200k-600k subscribers).

Can I improve something to make it faster or is it some Telegram limitation?

wiz0u commented 1 month ago

On very large groups/channel, it has been observed that the same message may be received with a delay between a full client and WTelegramClient. That is not due to slowness in the library. It's Telegram servers taking the time to dispatch the updates among thousands of members.

According to someone, the priority order when dispatching such updates to group members could be something like this: Replied person > Tagged people > Group Creator > Group admins > Recently active members > Everyone else So maybe being admin or active poster in the group can help reduce the delay.

Increasing the default PingInterval may have negative effects. Reducing Manager.InactivityThreshold can help, but if you reduce it too much, you might make the Manager crash as Telegram could reject the many Manager API calls with FLOOD_WAIT_X