Skip to content

Commit

Permalink
[reply_to_msg] adding ReferredProduct to message context
Browse files Browse the repository at this point in the history
  • Loading branch information
david-lev committed Nov 19, 2023
1 parent 437df0a commit dc9e74e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/source/content/types/update_fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Message Fields

.. autoclass:: ReplyToMessage()

.. autoclass:: ReferredProduct()

.. autoclass:: Metadata()

.. currentmodule:: pywa.types.message_status
Expand Down
1 change: 1 addition & 0 deletions pywa/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ProductsSection,
Reaction,
ReplyToMessage,
ReferredProduct,
System,
User,
)
Expand Down
36 changes: 35 additions & 1 deletion pywa/types/others.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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
)
Expand Down

0 comments on commit dc9e74e

Please sign in to comment.