Created
November 28, 2023 02:15
-
-
Save JonahTzuChi/8d9924a114f8ad808c914c12eb7b3f29 to your computer and use it in GitHub Desktop.
A simple way Telegram Bot can store input photo to local drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
# requirements.txt | |
python-telegram-bot[rate-limiter]==20.1 | |
""" | |
from telegram import Update | |
from telegram.ext import CallbackContext | |
async def photo_handler(update: Update, context: CallbackContext): | |
# photos = update.message.photo | |
# for photo in photos: | |
# print(photo) | |
file_id = update.message.photo[-1]["file_id"] | |
photo_file = await context.bot.get_file(file_id) | |
await photo_file.download_to_drive( | |
f"/data/img_{update.message.from_user.id}.jpg", | |
read_timeout=3000, | |
write_timeout=3000, | |
connect_timeout=3000, | |
) | |
print("done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment