Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Telethon forward image with spoiler

I create a userbot, who gets some memes from several channels and resend it to my chat with friends.
Bot listens channel and successfull send messages by this code:
await bot.send_message(chat_id, event.message)
But because of some photos may be not safe for work, i would like to hide media by spoiler.

I see that question Telethon send image with spoiler , where Lonami’s code suggest downloading and then uploading file, but my server, where bot hosted has limit internet connection, so that solution didn’t work.
Is there any chance to make file object, that can be send as uploaded file in this construction?
await client.send_file(chat, types.InputMediaUploadedPhoto( uploaded, spoiler=True, ))

Tried to use types.MessageMediaDocument and other, but it raises errors.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since telethon is in a hiatus, proper fields aren’t implemented yet, however the api and utils are fully exposed and togglable to easily patch the media object directly to the event if event contained a media with spoilers, no need for a reupload, as the other SO question, since that’s a different one.

from telethon.utils import get_input_media

... # the rest of your NewMeasage code

if getattr(event.media, 'spoiler', None):
    event.media = get_input_media(event.media)
    event.media.spoiler=True

await bot.send_message(chat_id, event.message)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading