| | 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__': |
| | |
| | |
| | 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) |
| |
|