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
30 changes: 28 additions & 2 deletions src/automations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
list_opts::{ListOptions, ListResponse},
types::{
Automation, AutomationMinimal, AutomationRun, CreateAutomationOptions,
CreateAutomationResponse, DeleteAutomationResponse, StopAutomationResponse,
UpdateAutomationOptions, UpdateAutomationResponse,
CreateAutomationResponse, DeleteAutomationResponse, DuplicateAutomationResponse,
StopAutomationResponse, UpdateAutomationOptions, UpdateAutomationResponse,
},
};

Expand Down Expand Up @@ -93,6 +93,20 @@ impl AutomationsSvc {
Ok(content)
}

/// Duplicate an existing automation.
///
/// <https://resend.com/docs/api-reference/automations/duplicate-automation>
#[maybe_async::maybe_async]
pub async fn duplicate(&self, automation_id: &str) -> Result<DuplicateAutomationResponse> {
let path = format!("/automations/{automation_id}/duplicate");

let request = self.0.build(Method::POST, &path);
let response = self.0.send(request).await?;
let content = response.json::<DuplicateAutomationResponse>().await?;

Ok(content)
}

/// Remove an existing automation.
///
/// <https://resend.com/docs/api-reference/automations/delete-automation>
Expand Down Expand Up @@ -429,6 +443,12 @@ pub mod types {
pub status: AutomationStatus,
}

#[must_use]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DuplicateAutomationResponse {
pub id: AutomationId,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteAutomationResponse {
pub id: AutomationId,
Expand Down Expand Up @@ -594,6 +614,12 @@ mod test {
.await?;
assert!(runs.data.is_empty());

// Duplicate
let duplicated = resend.automations.duplicate(&automation.id).await?;
std::thread::sleep(std::time::Duration::from_secs(2));
let deleted = resend.automations.delete(&duplicated.id).await?;
assert!(deleted.deleted);

// Stop
let automation = resend.automations.stop(&automation.id).await?;

Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ pub mod types {
AddToSegmentStepConfig, Automation, AutomationId, AutomationMinimal, AutomationRun,
AutomationRunId, AutomationStatus, AutomationTemplate, Connection, ConnectionType,
CreateAutomationOptions, CreateAutomationResponse, DelayStepConfig,
DeleteAutomationResponse, SendEmailStepConfig, Step, StopAutomationResponse,
TriggerStepConfig, UpdateAutomationOptions, UpdateAutomationResponse,
WaitForEventStepConfig,
DeleteAutomationResponse, DuplicateAutomationResponse, SendEmailStepConfig, Step,
StopAutomationResponse, TriggerStepConfig, UpdateAutomationOptions,
UpdateAutomationResponse, WaitForEventStepConfig,
};
pub use super::batch::types::{
BatchValidation, PermissiveBatchErrors, SendEmailBatchPermissiveResponse,
Expand Down