Text

Is useful for filtering text Message, any CallbackQuery with data, InlineQuery or Poll question.

Can be imported:

  • from aiogram.dispatcher.filters.text import Text
  • from aiogram.dispatcher.filters import Text
  • from aiogram.filters import Text

Or used from filters factory by passing corresponding arguments to handler registration line

Specification

Argument Type Description
text Optional[Union[Sequence[str], str]] Text equals value or one of values
text_contains Optional[Union[Sequence[str], str]] Text contains value or one of values
text_startswith Optional[Union[Sequence[str], str]] Text starts with value or one of values
text_endswith Optional[Union[Sequence[str], str]] Text ends with value or one of values
text_ignore_case bool Ignore case when checks (Default: False)

Warning

Only one of text, text_contains, text_startswith or text_endswith argument can be used at once. Any of that arguments can be string, list, set or tuple of strings.

Usage

  1. Text equals with the specified value: Text(text="text") # value == 'text'
  2. Text starts with the specified value: Text(text_startswith="text") # value.startswith('text')
  3. Text ends with the specified value: Text(text_endswith="text") # value.endswith('text')
  4. Text contains the specified value: Text(text_endswith="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", 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