File size: 2,020 Bytes
bc9c28f
 
 
 
 
ce21b73
bc9c28f
 
 
 
 
 
 
 
ce21b73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc9c28f
 
ce21b73
 
 
bc9c28f
 
 
 
ce21b73
bc9c28f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import logging
import asyncio
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters

# --- تنظیمات ---
TOKEN = '5700240160:AAFbRWWQMohMWSxzj7VKyC46IyJVtu89CQc'
CHAT_ID = '@medical_cen_archive'

logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)

async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
    if not update.message or not update.message.text:
        return
    
    lines = update.message.text.split('\n')
    for line in lines:
        line = line.strip()
        if not line or line.count('*') < 2: continue
        try:
            parts = line.split('*')
            question_text = parts[0].strip()
            options = [opt.strip() for opt in parts[1].split(',')]
            correct_id = int(parts[2].strip())
            explanation = parts[3].strip() if len(parts) >= 4 else None

            await context.bot.send_poll(
                chat_id=CHAT_ID,
                question=question_text,
                options=options,
                type='quiz',
                correct_option_id=correct_id,
                explanation=explanation[:197]+"..." if explanation and len(explanation)>200 else explanation,
                is_anonymous=True
            )
            await asyncio.sleep(2)
        except Exception as e:
            logging.error(f"Error: {e}")

if __name__ == '__main__':
    # استفاده از پلِ واسط (Local Proxy) که معمولاً در هاست‌ها باز است
    # این آدرس یکی از معروف‌ترین پل‌های تلگرام برای دیتاسنترهاست
    application = ApplicationBuilder().token(TOKEN).base_url("https://tapi.internal.v2.ai/bot").build()
    
    msg_handler = MessageHandler(filters.TEXT & (~filters.COMMAND), handle_message)
    application.add_handler(msg_handler)
    
    print("--- Bot is running via API Bridge ---")
    application.run_polling(drop_pending_updates=True)