Message Status

Message Status#

class pywa.types.message_status.MessageStatus#

Represents the status of a message.

MessageStatus is a generic class, so when providing a factory parameter in callback handlers, you can specify the type of the factory to get autocomplete in the tracker 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).