Text#

class aiogram.filters.text.Text(text: Optional[Union[Sequence[Union[str, LazyProxy]], str, LazyProxy]] = None, *, contains: Optional[Union[Sequence[Union[str, LazyProxy]], str, LazyProxy]] = None, startswith: Optional[Union[Sequence[Union[str, LazyProxy]], str, LazyProxy]] = None, endswith: Optional[Union[Sequence[Union[str, LazyProxy]], str, LazyProxy]] = None, ignore_case: bool = False)[source]#

Is useful for filtering text aiogram.types.message.Message, any aiogram.types.callback_query.CallbackQuery with data, aiogram.types.inline_query.InlineQuery or aiogram.types.poll.Poll question.

Warning

Only one of text, contains, startswith or endswith argument can be used at once. Any of that arguments can be string, list, set or tuple of strings.

Deprecated since version 3.0: use magic-filter. For example do F.text == "text" instead

text#
contains#
startswith#
endswith#
ignore_case#
prepare_text(text: str) str[source]#

Can be imported:

  • from aiogram.filters.text import Text

  • from aiogram.filters import Text

Usage#

  1. Text equals with the specified value: Text(text="text")  # value == 'text'

  2. Text starts with the specified value: Text(startswith="text")  # value.startswith('text')

  3. Text ends with the specified value: Text(endswith="text")  # value.endswith('text')

  4. Text contains the specified value: Text(contains="text")  # value in 'text'

  5. Any of previous listed filters can be list, set or tuple of strings that’s mean any of listed value should be equals/startswith/endswith/contains: Text(text=["text", "spam"])

  6. Ignore case can be combined with any previous listed filter: Text(text="Text", ignore_case=True)  # value.lower() == 'text'.lower()

Allowed handlers#

Allowed update types for this filter:

  • message

  • edited_message

  • channel_post

  • edited_channel_post

  • inline_query

  • callback_query