From ef988e73c95a4b3cb9b5e19768e91d4a33842a44 Mon Sep 17 00:00:00 2001 From: Onur Atakan ULUSOY Date: Mon, 15 Apr 2024 01:34:38 +0300 Subject: [PATCH] Fix for get_last_messages --- .../telegram/as_user/get_last_messages.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tiger/tools/communication/telegram/as_user/get_last_messages.py b/tiger/tools/communication/telegram/as_user/get_last_messages.py index 52db464..384e058 100644 --- a/tiger/tools/communication/telegram/as_user/get_last_messages.py +++ b/tiger/tools/communication/telegram/as_user/get_last_messages.py @@ -22,6 +22,19 @@ async def get_messages(num, limit): messages = await client.get_messages(num, limit=limit) the_messages_list = {} for each_ms in messages: + number = "" + type_of_entity = "" + try: + number = (await client.get_entity(each_ms.peer_id.user_id)).phone + type_of_entity = "user" + except: + try: + number = (await client.get_entity(each_ms.peer_id.user_id)).username + type_of_entity = "channel" + except: + number = (await client.get_entity(each_ms.peer_id.user_id)).id + type_of_entity = "group" + the_messages_list[each_ms.id] = { "id": each_ms.id, @@ -29,9 +42,10 @@ async def get_messages(num, limit): each_ms.text, "date": each_ms.date, - "sender": - (await - client.get_entity(each_ms.peer_id.user_id)).username, + "number": + number, + "type_of_entity": + type_of_entity, } return the_messages_list