-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbroadcasts_async.py
More file actions
76 lines (61 loc) · 2.19 KB
/
broadcasts_async.py
File metadata and controls
76 lines (61 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import asyncio
import os
from typing import List
import resend
import resend.broadcasts
if not os.environ["RESEND_API_KEY"]:
raise EnvironmentError("RESEND_API_KEY is missing")
# Set up async HTTP client
# replace with some existing audience id
audience_id: str = "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e"
async def main() -> None:
create_params: resend.Broadcasts.CreateParams = {
"audience_id": audience_id,
"from": "onboarding@resend.dev",
"subject": "Hello, world! (Async)",
"html": "<p>Hello, world!</p>",
"text": "Hello, world!",
"reply_to": ["foo@resend.dev", "bar@resend.dev"],
"name": "Hello, world! (Async)",
}
broadcast: resend.Broadcasts.CreateResponse = await resend.Broadcasts.create_async(
create_params
)
print("Created broadcast !")
print(broadcast)
update_params: resend.Broadcasts.UpdateParams = {
"broadcast_id": broadcast["id"],
"html": "<p>Hello, world! Updated (Async)</p>",
"text": "Hello, world! Updated (Async)",
"name": "Hello, world! Updated (Async)",
}
updated_broadcast: resend.Broadcasts.UpdateResponse = (
await resend.Broadcasts.update_async(update_params)
)
print("Updated broadcast!")
print(updated_broadcast)
send_params: resend.Broadcasts.SendParams = {
"broadcast_id": broadcast["id"],
}
sent: resend.Broadcasts.SendResponse = await resend.Broadcasts.send_async(
send_params
)
print("Sent broadcast !\n")
print(sent)
retrieved: resend.Broadcast = await resend.Broadcasts.get_async(id=broadcast["id"])
print("retrieved broadcast !\n")
print(retrieved)
if retrieved["status"] == "draft":
removed: resend.Broadcasts.RemoveResponse = (
await resend.Broadcasts.remove_async(id=broadcast["id"])
)
print("Removed broadcast !\n")
print(removed)
print("\n")
else:
print("Broadcast is not in draft status, cannot remove it.\n")
list_response: resend.Broadcasts.ListResponse = await resend.Broadcasts.list_async()
print("List of broadcasts !\n")
print(list_response)
if __name__ == "__main__":
asyncio.run(main())