From aad8ac846452148535f2294cce6821cdf9f481e6 Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 14 Jun 2020 16:33:36 +0500 Subject: [PATCH] feat: add example of usage --- examples/chat_types_filter.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/examples/chat_types_filter.py b/examples/chat_types_filter.py index e69de29b..6f243325 100644 --- a/examples/chat_types_filter.py +++ b/examples/chat_types_filter.py @@ -0,0 +1,30 @@ +""" +This is an example with usage of ChatTypesFilter +It filters incoming object based on type of its chat type +""" + +import logging + +from aiogram import Bot, Dispatcher, executor, types +from aiogram.types import ChatType + +API_TOKEN = 'BOT TOKEN HERE' + +# Configure logging +logging.basicConfig(level=logging.INFO) + +# Initialize bot and dispatcher +bot = Bot(token=API_TOKEN) +dp = Dispatcher(bot) + + +@dp.message_handler(chat_types=[ChatType.PRIVATE, ChatType.CHANNEL]) +async def send_welcome(message: types.Message): + """ + This handler will be called when user sends `/start` or `/help` command + """ + await message.reply("Hi!\nI'm hearing your messages in private chats and channels") + + +if __name__ == '__main__': + executor.start_polling(dp, skip_updates=True)