Skip to content

3.9.0

Latest

Choose a tag to compare

@david-lev david-lev released this 11 Mar 21:06
· 2 commits to master since this release
cbd51fb

What's Changed

Update with pip: pip3 install -U pywa

  • [base_update] edit reply_template to accept Template obj
  • [templates] add auto_promotion_tag field to CreativeFeaturesSpec
  • [templates] fix template params validation in async (reported by @val-2 in #171)
  • [templates] fix filters import in wait_until_approved (reported by @SirKaiMartin in #175)
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.on_message
def send_marketing_message(_: WhatsApp, m: Message):
    m.reply_template(
        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.8.0...3.9.0