Common filters#
- pywa.filters.new(func: Callable[[_Wa, _T], bool | Awaitable[bool]], name: str | None = None) Filter#
Factory function to create a filter from a function (sync or async).
- filters.message = <pywa.filters.message object>#
- filters.callback_button = <pywa.filters.callback_button object>#
- filters.callback_selection = <pywa.filters.callback_selection object>#
- filters.message_status = <pywa.filters.message_status object>#
- filters.flow_completion = <pywa.filters.flow_completion object>#
- filters.template_status = <pywa.filters.template_status object>#
- filters.chat_opened = <pywa.filters.chat_opened object>#
- pywa.filters.sent_to(*, display_phone_number: str = None, phone_number_id: str = None) Filter#
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")
- filters.sent_to_me = <pywa.filters.sent_to_me object>#
- pywa.filters.from_users(*numbers: str) Filter#
Filter for updates that are sent from the given numbers.
>>> from_users("+1 555-555-5555", "972123456789")
- pywa.filters.from_countries(*prefixes: str | int) Filter#
Filter for updates that are sent from the given country codes.
See https://countrycode.org/ for a list of 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
- pywa.filters.matches(*strings: str, ignore_case: bool = False) Filter#
Filter for messages that are matching (
==) any of the given strings.- The strings will be checked against the following fields:
Message:text,captionCallbackButton:dataCallbackSelection:dataMessageStatus:trackerFlowCompletion:token,body
>>> matches("Hello", "Hi")
- Parameters:
*strings – The strings to match.
ignore_case – Whether to ignore case when matching.
- pywa.filters.contains(*words: str, ignore_case: bool = False) Filter#
Filter for updates that contain any of the given words.
- The words will be checked against the following fields:
Message:text,captionCallbackButton:dataCallbackSelection:dataMessageStatus:trackerFlowCompletion:token,body
>>> contains("Hello", "Hi", ignore_case=True)
- Parameters:
*words – The words to match.
ignore_case – Whether to ignore case when matching.
- pywa.filters.startswith(*prefixes: str, ignore_case: bool = False) Filter#
Filter for updates that start with any of the given prefixes.
- The prefixes will be checked against the following fields:
Message:text,captionCallbackButton:dataCallbackSelection:dataMessageStatus:trackerFlowCompletion:token,body
>>> startswith("Hello", "Hi", ignore_case=True)
- Parameters:
*prefixes – The prefixes to match.
ignore_case – Whether to ignore case when matching.
- pywa.filters.endswith(*suffixes: str, ignore_case: bool = False) Filter#
Filter for updates that end with any of the given suffixes.
- The suffixes will be checked against the following fields:
Message:text,captionCallbackButton:dataCallbackSelection:dataMessageStatus:trackerFlowCompletion:token,body
>>> endswith("Hello", "Hi", ignore_case=True)
- Parameters:
*suffixes – The suffixes to match.
ignore_case – Whether to ignore case when matching.
- pywa.filters.regex(*patterns: str | Pattern, flags: int = 0) Filter#
Filter for updates that match any of the given regex patterns.
- The patterns will be checked against the following fields:
Message:text,captionCallbackButton:dataCallbackSelection:dataMessageStatus:trackerFlowCompletion:token,body
>>> regex(r"Hello|Hi")
- Parameters:
*patterns – The regex patterns to match.
flags – The regex flags to use.