From 1ff75b0d1966726b51c2219f43e103046584f913 Mon Sep 17 00:00:00 2001 From: Derich Pacheco Date: Fri, 16 Jan 2026 22:23:32 -0300 Subject: [PATCH] feat: support for send/scheduled_at in broadcasts --- resend/broadcasts/_broadcasts.py | 13 +++++++++++++ tests/broadcasts_test.py | 27 +++++++++++++++++++++++++++ tests/exceptions_test.py | 4 +++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/resend/broadcasts/_broadcasts.py b/resend/broadcasts/_broadcasts.py index 676ebc6..5211b4e 100644 --- a/resend/broadcasts/_broadcasts.py +++ b/resend/broadcasts/_broadcasts.py @@ -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] @@ -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. diff --git a/tests/broadcasts_test.py b/tests/broadcasts_test.py index e669550..6e2c1dd 100644 --- a/tests/broadcasts_test.py +++ b/tests/broadcasts_test.py @@ -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( { diff --git a/tests/exceptions_test.py b/tests/exceptions_test.py index cb76542..bf34089 100644 --- a/tests/exceptions_test.py +++ b/tests/exceptions_test.py @@ -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"