From 1d9e80a4dc5874b36528ac4a54a030ce59f4424a Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 11 Dec 2019 21:42:56 +0200 Subject: [PATCH] Add docs for ContentTypesFilter --- docs/dispatcher/filters/content_types.md | 38 ++++++++++++++++++++++++ docs/dispatcher/filters/index.md | 11 +++---- mkdocs.yml | 1 + 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 docs/dispatcher/filters/content_types.md diff --git a/docs/dispatcher/filters/content_types.md b/docs/dispatcher/filters/content_types.md new file mode 100644 index 00000000..30a635b1 --- /dev/null +++ b/docs/dispatcher/filters/content_types.md @@ -0,0 +1,38 @@ +# ContentTypesFilter + +Is useful for handling specific types of messages (For example separate text and stickers handlers). +This is always automatically adds to the filters list for message handlers. + +Can be imported: + +- `#!python3 from aiogram.dispatcher.filters.content_types import ContentTypesFilter` +- `#!python3 from aiogram.dispatcher.filters import ContentTypesFilter` +- `#!python3 from aiogram.filters import ContentTypesFilter` + +Or used from filters factory by passing corresponding arguments to handler registration line + +!!! warning "Please be patient!" + If no one content type filter is specified the `["text"]` value is automatically will be used. + + +## Specification + +| Argument | Type | Description | +| --- | --- | --- | +| `content_types` | `#!python3 Optional[List[str]]` | List of allowed content types | + +## Usage + +1. Single content type: `#!python3 ContentTypesFilter(content_types=["sticker"])` +1. Multiple content types: `#!python3 ContentTypesFilter(content_types=["sticker", "photo"])` +1. Recommended: With usage of `ContentType` helper: `#!python3 ContentTypesFilter(content_types=[ContentType.PHOTO])` +1. Any content type: `#!python3 ContentTypesFilter(content_types=[ContentType.ANY])` + +## Allowed handlers + +Allowed update types for this filter: + +- `message` +- `edited_message` +- `channel_post` +- `edited_channel_post` diff --git a/docs/dispatcher/filters/index.md b/docs/dispatcher/filters/index.md index 5abe9eb4..79dd72bc 100644 --- a/docs/dispatcher/filters/index.md +++ b/docs/dispatcher/filters/index.md @@ -9,11 +9,12 @@ Searching of handler is always stops on first match set of filters are pass. Here is list of builtin filters and event types where it can be used: -| Filter | update | message | edited_message | channel_post | edited_channel_post | inline_query | chosen_inline_result | callback_query | shipping_query | pre_checkout_query | poll | -| --------------------------- |:------:|:-------:|:--------------:|:------------:|:-------------------:|:------------:|:--------------------:|:--------------:|:--------------:|:------------------:|:----:| -| [Text](text.md) | | + | + | + | + | + | | + | | | + | -| [Command](command.md) | | + | | | | | | | | | | -| | | | | | | | | | | | | +| Filter | update | message | edited_message | channel_post | edited_channel_post | inline_query | chosen_inline_result | callback_query | shipping_query | pre_checkout_query | poll | +| ----------------------------------------- |:------:|:-------:|:--------------:|:------------:|:-------------------:|:------------:|:--------------------:|:--------------:|:--------------:|:------------------:|:----:| +| [Text](text.md) | | + | + | + | + | + | | + | | | + | +| [ContentTypesFilter](content_types.md) | | + | + | + | + | | | | | | | +| [Command](command.md) | | + | | | | | | | | | | +| | | | | | | | | | | | | ## Own filters specification diff --git a/mkdocs.yml b/mkdocs.yml index de32210b..c74954ac 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -226,6 +226,7 @@ nav: - dispatcher/filters/index.md - dispatcher/filters/text.md - dispatcher/filters/command.md + - dispatcher/filters/content_types.md - Class based handlers: - dispatcher/class_based_handlers/basics.md - dispatcher/class_based_handlers/message.md