Skip to content
Merged
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
13 changes: 13 additions & 0 deletions resend/broadcasts/_broadcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class CreateParams(_CreateParamsFrom):
html (NotRequired[str]): The HTML version of the message.
text (NotRequired[str]): The text version of the message.
name (NotRequired[str]): The friendly name of the broadcast. Only used for internal reference.
send (NotRequired[bool]): When true, the broadcast will be sent immediately after creation.
scheduled_at (NotRequired[str]): Schedule the broadcast to be sent later. Only valid when send is true.
"""

segment_id: NotRequired[str]
Expand Down Expand Up @@ -72,6 +74,17 @@ class CreateParams(_CreateParamsFrom):
"""
The friendly name of the broadcast. Only used for internal reference.
"""
send: NotRequired[bool]
"""
When set to true, the broadcast will be sent immediately after creation.
If false or not provided, the broadcast will be created as a draft.
"""
scheduled_at: NotRequired[str]
"""
Schedule the broadcast to be sent later.
Only valid when send is set to true.
The date should be in natural language (e.g.: in 1 min) or ISO 8601 format (e.g: 2024-08-05T11:52:01.858Z).
"""

class UpdateParams(_UpdateParamsFrom):
"""UpdateParams is the class that wraps the parameters for the update method.
Expand Down
27 changes: 27 additions & 0 deletions tests/broadcasts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,33 @@ def test_broadcasts_send(self) -> None:
broadcast = resend.Broadcasts.send(params)
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e791"

def test_broadcasts_create_and_send(self) -> None:
self.set_mock_json({"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"})

params: resend.Broadcasts.CreateParams = {
"audience_id": "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e",
"from": "hi@example.com",
"subject": "Hello, world!",
"name": "Python SDK Broadcast",
"send": True,
}
broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(params)
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"

def test_broadcasts_create_and_schedule(self) -> None:
self.set_mock_json({"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"})

params: resend.Broadcasts.CreateParams = {
"audience_id": "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e",
"from": "hi@example.com",
"subject": "Hello, world!",
"name": "Python SDK Broadcast",
"send": True,
"scheduled_at": "2024-12-21T19:32:22.980Z",
}
broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(params)
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"

def test_broadcasts_remove(self) -> None:
self.set_mock_json(
{
Expand Down
4 changes: 3 additions & 1 deletion tests/exceptions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def test_daily_quota_exceeded_error(self) -> None:

def test_monthly_quota_exceeded_error(self) -> None:
with pytest.raises(RateLimitError) as e:
raise_for_code_and_type(429, "monthly_quota_exceeded", "Monthly quota exceeded")
raise_for_code_and_type(
429, "monthly_quota_exceeded", "Monthly quota exceeded"
)
assert e.type is RateLimitError
assert e.value.code == 429
assert e.value.error_type == "monthly_quota_exceeded"
Loading