Common filters#

pywa.filters.all_(*filters: Callable[[_Wa, _T], bool]) Callable[[_Wa, _T], bool]#

Filter for updates that pass all the given filters.

>>> all_(text.startswith("Hello"), text.endswith("Word"))
pywa.filters.any_(*filters: Callable[[_Wa, _T], bool]) Callable[[_Wa, _T], bool]#

Filter for updates that pass any of the given filters.

>>> any_(text.contains("Hello"), text.regex(r"^World"))
pywa.filters.not_(fil: Callable[[_Wa, _T], bool]) Callable[[_Wa, _T], bool]#

Filter for updates that don’t pass the given filter.

>>> not_(text.contains("Hello"))
pywa.filters.sent_to(*, display_phone_number: str = None, phone_number_id: str = None)#

Filter for updates that are sent to the given phone number.

  • Use this filter when you choose not filter updates (e.g. WhatsApp(..., filter_updates=False)) so you can still filter for messages that are sent to specific phone numbers.

>>> sent_to(display_phone_number="+1 555-555-5555")
>>> sent_to(phone_number_id="123456789")
pywa.filters.from_users(*numbers: str) _MessageFilterT | _CallbackFilterT | _MessageStatusFilterT#

Filter for messages that are sent from the given numbers.

>>> from_users("+1 555-555-5555", "972123456789")
pywa.filters.from_countries(*prefixes: str | int) _MessageFilterT | _CallbackFilterT | _MessageStatusFilterT#

Filter for messages that are sent from the given country codes.

It is always recommended to restrict the countries that can use your bot. remember that you pay for every conversation that you reply to.

>>> from_countries("972", "1") # Israel and USA