Skip to content

1.6.0

Compare
Choose a tag to compare
@david-lev david-lev released this 11 Oct 11:58
· 409 commits to master since this release

What's Changed

Update with pip: pip3 install -U pywa

  • handlers: apply callback data factory before filters by setting factory_before_filters to True when registering the handler
import dataclasses
from pywa import WhatsApp
from pywa.types import CallbackData, CallbackButton

@dataclasses.dataclass(frozen=True, slots=True)
class User(CallbackData):
    id: int
    admin: bool

wa = WhatsApp(...)

@wa.on_callback_button(
    lambda _, b: b.data.admin, lambda _, b: b.data.id == 1, # filters get access to user data
    factory=User, # factory to convert the callback data to the user object
    factory_before_filters=True # factory will run before the filters
)
def on_callback_button(_: WhatsApp, clb: CallbackButton[User]):
    print(f"User with id {clb.data.id} is admin")

Full Changelog: 1.5.4...1.6.0