Skip to content

Commit

Permalink
[user] add input field, available when sending a message
Browse files Browse the repository at this point in the history
  • Loading branch information
david-lev committed Jan 25, 2025
1 parent 8fd9ae8 commit b26df71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pywa/types/others.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ class User:
Attributes:
wa_id: The WhatsApp ID of the user (The phone number with the country code).
name: The name of the user (``None`` on :class:`MessageStatus` or when message type is :class:`MessageType.SYSTEM`).
input: The input of the recipient is only available when sending a message.
"""

wa_id: str
name: str | None
input: str | None = dataclasses.field(
default=None, repr=False, hash=False, compare=False
)

@classmethod
def from_dict(cls, data: dict) -> User:
return cls(wa_id=data["wa_id"], name=data["profile"]["name"])
return cls(
wa_id=data["wa_id"],
name=data.get("profile", {}).get("name"),
input=data.get("input"),
)

def as_vcard(self) -> str:
"""Get the user as a vCard."""
Expand Down
4 changes: 2 additions & 2 deletions pywa/types/sent_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def from_sent_update(
) -> SentMessage:
msg_id, user = (
update["messages"][0]["id"],
User(update["contacts"][0]["wa_id"], name=None),
User.from_dict(update["contacts"][0]),
)
return cls(
_client=client,
Expand Down Expand Up @@ -421,7 +421,7 @@ def from_sent_update(
) -> SentTemplate:
msg, user = (
update["messages"][0],
User(update["contacts"][0]["wa_id"], name=None),
User.from_dict(update["contacts"][0]),
)
return cls(
_client=client,
Expand Down

0 comments on commit b26df71

Please sign in to comment.