feat: add ChatType builtin filter (#356)

* feat: ChatTypesFilter

* feat: add example of usage

* feat: docs

* fix: add import in filters/__init__

* fix: remove some of event_handlers

* fix

* fix imports

* fix: rename to ChatTypeFilter

* fix: rename argument to chat_type

fix: rename example file name

fix: str is container also lol. example fixed also

* fix: respect type hints

* fix: add warning with respect to type hint

* fix: use warnings instead of logging
This commit is contained in:
Egor 2020-07-02 14:17:48 +03:00 committed by GitHub
parent d179789ea7
commit 81b36bd192
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 5 deletions

View file

@ -0,0 +1,42 @@
"""
This is an example with usage of ChatTypeFilter
It filters incoming object based on type of its chat type
"""
import logging
from aiogram import Bot, Dispatcher, executor, types
from aiogram.dispatcher.handler import SkipHandler
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_type=[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")
# propagate message to the next handler
raise SkipHandler
@dp.message_handler(chat_type=ChatType.PRIVATE)
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 only in private chats")
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)