Skip to content

Commit 1ff75b0

Browse files
committed
feat: support for send/scheduled_at in broadcasts
1 parent 0742e3f commit 1ff75b0

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

resend/broadcasts/_broadcasts.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class CreateParams(_CreateParamsFrom):
3939
html (NotRequired[str]): The HTML version of the message.
4040
text (NotRequired[str]): The text version of the message.
4141
name (NotRequired[str]): The friendly name of the broadcast. Only used for internal reference.
42+
send (NotRequired[bool]): When true, the broadcast will be sent immediately after creation.
43+
scheduled_at (NotRequired[str]): Schedule the broadcast to be sent later. Only valid when send is true.
4244
"""
4345

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

7689
class UpdateParams(_UpdateParamsFrom):
7790
"""UpdateParams is the class that wraps the parameters for the update method.

tests/broadcasts_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,33 @@ def test_broadcasts_send(self) -> None:
7474
broadcast = resend.Broadcasts.send(params)
7575
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e791"
7676

77+
def test_broadcasts_create_and_send(self) -> None:
78+
self.set_mock_json({"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"})
79+
80+
params: resend.Broadcasts.CreateParams = {
81+
"audience_id": "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e",
82+
"from": "hi@example.com",
83+
"subject": "Hello, world!",
84+
"name": "Python SDK Broadcast",
85+
"send": True,
86+
}
87+
broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(params)
88+
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
89+
90+
def test_broadcasts_create_and_schedule(self) -> None:
91+
self.set_mock_json({"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"})
92+
93+
params: resend.Broadcasts.CreateParams = {
94+
"audience_id": "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e",
95+
"from": "hi@example.com",
96+
"subject": "Hello, world!",
97+
"name": "Python SDK Broadcast",
98+
"send": True,
99+
"scheduled_at": "2024-12-21T19:32:22.980Z",
100+
}
101+
broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(params)
102+
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
103+
77104
def test_broadcasts_remove(self) -> None:
78105
self.set_mock_json(
79106
{

tests/exceptions_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def test_daily_quota_exceeded_error(self) -> None:
4949

5050
def test_monthly_quota_exceeded_error(self) -> None:
5151
with pytest.raises(RateLimitError) as e:
52-
raise_for_code_and_type(429, "monthly_quota_exceeded", "Monthly quota exceeded")
52+
raise_for_code_and_type(
53+
429, "monthly_quota_exceeded", "Monthly quota exceeded"
54+
)
5355
assert e.type is RateLimitError
5456
assert e.value.code == 429
5557
assert e.value.error_type == "monthly_quota_exceeded"

0 commit comments

Comments
 (0)