COPY bot.py .
# Add handlers application.add_handler(CommandHandler("start", start)) application.add_handler(CommandHandler("help", help_command)) application.add_handler(CommandHandler("cancel", cancel)) application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_url)) application.add_handler(CallbackQueryHandler(button_callback)) application.add_error_handler(error_handler)
worker: python bot.py FROM python:3.9-slim RUN apt-get update && apt-get install -y ffmpeg
Build and run:
[Service] Type=simple User=youruser WorkingDirectory=/path/to/bot ExecStart=/usr/bin/python3 /path/to/bot/bot.py Restart=always
import os import logging from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import Application, CommandHandler, MessageHandler, CallbackQueryHandler, filters, ContextTypes import yt_dlp Enable logging logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO ) logger = logging.getLogger( name ) Bot token from @BotFather BOT_TOKEN = "YOUR_BOT_TOKEN_HERE" Download directory DOWNLOAD_DIR = "downloads" if not os.path.exists(DOWNLOAD_DIR): os.makedirs(DOWNLOAD_DIR) User data storage (in production, use a database) user_data = {} YT-DLP options YDL_OPTS_INFO = { 'quiet': True, 'no_warnings': True, 'extract_flat': False, }
COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt
# Validate URL if not ('youtube.com/watch' in url or 'youtu.be/' in url): await update.message.reply_text("❌ Please send a valid YouTube URL!") return