Visitar URL original
Add filters.IS_BOT for bot-authored messages by ShahadatTest · Pull Request #5384 · python-telegram-bot/python-telegram-bot · GitHub
Skip to content

Add filters.IS_BOT for bot-authored messages - #5384

Open
ShahadatTest wants to merge 2 commits into
python-telegram-bot:masterfrom
ShahadatTest:bot-sender-filter
Open

ShahadatTest wants to merge 2 commits into
python-telegram-bot:masterfrom
ShahadatTest:bot-sender-filter

Conversation

@ShahadatTest

@ShahadatTest ShahadatTest commented Oct 21, 2026 •

Copy link
Copy Markdown

Add filters.IS_BOT so message handlers can select messages whose sender is a bot. It checks Update.effective_user.is_bot, following the existing user-attribute filters. A missing sender returns False; via_bot does not determine whether the sender is a bot.

Closes #5315. The constant is exported, documented through the existing filters automodule, and marked versionadded:: NEXT.VERSION.

Tests follow the existing filter-test style: mutate the sender's is_bot flag and assert the result directly. A separate test covers a missing sender using a fresh fixture, since Update.effective_user caches a resolved user.

Validation on Windows with CPython 3.14.6:

  • pytest tests/ext/test_filters.py --disable-socket -q: 217 passed.
  • prek run --files tests/ext/test_filters.py: Ruff lint and formatting passed; source-only hooks skipped because this update changes tests only.
  • git diff --check: passed.

The existing Chango workflow handles the PR's changelog fragment.

AI disclosure: the implementation, tests, and this description were prepared with OpenAI Codex.

Comment thread tests/ext/test_filters.py Outdated
Comment on lines +2170 to +2192
@pytest.mark.parametrize(
"message_type",
[
"message",
"edited_message",
"channel_post",
"edited_channel_post",
"business_message",
"edited_business_message",
"guest_message",
],
)
@pytest.mark.parametrize("is_bot", [True, False, None])
def test_filters_is_bot(self, update, message_type, is_bot):
if is_bot is None:
update.message.from_user = None
else:
update.message.from_user.is_bot = is_bot
message_update = Update(0, **{message_type: update.message})

assert filters.IS_BOT.check_update(message_update) is (is_bot is True)
assert (~filters.IS_BOT).check_update(message_update) is (is_bot is not True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no make this test like the others

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add filters.IS_BOT — no filter exposes User.is_bot (needed for multi-bot group chats)

2 participants