Skip to content

2.8.0

Choose a tag to compare

@david-lev david-lev released this 27 Apr 13:56
· 400 commits to master since this release

What's Changed

Update with pip: pip3 install -U pywa

  • [client] indicate text typing status when preparing a message
  • [client] adding methods to block/unblock and get blocked users
  • [types] adding Result and Pagination classes to help paginate results in some methods
  • [user] adding .block() and .unblock() shortcuts
  • [user] adding input field, available when sending a message to a user
  • [flows] adding label_variant to TextInput and TextArea
  • [flows] adding generics to prevent type errors when using ScreenData and Components as refs
  • [flows] adding CalendarRangeValues to use when CalendarPicker mode is range
  • [utils] update Version FLOW_JSON to 7.0 and GRAPH_API to 22.0
from pywa import WhatsApp, types, filters

wa = WhatsApp(...)

@wa.on_message(filters.contains(*list_of_very_very_bad_words), priority=100)
def check(_: WhatsApp, m: types.Message):
    m.indicate_typing() # it can take a while to respond so we indicate typing
    if db.check_if_user_already_warned(m.from_user.wa_id):
        m.reply("You are blocked for using bad words")
        m.from_user.block() # block the user
        m.stop_handling()
    else:
        m.reply("You are warned for using bad words")
        db.mark_user_as_warned(m.from_user.wa_id)
        m.continue_handling()
from pywa.types.flows import *

my_flow = FlowJSON(
    screens=[
        Screen(
            id="WELCOME",
            data=[
                is_new_user := ScreenData( # boolean screen data
                    key="is_new_user",
                    example=True
                ),
                welcome_msg := ScreenData( # string screen data
                    key="welcome_msg",
                    example="Welcome to our service!"
                ),
            ],
            layout=Layout(
                children=[
                    TextBody(
                        # The type checker will warn you
                        text=is_new_user.ref,
                        visible=welcome_msg.ref
                        
                    ),
                    TextBody(
                        # Everything is fine here
                        text=welcome_msg.ref,
                        visible=is_new_user.ref
                    )
                ]
            )
        )
    ]
)

Full Changelog: 2.7.0...2.8.0