import logging from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import ( ApplicationBuilder, CommandHandler, MessageHandler, ContextTypes, filters, CallbackQueryHandler, ) # ============================== TOKEN = "8226590228:AAEFWlywzxJfoot9cc9S03VZLR7N6yONzQs" # 👈 Yahan apne BotFather ka token daalein ADMIN_ID = 7265634689 # 👈 Apni numeric Telegram ID daalein # ============================== CHANNELS = [ ("Shield X Protecter", "shieldxprotecter"), ("UP Board 10th 12th Target", "upboard10th12thtarget"), ("IQ Education Class 12", "iq_eduction_class_12"), ] logging.basicConfig(level=logging.INFO) # ===== Check Channel Join ===== async def is_joined(user_id, bot): for name, username in CHANNELS: try: member = await bot.get_chat_member(f"@{username}", user_id) if member.status in ["left", "kicked"]: return False except: return False return True # ===== Start Command ===== async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): user = update.effective_user joined = await is_joined(user.id, context.bot) if not joined: buttons = [] for name, username in CHANNELS: buttons.append( [InlineKeyboardButton(f"🔔 {name}", url=f"https://t.me/{username}")] ) buttons.append([InlineKeyboardButton("✅ Verify", callback_data="verify")]) await update.message.reply_text( "⚠️ Sabhi channel join karein aur phir /start karein.\n\nNeeche diye gaye sabhi channels join karein:", reply_markup=InlineKeyboardMarkup(buttons), ) else: await update.message.reply_text( "✅ Verification Successful!\n\nApni problem likh kar bhejein." ) # ===== Verify Button ===== async def verify(update: Update, context: ContextTypes.DEFAULT_TYPE): query = update.callback_query await query.answer() user = query.from_user joined = await is_joined(user.id, context.bot) if joined: await query.message.reply_text( "✅ Verification Successful!\n\nAb apni problem likhein." ) else: await query.message.reply_text( "❌ Abhi tak sabhi channel join nahi kiye.\nPehle join karein phir /start karein." ) # ===== Forward User Message to Admin ===== async def forward_to_admin(update: Update, context: ContextTypes.DEFAULT_TYPE): user = update.effective_user # Force Join Check joined = await is_joined(user.id, context.bot) if not joined: await update.message.reply_text("⚠️ Pehle sabhi channel join karein. /start dabayein.") return text = update.message.text msg = f"""📩 New Support Message 👤 Name: {user.first_name} 🆔 ID: {user.id} 💬 Message: {text} """ await context.bot.send_message(chat_id=ADMIN_ID, text=msg) # Auto Reply to User await update.message.reply_text( "⏳ Abhi admin busy hai.\n\nAapko aate hi reply de diya jayega." ) # ===== Admin Reply System ===== async def admin_reply(update: Update, context: ContextTypes.DEFAULT_TYPE): if update.message.reply_to_message and update.message.from_user.id == ADMIN_ID: original_text = update.message.reply_to_message.text try: user_id = int(original_text.split("ID: ")[1].split("\n")[0]) await context.bot.send_message( chat_id=user_id, text=update.message.text ) except: await update.message.reply_text("❌ User ID detect nahi hui.") # ===== App Setup ===== app = ApplicationBuilder().token(TOKEN).build() app.add_handler(CommandHandler("start", start)) app.add_handler(CallbackQueryHandler(verify, pattern="verify")) # ⚠️ Reply handler pehle app.add_handler(MessageHandler(filters.REPLY, admin_reply)) # Normal messages baad me app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, forward_to_admin)) print("Bot Running...") app.run_polling()