Files
z420-misc/telegram_bot/bot.py
Elias Ahokas b6e94fa231
Some checks failed
deploy misc services / deploy (push) Failing after 0s
add services
2025-11-24 20:05:49 +02:00

24 lines
917 B
Python

import os
from telegram import Update
from telegram.ext import ApplicationBuilder, MessageHandler, filters, ContextTypes
with open("/run/secrets/bot_token", 'r') as f:
BOT_TOKEN = f.read().strip()
SAVE_FOLDER = "/app/media_folder"
async def media_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.message.photo:
file = await update.message.photo[-1].get_file()
filename = os.path.join(SAVE_FOLDER, f"{file.file_unique_id}.jpg")
await file.download_to_drive(filename)
elif update.message.video:
file = await update.message.video.get_file()
filename = os.path.join(SAVE_FOLDER, f"{file.file_unique_id}.mp4")
await file.download_to_drive(filename)
if __name__ == "__main__":
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(MessageHandler(filters.PHOTO | filters.VIDEO, media_handler))
app.run_polling()