Models (astra.models)
Overview
Models provide typed views of bridge payloads. Main models are exposed below and documented via autodoc for quick reference.
- class Message(*, _client=None, id='', chat_id, sender=None, body='', type=MessageType.TEXT, timestamp=0, from_me=False, is_forwarded=False, is_newsletter=False, is_poll=False, is_reaction=False, is_status=False, ack=MessageAck.SENT, is_editable=False, sender_name=None, pushname=None, verified_name=None, quoted_message_id=None, quoted_participant=None, quoted_type=None, has_quoted_msg=False, mentioned_jids=<factory>, subtype=None, recipients=<factory>, mimetype=None, size=None)[source]
Represents a complete WhatsApp message record.
This class manages message metadata, sender identity, status flags, and provides methods for responding to or modifying messages.
- Parameters:
_client (Any)
id (str)
chat_id (JID)
sender (JID | None)
body (str)
type (MessageType)
timestamp (int)
from_me (bool)
is_forwarded (bool)
is_newsletter (bool)
is_poll (bool)
is_reaction (bool)
is_status (bool)
ack (MessageAck)
is_editable (bool)
sender_name (str | None)
pushname (str | None)
verified_name (str | None)
quoted_message_id (str | None)
quoted_participant (JID | None)
quoted_type (MessageType | None)
has_quoted_msg (bool)
subtype (str | None)
mimetype (str | None)
size (int | None)
- property quoted: Message | None
Returns the quoted message object if available. Note: This is a synchronous property, it doesn’t fetch from server. Only works if the quoted message was included in the payload.
- classmethod from_payload(data, client=None)[source]
Translates a raw JS runtime payload into a typed Message object.
- class Chat(id, title, is_group=False, is_readonly=False, unread_count=0, mute_expiration=0, last_message_timestamp=0, _client=None)[source]
Represents a conversational thread on WhatsApp.
Holds metadata about the chat such as its title, unread message count, and synchronization status.
- Parameters:
- class User(id, name=None, push_name=None, is_me=False, is_business=False, is_my_contact=False, verified_name=None, _client=None)[source]
Represents a WhatsApp Actor - a person, group participant, or yourself.
This class holds metadata about a contact or user, such as their display name and business status.
- Parameters:
- class JID(user, server, serialized)[source]
Represents a WhatsApp Jabber ID (JID).
A JID uniquely identifies a user, group, or newsletter on WhatsApp. Example: ‘1234567890@c.us’ (User) or ‘1234567890@g.us’ (Group).
- classmethod parse(raw)[source]
Parses a raw JID string into a structured JID object.
- Parameters:
raw (str) – The raw WhatsApp ID string (e.g., “12345@c.us”).
- Returns:
A structured JID instance.
- Return type:
Example
>>> jid = JID.parse("12345@c.us") >>> print(jid.user) "12345"
- property primary: str
Returns the primary (base) JID without device suffixes. Example: ‘12345:4@lid’ -> ‘12345@lid’
Important fields
Message.body/Message.text— message contentMessage.id/Message.chat_id— unique identifiersMessage.is_media/Message.is_group— boolean status flagsMessage.quoted— access to the replied-to message objectChat.title/Chat.is_group— thread metadata
Example: converting a payload
from astra.protocol.serializers import DataTransformer
message = DataTransformer.to_message(raw_payload, client)
Async notes
Model constructors are synchronous; hydration occurs from bridge results
(synchronous mapping in Python after an async bridge call).