Reputation: 41
I can't make a script for a long time. I have one telegram channel, I don't want to resend an album from this channel, but just send it to me in one message
from telethon import TelegramClient, events
from telethon import events
api_id =
api_hash = ""
chat = ''
client = TelegramClient('', api_id, api_hash)
print('started')
@client.on(events.Album)
async def handler(event):
#what farther
Upvotes: 4
Views: 3009
Reputation: 4487
There is send_file
which says
file (...): To send an album, you should provide a list in this parameter. If a list or similar is provided, the files in it will be sent as an album in the order in which they appear, sliced in chunks of 10 if more than 10 are given.
caption (str, optional):
Optional caption for the sent media message. When sending an album, the caption may be a list of strings, which will be assigned to the files pairwise.
So extending @Tibebes answer
await client.send_file( # Note this is send_file not send_message
chat,
file=event.messages
caption=list(map(lambda a: str(a.message), event.messages))
)
Upvotes: 3
Reputation: 7548
Here is one approach to do that:
from telethon import TelegramClient, events
api_id = ...
api_hash = ' ... '
chat = -1001277xxxxxx
client = TelegramClient('session', api_id, api_hash)
@client.on(events.Album)
async def handler(event):
# craft a new message and send
await client.send_message(
chat,
file=event.messages, # event.messages is a List - meaning we're sending an album
message=event.original_update.message.message, # get the caption message from the album
)
## or forward it directly
# await event.forward_to(chat)
client.start()
client.run_until_disconnected()
Upvotes: 5