3.8.0
What's Changed
Update with pip:
pip3 install -U pywa
- [templates] enhance template parameters validation and improve component handling
- [types] update
BusinessProfileto allow optional 'about' field (reported by @riklaunim in #169)
from pywa import WhatsApp
from pywa.types.templates import *
template = Template(
name="buy_new_iphone_x",
category=TemplateCategory.MARKETING,
language=TemplateLanguage.ENGLISH_US,
parameter_format=ParamFormat.NAMED,
components=[
ht := HeaderText("The New iPhone {{iphone_num}} is here!", iphone_num=17),
bt := BodyText(
"Buy now and use the code {{code}} to get {{per}}% off!",
code="WA_IPHONE_15",
per=17,
),
FooterText(text="Powered by PyWa"),
Buttons(
buttons=[
url := URLButton(
text="Buy Now",
url="https://example.com/shop/{{1}}",
example="iphone17",
),
PhoneNumberButton(text="Call Us", phone_number="1234567890"),
qrb1 := QuickReplyButton(text="Unsubscribe from marketing messages"),
qrb2 := QuickReplyButton(text="Unsubscribe from all messages"),
]
),
],
)
wa = WhatsApp(...)
wa.send_template(
to="9876543210",
template=template, # Use the template object to validate params *before* sending
params=[
ht.params(iphone_num=30),
bt.params(code="WA_IPHONE_30", per=30),
url.params(url_variable="iphone30", index=0),
qrb1.params(callback_data="unsubscribe_from_marketing_messages", index=1),
qrb2.params(callback_data="unsubscribe_from_all_messages", index=2),
],
)Full Changelog: 3.7.0...3.8.0