diff --git a/docs/source/content/types/update_fields.rst b/docs/source/content/types/update_fields.rst index 4941e05c..f548602d 100644 --- a/docs/source/content/types/update_fields.rst +++ b/docs/source/content/types/update_fields.rst @@ -19,6 +19,8 @@ Message Fields .. autoclass:: ReplyToMessage() +.. autoclass:: ReferredProduct() + .. autoclass:: Metadata() .. currentmodule:: pywa.types.message_status diff --git a/pywa/types/__init__.py b/pywa/types/__init__.py index 5591f114..b7a7dad4 100644 --- a/pywa/types/__init__.py +++ b/pywa/types/__init__.py @@ -34,6 +34,7 @@ ProductsSection, Reaction, ReplyToMessage, + ReferredProduct, System, User, ) diff --git a/pywa/types/others.py b/pywa/types/others.py index 21e6b8b9..22fe3cdc 100644 --- a/pywa/types/others.py +++ b/pywa/types/others.py @@ -352,6 +352,32 @@ class Address(utils.FromDict): type: str | None = None +@dataclasses.dataclass(frozen=True, slots=True) +class ReferredProduct: + """ + Represents a product this message is referring to. + + Attributes: + catalog_id: + sku: Unique identifier of the product in a catalog (also referred to as ``Content ID`` or ``Retailer ID``). + + """ + + catalog_id: str + sku: str + + @classmethod + def from_dict(cls, data: dict | None) -> ReferredProduct | None: + return ( + cls( + catalog_id=data["catalog_id"], + sku=data["product_retailer_id"], + ) + if data + else None + ) + + @dataclasses.dataclass(frozen=True, slots=True) class ReplyToMessage: """ @@ -360,15 +386,23 @@ class ReplyToMessage: Attributes: message_id: The ID of the message that was replied to. from_user_id: The ID of the user who sent the message that was replied to. + referred_product: Referred product describing the product the user is requesting information about. """ message_id: str from_user_id: str + referred_product: ReferredProduct | None @classmethod def from_dict(cls, data: dict | None) -> ReplyToMessage | None: return ( - cls(message_id=data["id"], from_user_id=data["from"]) + cls( + message_id=data["id"], + from_user_id=data["from"], + referred_product=ReferredProduct.from_dict( + data.get("referred_product") + ), + ) if (data and "id" in data) else None )