| import logging |
| from telegram import Update |
| from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext |
|
|
| |
| logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) |
| logger = logging.getLogger(__name__) |
|
|
| |
| def start(update: Update, context: CallbackContext) -> None: |
| update.message.reply_text('Привет! Я тестовый бот. Используйте /help для получения списка команд.') |
|
|
| def help_command(update: Update, context: CallbackContext) -> None: |
| update.message.reply_text('Доступные команды:\n/start - Запустить бота\n/help - Получить помощь') |
|
|
| def echo(update: Update, context: CallbackContext) -> None: |
| update.message.reply_text(update.message.text) |
|
|
| def main() -> None: |
| |
| TOKEN = 'YOUR_TOKEN_HERE' |
|
|
| |
| updater = Updater(TOKEN) |
|
|
| |
| dispatcher = updater.dispatcher |
|
|
| |
| dispatcher.add_handler(CommandHandler("start", start)) |
| dispatcher.add_handler(CommandHandler("help", help_command)) |
|
|
| |
| dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, echo)) |
|
|
| |
| updater.start_polling() |
|
|
| |
| updater.idle() |
|
|
| if __name__ == '__main__': |
| main() |
| |