skip to Main Content

I’m implementing a code to forward Telegram messages from one channel to another channel I can forward messages but I cannot find a way to update the Source messages when the destination message edited or deleted

Here is the code i already have this is working fine

client = TelegramClient('telegramfw', api_id, api_hash)

@client.on(events.NewMessage)
@client.on(events.MessageEdited)
async def handler(event):
    chat = await event.get_chat()

    chat_id = event.chat_id
    print(chat_id)
    if chat_id == -1001629488043:
        if event.photo:
            await client.send_file(-1001567215170, event.photo,  caption=event.raw_text)
        elif event.video:
            await client.send_file(-1001567215170, event.video, caption=event.raw_text)
        else:
            msg = event.raw_text
            print(msg)
            msg_id_source = event.message.id
            await client.send_message(-1001567215170, msg)


client.start()
client.run_until_disconnected()

Is there any way to do this im new to python and telethon it is grate help some one can help with

3

Answers


  1. Chosen as BEST ANSWER

    Found the solutions i dont know is this the correct way but it solve my problem

    Need to keep message id's in a database and telethon have an option to get edited message

    i used SQLite for DB that is inbuilt with python

    here is the code i use

    @client.on(events.MessageEdited)
    async def handler(event):
        for row in cur.execute("SELECT * FROM keepmsgid where sid=:id", {"id": event.id}):
            Source_message_id = row[0]
            await client.edit_message(destination_id, Source_message_id, event.raw_text)
    

    Let me know if any one need any help with this


  2. i’m also want to know that how to add two decorate on a handler,please

    Login or Signup to reply.
  3. #@client.on(events.NewMessage)
    #@client.on(events.MessageEdited)
    #could delete it and add
    
    client.add_event_handler(handler,events.NewMessage)
    client.add_event_handler(handler,events.MessageEdited)
    

    but i don’t think it is a elegent way

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search