diff --git a/requirements.txt b/requirements.txt index c4c861c..e35db29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ requests python-dotenv==1.0.0 duckduckgo-search==5.3.0 tinydb==4.8.0 +telethon==1.34.0 upsonic diff --git a/tiger/tools/communication/telegram/delete_message.py b/tiger/tools/communication/telegram/delete_message.py new file mode 100644 index 0000000..1729a38 --- /dev/null +++ b/tiger/tools/communication/telegram/delete_message.py @@ -0,0 +1,29 @@ +import asyncio +import time + +from telethon.sync import TelegramClient + + +def delete_message(number: str, message: str): + """ + + :param number: str: + :param message: str: + + """ + import nest_asyncio + + nest_asyncio.apply() + + async def del_message(num, message): + async with TelegramClient( + "upsonic_tiger", 21659296, + "7d0ebd20538d88ab0629eb926acb08f7") as client: + await client.delete_messages(num, message) + + asyncio.run(del_message(number, message)) + + +tool_name = "communication.telegram.delete_message" +tool_obj = delete_message +tool_requirements = ["telethon==1.34.0"] diff --git a/tiger/tools/communication/telegram/get_last_dialogs.py b/tiger/tools/communication/telegram/get_last_dialogs.py new file mode 100644 index 0000000..098586f --- /dev/null +++ b/tiger/tools/communication/telegram/get_last_dialogs.py @@ -0,0 +1,49 @@ +import asyncio +import time + +from telethon.sync import TelegramClient + + +def get_last_dialogs(limit=100): + """ + + :param limit: (Default value = 100) + + """ + import nest_asyncio + + nest_asyncio.apply() + + async def fetch_recent_chats(limit): + async with TelegramClient( + "upsonic_tiger", 21659296, + "7d0ebd20538d88ab0629eb926acb08f7") as client: + recent_chats = await client.get_dialogs(limit=limit) + chat_names = {} + for chat in recent_chats: + number = "" + type_of_entity = "" + if chat.is_user: + number = chat.entity.phone + type_of_entity = "user" + if chat.is_channel: + number = chat.entity.username or chat.entity.id + type_of_entity = "channel" + if chat.is_group: + number = chat.entity.id + type_of_entity = "group" + chat_names[chat.id] = { + "number": number, + "title": chat.name or chat.title, + "type_of_entity": type_of_entity, + "unread_count": chat.unread_count, + } + return chat_names + + chats = asyncio.run(fetch_recent_chats(limit=limit)) + return chats + + +tool_name = "communication.telegram.get_last_dialogs" +tool_obj = get_last_dialogs +tool_requirements = ["telethon==1.34.0"] diff --git a/tiger/tools/communication/telegram/get_last_messages.py b/tiger/tools/communication/telegram/get_last_messages.py new file mode 100644 index 0000000..68bf5d8 --- /dev/null +++ b/tiger/tools/communication/telegram/get_last_messages.py @@ -0,0 +1,44 @@ +import asyncio +import time + +from telethon.sync import TelegramClient + + +def get_last_messages(number: str, limit=100): + """ + + :param number: str: + :param limit: (Default value = 100) + + """ + import nest_asyncio + + nest_asyncio.apply() + + async def get_messages(num, limit): + async with TelegramClient( + "upsonic_tiger", 21659296, + "7d0ebd20538d88ab0629eb926acb08f7") as client: + messages = await client.get_messages(num, limit=limit) + the_messages_list = {} + for each_ms in messages: + the_messages_list[each_ms.id] = { + "id": + each_ms.id, + "message": + each_ms.text, + "date": + each_ms.date, + "sender": + (await + client.get_entity(each_ms.peer_id.user_id)).username, + } + return the_messages_list + + messages = asyncio.run(get_messages(number, limit)) + return messages + + +tool_name = "communication.telegram.get_last_messages" +tool_obj = get_last_messages +tool_requirements = ["telethon==1.34.0"] diff --git a/tiger/tools/communication/telegram/send_message.py b/tiger/tools/communication/telegram/send_message.py new file mode 100644 index 0000000..f8f950e --- /dev/null +++ b/tiger/tools/communication/telegram/send_message.py @@ -0,0 +1,30 @@ +import asyncio +import time + +from telethon.sync import TelegramClient + + +def send_message(number: str, message: str) -> str: + """ + + :param number: str: + :param message: str: + + """ + import nest_asyncio + + nest_asyncio.apply() + + async def send_message(number, message): + async with TelegramClient( + "upsonic_tiger", 21659296, + "7d0ebd20538d88ab0629eb926acb08f7") as client: + return (await client.send_message(number, message)).id + + result = asyncio.run(send_message(number, message)) + return result + + +tool_name = "communication.telegram.send_message" +tool_obj = send_message +tool_requirements = ["telethon==1.34.0"] diff --git a/tiger/tools/communication/telegram/signin.py b/tiger/tools/communication/telegram/signin.py new file mode 100644 index 0000000..bb70c38 --- /dev/null +++ b/tiger/tools/communication/telegram/signin.py @@ -0,0 +1,27 @@ +import asyncio +import time + +from telethon.sync import TelegramClient + + +def signin(): + """ """ + import nest_asyncio + + nest_asyncio.apply() + + async def send_message(): + async with TelegramClient( + "upsonic_tiger", 21659296, + "7d0ebd20538d88ab0629eb926acb08f7") as client: + message = await client.send_message("me", "upsonic_tiger_test") + await time.sleep(2) + await message.delelete + + result = asyncio.run(send_message()) + return result + + +tool_name = "communication.telegram.signin" +tool_obj = signin +tool_requirements = ["telethon==1.34.0"]