Common filters#
- pywa.filters.new(func, name=None)#
Factory function to create a filter from a function (sync or async).
- Return type:
Filter
- 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.call_connect = <pywa.filters.call_connect object>#
- filters.call_terminate = <pywa.filters.call_terminate object>#
- filters.call_status = <pywa.filters.call_status object>#
- filters.call_permission_update = <pywa.filters.call_permission_update object>#
- filters.user_marketing_preferences = <pywa.filters.user_marketing_preferences object>#
- filters.template_status = <pywa.filters.template_status object>#
- filters.template_category = <pywa.filters.template_category object>#
- filters.template_quality = <pywa.filters.template_quality object>#
- filters.template_components = <pywa.filters.template_components object>#
- filters.phone_number_change = <pywa.filters.phone_number_change object>#
- filters.identity_change = <pywa.filters.identity_change object>#
- pywa.filters.sent_to(*, display_phone_number=None, phone_number_id=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")
- Return type:
Filter
- filters.sent_to_me = <pywa.filters.sent_to_me object>#
- pywa.filters.from_users(*numbers)#
Filter for updates that are sent from the given numbers.
>>> from_users("+1 555-555-5555", "972123456789")
- Return type:
Filter
- pywa.filters.from_countries(*prefixes_or_codes)#
Filter for updates that are sent from the given country codes.
You can pass either country codes (e.g. “US”, “IL”) or phone number prefixes (e.g. “+1”, “972”).
See https://countrycode.org/ for a list of country codes.
>>> from_countries("972", "1", "+972", "US", "IL") # Israel and USA
- Return type:
Filter
- pywa.filters.matches(*strings, ignore_case=False)#
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")
- pywa.filters.contains(*words, ignore_case=False)#
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)
- pywa.filters.startswith(*prefixes, ignore_case=False)#
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)
- pywa.filters.endswith(*suffixes, ignore_case=False)#
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)
- pywa.filters.regex(*patterns, flags=0)#
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")