What's Changed
Update with pip:
pip3 install -U pywa
- [handlers] adding
on_init
,on_data_exchange
andon_back
decorators for flow request callback wrapper - [flows]
FlowRequest.respond
defaults to request flow token - [flows] adding
FlowRequest.token_no_longer_valid
shortcut - [flows] deprecate
FlowRequest.is_health_check
andFlowRequestActionType.PING
from pywa import WhatsApp, filters
from pywa.types import FlowRequest, FlowResponse
wa = WhatsApp(...)
@wa.on_flow_request("/survey-flow")
def survey(_: WhatsApp, req: FlowRequest) -> FlowResponse:
raise NotImplementedError(req)
@survey.on_init
def on_init(_: WhatsApp, req: FlowRequest) -> FlowResponse:
return req.respond(screen="SURVEY", data={"first_name": "David"})
@survey.on_data_exchange(screen="SURVEY", filters=filters.new(lambda _, r: int(r.data["rating"]) > 3))
def on_good_rating(_: WhatsApp, req: FlowRequest) -> FlowResponse:
return req.respond(screen="GOOD_RATING")
@survey.on_data_exchange(call_on_error=True)
def on_error(_: WhatsApp, req: FlowRequest) -> None:
logging.error("Error in survey flow: %s", req.data)
Full Changelog: 2.4.0...2.5.1