telebot_py.filters¶
Update and message filtering with boolean algebra (FR-002).
Filters compose with &, | and ~ (or the and_/or_/not_
aliases) and gate which updates reach a handler:
from telebot_py import filters
from telebot_py.routing import MessageHandler
private_text = filters.TEXT & filters.ChatType.PRIVATE
handler = MessageHandler(private_text, callback)
telebot_py.filters.base¶
Message filter base class with boolean-algebra composition (FR-002).
- telebot_py.filters.base.FilterResult = bool | dict[str, typing.Any] | None¶
True/Falsefor plain filters, or a dict of extracted data (truthy on match) fordata_filterfilters.- Type:
Result of evaluating a filter
- class telebot_py.filters.base.MessageFilter¶
Bases:
objectBase class for filters inspecting
Messageobjects.Subclass and override
filter(), or combine instances with&,|and~(also available asand_(),or_(),not_()sinceand/or/notare Python keywords). Evaluation of combined filters short-circuits. Filters withdata_filterset return a dict of extracted data on a match, which handlers merge into the callback context.- Variables:
data_filter (bool) – Whether the filter yields extracted data instead of a plain bool.
- and_(other: MessageFilter) MessageFilter¶
Combine with
othervia logical AND (alias of&).- Parameters:
other – The filter to combine with.
- Returns:
A new composite filter matching only when both sides match.
- data_filter: bool = False¶
- filter(message: Message) bool | dict[str, Any] | None¶
Evaluate this filter against
message.- Parameters:
message – The message to inspect.
- Returns:
Trueon a match andFalseotherwise; for data filters a non-empty dict on a match and a falsy value otherwise.
- not_() MessageFilter¶
Invert this filter (alias of
~).- Returns:
A new filter matching when this one does not.
- or_(other: MessageFilter) MessageFilter¶
Combine with
othervia logical OR (alias of|).- Parameters:
other – The filter to combine with.
- Returns:
A new composite filter matching when either side matches.
telebot_py.filters.matchers¶
Built-in message filters mirroring python-telegram-bot’s filters module.
- telebot_py.filters.matchers.ALL: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
Matches every message unconditionally.
- telebot_py.filters.matchers.COMMAND: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
Messages that start with a bot command entity.
- class telebot_py.filters.matchers.Chat(chat_id: int | Iterable[int] | None = None, username: str | Iterable[str] | None = None)¶
Bases:
MessageFilterFilter matching messages sent in a specific chat.
- Variables:
chat_ids – Chat ids accepted by this filter.
usernames – Lower-cased chat usernames accepted by this filter.
- class telebot_py.filters.matchers.ChatType¶
Bases:
objectFilters matching the type of chat a message was sent in.
- Variables:
PRIVATE (telebot_py.filters.base.MessageFilter) – Matches messages from private (1-on-1) chats.
GROUP (telebot_py.filters.base.MessageFilter) – Matches messages from basic group chats.
SUPERGROUP (telebot_py.filters.base.MessageFilter) – Matches messages from supergroup chats.
CHANNEL (telebot_py.filters.base.MessageFilter) – Matches messages posted to channels.
GROUPS (telebot_py.filters.base.MessageFilter) – Matches messages from basic groups or supergroups.
- CHANNEL: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
- GROUP: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
- GROUPS: MessageFilter = <telebot_py.filters.base._OrFilter object>¶
- PRIVATE: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
- SUPERGROUP: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
- telebot_py.filters.matchers.DOCUMENT: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
Messages that carry a document.
- telebot_py.filters.matchers.NONE: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
Matches no message ever.
- telebot_py.filters.matchers.PHOTO: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
Messages that carry a photo.
- class telebot_py.filters.matchers.Regex(pattern: str | Pattern[str])¶
Bases:
MessageFilterData filter matching message text (or caption) against a regular expression.
On a match the filter yields
{"matches": [re.Match]}, which handlers merge onto the callback context ascontext.matches. The pattern is searched (re.searchsemantics) againstmessage.textfalling back tomessage.caption.- Variables:
pattern – The compiled regular expression to search for.
data_filter (bool) – Always
True; this filter extracts match data.
- data_filter: bool = True¶
- telebot_py.filters.matchers.TEXT: MessageFilter = <telebot_py.filters.matchers._PredicateFilter object>¶
Messages that contain non-empty text.
- class telebot_py.filters.matchers.User(user_id: int | Iterable[int] | None = None, username: str | Iterable[str] | None = None)¶
Bases:
MessageFilterFilter matching messages sent by a specific user.
- Variables:
user_ids – User ids accepted by this filter.
usernames – Lower-cased usernames accepted by this filter.