Forward message (album) telethon
Asked Answered
R

1

2

I'm trying to forward a message with a group of photos. But they are redirected by separate messages in destination channel. How can I redirect with one message?

@client.on(events.NewMessage(incoming=True, chats=FROM))
async def handler_frw(event):
    await client.forward_messages(CHANNEL_TO, event.message)

If I use "send_message" it send as one message. But TO_NAME - doesn't work with id Channel, only name :( And i need "Forward from" in destination channel.

@client.on(events.Album(chats=FROM))
async def handler_snd(event):
    print("Have album.")
    caps = []
    for item in event.messages:
        caps.append(item.message)
    await client.send_message(TO_NAME, file=event.messages, message=caps)
Ruthy answered 11/3, 2022 at 14:31 Comment(0)
J
1

If you want to forward the whole album, utilize the corresponding Album event instead of the New Message event. Telethon supposedly does the necessary hacks to collect the single messages together.

See the docu

from telethon import events

@events.register(events.Album)
async def albumHandler(self, event):
    # Forwarding the album as a whole to some chat
    event.forward_to(chat)
Jann answered 28/3, 2022 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.