kagali-san
kagali-san

Reputation: 3082

Telegram, tracking message edit/delete and editing my own messages (Client, not Bot API)

So I'm trying to implement the logging of telegram chats into my ELK storage in a proper way, and the existing solution with tgcli is too old (I also have a PoC which logs message edits from Android client via Xposed, but its implemented on top of UI level and is ineffective)

I need to receive edits/deletion of messages, and do it with client Telegram API.

Spent a day on researching it:

Now I don't want to lose more time picking the libraries/sources. So, I'm asking about the experience with either of the following libraries, I'm looking for exactly one library which will allow to implement the required features fast - for someone who doesn't want to dive deep into MTProto's specifics.

Upvotes: 8

Views: 2755

Answers (1)

Tibebes. M
Tibebes. M

Reputation: 7548

It's much easier to do it in telethon.

Here is a sample code I've put together gathering snippets directly from the docs.

from telethon import TelegramClient, events

API_ID = ...
API_HASH = " ... "

client = TelegramClient('session', api_id=API_ID, api_hash=API_HASH)

@client.on(events.MessageDeleted)
async def handler(event):
    # Log all deleted message IDs
    for msg_id in event.deleted_ids:
        print('Message', msg_id, 'was deleted in', event.chat_id)

@client.on(events.MessageEdited)
async def handler(event):
    # Log the date of new edits
    print('Message', event.id, 'changed at', event.date)


with client:
    client.run_until_disconnected()

Docs for: MessageEdited, MessageDeleted)

Upvotes: 1

Related Questions