What's Changed
Update with pip:
pip3 install -U pywa
- [base_update] adding
shared_data
to help sharing context between handlers & filters (suggested by @mhaugestad in #94) - [flows] adding
FlowStr
- A helper class to create strings containing vars and math expressions without escaping and quoting them
from pywa import WhatsApp, types, filters
wa = WhatsApp(...)
@wa.on_message(filters.text, priority=100) # a higher priority will be executed first
def on_every_text_message(_: WhatsApp, m: types.Message):
m.shared_data["key"] = "some_value" # .shared_data is a dict that can be used to store data between handlers
m.continue_handling() # continue to the next handler
# access shared_data from filters
@wa.on_message(filters.new(lambda _, m: m.shared_data["key"] == "value"))
def handle_value(_: WhatsApp, m: types.Message):
if m.shared_data["other_key"] == "other_value":
...
from pywa.types.flows import *
FlowJSON(
screens=[
Screen(
id="START",
layout=Layout(
children=[
bill := TextInput(name="bill", input_type=InputType.NUMBER),
tip := TextInput(name="tip", input_type=InputType.NUMBER),
TextHeading(
# text=f"`'Your total bill is ' {bill.ref + (bill.ref * tip.ref / 100)}`",
text=FlowStr(
# avoid escaping and quoting vars and math expressions
string="Your total bill is {bill}",
bill=bill.ref + (bill.ref * tip.ref / 100),
)
),
]
),
)
]
)
Full Changelog: 2.5.2...2.6.0