Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/contacts_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
print("Retrieved contact by ID:")
print(cont_by_id)
if "properties" in cont_by_id:
print(f"Custom properties: {cont_by_id['properties']}")
for name, prop in cont_by_id["properties"].items():
print(f"Custom property {name}: {prop['value']} ({prop['type']})")

# List all global contacts
print("\n--- Listing all global contacts ---")
Expand Down
15 changes: 13 additions & 2 deletions resend/contacts/_contact.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
from typing import Any, Dict
from typing import Dict, Union

from typing_extensions import NotRequired, TypedDict


class ContactPropertyValue(TypedDict):
value: Union[str, int, float, bool]
"""
The property value, a string, number, or boolean depending on type.
"""
type: str
"""
The property type ("string", "number", or "boolean").
"""


class Contact(TypedDict):
id: str
"""
Expand All @@ -28,7 +39,7 @@ class Contact(TypedDict):
"""
The unsubscribed status of the contact.
"""
properties: NotRequired[Dict[str, Any]]
properties: NotRequired[Dict[str, ContactPropertyValue]]
"""
Custom properties for the contact. Only available for global contacts.
"""
8 changes: 4 additions & 4 deletions tests/contacts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,16 @@ def test_contacts_get_global(self) -> None:
"last_name": "Contact",
"created_at": "2023-10-06 23:47:56.678+00",
"unsubscribed": False,
"properties": {"tier": "premium"},
"properties": {"tier": {"value": "premium", "type": "string"}},
}
)

contact: resend.Contact = resend.Contacts.get(id="global-contact-123")
assert contact["id"] == "global-contact-123"
assert contact["email"] == "global@example.com"
assert contact.get("properties") == {"tier": "premium"}
assert contact.get("properties") == {
"tier": {"value": "premium", "type": "string"}
}

def test_contacts_list_global(self) -> None:
self.set_mock_json(
Expand All @@ -399,7 +401,6 @@ def test_contacts_list_global(self) -> None:
"last_name": "One",
"created_at": "2023-10-06 23:47:56.678+00",
"unsubscribed": False,
"properties": {"tier": "free"},
},
{
"id": "global-2",
Expand All @@ -408,7 +409,6 @@ def test_contacts_list_global(self) -> None:
"last_name": "Two",
"created_at": "2023-10-07 23:47:56.678+00",
"unsubscribed": False,
"properties": {"tier": "premium"},
},
],
}
Expand Down
Loading