From 98809e62a40254df7763c77eb304579f67c8efae Mon Sep 17 00:00:00 2001 From: Sphericalkat Date: Sat, 25 May 2024 12:40:59 +0530 Subject: [PATCH] feat(handlers): add a message handler Signed-off-by: Sphericalkat --- main.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9600b17..a847ac3 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,13 @@ import logging from telegram import Update -from telegram.ext import ContextTypes, ApplicationBuilder, CommandHandler +from telegram.ext import ( + ContextTypes, + ApplicationBuilder, + CommandHandler, + MessageHandler, + filters, +) from settings import Settings @@ -20,9 +26,19 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): ) +async def message_handler(update: Update, context: ContextTypes.DEFAULT_TYPE): + await context.bot.send_message( + chat_id=update.effective_chat.id, + text="I'm sorry, I'm a bot and I can't understand that.", + ) + + if __name__ == "__main__": app = ApplicationBuilder().token(settings.bot_token).build() start_handler = CommandHandler("start", start) + message_handler = MessageHandler(filters.ALL, message_handler) + app.add_handler(start_handler) + app.add_handler(message_handler) app.run_polling()