Skip to content

feat: add filters.IS_BOT to filter messages by sender bot status - #5380

Open
rahulrajarapu158-arch wants to merge 1 commit into
python-telegram-bot:masterfrom
rahulrajarapu158-arch:feat/add-is-bot-filter
Open

rahulrajarapu158-arch wants to merge 1 commit into
python-telegram-bot:masterfrom
rahulrajarapu158-arch:feat/add-is-bot-filter

Conversation

@rahulrajarapu158-arch

Copy link
Copy Markdown

Summary

Closes #5315 — adds filters.IS_BOT to filter messages by whether the sender is a bot.

Changes

  • filters.py: Added _IsBot MessageFilter class and IS_BOT constant
  • filters.py: Added IS_BOT to __all__ exports
  • test_filters.py: Added test_filters_is_bot test covering: bot user match, negation, and from_user=None edge case
  • changes/unreleased/: Added changelog entry

API

from telegram.ext import filters

# In a handler:
@router.message(filters.IS_BOT)
def handle_bot_message(update, context): ...

# Negation works as expected:
@router.message(~filters.IS_BOT)
def handle_human_message(update, context): ...

Note: Channel posts and anonymous-admin messages have no from_user and therefore do not match; use filters.SenderChat for those.

Acceptance criteria

  • filters.IS_BOT exists and filters by User.is_bot
  • Negation via ~filters.IS_BOT works
  • Edge case from_user=None handled correctly
  • Tests added and passing
  • Changelog entry added

Adds IS_BOT filter exposing User.is_bot for multi-bot group chat scenarios.
Includes negation support via ~filters.IS_BOT.

Closes python-telegram-bot#5315
@harshil21

Copy link
Copy Markdown
Member

Did you bother to look at the review I left all the other closed PR's for this?

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