Skip to content

Instantly share code, notes, and snippets.

@JonahTzuChi
Created November 28, 2023 02:15
Show Gist options
  • Save JonahTzuChi/8d9924a114f8ad808c914c12eb7b3f29 to your computer and use it in GitHub Desktop.
Save JonahTzuChi/8d9924a114f8ad808c914c12eb7b3f29 to your computer and use it in GitHub Desktop.
A simple way Telegram Bot can store input photo to local drive
"""
# 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