LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!

Home Page:https://docs.telethon.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New Message Event handler missing messages randomly

sushilronghe99 opened this issue · comments

Code that causes the issue

client.add_event_handler(new_message_hdl)
async def processMessage(client,message):
            await asyncio.sleep(0.03) 
            me = await client.get_me()
            #do some stuff with this message

@events.register(events.NewMessage(incoming=True))
async def new_message_hdl(event):
        asyncio.create_task(processMessage(event.client,event.message))```

### Expected behavior

All new messages should be received from telegram. 

### Actual behavior

I have joined around 10 channels and  expecting that when ever there is new message in the channel it should be received in my processMessage routine. Tested this for over a month now. Some days it works perfectly fine not missing a single message and some days it misses few messages. 

I have not changed my code for over a month since the tested has started. 


### Traceback

_No response_

### Telethon version

1.34.0

### Python version

3.10.4

### Operating system (including distribution name and version)

Ubuntu,Mac 

### Other details

In past (during early days of development of this app) I was using the following code and it was receiving all messages. As far as i remember. 
```@client.on(events.NewMessages(chats = [names of the channels]))```
Later i have changed the implementation to the register, since the channel names are dynamic, i had to use this approach. 
```@events.register(events.NewMessage(incoming=True))```

I have observed that the message which comes after a long pause in the channel (lets say first message of the day) or a when there is sudden surge of messages in all channels the message are missed. Its kind of a blackout for 1-2 minute. After that everything goes normal. I am not sure if this black out is happening from telegram side or its a telethon problem. 

I have also implemented a periodic (60 sec) getMe method for all clients just to ensure that telegram knows the clients are willing to accepts notifications. Every minute the logs are printing and during the blackouts also the getMe methods are working fine. 

Please let me know if i should provide more details. Any help here would be appreciated. 




### Checklist

- [X] The error is in the library's code, and not in my own.
- [X] I have searched for this issue before posting it and there isn't an open duplicate.
- [X] I ran `pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip` and triggered the bug in the latest version.