This commit is contained in:
8
telegram_bot/Dockerfile
Normal file
8
telegram_bot/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
RUN pip install --no-cache-dir python-telegram-bot
|
||||
|
||||
CMD ["python", "bot.py"]
|
||||
23
telegram_bot/bot.py
Normal file
23
telegram_bot/bot.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user