Message Status#
- class pywa.types.message_status.MessageStatus#
Represents the status of a message.
MessageStatus
is a generic class, so when providing afactory
parameter in callback handlers, you can specify the type of the factory to get autocomplete in thetracker
attribute.Here is an example:
>>> from pywa.types import CallbackData >>> from dataclasses import dataclass >>> @dataclass(frozen=True, slots=True) >>> class UserData(CallbackData): # Subclass CallbackData ... id: int ... name: str ... admin: bool
>>> from pywa import WhatsApp >>> from pywa.types import Button, CallbackButton >>> wa = WhatsApp(...) >>> wa.send_message( ... to='972987654321', ... text='Hi user', ... tracker=UserData(id=123, name='david', admin=True) # Here ^^^ we use the UserData class as the tracker ... ) # Here ^^^ we use the UserData class as the tracker data
>>> @wa.on_message_status(factory=UserData) # Use the factory parameter to convert the tracker data ... def on_status(_: WhatsApp, s: MessageStatus[UserData]): # For autocomplete ... if s.tracker.admin: print(s.tracker.id) # Access the tracker data
You can even use multiple factories, and not only
CallbackData
subclasses!>>> from enum import Enum >>> class State(str, Enum): ... START = 's' ... END = 'e'
>>> wa.send_message( ... to='972987654321', ... text='Hi user', ... tracker=(UserData(id=123, name='david', admin=True), State.START) ... ) # Here ^^^ we send a tuple of UserData and State
>>> @wa.on_message_status(factory=(UserData, State)) # Use the factory parameter to convert the tracker data ... def on_user_data(_: WhatsApp, s: MessageStatus[tuple[UserData, State]]): # For autocomplete ... user, state = s.tracker # Unpack the tuple ... if user.admin: print(user.id, state)
- Variables:
id (str) β The ID of the message that the status is for.
metadata (Metadata) β The metadata of the message (to which phone number it was sent).
status (MessageStatusType) β The status of the message.
timestamp (datetime.datetime) β The timestamp when the status was updated.
from_user (User) β The user who the message was sent to.
tracker (CallbackDataT | None) β The tracker that the message was sent with (e.g.
wa.send_message(tracker=...)
).conversation (Conversation | None) β The conversation the given status notification belongs to (Optional).
pricing_model (str | None) β Type of pricing model used by the business. Current supported value is CBP.
error (WhatsAppError | None) β The error that occurred (if status is
MessageStatusType.FAILED
).
- class pywa.types.message_status.MessageStatusType#
Message status type.
- Variables:
SENT β The message was sent.
DELIVERED β The message was delivered.
READ β The message was read.
FAILED β The message failed to send (you can access the
.error
attribute for more information).