Этап 1: Базовый Telegram-бот с прокси
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from telegram import Update
|
||||
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
|
||||
from config.config import get_settings
|
||||
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||
level=logging.INFO
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
|
||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await update.message.reply_text(
|
||||
f"Привет! Я {settings.bot_name}, ваш ИИ-ассистент.\n"
|
||||
"Я помогу вам с программированием и не только."
|
||||
)
|
||||
|
||||
|
||||
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await update.message.reply_text(update.message.text)
|
||||
|
||||
|
||||
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
help_text = (
|
||||
f"Я {settings.bot_name}, ваш ИИ-ассистент.\n\n"
|
||||
"Доступные команды:\n"
|
||||
"/start - Начать работу\n"
|
||||
"/help - Показать эту справку\n"
|
||||
)
|
||||
await update.message.reply_text(help_text)
|
||||
|
||||
|
||||
def main():
|
||||
builder = Application.builder()
|
||||
builder.token(settings.telegram_bot_token)
|
||||
|
||||
if settings.telegram_proxy_url:
|
||||
builder.proxy_url(settings.telegram_proxy_url)
|
||||
builder.proxy_type(settings.telegram_proxy_type)
|
||||
|
||||
application = builder.build()
|
||||
|
||||
application.add_handler(CommandHandler("start", start))
|
||||
application.add_handler(CommandHandler("help", help_command))
|
||||
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
|
||||
|
||||
logger.info("Бот запущен")
|
||||
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user