If you send a message from WS to the chat, and then send a message from the chat, then Event is not deleted, if you send another message, it will be processed
Checklist
- [ ] The error is in the library's code, and not in my own.
- [х] I have searched for this issue before posting it and there isn't a duplicate.
- [ ] I ran
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.
Code that causes the issue
from telethon import TelegramClient, events
from telethon.events import StopPropagation
import sys
import asyncio
import websockets
class TG(TelegramClient):
chat = 0
def __init__(self, session_user_id, api_id, api_hash):
super().__init__(
session_user_id, api_id, api_hash,
)
print('Connecting to Telegram servers...')
print(self)
async def get_dialog_id(self):
username = await self.get_entity('AoAnima')
self.chat = username.id
async def run(self):
await self.start()
print('connected Telegram servers...')
print(await self.is_user_authorized())
await self.get_dialog_id()
async def send_messages(self, message, ws):
await self.send_message(self.chat, message)
@self.on(events.NewMessage(chats=self.chat))
async def handler(event):
print("message", event)
# await ws.send(event.message.stringify())
delstat = await event.delete() # NOT WORK
print("self", self)
print("delstat", delstat[0])
print("event", event.delete)
raise StopPropagation
class WS():
tgclient = ''
def __init__(self, tg):
# super.__init__(self)
self.tgclient = tg
async def run(self):
async with websockets.serve(self.incomming_message_handler, "localhost", 8765):
await asyncio.Future()
async def incomming_message_handler(self, websocket):
print(websocket)
async for message in websocket:
# отправим сообщение в телеграм
await self.tgclient.send_messages(message, websocket)
# await websocket.send(message)
async def main():
api_id = 2222222
api_hash = 'xxxxxxxx'
client = TG('session_name', api_id, api_hash)
ws = WS(client)
a = await asyncio.gather(
client.run(),
ws.run(),
)
await asyncio.Future()
if __name__ == "__main__":
asyncio.run(main())
Traceback
Connecting to Telegram servers...
<__main__.TG object at 0x00000184192D3A90>
Соединение установленно to Telegram servers...
True
<websockets.legacy.server.WebSocketServerProtocol object at 0x00000184193A3650>
message NewMessage.Event(original_update=UpdateNewMessage(message=Message(id=83875, peer_id=PeerUser(user_id=495654811), date=datetime.datetime(2022, 12, 7, 13, 34, 59, tzinfo=datetime.timezone.utc), message='asd', out=True, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None), pts=199485, pts_count=1), pattern_match=None, message=Message(id=83875, peer_id=PeerUser(user_id=495654811), date=datetime.datetime(2022, 12, 7, 13, 34, 59, tzinfo=datetime.timezone.utc), message='asd', out=True, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None))
self <__main__.TG object at 0x00000184192D3A90>
delstat AffectedMessages(pts=199487, pts_count=1)
event <bound method Message.delete of <telethon.tl.patched.Message object at 0x0000018419401F10>>
message NewMessage.Event(original_update=UpdateNewMessage(message=Message(id=83876, peer_id=PeerUser(user_id=495654811), date=datetime.datetime(2022, 12, 7, 13, 35, 1, tzinfo=datetime.timezone.utc), message='asd', out=True, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None), pts=0, pts_count=0), pattern_match=None, message=Message(id=83876, peer_id=PeerUser(user_id=495654811), date=datetime.datetime(2022, 12, 7, 13, 35, 1, tzinfo=datetime.timezone.utc), message='asd', out=True, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None))
self <__main__.TG object at 0x00000184192D3A90>
delstat AffectedMessages(pts=199490, pts_count=1)
event <bound method Message.delete of <telethon.tl.patched.Message object at 0x0000018419400110>>
message NewMessage.Event(original_update=UpdateNewMessage(message=Message(id=83877, peer_id=PeerUser(user_id=495654811), date=datetime.datetime(2022, 12, 7, 13, 35, 3, tzinfo=datetime.timezone.utc), message='asd', out=True, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None), pts=0, pts_count=0), pattern_match=None, message=Message(id=83877, peer_id=PeerUser(user_id=495654811), date=datetime.datetime(2022, 12, 7, 13, 35, 3, tzinfo=datetime.timezone.utc), message='asd', out=True, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None))
self <__main__.TG object at 0x00000184192D3A90>
delstat AffectedMessages(pts=199493, pts_count=1)
event <bound method Message.delete of <telethon.tl.patched.Message object at 0x0000018419402CD0>>