From e8bc71cf871b3639062a291aaf90c5d23b831f21 Mon Sep 17 00:00:00 2001 From: mrakweek <152392553+mrakweek@users.noreply.github.com> Date: Sat, 15 Jun 2024 17:16:07 +0300 Subject: [PATCH] eho_bot --- eho_bot/bot.py | 39 +++++++++++++++++++++++++++++++++++++++ eho_bot/requirements.txt | 1 + 2 files changed, 40 insertions(+) create mode 100644 eho_bot/bot.py create mode 100644 eho_bot/requirements.txt diff --git a/eho_bot/bot.py b/eho_bot/bot.py new file mode 100644 index 0000000..e1a165f --- /dev/null +++ b/eho_bot/bot.py @@ -0,0 +1,39 @@ +import logging + +from telegram import Update +from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters + +TELEGRAM_BOT_TOKEN = '' + +logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO +) + +logger = logging.getLogger(__name__) + + +async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + await update.message.reply_text("Привет, я эхо бот. Напиши мне сообщение и я повторю его") + + +async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + await update.message.reply_text("Я эхо бот, напиши мне сообщение и я повторю его") + + +async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + await update.message.reply_text(update.message.text) + + +def main() -> None: + application = Application.builder().token(TELEGRAM_BOT_TOKEN).build() + + application.add_handler(CommandHandler("start", start)) + application.add_handler(CommandHandler("help", help_command)) + + application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) + + application.run_polling(allowed_updates=Update.ALL_TYPES) + + +if __name__ == "__main__": + main() diff --git a/eho_bot/requirements.txt b/eho_bot/requirements.txt new file mode 100644 index 0000000..11a50f9 --- /dev/null +++ b/eho_bot/requirements.txt @@ -0,0 +1 @@ +python-telegram-bot \ No newline at end of file