1010async def main () -> None :
1111 # Create and publish a template to use in the automation
1212 print ("--- Create and publish template ---" )
13- tpl : resend .Templates .CreateResponse = await resend .Templates .create_async ({
14- "name" : "welcome-email" ,
15- "subject" : "Welcome!" ,
16- "html" : "<strong>Welcome to our service!</strong>" ,
17- })
13+ tpl : resend .Templates .CreateResponse = await resend .Templates .create_async (
14+ {
15+ "name" : "welcome-email" ,
16+ "subject" : "Welcome!" ,
17+ "html" : "<strong>Welcome to our service!</strong>" ,
18+ }
19+ )
1820 await resend .Templates .publish_async (tpl ["id" ])
1921 print (f"Template: { tpl ['id' ]} " )
2022
2123 # --- Create a simple automation (trigger → send_email) ---
2224 print ("\n --- Create automation ---" )
23- simple : resend .Automations .CreateResponse = await resend .Automations .create_async ({
24- "name" : "Welcome Flow" ,
25- "status" : "disabled" ,
26- "steps" : [
27- {
28- "key" : "trigger_1" ,
29- "type" : "trigger" ,
30- "config" : {"event_name" : "user.created" },
31- },
32- {
33- "key" : "send_1" ,
34- "type" : "send_email" ,
35- "config" : {"template" : {"id" : tpl ["id" ]}},
36- },
37- ],
38- "connections" : [
39- {"from" : "trigger_1" , "to" : "send_1" },
40- ],
41- })
25+ simple : resend .Automations .CreateResponse = await resend .Automations .create_async (
26+ {
27+ "name" : "Welcome Flow" ,
28+ "status" : "disabled" ,
29+ "steps" : [
30+ {
31+ "key" : "trigger_1" ,
32+ "type" : "trigger" ,
33+ "config" : {"event_name" : "user.created" },
34+ },
35+ {
36+ "key" : "send_1" ,
37+ "type" : "send_email" ,
38+ "config" : {"template" : {"id" : tpl ["id" ]}},
39+ },
40+ ],
41+ "connections" : [
42+ {"from" : "trigger_1" , "to" : "send_1" },
43+ ],
44+ }
45+ )
4246 automation_id = simple ["id" ]
4347 print (f"Created automation: { automation_id } " )
4448
@@ -51,10 +55,12 @@ async def main() -> None:
5155
5256 # --- Update automation ---
5357 print ("\n --- Update automation ---" )
54- updated : resend .Automations .UpdateResponse = await resend .Automations .update_async ({
55- "automation_id" : automation_id ,
56- "status" : "enabled" ,
57- })
58+ updated : resend .Automations .UpdateResponse = await resend .Automations .update_async (
59+ {
60+ "automation_id" : automation_id ,
61+ "status" : "enabled" ,
62+ }
63+ )
5864 print (f"Updated: { updated ['id' ]} " )
5965
6066 # --- List automations ---
@@ -64,54 +70,62 @@ async def main() -> None:
6470
6571 # --- Stop automation ---
6672 print ("\n --- Stop automation ---" )
67- stopped : resend .Automations .StopResponse = await resend .Automations .stop_async (automation_id )
73+ stopped : resend .Automations .StopResponse = await resend .Automations .stop_async (
74+ automation_id
75+ )
6876 print (f"Stopped: { stopped ['id' ]} , status: { stopped ['status' ]} " )
6977
7078 # --- List runs ---
7179 print ("\n --- List runs ---" )
72- runs : resend .Automations .Runs .ListResponse = await resend .Automations .Runs .list_async (automation_id )
80+ runs : resend .Automations .Runs .ListResponse = (
81+ await resend .Automations .Runs .list_async (automation_id )
82+ )
7383 print (f"Total runs: { len (runs ['data' ])} " )
7484 if runs ["data" ]:
7585 run_id = runs ["data" ][0 ]["id" ]
76- run : resend .AutomationRun = await resend .Automations .Runs .get_async (automation_id , run_id )
86+ run : resend .AutomationRun = await resend .Automations .Runs .get_async (
87+ automation_id , run_id
88+ )
7789 print (f"Run status: { run ['status' ]} " )
7890
7991 # --- Multi-step automation: delay + wait_for_event ---
8092 print ("\n --- Create multi-step automation (delay + wait_for_event) ---" )
81- multi : resend .Automations .CreateResponse = await resend .Automations .create_async ({
82- "name" : "Onboarding Flow" ,
83- "status" : "disabled" ,
84- "steps" : [
85- {
86- "key" : "trigger_1" ,
87- "type" : "trigger" ,
88- "config" : {"event_name" : "user.created" },
89- },
90- {
91- "key" : "delay_1" ,
92- "type" : "delay" ,
93- # duration is a human-readable string; "seconds" (int) is also accepted
94- "config" : {"duration" : "30 minutes" },
95- },
96- {
97- "key" : "wait_1" ,
98- "type" : "wait_for_event" ,
99- # timeout is a human-readable string; timeout_seconds is NOT supported
100- "config" : {"event_name" : "user.verified" , "timeout" : "1 hour" },
101- },
102- {
103- "key" : "send_1" ,
104- "type" : "send_email" ,
105- "config" : {"template" : {"id" : tpl ["id" ]}},
106- },
107- ],
108- "connections" : [
109- {"from" : "trigger_1" , "to" : "delay_1" },
110- {"from" : "delay_1" , "to" : "wait_1" },
111- {"from" : "wait_1" , "to" : "send_1" , "type" : "event_received" },
112- {"from" : "wait_1" , "to" : "send_1" , "type" : "timeout" },
113- ],
114- })
93+ multi : resend .Automations .CreateResponse = await resend .Automations .create_async (
94+ {
95+ "name" : "Onboarding Flow" ,
96+ "status" : "disabled" ,
97+ "steps" : [
98+ {
99+ "key" : "trigger_1" ,
100+ "type" : "trigger" ,
101+ "config" : {"event_name" : "user.created" },
102+ },
103+ {
104+ "key" : "delay_1" ,
105+ "type" : "delay" ,
106+ # duration is a human-readable string; "seconds" (int) is also accepted
107+ "config" : {"duration" : "30 minutes" },
108+ },
109+ {
110+ "key" : "wait_1" ,
111+ "type" : "wait_for_event" ,
112+ # timeout is a human-readable string; timeout_seconds is NOT supported
113+ "config" : {"event_name" : "user.verified" , "timeout" : "1 hour" },
114+ },
115+ {
116+ "key" : "send_1" ,
117+ "type" : "send_email" ,
118+ "config" : {"template" : {"id" : tpl ["id" ]}},
119+ },
120+ ],
121+ "connections" : [
122+ {"from" : "trigger_1" , "to" : "delay_1" },
123+ {"from" : "delay_1" , "to" : "wait_1" },
124+ {"from" : "wait_1" , "to" : "send_1" , "type" : "event_received" },
125+ {"from" : "wait_1" , "to" : "send_1" , "type" : "timeout" },
126+ ],
127+ }
128+ )
115129 multi_id = multi ["id" ]
116130 print (f"Created: { multi_id } " )
117131
@@ -121,9 +135,13 @@ async def main() -> None:
121135
122136 # --- Cleanup ---
123137 print ("\n --- Cleanup ---" )
124- del1 : resend .Automations .DeleteResponse = await resend .Automations .remove_async (automation_id )
138+ del1 : resend .Automations .DeleteResponse = await resend .Automations .remove_async (
139+ automation_id
140+ )
125141 print (f"Deleted automation { del1 ['id' ]} : { del1 ['deleted' ]} " )
126- del2 : resend .Automations .DeleteResponse = await resend .Automations .remove_async (multi_id )
142+ del2 : resend .Automations .DeleteResponse = await resend .Automations .remove_async (
143+ multi_id
144+ )
127145 print (f"Deleted automation { del2 ['id' ]} : { del2 ['deleted' ]} " )
128146 await resend .Templates .remove_async (tpl ["id" ])
129147 print (f"Deleted template { tpl ['id' ]} " )
0 commit comments